From dfb93f11587ca08b820c7c785278366f2505cfd1 Mon Sep 17 00:00:00 2001 From: James Cowgill Date: Sat, 3 Mar 2018 15:49:21 +0000 Subject: [PATCH] PR ld/21900: MIPS: Fix relocation processing with undefined symbols Currently, when `mips_elf_calculate_relocation' is asked to relocate an undefined symbol, it reports an error or a warning and immediately returns without performing the relocation. This is fine if the link fails, but if unresolved_syms_in_objects == RM_GENERATE_WARNING, the link will continue and output some unrelocated code, which is a regression from commit e7e2196da3f0 ("MIPS/BFD: Correctly report undefined relocations"). Fix this by continuing after calling the `undefined_symbol' hook unless this is an error condition. bfd/ PR ld/21900 * elfxx-mips.c (mips_elf_calculate_relocation): Only return after calling `undefined_symbol' hook if this is an error condition. Assume the value of 0 for the symbol requested otherwise. ld/ PR ld/21900 * testsuite/ld-mips-elf/undefined-warn.d: New test. * testsuite/ld-mips-elf/undefined.s: Add padding at the end. * testsuite/ld-mips-elf/mips-elf.exp: Run the new test. --- bfd/ChangeLog | 9 +++++++++ bfd/elfxx-mips.c | 14 ++++++++++---- ld/ChangeLog | 8 ++++++++ ld/testsuite/ld-mips-elf/mips-elf.exp | 1 + ld/testsuite/ld-mips-elf/undefined-warn.d | 13 +++++++++++++ ld/testsuite/ld-mips-elf/undefined.s | 4 ++++ 6 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 ld/testsuite/ld-mips-elf/undefined-warn.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 003f8a3c66..6e20330223 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2018-03-03 James Cowgill + Maciej W. Rozycki + + PR ld/21900 + * elfxx-mips.c (mips_elf_calculate_relocation): Only return + after calling `undefined_symbol' hook if this is an error + condition. Assume the value of 0 for the symbol requested + otherwise. + 2018-03-02 Jim Wilson PR 22903 diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 32b93fe7ad..ce645817bb 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -5478,12 +5478,18 @@ mips_elf_calculate_relocation (bfd *abfd, bfd *input_bfd, } else { + bfd_boolean reject_undefined + = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR + || ELF_ST_VISIBILITY (h->root.other) != STV_DEFAULT); + (*info->callbacks->undefined_symbol) (info, h->root.root.root.string, input_bfd, - input_section, relocation->r_offset, - (info->unresolved_syms_in_objects == RM_GENERATE_ERROR) - || ELF_ST_VISIBILITY (h->root.other)); - return bfd_reloc_undefined; + input_section, relocation->r_offset, reject_undefined); + + if (reject_undefined) + return bfd_reloc_undefined; + + symbol = 0; } target_is_16_bit_code_p = ELF_ST_IS_MIPS16 (h->root.other); diff --git a/ld/ChangeLog b/ld/ChangeLog index 6f9abfa3e9..c7961253e5 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,11 @@ +2018-03-03 James Cowgill + Maciej W. Rozycki + + PR ld/21900 + * testsuite/ld-mips-elf/undefined-warn.d: New test. + * testsuite/ld-mips-elf/undefined.s: Add padding at the end. + * testsuite/ld-mips-elf/mips-elf.exp: Run the new test. + 2018-03-02 Jim Wilson PR 22903 diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp index 144b007089..95d677e577 100644 --- a/ld/testsuite/ld-mips-elf/mips-elf.exp +++ b/ld/testsuite/ld-mips-elf/mips-elf.exp @@ -995,6 +995,7 @@ if { $linux_gnu } { } run_dump_test "undefined" +run_dump_test "undefined-warn" # Test the conversion from jr to b if { $linux_gnu } { diff --git a/ld/testsuite/ld-mips-elf/undefined-warn.d b/ld/testsuite/ld-mips-elf/undefined-warn.d new file mode 100644 index 0000000000..b43018e79e --- /dev/null +++ b/ld/testsuite/ld-mips-elf/undefined-warn.d @@ -0,0 +1,13 @@ +#objdump: -d --prefix-addresses --show-raw-insn +#name: MIPS undefined reference with --warn-unresolved-symbols +#source: undefined.s +#ld: -e foo --warn-unresolved-symbols +#warning: \A[^\n]*\.o: in function `foo':\n\(\.text\+0x0\): warning: undefined reference to `bar'\Z + +.*: file format .* + +Disassembly of section \.text: + +# Loaded value must not be 0. +[0-9a-f]+ <[^>]*> 2402.... li v0,[-1-9][0-9]* + \.\.\. diff --git a/ld/testsuite/ld-mips-elf/undefined.s b/ld/testsuite/ld-mips-elf/undefined.s index d946a5ab6f..98f46de6f4 100644 --- a/ld/testsuite/ld-mips-elf/undefined.s +++ b/ld/testsuite/ld-mips-elf/undefined.s @@ -22,3 +22,7 @@ foo: li $2, %got_page(bar) .end foo .size foo, . - foo + +# Force some (non-delay-slot) zero bytes, to make 'objdump' print ... + .align 4, 0 + .space 16 -- 2.34.1