Go to file
Alex Coplan b46584d783 driver: Fix several memory leaks [PR63854]
This patch fixes several memory leaks in the driver, all of which relate
to the handling of static specs. We introduce functions
set_static_spec_{shared,owned}() which are used to enforce proper memory
management when updating the strings in the static_specs table.

This is achieved by making use of the alloc_p field in the table
entries. Similarly to set_spec(), each time we update an entry, we check
whether alloc_p is set, and free the old value if so. We then set
alloc_p correctly based on whether we "own" this memory or whether we're
just taking a pointer to a shared string which we shouldn't free.

The following table shows the number of leaks found by AddressSanitizer
when running a minimal libgccjit program on AArch64. The test program
does the whole libgccjit compilation cycle in a loop (including acquiring
and releasing the context), and the table below shows the number of leaks
for different iterations of that loop.

+--------------+-----+-----+------+---------------+
| # of runs >  | 1   | 2   | 3    | Leaks per run |
+--------------+-----+-----+------+---------------+
| Before patch | 463 | 940 | 1417 | 477           |
+--------------+-----+-----+------+---------------+
| After patch  | 416 | 846 | 1276 | 430           |
+--------------+-----+-----+------+---------------+

gcc/ChangeLog:

	PR jit/63854
	* gcc.c (set_static_spec): New.
	(set_static_spec_owned): New.
	(set_static_spec_shared): New.
	(driver::maybe_putenv_COLLECT_LTO_WRAPPER): Use
	set_static_spec_owned() to take ownership of lto_wrapper_file
	such that it gets freed in driver::finalize.
	(driver::maybe_run_linker): Use set_static_spec_shared() to
	ensure that we don't try and free() the static string "ld",
	also ensuring that any previously-allocated string in
	linker_name_spec is freed. Likewise with argv0.
	(driver::finalize): Use set_static_spec_shared() when resetting
	specs that previously had allocated strings; remove if(0)
	around call to free().
2020-08-21 14:26:11 +01:00
config Daily bump. 2020-08-21 00:16:23 +00:00
contrib Daily bump. 2020-07-30 00:16:24 +00:00
fixincludes
gcc driver: Fix several memory leaks [PR63854] 2020-08-21 14:26:11 +01:00
gnattools
gotools
include Daily bump. 2020-08-04 00:16:24 +00:00
INSTALL
intl
libada
libatomic Daily bump. 2020-07-15 00:16:35 +00:00
libbacktrace Daily bump. 2020-07-31 00:16:26 +00:00
libcc1 Daily bump. 2020-08-15 00:16:22 +00:00
libcpp Daily bump. 2020-07-31 00:16:26 +00:00
libdecnumber Daily bump. 2020-07-31 00:16:26 +00:00
libffi
libgcc Daily bump. 2020-08-14 00:16:24 +00:00
libgfortran Daily bump. 2020-08-21 00:16:23 +00:00
libgo libgo: correctly handle AIX FAT library creation 2020-08-12 11:33:54 -07:00
libgomp Daily bump. 2020-08-21 00:16:23 +00:00
libhsail-rt
libiberty Daily bump. 2020-08-04 00:16:24 +00:00
libitm Daily bump. 2020-07-25 00:16:22 +00:00
libobjc Daily bump. 2020-05-30 00:16:27 +00:00
liboffloadmic
libphobos Daily bump. 2020-06-26 00:16:23 +00:00
libquadmath Daily bump. 2020-05-30 00:16:27 +00:00
libsanitizer Daily bump. 2020-07-17 00:16:27 +00:00
libssp Daily bump. 2020-05-30 00:16:27 +00:00
libstdc++-v3 libstdc++: Skip PSTL tests when installed TBB is too old [PR 96718] 2020-08-21 12:01:05 +01:00
libvtv Daily bump. 2020-05-30 00:16:27 +00:00
lto-plugin Daily bump. 2020-07-31 00:16:26 +00:00
maintainer-scripts Daily bump. 2020-05-30 00:16:27 +00:00
zlib Daily bump. 2020-05-30 00:16:27 +00:00
.dir-locals.el
.gitattributes
.gitignore Add .clang-tidy to git ignored. 2020-06-12 16:03:02 +02:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2020-08-21 00:16:23 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in
config.guess
config.rpath
config.sub
configure configure: Also check C++11 (flags) for ${build} compiler not only for ${host} 2020-08-20 21:59:00 +02:00
configure.ac configure: Also check C++11 (flags) for ${build} compiler not only for ${host} 2020-08-20 21:59:00 +02:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself for write after approval 2020-08-16 09:28:10 +01:00
Makefile.def
Makefile.in
Makefile.tpl
missing Update from upstream Automake files. 2014-11-16 14:07:13 +00:00
mkdep
mkinstalldirs
move-if-change
multilib.am
README
symlink-tree
test-driver
ylwrap

This directory contains the GNU Compiler Collection (GCC).

The GNU Compiler Collection is free software.  See the files whose
names start with COPYING for copying permission.  The manuals, and
some of the runtime libraries, are under different terms; see the
individual source files for details.

The directory INSTALL contains copies of the installation information
as HTML and plain text.  The source of this information is
gcc/doc/install.texi.  The installation information includes details
of what is included in the GCC sources and what files GCC installs.

See the file gcc/doc/gcc.texi (together with other files that it
includes) for usage and porting information.  An online readable
version of the manual is in the files gcc/doc/gcc.info*.

See http://gcc.gnu.org/bugs/ for how to report bugs usefully.

Copyright years on GCC source files may be listed using range
notation, e.g., 1987-2012, indicating that every year in the range,
inclusive, is a copyrightable year that could otherwise be listed
individually.