Bug 17973 - Useless FILE entries in symbol table
Summary: Useless FILE entries in symbol table
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.26
: P2 normal
Target Milestone: 2.26
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-13 17:29 UTC by H.J. Lu
Modified: 2016-05-04 12:05 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2015-02-13 17:29:14 UTC
ld generates useless FILE entries in symbol table:

[hjl@gnu-6 symtab-2]$ cat foo.s
	.text
	.globl	foo
	.type	foo, @function
foo:
	.cfi_startproc
	rep ret
	.cfi_endproc
	.size	foo, .-foo
	.type	bar, @function
bar:
	.cfi_startproc
	rep ret
	.cfi_endproc
	.size	bar, .-bar
[hjl@gnu-6 symtab-2]$ make
as   -o foo.o foo.s
ld -shared -o lib.so foo.o
ld.gold -shared -o gold.so foo.o
readelf -sW lib.so | grep FILE
     7: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS foo.o
     9: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
readelf -sW gold.so | grep FILE
make: *** [all] Error 1
[hjl@gnu-6 symtab-2]$ 

It leads to

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65015
Comment 1 H.J. Lu 2015-02-13 18:04:33 UTC
It is done on purpose

https://sourceware.org/ml/binutils/2012-06/msg00032.html
Comment 2 H.J. Lu 2015-02-13 19:30:37 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2015-02/msg00193.html
Comment 3 H.J. Lu 2015-02-13 20:08:08 UTC
Maybe we should fix GCC instead:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65015#c17
Comment 4 cvs-commit@gcc.gnu.org 2015-02-14 13:16:53 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ce875075f9c8acc57bb0ec516ae3ba50064e52b7

commit ce875075f9c8acc57bb0ec516ae3ba50064e52b7
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Feb 14 18:38:32 2015 +1030

    PR ld/17973 LTO file syms
    
    LTO output objects have an STT_FILE symbol using the name of the file,
    a temporary file.  This results in executables that can't be exactly
    reproduced, so the file name needs to be dropped.  We don't want to
    lose all file symbols when linking a mix of lto and non-lto objects as
    a file symbol can be used to figure which source file generated a
    given local symbol.  So lto output objects need to be marked.
    
    I chose to mark lto output objects with a new bfd flag.  This flag is
    also used to fix a bug in the link-once handling;  An object being
    loaded after "loading_lto_outputs" is set might be one extracted from
    an archive to satisfy new references from lto objects, not an lto
    object itself.
    
    The new flag is copied from archive to elements, and the same done
    for no_export.  This fixes a bug in that --exclude-libs doesn't work
    with thin archives.  I'm not completely happy with this part of the
    patch and may revist this to avoid the hack in
    _bfd_look_for_bfd_in_cache.
    
    	PR ld/17973
    include/
    	* bfdlink.h (struct bfd_link_info): Delete loading_lto_outputs.
    bfd/
    	* bfd.c (struct bfd): Add lto_output.
    	* linker.c (_bfd_handle_already_linked): Explicitly test for
    	objects added by the lto plugin.
    	* opncls.c (_bfd_new_bfd_contained_in): Copy lto_output and
    	no_export flags from archive.
    	* archive.c (open_nested_file): New function, setting lto_output
    	and no_export, extracted from..
    	(find_nested_archive): ..here.  Flip params.  Rename from
    	_bfd_find_nested_archive.
    	(_bfd_get_elt_at_filepos): Correct var typo.  Use open_nested_file.
    	(_bfd_look_for_bfd_in_cache): Copy no_export.
    	* elflink.c (elf_link_add_object_symbols): Remove now unnecessary
    	my_archive->no_export test.
    	(elf_link_input_bfd): Drop existing lto_output STT_FILE syms.
    	Don't use the file name when adding lto_output STT_FILE sym.
    	* bfd-in2.h: Regenerate.
    ld/
    	* ldlang.h (struct lang_input_statement_flags): Add lto_output.
    	* ldlang.c (lang_process): Don't set loading_lto_outputs.
    	* ldfile.c (ldfile_try_open_bfd): Transfer entry flags.lto_output
    	to bfd.
    	* plugin.c (add_input_file, add_input_library): Set flags.lto_output.
Comment 5 cvs-commit@gcc.gnu.org 2015-02-14 14:27:54 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f58926a652e71cc4809758c693ff005d9fdc46e1

commit f58926a652e71cc4809758c693ff005d9fdc46e1
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Feb 14 05:45:08 2015 -0800

    Add a testcase for PR ld/17973
    
    ld/
    
    	PR ld/17973
    	* testplug2.c (allsymbolsread_silent): New.
    	(set_register_hook): Handle allsymbolsreadsilent.
    	(onall_symbols_read): Skip a message if allsymbolsread_silent is
    	TRUE.
    
    ld/testsuite/
    
    	PR ld/17973
    	* ld-plugin/plugin.exp (regassilent): New.
    	Compile tmpdir/dummy.s and ld-plugin/pr17973.s.
    	(plugin_tests): Add a test for PR ld/17973.
    	* ld-plugin/pr17973.d: New file.
    	* ld-plugin/pr17973.s: Likewise.
Comment 6 H.J. Lu 2015-02-14 14:28:33 UTC
Fixed.
Comment 7 cvs-commit@gcc.gnu.org 2016-05-04 12:05:19 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4a85cc09258dfe2ab3cefb503221696a0f439c63

commit 4a85cc09258dfe2ab3cefb503221696a0f439c63
Author: Senthil Kumar Selvaraj <senthil_kumar.selvaraj@atmel.com>
Date:   Wed May 4 13:03:52 2016 +0100

    Fix some AVR test failures.
    
    binutils* testsuite/lib/binutils-common.exp (is_elf_format): Add avr-*-*.
    
    ld	* testsuite/ld-elf/pr18735.d: Allow other symbols.
    	* testsuite/ld-elf/sec64k.exp: Skip 64ksec for avr.
    	* testsuite/ld-gc/pr14265.d: Allow other symbols.
    	* testsuite/ld-plugin/plugin.exp: Add PR ld/17973 to
    	plugin_tests only if check_shared_lib_support is true.
    	* testsuite/ld-selective/selective.exp: Add --section-start
    	flag for avr.