Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mike Frysinger via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] sim/m32c: fix memory leaks in opc2c
Date: Tue, 6 Apr 2021 06:41:49 -0400	[thread overview]
Message-ID: <YGw67Sp4XV6N+OFo@vapier> (raw)
In-Reply-To: <b5925b06-5de4-904e-4c1c-5e96e5ee1398@polymtl.ca>

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)

  reply	other threads:[~2021-04-06 10:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-05 14:58 Simon Marchi via Gdb-patches
2021-04-05 16:23 ` Mike Frysinger via Gdb-patches
2021-04-05 18:46   ` Simon Marchi via Gdb-patches
2021-04-05 21:51     ` Mike Frysinger via Gdb-patches
2021-04-06  1:36       ` Simon Marchi via Gdb-patches
2021-04-06 10:41         ` Mike Frysinger via Gdb-patches [this message]
2021-04-06 13:28           ` Simon Marchi via Gdb-patches
2021-04-06 13:45             ` Tom Tromey
2021-04-06 18:01               ` Philippe Waroquiers via Gdb-patches
2021-04-06 22:45             ` Mike Frysinger via Gdb-patches
2021-04-07  1:45               ` Simon Marchi via Gdb-patches
2021-04-07 11:38                 ` Mike Frysinger via Gdb-patches
2021-04-07 14:19                   ` Simon Marchi via Gdb-patches
2021-04-08  4:51                     ` Mike Frysinger via Gdb-patches
2021-04-08 13:52                       ` Simon Marchi via Gdb-patches
2021-04-08  4:50 ` Mike Frysinger via Gdb-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YGw67Sp4XV6N+OFo@vapier \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox