From 66cae56016a12f7cbdc94be6f82c1cad1c59b521 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 23 Oct 2017 18:16:49 +0100 Subject: [PATCH] Make sure that undefined symbols added to the linker command line via the -u option appear in the output executable, if they have not been resolved. PR 22319 bfd * elflink.c (elf_link_output_extsym): Keep global undefined symbols if they have been marked as needed. ld * testsuite/ld-elf/pr22310.s: New test source file. * testsuite/ld-elf/pr22310.d: New test driver. * testsuite/ld-mmix/undef-3.d: Update expected output from readelf. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 3 +++ ld/ChangeLog | 7 +++++++ ld/testsuite/ld-elf/pr22319.d | 9 +++++++++ ld/testsuite/ld-elf/pr22319.s | 2 ++ ld/testsuite/ld-mmix/undef-3.d | 17 +++++++++-------- 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 ld/testsuite/ld-elf/pr22319.d create mode 100644 ld/testsuite/ld-elf/pr22319.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index fde334d..73d1f4b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2017-10-23 Nick Clifton + + PR 22319 + * elflink.c (elf_link_output_extsym): Keep global undefined + symbols if they have been marked as needed. + 2017-10-23 Maciej W. Rozycki * elfn32-mips.c (mips_elf_n32_mkobject): New prototype and diff --git a/bfd/elflink.c b/bfd/elflink.c index b401e68..de13d04 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -9910,8 +9910,11 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data) relocatable output or when needed for --emit-relocs. */ else if (input_sec == bfd_und_section_ptr && h->indx != -2 + /* PR 22319 Do not strip global undefined symbols marked as being needed. */ + && (h->mark != 1 || ELF_ST_BIND (sym.st_info) != STB_GLOBAL) && !bfd_link_relocatable (flinfo->info)) return TRUE; + /* Also strip others that we couldn't earlier due to dynamic symbol processing. */ if (strip) diff --git a/ld/ChangeLog b/ld/ChangeLog index 041778e..24b6fa4 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,10 @@ +2017-10-23 Nick Clifton + + PR 22310 + * testsuite/ld-elf/pr22310.s: New test source file. + * testsuite/ld-elf/pr22310.d: New test driver. + * testsuite/ld-mmix/undef-3.d: Update expected output from readelf. + 2017-10-21 Hans-Peter Nilsson PR ld/21233 diff --git a/ld/testsuite/ld-elf/pr22319.d b/ld/testsuite/ld-elf/pr22319.d new file mode 100644 index 0000000..68a5706 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22319.d @@ -0,0 +1,9 @@ +#name: PR 22319 - required undefined symbols in output +#ld: -u undefined_symbol -e 0 +#nm: -u +#notarget: dlx-*-* +# The DLX target fails because it needs a special linker script to handle file symbols. + +[ ]+U+[ ]+undefined_symbol +#pass + diff --git a/ld/testsuite/ld-elf/pr22319.s b/ld/testsuite/ld-elf/pr22319.s new file mode 100644 index 0000000..5a02e47 --- /dev/null +++ b/ld/testsuite/ld-elf/pr22319.s @@ -0,0 +1,2 @@ + .data + .dc.b 0 diff --git a/ld/testsuite/ld-mmix/undef-3.d b/ld/testsuite/ld-mmix/undef-3.d index 6afb52b..2484d76 100644 --- a/ld/testsuite/ld-mmix/undef-3.d +++ b/ld/testsuite/ld-mmix/undef-3.d @@ -12,20 +12,21 @@ Section Headers: +\[ 1\] \.text +PROGBITS +0+ +0+78 +0+4 +0+ +AX +0 +0 +4 +\[ 2\] \.symtab +SYMTAB +0+ .* - +0+a8 +0+18 +3 +2 +8 + +0+c0 +0+18 +3 +2 +8 +\[ 3\] \.strtab +STRTAB +0+ .* - +0+21 +0+ +0 +0 +1 + +0+28 +0+ +0 +0 +1 +\[ 4\] \.shstrtab +STRTAB +0+ +[0-9a-f]+ +0+21 +0+ +0 +0 +1 Key to Flags: #... -Symbol table '\.symtab' contains 7 entries: +Symbol table '\.symtab' contains 8 entries: +Num: +Value +Size +Type +Bind +Vis +Ndx +Name +0: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND +1: 0+ +0 +SECTION +LOCAL +DEFAULT +1 - +2: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +1 _start - +3: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 __bss_start - +4: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 _edata - +5: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 _end - +6: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +1 _start\. +[ ]+2: 0+[ ]+0[ ]+NOTYPE[ ]+GLOBAL[ ]+DEFAULT[ ]+UND[ ]+undefd + +3: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +1 _start + +4: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 __bss_start + +5: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 _edata + +6: 2000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 _end + +7: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +1 _start\. -- 2.7.4