From 12b2843a6bb12292d8e36d8df22c788a3c91cb2f Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 23 Dec 2014 19:07:23 +1030 Subject: [PATCH] Use a symbol flag bit to mark linker defined symbols Trying to use the SEC_LINKER_CREATED section flag to determine whether a symbol is linker defined fails to work on targets like alpha that define special SEC_COMMON sections. These might contain symbols that originated in an object file. include/ * bfdlink.h (struct bfd_link_hash_entry): Comment non_ir_ref. Add linker_def. bfd/ * elflink.c (_bfd_elf_define_linkage_sym): Set linker_def. * linker.c (_bfd_generic_link_add_one_symbol): Clear linker_def for CDEF, DEF, DEFW, COM. ld/ * ldexp.c (exp_fold_tree_1 ): Test linker_def. ld/testsuite/ * ld-powerpc/sdabase.s, * ld-powerpc/sdabase.t, * ld-powerpc/sdabase.d: New test. * ld-powerpc/sdabase2.t, * ld-powerpc/sdabase2.d: New test. * ld-powerpc/powerpc.exp: Run them. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 1 + bfd/linker.c | 2 ++ include/ChangeLog | 5 +++++ include/bfdlink.h | 6 ++++++ ld/ChangeLog | 4 ++++ ld/ldexp.c | 4 +--- ld/testsuite/ChangeLog | 9 +++++++++ ld/testsuite/ld-powerpc/powerpc.exp | 2 ++ ld/testsuite/ld-powerpc/sdabase.d | 10 ++++++++++ ld/testsuite/ld-powerpc/sdabase.s | 9 +++++++++ ld/testsuite/ld-powerpc/sdabase.t | 6 ++++++ ld/testsuite/ld-powerpc/sdabase2.d | 10 ++++++++++ ld/testsuite/ld-powerpc/sdabase2.t | 6 ++++++ 14 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 ld/testsuite/ld-powerpc/sdabase.d create mode 100644 ld/testsuite/ld-powerpc/sdabase.s create mode 100644 ld/testsuite/ld-powerpc/sdabase.t create mode 100644 ld/testsuite/ld-powerpc/sdabase2.d create mode 100644 ld/testsuite/ld-powerpc/sdabase2.t diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 50ff01f8430..4bb379bf4cf 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2014-12-23 Alan Modra + + * elflink.c (_bfd_elf_define_linkage_sym): Set linker_def. + * linker.c (_bfd_generic_link_add_one_symbol): Clear linker_def + for CDEF, DEF, DEFW, COM. + 2014-12-22 Nick Clifton PR binutils/17512 diff --git a/bfd/elflink.c b/bfd/elflink.c index b701fa0d536..16421cfd5e7 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -85,6 +85,7 @@ _bfd_elf_define_linkage_sym (bfd *abfd, h = (struct elf_link_hash_entry *) bh; h->def_regular = 1; h->non_elf = 0; + h->root.linker_def = 1; h->type = STT_OBJECT; if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL) h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN; diff --git a/bfd/linker.c b/bfd/linker.c index abdf5b0e264..92238101010 100644 --- a/bfd/linker.c +++ b/bfd/linker.c @@ -1560,6 +1560,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, h->type = bfd_link_hash_defined; h->u.def.section = section; h->u.def.value = value; + h->linker_def = 0; /* If we have been asked to, we act like collect2 and identify all functions that might be global @@ -1659,6 +1660,7 @@ _bfd_generic_link_add_one_symbol (struct bfd_link_info *info, } else h->u.c.p->section = section; + h->linker_def = 0; break; case REF: diff --git a/include/ChangeLog b/include/ChangeLog index 1114a638ad2..d2e057b2b13 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,8 @@ +2014-12-23 Alan Modra + + * bfdlink.h (struct bfd_link_hash_entry): Comment non_ir_ref. Add + linker_def. + 2014-12-12 Phil Muldoon Jan Kratochvil Tom Tromey diff --git a/include/bfdlink.h b/include/bfdlink.h index f3181ba6256..48c91da75a1 100644 --- a/include/bfdlink.h +++ b/include/bfdlink.h @@ -91,8 +91,14 @@ struct bfd_link_hash_entry /* Type of this entry. */ ENUM_BITFIELD (bfd_link_hash_type) type : 8; + /* Symbol is referenced in a normal object file, as distict from a LTO + IR object file. */ unsigned int non_ir_ref : 1; + /* Symbol is a built-in define. These will be overridden by PROVIDE + in a linker script. */ + unsigned int linker_def : 1; + /* A union of information depending upon the type. */ union { diff --git a/ld/ChangeLog b/ld/ChangeLog index f16d1d53076..7f6eca28cf1 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,7 @@ +2014-12-23 Alan Modra + + * ldexp.c (exp_fold_tree_1 ): Test linker_def. + 2014-12-23 Alan Modra * ldexp.c (exp_fold_tree_1 ): Leave bfd_link_hash_common diff --git a/ld/ldexp.c b/ld/ldexp.c index 8615869b729..b4af893c86e 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -1072,9 +1072,7 @@ exp_fold_tree_1 (etree_type *tree) if (h == NULL || !(h->type == bfd_link_hash_new || h->type == bfd_link_hash_undefined - || (h->type == bfd_link_hash_defined - && (h->u.def.section->flags - & SEC_LINKER_CREATED) != 0))) + || h->linker_def)) { /* Do nothing. The symbol was never referenced, or was defined in some object file. Undefined weak diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index c901bb722bd..cfc028416ac 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2014-12-23 Alan Modra + + * ld-powerpc/sdabase.s, + * ld-powerpc/sdabase.t, + * ld-powerpc/sdabase.d: New test. + * ld-powerpc/sdabase2.t, + * ld-powerpc/sdabase2.d: New test. + * ld-powerpc/powerpc.exp: Run them. + 2014-12-23 Alan Modra * ld-elf/endsym.s, *ld-elf/endsym.d: New test. diff --git a/ld/testsuite/ld-powerpc/powerpc.exp b/ld/testsuite/ld-powerpc/powerpc.exp index 599b980f1f4..645236d35ba 100644 --- a/ld/testsuite/ld-powerpc/powerpc.exp +++ b/ld/testsuite/ld-powerpc/powerpc.exp @@ -289,6 +289,8 @@ if { [istarget "powerpc*-eabi*"] } { } run_dump_test "plt1" +run_dump_test "sdabase" +run_dump_test "sdabase2" run_dump_test "attr-gnu-4-00" run_dump_test "attr-gnu-4-01" diff --git a/ld/testsuite/ld-powerpc/sdabase.d b/ld/testsuite/ld-powerpc/sdabase.d new file mode 100644 index 00000000000..c54f7502804 --- /dev/null +++ b/ld/testsuite/ld-powerpc/sdabase.d @@ -0,0 +1,10 @@ +#source: sdabase.s +#as: -a32 +#ld: -melf32ppc -T sdabase.t +#objdump: -s +#target: powerpc*-*-* + +.*: file format .* + +Contents of section \.sdata: + 0400 (00008400|00840000) (00000400|00040000) .* diff --git a/ld/testsuite/ld-powerpc/sdabase.s b/ld/testsuite/ld-powerpc/sdabase.s new file mode 100644 index 00000000000..8c85688cb76 --- /dev/null +++ b/ld/testsuite/ld-powerpc/sdabase.s @@ -0,0 +1,9 @@ + .text + .globl _start +_start: + + .section .sdata,"aw",@progbits + .globl my_sdata +my_sdata: + .dc.a _SDA_BASE_ + .dc.a my_sdata diff --git a/ld/testsuite/ld-powerpc/sdabase.t b/ld/testsuite/ld-powerpc/sdabase.t new file mode 100644 index 00000000000..248696269a5 --- /dev/null +++ b/ld/testsuite/ld-powerpc/sdabase.t @@ -0,0 +1,6 @@ +SECTIONS +{ + .text 0x100 : { *(.text) } + .sdata 0x400 : { *(.sdata) } + /DISCARD/ : { *(*) } +} diff --git a/ld/testsuite/ld-powerpc/sdabase2.d b/ld/testsuite/ld-powerpc/sdabase2.d new file mode 100644 index 00000000000..a0da6f55287 --- /dev/null +++ b/ld/testsuite/ld-powerpc/sdabase2.d @@ -0,0 +1,10 @@ +#source: sdabase.s +#as: -a32 +#ld: -melf32ppc -T sdabase2.t +#objdump: -s +#target: powerpc*-*-* + +.*: file format .* + +Contents of section \.sdata: + 0400 (00000400|00040000) (00000400|00040000) .* diff --git a/ld/testsuite/ld-powerpc/sdabase2.t b/ld/testsuite/ld-powerpc/sdabase2.t new file mode 100644 index 00000000000..2a8f5d01bfd --- /dev/null +++ b/ld/testsuite/ld-powerpc/sdabase2.t @@ -0,0 +1,6 @@ +SECTIONS +{ + .text 0x100 : { *(.text) } + .sdata 0x400 : { PROVIDE (_SDA_BASE_ = .); *(.sdata) } + /DISCARD/ : { *(*) } +} -- 2.30.2