From 02d2a36902c7b0fefe05e8d9bdbf11e846ac71fe Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 15 Jul 2023 19:47:10 +0930 Subject: [PATCH] PR10957, Missing option to really print section+offset Many of the reloc error messages have already been converted from using %C to using %H in ld.bfd, to print section+offset as well as file/line/function. This catches a few remaining, and changes gold to do the same. PR 10957 bfd/ * elf32-sh.c (sh_elf_relocate_section): Use %H in error messages. gold/ * object.cc (Relocate_info::location): Always report section+offset. * testsuite/debug_msg.sh: Adjust to suit. * testsuite/x32_overflow_pc32.sh: Likewise. * testsuite/x86_64_overflow_pc32.sh: Likewise. ld/ * emultempl/pe.em (read_addend): Use %H in error message. * emultempl/pep.em (read_addend): Likewise. * ldcref.c (check_reloc_refs): Likewise. * ldmain.c (warning_find_reloc, undefined_symbol): Likewise. * pe-dll.c (pe_create_import_fixup): Likewise. * testsuite/ld-cris/undef2.d: Adjust expected output to suit. * testsuite/ld-cris/undef3.d: Likewise. * testsuite/ld-elf/shared.exp: Likewise. * testsuite/ld-i386/compressed1.d: Likewise. * testsuite/ld-ia64/line.exp: Likewise. * testsuite/ld-plugin/lto.exp: Likewise. * testsuite/ld-undefined/undefined.exp: Likewise. * testsuite/ld-x86-64/compressed1.d: Likewise. * testsuite/ld-x86-64/line.exp: Likewise. * testsuite/ld-x86-64/pr27587.err: Likewise. --- bfd/elf32-sh.c | 4 ++-- gold/object.cc | 2 +- gold/testsuite/debug_msg.sh | 12 ++++++------ gold/testsuite/x32_overflow_pc32.sh | 2 +- gold/testsuite/x86_64_overflow_pc32.sh | 2 +- ld/emultempl/pe.em | 2 +- ld/emultempl/pep.em | 2 +- ld/ldcref.c | 2 +- ld/ldmain.c | 6 +++--- ld/pe-dll.c | 2 +- ld/testsuite/ld-cris/undef2.d | 12 ++++++------ ld/testsuite/ld-cris/undef3.d | 2 +- ld/testsuite/ld-elf/shared.exp | 4 ++-- ld/testsuite/ld-i386/compressed1.d | 2 +- ld/testsuite/ld-ia64/line.exp | 2 +- ld/testsuite/ld-plugin/lto.exp | 2 +- ld/testsuite/ld-undefined/undefined.exp | 2 +- ld/testsuite/ld-x86-64/compressed1.d | 2 +- ld/testsuite/ld-x86-64/line.exp | 2 +- ld/testsuite/ld-x86-64/pr27587.err | 2 +- 20 files changed, 34 insertions(+), 34 deletions(-) diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index 499233d1355..cba3529e2a5 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -5010,14 +5010,14 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, { info->callbacks->einfo /* xgettext:c-format */ - (_("%X%C: relocation to \"%s\" references a different segment\n"), + (_("%X%H: relocation to \"%s\" references a different segment\n"), input_bfd, input_section, rel->r_offset, symname); return false; } else info->callbacks->einfo /* xgettext:c-format */ - (_("%C: warning: relocation to \"%s\" references a different segment\n"), + (_("%H: warning: relocation to \"%s\" references a different segment\n"), input_bfd, input_section, rel->r_offset, symname); } diff --git a/gold/object.cc b/gold/object.cc index ccb74057275..77b2690c381 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -3358,7 +3358,7 @@ Relocate_info::location(size_t, off_t offset) const if (info.enclosing_symbol_type == elfcpp::STT_FUNC) ret += _("function "); ret += info.enclosing_symbol_name; - return ret; + ret += ":"; } ret += "("; diff --git a/gold/testsuite/debug_msg.sh b/gold/testsuite/debug_msg.sh index b808fb8a6e0..51e8a83e1d4 100755 --- a/gold/testsuite/debug_msg.sh +++ b/gold/testsuite/debug_msg.sh @@ -55,9 +55,9 @@ check_missing() # We don't know how the compiler might order these variables, so we # can't test for the actual offset from .data, hence the regexp. -check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn1()'" -check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn2()'" -check debug_msg.err "debug_msg.o:debug_msg.cc:badref1: error: undefined reference to 'undef_int'" +check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array:(.*): error: undefined reference to 'undef_fn1()'" +check debug_msg.err "debug_msg.o:debug_msg.cc:fn_array:(.*): error: undefined reference to 'undef_fn2()'" +check debug_msg.err "debug_msg.o:debug_msg.cc:badref1:(.*): error: undefined reference to 'undef_int'" # These tests check only for the source file's file name (not the complete # path) because use of -fdebug-prefix-map may change the path to the source @@ -93,9 +93,9 @@ check debug_msg.err "odr_violation2.cc:3[0-7]" # Check for the same error messages when using --compressed-debug-sections. if test -r debug_msg_cdebug.err then - check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn1()'" - check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array: error: undefined reference to 'undef_fn2()'" - check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:badref1: error: undefined reference to 'undef_int'" + check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array:(.*): error: undefined reference to 'undef_fn1()'" + check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:fn_array:(.*): error: undefined reference to 'undef_fn2()'" + check debug_msg_cdebug.err "debug_msg_cdebug.o:debug_msg.cc:badref1:(.*): error: undefined reference to 'undef_int'" check debug_msg_cdebug.err ".*/debug_msg.cc:50: error: undefined reference to 'undef_fn1()'" check debug_msg_cdebug.err ".*/debug_msg.cc:55: error: undefined reference to 'undef_fn2()'" check debug_msg_cdebug.err ".*/debug_msg.cc:4[356]: error: undefined reference to 'undef_fn1()'" diff --git a/gold/testsuite/x32_overflow_pc32.sh b/gold/testsuite/x32_overflow_pc32.sh index d0a4cf0374a..6da575e8f2f 100755 --- a/gold/testsuite/x32_overflow_pc32.sh +++ b/gold/testsuite/x32_overflow_pc32.sh @@ -37,6 +37,6 @@ check() # We don't know how the compiler might order these variables, so we # can't test for the actual offset from .data, hence the regexp. -check x86_64_overflow_pc32.err "function bar: error: relocation overflow" +check x86_64_overflow_pc32.err "function bar:(.*): error: relocation overflow" exit 0 diff --git a/gold/testsuite/x86_64_overflow_pc32.sh b/gold/testsuite/x86_64_overflow_pc32.sh index d0a4cf0374a..6da575e8f2f 100755 --- a/gold/testsuite/x86_64_overflow_pc32.sh +++ b/gold/testsuite/x86_64_overflow_pc32.sh @@ -37,6 +37,6 @@ check() # We don't know how the compiler might order these variables, so we # can't test for the actual offset from .data, hence the regexp. -check x86_64_overflow_pc32.err "function bar: error: relocation overflow" +check x86_64_overflow_pc32.err "function bar:(.*): error: relocation overflow" exit 0 diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 7d956bf555c..cd2abe460b9 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -1270,7 +1270,7 @@ read_addend (arelent *rel, asection *s) bfd_vma addend = 0; if (!bfd_get_section_contents (s->owner, s, buf, rel->address, sizeof (buf))) - einfo (_("%P: %C: cannot get section contents - auto-import exception\n"), + einfo (_("%P: %H: cannot get section contents - auto-import exception\n"), s->owner, s, rel->address); else addend = bfd_get_32 (s->owner, buf); diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index 99e71951b8a..28d8c8decb3 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -1269,7 +1269,7 @@ read_addend (arelent *rel, asection *s) break; } if (!ok) - einfo (_("%P: %C: cannot get section contents - auto-import exception\n"), + einfo (_("%P: %H: cannot get section contents - auto-import exception\n"), s->owner, s, rel->address); return addend; } diff --git a/ld/ldcref.c b/ld/ldcref.c index da4a4217c20..cf4eba30bdc 100644 --- a/ld/ldcref.c +++ b/ld/ldcref.c @@ -721,7 +721,7 @@ check_reloc_refs (bfd *abfd, asection *sec, void *iarg) in OUTSECNAME. This reloc is from a section which is mapped into a section from which references to OUTSECNAME are prohibited. We must report an error. */ - einfo (_("%X%P: %C: prohibited cross reference from %s to `%pT' in %s\n"), + einfo (_("%X%P: %H: prohibited cross reference from %s to `%pT' in %s\n"), abfd, sec, q->address, outsecname, bfd_asymbol_name (*q->sym_ptr_ptr), outdefsecname); } diff --git a/ld/ldmain.c b/ld/ldmain.c index 25cc89b72f9..06ac2c64fa8 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -1394,7 +1394,7 @@ warning_find_reloc (bfd *abfd, asection *sec, void *iarg) && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0) { /* We found a reloc for the symbol we are looking for. */ - einfo ("%P: %C: %s%s\n", abfd, sec, q->address, _("warning: "), + einfo ("%P: %H: %s%s\n", abfd, sec, q->address, _("warning: "), info->warning); info->found = true; break; @@ -1484,10 +1484,10 @@ undefined_symbol (struct bfd_link_info *info, if (error_count < MAX_ERRORS_IN_A_ROW) { if (error) - einfo (_("%X%P: %C: undefined reference to `%pT'\n"), + einfo (_("%X%P: %H: undefined reference to `%pT'\n"), abfd, section, address, name); else - einfo (_("%P: %C: warning: undefined reference to `%pT'\n"), + einfo (_("%P: %H: warning: undefined reference to `%pT'\n"), abfd, section, address, name); } else if (error_count == MAX_ERRORS_IN_A_ROW) diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 371915ac1cb..02e03d16948 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -2911,7 +2911,7 @@ pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name, } else if (addend != 0) - einfo (_("%X%P: %C: variable '%pT' can't be auto-imported; please read the documentation for ld's --enable-auto-import for details\n"), + einfo (_("%X%P: %H: variable '%pT' can't be auto-imported; please read the documentation for ld's --enable-auto-import for details\n"), s->owner, s, rel->address, (*rel->sym_ptr_ptr)->name); } diff --git a/ld/testsuite/ld-cris/undef2.d b/ld/testsuite/ld-cris/undef2.d index 46015c00add..cd2c43eee4f 100644 --- a/ld/testsuite/ld-cris/undef2.d +++ b/ld/testsuite/ld-cris/undef2.d @@ -1,6 +1,6 @@ -# source: start1.s -# source: stabs1.s -# target: cris-*-*elf* cris-*-*aout* -# as: --em=crisaout -# ld: -mcrisaout -# error: .o:/blah/foo.c:96: undefined reference to `globsym1'$ +#source: start1.s +#source: stabs1.s +#target: cris-*-*elf* cris-*-*aout* +#as: --em=crisaout +#ld: -mcrisaout +#error: .o:/blah/foo.c:96:\(.*\): undefined reference to `globsym1'$ diff --git a/ld/testsuite/ld-cris/undef3.d b/ld/testsuite/ld-cris/undef3.d index e7bca10caf7..e21456b2bae 100644 --- a/ld/testsuite/ld-cris/undef3.d +++ b/ld/testsuite/ld-cris/undef3.d @@ -3,4 +3,4 @@ #target: cris-*-*elf* cris-*-*aout* #as: --em=criself #ld: -mcriself -#error: .o:/blah/foo.c:96: undefined reference to `globsym1'$ +#error: .o:/blah/foo.c:96:\(.*\): undefined reference to `globsym1'$ diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp index 1eef9f45667..cf010e5b0e5 100644 --- a/ld/testsuite/ld-elf/shared.exp +++ b/ld/testsuite/ld-elf/shared.exp @@ -554,7 +554,7 @@ set build_tests { "-shared" "-fPIC" {beginwarn.c end.c} {{readelf {-S --wide} libbarw.rd} - {warning "^.*beginwarn.c:7: warning: function foo is deprecated\n?$"}} + {warning {^.*beginwarn.c:7:\(.*\): warning: function foo is deprecated\n?$}}} "libbarw.so" "c"} {"Build hidden libbar.so" "-shared" "-fPIC" @@ -1017,7 +1017,7 @@ set run_tests [list \ [list "Run warn with versioned libfoo.so" \ "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \ {main.c} "warn" "warn.out" \ - "" "c" {^.*beginwarn.c:7: warning: function foo is deprecated\n?$} ] \ + "" "c" {^.*beginwarn.c:7:\(.*\): warning: function foo is deprecated\n?$} ] \ [list "Run protected with versioned libfoo.so" \ "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \ {main.c} "protected" "normal.out" ] \ diff --git a/ld/testsuite/ld-i386/compressed1.d b/ld/testsuite/ld-i386/compressed1.d index e9eeef9ae2a..a4294784daa 100644 --- a/ld/testsuite/ld-i386/compressed1.d +++ b/ld/testsuite/ld-i386/compressed1.d @@ -1,7 +1,7 @@ #name: undefined symbol with compressed debug sections #as: --32 #ld: -e foo -melf_i386 --noinhibit-exec -#warning: .*/compressed1.c:13: undefined reference to .bar. +#warning: .*/compressed1.c:13:\(.*\): undefined reference to .bar. #nm: -n #failif diff --git a/ld/testsuite/ld-ia64/line.exp b/ld/testsuite/ld-ia64/line.exp index d39e3ac249d..1fe32cdab9d 100644 --- a/ld/testsuite/ld-ia64/line.exp +++ b/ld/testsuite/ld-ia64/line.exp @@ -52,6 +52,6 @@ proc checkund { string testname } { } } -set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'" +set ml {undefined.c:9:(*): undefined reference to `*this_function_is_not_defined'} checkund $ml $testline diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp index 9a11de315b8..6f728d77448 100644 --- a/ld/testsuite/ld-plugin/lto.exp +++ b/ld/testsuite/ld-plugin/lto.exp @@ -304,7 +304,7 @@ set lto_link_elf_tests [list \ {pr12760b.c} {} "libpr12760.a"] \ [list "PR ld/12760" \ "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \ - {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \ + {dummy.c} {{warning {pr12760a.c:6:\(.*\): warning: Bad \.?bar}}} \ "pr12760.exe" "c"] \ [list "PR ld/12975" \ "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \ diff --git a/ld/testsuite/ld-undefined/undefined.exp b/ld/testsuite/ld-undefined/undefined.exp index 69a8f9bf6a9..05b1131d5b4 100644 --- a/ld/testsuite/ld-undefined/undefined.exp +++ b/ld/testsuite/ld-undefined/undefined.exp @@ -89,7 +89,7 @@ if { ![check_compiler_available] } { #setup_xfail "arm*-*-pe*" } - set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'" + set ml {undefined.c:9:(*): undefined reference to `*this_function_is_not_defined'} # With targets that use elf/dwarf2, such as the arm-elf toolchain, # the code in bfd/elf.c:_bfd_elf_find_nearest_line() is called in # order to locate the file name/line number where the undefined diff --git a/ld/testsuite/ld-x86-64/compressed1.d b/ld/testsuite/ld-x86-64/compressed1.d index f97c9ad7da6..8b92278d7b0 100644 --- a/ld/testsuite/ld-x86-64/compressed1.d +++ b/ld/testsuite/ld-x86-64/compressed1.d @@ -1,7 +1,7 @@ #name: undefined symbol with compressed debug sections #as: --64 #ld: -e foo -melf_x86_64 --noinhibit-exec -#warning: .*/compressed1.c:13: undefined reference to .bar. +#warning: .*/compressed1.c:13:\(.*\): undefined reference to .bar. #nm: -n #failif diff --git a/ld/testsuite/ld-x86-64/line.exp b/ld/testsuite/ld-x86-64/line.exp index f5163998862..af01ea227b7 100644 --- a/ld/testsuite/ld-x86-64/line.exp +++ b/ld/testsuite/ld-x86-64/line.exp @@ -52,6 +52,6 @@ proc checkund { string testname } { } } -set ml "undefined.c:9: undefined reference to `*this_function_is_not_defined'" +set ml {undefined.c:9:(*): undefined reference to `*this_function_is_not_defined'} checkund $ml $testline diff --git a/ld/testsuite/ld-x86-64/pr27587.err b/ld/testsuite/ld-x86-64/pr27587.err index 807750ca9d3..9ccca0aec38 100644 --- a/ld/testsuite/ld-x86-64/pr27587.err +++ b/ld/testsuite/ld-x86-64/pr27587.err @@ -1,3 +1,3 @@ #... -.*pr27587/:4: undefined reference to `stack_size' +.*pr27587/:4:\(.*\): undefined reference to `stack_size' #... -- 2.30.2