Skip to content

Commit

Permalink
PR10957, Missing option to really print section+offset
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amodra committed Jul 16, 2023
1 parent 63e8fb8 commit 02d2a36
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions bfd/elf32-sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion gold/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,7 @@ Relocate_info<size, big_endian>::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 += "(";
Expand Down
12 changes: 6 additions & 6 deletions gold/testsuite/debug_msg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()'"
Expand Down
2 changes: 1 addition & 1 deletion gold/testsuite/x32_overflow_pc32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion gold/testsuite/x86_64_overflow_pc32.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ld/emultempl/pe.em
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ld/emultempl/pep.em
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion ld/ldcref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions ld/ldmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ld/pe-dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 6 additions & 6 deletions ld/testsuite/ld-cris/undef2.d
Original file line number Diff line number Diff line change
@@ -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'$
2 changes: 1 addition & 1 deletion ld/testsuite/ld-cris/undef3.d
Original file line number Diff line number Diff line change
Expand Up @@ -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'$
4 changes: 2 additions & 2 deletions ld/testsuite/ld-elf/shared.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" ] \
Expand Down
2 changes: 1 addition & 1 deletion ld/testsuite/ld-i386/compressed1.d
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ld/testsuite/ld-ia64/line.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ld/testsuite/ld-plugin/lto.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
2 changes: 1 addition & 1 deletion ld/testsuite/ld-undefined/undefined.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ld/testsuite/ld-x86-64/compressed1.d
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ld/testsuite/ld-x86-64/line.exp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ld/testsuite/ld-x86-64/pr27587.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#...
.*pr27587/<artificial>:4: undefined reference to `stack_size'
.*pr27587/<artificial>:4:\(.*\): undefined reference to `stack_size'
#...

0 comments on commit 02d2a36

Please sign in to comment.