On Tue, 6 Sep 2016, Markus Trippelsdorf wrote:
> On 2016.09.06 at 13:17 +0200, Richard Biener wrote:
> >
> > The following is an updated patch, mainly stripped out old unnecessary
> > cruft and some fixes for an issue that arised when LTOing Firefox.
>
> One minor issue that I've noticed is that the patch generates a lot of
> empty *debugobj* files in $TMPDIR, e.g.:
>
> % echo 'int main(){}' | g++ -flto -o /dev/null-x c++ -
> % ls -l $TMPDIR
> total 0
> -rw-------. 1 trippels trippels 0 Sep 6 12:11 ccenD5Tcdebugobj
> -rw-------. 1 trippels trippels 0 Sep 6 12:11 ccXzvE4udebugobjtem
Ah, make_temp_file actually _creates_ the files already...
Fixed with the patch below.
> The new patch builds LLVM fine with "-flto -g".
Great.
Richard.
Index: early-lto-debug/gcc/lto-wrapper.c
===================================================================
--- early-lto-debug.orig/gcc/lto-wrapper.c 2016-09-06 14:26:29.233142490
+0200
+++ early-lto-debug/gcc/lto-wrapper.c 2016-09-06 14:25:44.316618249 +0200
@@ -943,9 +943,10 @@ find_and_merge_options (int fd, off_t fi
return true;
}
-int
-debug_objcopy (const char *infile, const char *outfile)
+const char *
+debug_objcopy (const char *infile)
{
+ const char *outfile;
const char *errmsg;
int err;
@@ -966,12 +967,12 @@ debug_objcopy (const char *infile, const
}
int infd = open (infile, O_RDONLY);
if (infd == -1)
- return 1;
+ return NULL;
simple_object_read *inobj = simple_object_start_read (infd, inoff,
"__GNU_LTO",
&errmsg, &err);
if (!inobj)
- return 1;
+ return NULL;
off_t off, len;
if (simple_object_find_section (inobj, ".gnu.debuglto_.debug_info",
@@ -982,17 +983,21 @@ debug_objcopy (const char *infile, const
simple_object_release_read (inobj);
close (infd);
- return 1;
+ return NULL;
}
+ outfile = make_temp_file ("debugobjtem");
errmsg = simple_object_copy_lto_debug_sections (inobj, outfile, &err);
if (errmsg)
- fatal_error (0, "%s: %s\n", errmsg, xstrerror (err));
+ {
+ unlink_if_ordinary (outfile);
+ fatal_error (0, "%s: %s\n", errmsg, xstrerror (err));
+ }
simple_object_release_read (inobj);
close (infd);
- return 0;
+ return outfile;
}
@@ -1401,8 +1406,8 @@ cont1:
if (! skip_debug)
for (i = 0; i < ltoobj_argc; ++i)
{
- char *tem = make_temp_file ("debugobjtem");
- if (!debug_objcopy (ltoobj_argv[i], tem))
+ const char *tem;
+ if ((tem = debug_objcopy (ltoobj_argv[i])))
{
obstack_ptr_grow (&argv_obstack, tem);
n_debugobj++;