Always define referenced __start_SECNAME/__stop_SECNAME
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 13 Jun 2017 15:53:22 +0000 (08:53 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 13 Jun 2017 15:53:22 +0000 (08:53 -0700)
commitcbd0eecf261c2447781f8c89b0d955ee66fae7e9
tree1a8139f0a7989d71079057f6000877af275b546d
parent6490dc678bc35f2204afb38449de5127ef8bcca0
Always define referenced __start_SECNAME/__stop_SECNAME

Currently, linker will define __start_SECNAME and __stop_SECNAME symbols
only for orphaned sections.

However, during garbage collection, ELF linker marks all sections with
references to __start_SECNAME and __stop_SECNAME symbols as used even
when section SECNAME isn't an orphaned section and linker won't define
__start_SECNAME nor __stop_SECNAME.  And ELF linker stores the first
input section whose name matches __start_SECNAME or __stop_SECNAME in
u.undef.section for garbage collection.  If these symbols are provided
in linker script, u.undef.section is set to the section where they will
defined by linker script, which leads to the incorrect output.

This patch changes linker to always define referenced __start_SECNAME and
__stop_SECNAME if the input section name is the same as the output section
name, which is always true for orphaned sections, and SECNAME is a C
identifier.  Also __start_SECNAME and __stop_SECNAME symbols are marked
as hidden by ELF linker so that __start_SECNAME and __stop_SECNAME symbols
for section SECNAME in different modules are unique.  For garbage
collection, ELF linker stores the first matched input section in the
unused vtable field.

bfd/

PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* elf-bfd.h (elf_link_hash_entry): Add start_stop.  Change the
vtable field to a union.
(_bfd_elf_is_start_stop): Removed.
* elf32-i386.c (elf_i386_convert_load_reloc): Also check for
__start_SECNAME and __stop_SECNAME symbols.
* elf64-x86-64.c (elf_x86_64_convert_load_reloc): Likewise.
* elflink.c (_bfd_elf_is_start_stop): Removed.
(_bfd_elf_gc_mark_rsec): Check start_stop instead of calling
_bfd_elf_is_start_stop.
(elf_gc_propagate_vtable_entries_used): Skip __start_SECNAME and
__stop_SECNAME symbols.  Updated.
(elf_gc_smash_unused_vtentry_relocs): Likewise.
(bfd_elf_gc_record_vtinherit): Likewise.
(bfd_elf_gc_record_vtentry): Likewise.

ld/

PR ld/20022
PR ld/21557
PR ld/21562
PR ld/21571
* ld.texinfo: Update __start_SECNAME/__stop_SECNAME symbols.
* ldlang.c (lang_insert_orphan): Move handling of __start_SECNAME
and __stop_SECNAME symbols to ...
(lang_set_startof): Here.  Also define __start_SECNAME and
__stop_SECNAME for -Ur.
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open): Mark
referenced __start_SECNAME and __stop_SECNAME symbols as hidden
and set start_stop for garbage collection.
* testsuite/ld-elf/pr21562a.d: New file.
* testsuite/ld-elf/pr21562a.s: Likewise.
* testsuite/ld-elf/pr21562a.t: Likewise.
* testsuite/ld-elf/pr21562b.d: Likewise.
* testsuite/ld-elf/pr21562b.s: Likewise.
* testsuite/ld-elf/pr21562b.t: Likewise.
* testsuite/ld-elf/pr21562c.d: Likewise.
* testsuite/ld-elf/pr21562c.t: Likewise.
* testsuite/ld-elf/pr21562d.d: Likewise.
* testsuite/ld-elf/pr21562d.t: Likewise.
* testsuite/ld-elf/pr21562e.d: Likewise.
* testsuite/ld-elf/pr21562f.d: Likewise.
* testsuite/ld-elf/pr21562g.d: Likewise.
* testsuite/ld-elf/pr21562h.d: Likewise.
* testsuite/ld-elf/pr21562i.d: Likewise.
* testsuite/ld-elf/pr21562j.d: Likewise.
* testsuite/ld-elf/pr21562k.d: Likewise.
* testsuite/ld-elf/pr21562l.d: Likewise.
* testsuite/ld-elf/pr21562m.d: Likewise.
* testsuite/ld-elf/pr21562n.d: Likewise.
* testsuite/ld-gc/pr20022.d: Likewise.
* testsuite/ld-gc/pr20022a.s: Likewise.
* testsuite/ld-gc/pr20022b.s: Likewise.
* testsuite/ld-gc/gc.exp: Run PR ld/20022 tests.
* testsuite/ld-gc/pr19161.d: Also accept local __start_SECNAME
symbol.
* testsuite/ld-gc/start.d: Likewise.
* testsuite/ld-x86-64/lea1a.d: Updated.
* testsuite/ld-x86-64/lea1b.d: Updated.
* testsuite/ld-x86-64/lea1d.d: Updated.
* testsuite/ld-x86-64/lea1e.d: Likewise.
39 files changed:
bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elflink.c
ld/ChangeLog
ld/emultempl/elf32.em
ld/ld.texinfo
ld/ldlang.c
ld/testsuite/ld-elf/pr21562a.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562a.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562a.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562b.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562b.s [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562b.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562c.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562c.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562d.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562d.t [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562e.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562f.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562g.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562h.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562i.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562j.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562k.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562l.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562m.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr21562n.d [new file with mode: 0644]
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-gc/pr19161.d
ld/testsuite/ld-gc/pr20022.d [new file with mode: 0644]
ld/testsuite/ld-gc/pr20022a.s [new file with mode: 0644]
ld/testsuite/ld-gc/pr20022b.s [new file with mode: 0644]
ld/testsuite/ld-gc/start.d
ld/testsuite/ld-x86-64/lea1a.d
ld/testsuite/ld-x86-64/lea1b.d
ld/testsuite/ld-x86-64/lea1d.d
ld/testsuite/ld-x86-64/lea1e.d