Bug 106686 - [lto][offloading] lto-wrapper leaves "target.o" temporay files behind when error diagnostic occurred
Summary: [lto][offloading] lto-wrapper leaves "target.o" temporay files behind when er...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-19 13:56 UTC by Tobias Burnus
Modified: 2022-08-22 07:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-08-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2022-08-19 13:56:20 UTC
I found a couple of /tmp/ccGARvpn.target.o files - which are surely unintended leftovers.

The filename is returned by lto-wrapper.cc's compile_offload_image and then
collected in
  offload_names[next_name_entry] = compile_offload_image (...)
and processed as
      if (offload_names)
        {
          find_crtoffloadtable (save_temps, dumppfx);
          for (i = 0; offload_names[i]; i++)
            printf ("%s\n", offload_names[i]);

That seems to work well if not error occurred - but if there was an error, it seems to be the only file suffix which is not cleaned up.


Reproducer:
- You need a GCC configured for offload (nvptx, gcn or intelmic)
- You need to get it to fail.

On mainline, one way is to compile the following with offloading: 'gcc -fopenmp *.c'
which outputs:
  lto1: error: OpenMP 'requires' directive with 'unified_shared_memory' specified only in some compilation units
  lto1: fatal error: errors during merging of translation units

Input:
------- 1.c ----------
#pragma omp requires unified_shared_memory
int i;
void foo() {
  #pragma omp target enter data map(to:i)
}

------- 2.c ----------
int j;
void foo() {
  #pragma omp target enter data map(to:j)
}
Comment 2 GCC Commits 2022-08-22 07:50:46 UTC
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:e228683b244c6afbe3bdfef7ba607fbda813bd0f

commit r13-2135-ge228683b244c6afbe3bdfef7ba607fbda813bd0f
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Aug 22 09:49:52 2022 +0200

    lto-wrapper.cc: Delete offload_names temp files in case of error [PR106686]
    
    Usually, the caller takes care of the .o files for the offload compilers
    (suffix: ".target.o"). However, if an error occurs during processing
    (e.g. fatal error by lto1), they were not deleted.
    
    gcc/ChangeLog:
    
            PR lto/106686
            * lto-wrapper.cc (free_array_of_ptrs): Move before tool_cleanup.
            (tool_cleanup): Unlink offload_names.
            (compile_offload_image): Take filename argument to set it early.
            (compile_images_for_offload_targets): Update call; set
            offload_names to NULL after freeing the array.
Comment 3 Tobias Burnus 2022-08-22 07:57:08 UTC
FIXED on GCC 13 (mainline).