Bug 17975 - Useless FILE entry in symbol table for linker generated symbols
Summary: Useless FILE entry in symbol table for linker generated symbols
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 19:37 UTC by H.J. Lu
Modified: 2015-02-17 14:05 UTC (History)
2 users (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 19:37:47 UTC
[hjl@gnu-6 new-2]$ cat foo.s
	.data
foo:
	.dc.a bar
[hjl@gnu-6 new-2]$ make
as   -o foo.o foo.s
./ld -shared   -o lib.so foo.o
readelf -sW lib.so | grep "ABS $"
    10: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
[hjl@gnu-6 new-2]$ 

It comes from:

https://sourceware.org/ml/binutils/2012-06/msg00016.html

But it is useless for linker generated symbols.
Comment 1 H.J. Lu 2015-02-13 22:09:34 UTC
How useful is adding add another NULL STT_FILE symbol before
outputting linker generated symbols or symbols defined by
linker scripts?  Do we have a testcase to show it is necessary?
Comment 2 H.J. Lu 2015-02-13 22:17:36 UTC
A NULL STT_FILE symbol is useful here:

[hjl@gnu-6 pr17975]$ cat foo.s 
	.data
foo:
	.dc.a bar
[hjl@gnu-6 pr17975]$ cat bar.s
	.data
foo:
	.dc.a bar
[hjl@gnu-6 pr17975]$ cat global.s 
	.data
	.hidden foo
	.global foo
foo:
	.dc.a bar
[hjl@gnu-6 pr17975]$ make hidden.so
as   -o foo.o foo.s
as   -o bar.o bar.s
as   -o global.o global.s
./ld -shared   -o hidden.so foo.o bar.o global.o
readelf -sW hidden.so

Symbol table '.dynsym' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000002002f0     0 SECTION LOCAL  DEFAULT    7 
     2: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 __bss_start
     3: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 _edata
     4: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 _end
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar

Symbol table '.symtab' contains 20 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000000000e8     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000118     0 SECTION LOCAL  DEFAULT    2 
     3: 00000000000001a8     0 SECTION LOCAL  DEFAULT    3 
     4: 00000000000001c8     0 SECTION LOCAL  DEFAULT    4 
     5: 0000000000000210     0 SECTION LOCAL  DEFAULT    5 
     6: 0000000000200210     0 SECTION LOCAL  DEFAULT    6 
     7: 00000000002002f0     0 SECTION LOCAL  DEFAULT    7 
     8: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS foo.o
     9: 00000000002002f0     0 NOTYPE  LOCAL  DEFAULT    7 foo
    10: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS bar.o
    11: 00000000002002f8     0 NOTYPE  LOCAL  DEFAULT    7 foo
    12: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
    13: 0000000000200210     0 OBJECT  LOCAL  DEFAULT    6 _DYNAMIC
    14: 0000000000200300     0 NOTYPE  LOCAL  DEFAULT    7 foo
    15: 00000000002002f0     0 OBJECT  LOCAL  DEFAULT    7 _GLOBAL_OFFSET_TABLE_
    16: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 __bss_start
    17: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 _edata
    18: 0000000000200308     0 NOTYPE  GLOBAL DEFAULT    7 _end
    19: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
[hjl@gnu-6 pr17975]$ 

But not here

[hjl@gnu-6 pr17975]$ make lib.so
./ld -shared   -o lib.so foo.o bar.o
readelf -sW lib.so

Symbol table '.dynsym' contains 6 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000002002d8     0 SECTION LOCAL  DEFAULT    7 
     2: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 __bss_start
     3: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 _edata
     4: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 _end
     5: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar

Symbol table '.symtab' contains 19 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000000000e8     0 SECTION LOCAL  DEFAULT    1 
     2: 0000000000000118     0 SECTION LOCAL  DEFAULT    2 
     3: 00000000000001a8     0 SECTION LOCAL  DEFAULT    3 
     4: 00000000000001c8     0 SECTION LOCAL  DEFAULT    4 
     5: 00000000000001f8     0 SECTION LOCAL  DEFAULT    5 
     6: 00000000002001f8     0 SECTION LOCAL  DEFAULT    6 
     7: 00000000002002d8     0 SECTION LOCAL  DEFAULT    7 
     8: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS foo.o
     9: 00000000002002d8     0 NOTYPE  LOCAL  DEFAULT    7 foo
    10: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS bar.o
    11: 00000000002002e0     0 NOTYPE  LOCAL  DEFAULT    7 foo
    12: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS 
    13: 00000000002001f8     0 OBJECT  LOCAL  DEFAULT    6 _DYNAMIC
    14: 00000000002002d8     0 OBJECT  LOCAL  DEFAULT    7 _GLOBAL_OFFSET_TABLE_
    15: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 __bss_start
    16: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 _edata
    17: 00000000002002e8     0 NOTYPE  GLOBAL DEFAULT    7 _end
    18: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
[hjl@gnu-6 pr17975]$
Comment 3 H.J. Lu 2015-02-13 22:33:17 UTC
We should generate a A NULL STT_FILE symbol before a forced_local
symbol which isn't linker created nor defined by linker script.
Comment 4 cvs-commit@gcc.gnu.org 2015-02-16 12:58:02 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=35f82954b5e46ef5f56653d4f3aa0d1236f558da

commit 35f82954b5e46ef5f56653d4f3aa0d1236f558da
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Feb 14 20:17:28 2015 -0800

    Properly place the NULL STT_FILE symbol
    
    We output a NULL STT_FILE symbol for forced local symbols so that they
    are not associated with the STT_FILE symbol for real local symbols. This
    patch makes sure that the NULL STT_FILE symbol is placed before forced
    local symbols.
    
    bfd/
    
    	PR ld/17975
    	* elflink.c (elf_link_output_extsym): Only check filesym_count
    	when outputting a NULL FILE symbol.  Set second_pass_sym to
    	h->forced_local && !h->root.linker_def.
    
    ld/testsuite/
    
    	PR ld/17975
    	* ld-i386/tlsbin-nacl.rd: Likewise.
    	* ld-i386/tlsbin.rd: Likewise.
    	* ld-i386/tlsbindesc-nacl.rd: Likewise.
    	* ld-i386/tlsbindesc.rd: Likewise.
    	* ld-i386/tlsdesc-nacl.rd: Likewise.
    	* ld-i386/tlsdesc.rd: Likewise.
    	* ld-i386/tlsnopic-nacl.rd: Likewise.
    	* ld-i386/tlsnopic.rd: Likewise.
    	* ld-i386/tlspic-nacl.rd: Likewise.
    	* ld-i386/tlspic.rd: Likewise.
    	* ld-x86-64/tlsbin-nacl.rd: Likewise.
    	* ld-x86-64/tlsbin.rd: Likewise.
    	* ld-x86-64/tlsbindesc-nacl.rd: Likewise.
    	* ld-x86-64/tlsbindesc.rd: Likewise.
    	* ld-x86-64/tlsdesc-nacl.rd: Likewise.
    	* ld-x86-64/tlsdesc.rd: Likewise.
    	* ld-x86-64/tlspic-nacl.rd: Likewise.
    	* ld-x86-64/tlspic.rd: Likewise.
Comment 5 cvs-commit@gcc.gnu.org 2015-02-16 15:32:52 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=6dfb72b9068626cbbf0017df092162d11304a3b0

commit 6dfb72b9068626cbbf0017df092162d11304a3b0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 16 07:31:46 2015 -0800

    Add ChangeLog entries for PR ld/17975 fix
Comment 6 cvs-commit@gcc.gnu.org 2015-02-16 16:37:32 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=49bd1d6e875d4b9ab0cdb909ae6db2bfc95f364b

commit 49bd1d6e875d4b9ab0cdb909ae6db2bfc95f364b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Feb 16 08:35:17 2015 -0800

    Update more ld testcases after PR ld/17975 fix
    
    	* ld-alpha/tlspic.rd: Updated.
    	* ld-powerpc/tlsexe.r: Likewise.
    	* ld-powerpc/tlsexetoc.r: Likewise.
    	* ld-powerpc/tlsso.r: Likewise.
    	* ld-powerpc/tlstocso.r: Likewise.
    	* ld-s390/tlspic.rd: Likewise.
    	* ld-s390/tlspic_64.rd: Likewise.
    	* ld-sparc/gotop32.dd: Likewise.
    	* ld-sparc/gotop64.dd: Likewise.
    	* ld-sparc/tlssunnopic32.rd: Likewise.
    	* ld-sparc/tlssunnopic64.rd: Likewise.
    	* ld-sparc/tlssunpic32.rd: Likewise.
    	* ld-sparc/tlssunpic64.rd: Likewise.
    	* ld-tic6x/shlib-1.rd: Likewise.
    	* ld-tic6x/shlib-1b.rd: Likewise.
    	* ld-tic6x/shlib-1r.rd: Likewise.
    	* ld-tic6x/shlib-1rb.rd: Likewise.
    	* ld-tic6x/shlib-noindex.rd: Likewise.
Comment 7 H.J. Lu 2015-02-16 16:40:22 UTC
Fixed.
Comment 8 cvs-commit@gcc.gnu.org 2015-02-17 14:05:50 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

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

commit 2ec55de302e4a6c49a06c673c8262a119fa6226f
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Feb 17 09:14:59 2015 +1030

    Properly place the NULL STT_FILE symbol revistited
    
    I was having a little closer look at what is going on here and noticed
    that HJ unconditionally emits a NULL STT_FILE symbol before emitting
    forced local symbols.  That means we really don't need a second pass
    over forced local symbols.  The only reason for two passes is when
    some forced local symbol can be emitted before the NULL STT_FILE.  So
    I set about removing the second pass, updating the testsuite all over
    again.  It's also unnecessary to emit the NULL STT_FILE when no
    previous file symbol has been emitted.
    
    bfd/
    	PR ld/17975
    	* elflink.c (struct elf_outext_info): Remove need_second_pass
    	and second_pass.
    	(elf_link_output_extsym): Delete code handling second forced
    	local pass.  Move code emitting NULL STT_FILE symbol later, so
    	that it can be omitted if forced local is stripped.  Don't
    	emit the NULL STT_FILE if no file symbols have been output.
    	(bfd_elf_final_link): Remove second forced local pass.
    	* elf32-ppc.c (add_stub_sym): Set linker_def on linker syms.
    	(ppc_elf_size_dynamic_sections): Likewise.
    	* elf64-ppc.c (ppc_build_one_stub): Likewise.
    	(build_global_entry_stubs): Likewise.
    	(ppc64_elf_build_stubs): Likewise.
    ld/testsuite/
    	PR ld/17975
    	* ld-aarch64/gc-tls-relocs.d, * ld-alpha/tlspic.rd,
    	* ld-cris/libdso-2.d, * ld-i386/tlsdesc-nacl.rd, * ld-i386/tlsdesc.rd,
    	* ld-i386/tlsnopic-nacl.rd, * ld-i386/tlsnopic.rd,
    	* ld-i386/tlspic-nacl.rd, * ld-i386/tlspic.rd, * ld-ia64/tlspic.rd,
    	* ld-powerpc/tlsexe.r, * ld-powerpc/tlsexetoc.r,
    	* ld-powerpc/tlsso.r, * ld-powerpc/tlstocso.r,
    	* ld-s390/tlspic.rd, * ld-s390/tlspic_64.rd,
    	* ld-sparc/tlssunnopic32.rd, * ld-sparc/tlssunnopic64.rd,
    	* ld-sparc/tlssunpic32.rd, * ld-sparc/tlssunpic64.rd,
    	* ld-tic6x/shlib-1.rd, * ld-tic6x/shlib-1b.rd, * ld-tic6x/shlib-1r.rd,
    	* ld-tic6x/shlib-1rb.rd, * ld-tic6x/shlib-noindex.rd,
    	* ld-x86-64/tlsdesc-nacl.rd, * ld-x86-64/tlsdesc.rd,
    	* ld-x86-64/tlspic-nacl.rd, * ld-x86-64/tlspic.rd: Update.