diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-01-19 20:37:19 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-01-19 20:37:19 +0000 |
commit | 199501ea411ff65a4749df39eeda5bb14b1caff7 (patch) | |
tree | 649ce43890fd6b2c7e61712f5be41ce8078d8103 /gcc/jit/jit-playback.c | |
parent | f57fc9606845a446659826a512aa78c70fb4c842 (diff) | |
download | gcc-199501ea411ff65a4749df39eeda5bb14b1caff7.zip gcc-199501ea411ff65a4749df39eeda5bb14b1caff7.tar.gz gcc-199501ea411ff65a4749df39eeda5bb14b1caff7.tar.bz2 |
PR jit/69144: Ensure that libgccjit's tempdir is fully cleaned-up
There were a couple of ways that libgccjit could fail to unlink all
of its tempfiles, leading to /tmp/libgccjit-* tempdirs lingering
after the build:
- dumpfiles requested by gcc_jit_context_enable_dump
- ahead-of-time compilation artifacts which lingered in the tempdir
after they've been copied up to the output_path. This was only
the case for GCC_JIT_OUTPUT_KIND_OBJECT_FILE and
GCC_JIT_OUTPUT_KIND_EXECUTABLE.
The following patch fixes these by introducing a vec of additional
cleanups to be performed by gcc:jit::tempdir's dtor.
In addition, if a gcc_jit_result * is leaked and
GCC_JIT_BOOL_OPTION_DEBUGINFO is enabled, the tempdir will also
not be cleaned up. This was the case for tut04-toyvm/toyvm.cc
which the patch fixes by introducing a wrapper around
gcc_jit_result *. Doing this required some updates to the
corresponding docs.
gcc/jit/ChangeLog:
PR jit/69144
* jit-playback.c (gcc::jit::playback::compile_to_file::postprocess):
Potentially add the temporary artifact to the tempdir's list of
tempfiles needing additional cleanup.
(gcc::jit::playback::context::extract_any_requested_dumps): Likewise
for the dumpfile.
* jit-tempdir.c (gcc::jit::tempdir::~tempdir): Clean up additional
tempfiles.
* jit-tempdir.h (gcc::jit::tempdir::add_temp_file): New method.
(gcc::jit::tempdir::m_tempfiles): New field.
* docs/cp/intro/tutorial04.rst: Update for changes to toyvm.cc.
* docs/examples/tut04-toyvm/toyvm.cc (class compilation_result):
New.
(toyvm_function::compile): Change return type from function ptr
to a compilation_result.
(toyvm_function::get_function_name): New accessor.
(toyvm_function::m_funcname): New field.
(get_function_name): Convert to...
(toyvm_function::make_function_name): ...this new method.
(toyvm_function::parse): Call make_function_name.
(toyvm_function::compile): Convert return type from function ptr
to a compilation_result. Use get_function_name.
(compilation_state::compile): Convert return type from
gcc_jit_result * to a compilation_result.
(test_script): Update for above changes, extracting the code from
the compilation_result.
(main): Likewise.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
From-SVN: r232582
Diffstat (limited to 'gcc/jit/jit-playback.c')
-rw-r--r-- | gcc/jit/jit-playback.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index ee129ae..d150ec1 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -1888,6 +1888,7 @@ playback::compile_to_file::postprocess (const char *ctxt_progname) case GCC_JIT_OUTPUT_KIND_ASSEMBLER: copy_file (get_tempdir ()->get_path_s_file (), m_output_path); + /* The .s file is automatically unlinked by tempdir::~tempdir. */ break; case GCC_JIT_OUTPUT_KIND_OBJECT_FILE: @@ -1902,9 +1903,13 @@ playback::compile_to_file::postprocess (const char *ctxt_progname) false, /* bool shared, */ false);/* bool run_linker */ if (!errors_occurred ()) - copy_file (tmp_o_path, - m_output_path); - free (tmp_o_path); + { + copy_file (tmp_o_path, + m_output_path); + get_tempdir ()->add_temp_file (tmp_o_path); + } + else + free (tmp_o_path); } break; @@ -1918,6 +1923,7 @@ playback::compile_to_file::postprocess (const char *ctxt_progname) if (!errors_occurred ()) copy_file (get_tempdir ()->get_path_so_file (), m_output_path); + /* The .so file is automatically unlinked by tempdir::~tempdir. */ break; case GCC_JIT_OUTPUT_KIND_EXECUTABLE: @@ -1932,9 +1938,13 @@ playback::compile_to_file::postprocess (const char *ctxt_progname) false, /* bool shared, */ true);/* bool run_linker */ if (!errors_occurred ()) - copy_file (tmp_exe_path, - m_output_path); - free (tmp_exe_path); + { + copy_file (tmp_exe_path, + m_output_path); + get_tempdir ()->add_temp_file (tmp_exe_path); + } + else + free (tmp_exe_path); } break; @@ -2279,7 +2289,7 @@ extract_any_requested_dumps (vec <recording::requested_dump> *requested_dumps) filename = g->get_dumps ()->get_dump_file_name (dfi); content = read_dump_file (filename); *(d->m_out_ptr) = content; - free (filename); + m_tempdir->add_temp_file (filename); } } |