From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id MSicKvQ6bGBRSQAAWB0awg (envelope-from ) for ; Tue, 06 Apr 2021 06:41:56 -0400 Received: by simark.ca (Postfix, from userid 112) id A10471E939; Tue, 6 Apr 2021 06:41:56 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id E31B91E590 for ; Tue, 6 Apr 2021 06:41:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 339CB3892474; Tue, 6 Apr 2021 10:41:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 339CB3892474 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617705714; bh=pAiVSeiceZjPyKO3ighCEHv+MBqrVtzdYPMEQRHH1CE=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=O/4f8zbyYOjoh9qtII/+hEhs8KDO4JKKIk1zGr8Fadb7Lct27KZq1Z2anM2CKSeJf 4chQfDVPBPq0NCkUmLDA6i26NMN1dFFM8rL9QzNMsEzPMXv/bX6OfvveqEKCXbG381 jnPO7+PJZWrXeZ4GV+RYy3aACFuUgUA0UbX5Cq2E= Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id E5D97384C003 for ; Tue, 6 Apr 2021 10:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E5D97384C003 Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C37DE335C77; Tue, 6 Apr 2021 10:41:50 +0000 (UTC) Date: Tue, 6 Apr 2021 06:41:49 -0400 To: Simon Marchi Subject: Re: [PATCH] sim/m32c: fix memory leaks in opc2c Message-ID: Mail-Followup-To: Simon Marchi , gdb-patches@sourceware.org References: <20210405145856.3925296-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Mike Frysinger via Gdb-patches Reply-To: Mike Frysinger Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" On 05 Apr 2021 21:36, Simon Marchi via Gdb-patches wrote: > On 2021-04-05 5:51 p.m., Mike Frysinger wrote: > > On 05 Apr 2021 14:46, Simon Marchi via Gdb-patches wrote: > >> On 2021-04-05 12:23 p.m., Mike Frysinger wrote: > >>> in other codebases, i've done things like: > >>> #ifdef __SANITIZE_ADDRESS__ > >>> # define ENABLE_CLEANUP_ONEXIT 1 > >>> #else > >>> # define ENABLE_CLEANUP_ONEXIT 0 > >>> #endif > >>> > >>> then this could be written: > >>> > >>> if (ENABLE_CLEANUP_ONEXIT) { > >>> for (i = 0; i < vn; i++) > >>> free (varnames[i]); > >>> } > >>> > >>> wdyt ? feel free to bikeshed the name. not sure if there's prior art in > >>> the tree currently. > >> > >> I find this complexity a bit unnecessary, versus just free-ing the > >> stuff. But I don't really mind, we can do as you like, I just want to > >> my build to be fixed! > >> > >> Note that the igen tool doesn't free anything, so it's next on the list > >> of things that break the -fsanizite=address build. I started to update > >> it to free things, it's a bit tedious but it should be do-able. > >> > >> Another option would be to change the Makefile to call igen with the > >> ASAN_OPTIONS=detect_leaks=0 environment variable. > > > > ah yes, this is exactly what i mean wrt "the tip of the iceberg" and it being > > "a slippery slope" ;). first it's the small build tools, then the larger > > build tools, then the programs we actually install, ... > > > > maybe an alternative would be to convert these to C++. then it would handle > > stack/heap resources for us. > > If you convert to C++ and the memory is managed automatically, isn't it > exactly the same (runtime-wise) as free-ing everything by hand in C? while i'm sure there is some automatic heap freeing, C++ stdlib can do smarter memory management, whether it be caches, or stack based. > Although I'm always in favor of using C++ for just not having to think > about free-ing stuff. right, and we don't have to debate this :). i can let it go for the sake of the gains with the better language. NB: this would only apply to build-time tools like opc2c. to be clear, if you want to take on changing these tools to C++, i'd be more than happy to help review. but if you feel that's too much to take on, we can do the aforementioned conditional frees. -mike --- a/sim/Makefile.am +++ b/sim/Makefile.am @@ -36,6 +36,7 @@ DISTCLEANFILES = MOSTLYCLEANFILES = core COMPILE_FOR_BUILD = $(CC_FOR_BUILD) $(AM_CPPFLAGS) $(CFLAGS_FOR_BUILD) +CXXCOMPILE_FOR_BUILD = $(CXX_FOR_BUILD) $(AM_CPPFLAGS) $(CXXFLAGS_FOR_BUILD) LINK_FOR_BUILD = $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o $@ # Generate nltvals.def for newlib/libgloss using devo and build tree. --- a/sim/m4/sim_ac_toolchain.m4 +++ b/sim/m4/sim_ac_toolchain.m4 @@ -27,15 +27,21 @@ AC_PROG_INSTALL dnl Setup toolchain settings for build-time tools.. if test "x$cross_compiling" = "xno"; then : "${CC_FOR_BUILD:=\$(CC)}" + : "${CXX_FOR_BUILD:=\$(CXX)}" : "${CFLAGS_FOR_BUILD:=\$(CFLAGS)}" + : "${CXXFLAGS_FOR_BUILD:=\$(CXXFLAGS)}" : "${LDFLAGS_FOR_BUILD:=\$(LDFLAGS)}" else : "${CC_FOR_BUILD:=gcc}" + : "${CXX_FOR_BUILD:=g++}" : "${CFLAGS_FOR_BUILD:=-g -O}" + : "${CXXFLAGS_FOR_BUILD:=-g -O}" : "${LDLFAGS_FOR_BUILD:=}" fi AC_SUBST(CC_FOR_BUILD) +AC_SUBST(CXX_FOR_BUILD) AC_SUBST(CFLAGS_FOR_BUILD) +AC_SUBST(CXXFLAGS_FOR_BUILD) AC_SUBST(LDFLAGS_FOR_BUILD) AC_SUBST(CFLAGS)