Bogus "final link failed" messages
authorAlan Modra <amodra@gmail.com>
Mon, 7 Oct 2019 03:07:23 +0000 (13:37 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 7 Oct 2019 03:07:23 +0000 (13:37 +1030)
This patch is a result of noticing messages like the following:
tmpdir/tls32.o: in function `_start':
(.text+0x1c): unresolvable R_PPC_REL24 relocation against symbol `__tls_get_addr_opt'
./ld-new: final link failed: symbol needs debug section which does not exist

The "needs debug section" comes from attempting to use debug info to
find source line information to print the first error message.  That
error isn't of interest to the user, and any previous bfd_error value
which might be of interest is overwritten.  So save and restore
bfd_error around the fancy error reporting code.

That still doesn't leave us with a clean bfd_error.  Now we get
./ld-new: final link failed: nonrepresentable section on output
An unresolvable relocation surely doesn't mean there is some bfd
section that ld doesn't know how to output!  Digging into that showed
a _bfd_elf_section_from_bfd_section failure attempting to find an elf
section correcsponding to ".interp".  So don't go looking for elf
sections on linker created bfd sections.

And then fix the linker testsuite which expected the bogus message..

bfd/
* elflink.c (elf_fixup_link_order): Don't attempt to find
an elf_section for linker created bfd sections.
ld/
* ldmisc.c (vfinfo): Save and restore bfd_error around bfd
function calls that might set it.
* testsuite/ld-elf/indirect.exp: Don't expect "nonrepresentable
section" message.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/ldmisc.c
ld/testsuite/ld-elf/indirect.exp

index b691d585712c5e0bf3c26c5a1fe4ea7846f36677..607f37cfb27533a8022169c6667ce575167c1d23 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-07  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (elf_fixup_link_order): Don't attempt to find
+       an elf_section for linker created bfd sections.
+
 2019-10-07  Alan Modra  <amodra@gmail.com>
 
        * elf32-ppc.c (ppc_elf_tls_optimize): Don't process R_PPC_TLSLD
index 371c0969e611b5a36992dbfdf8fc1eb99de4348f..395d96d6cfb5ed6ccdcef1522a72b3d55e6cb885 100644 (file)
@@ -11535,7 +11535,8 @@ elf_fixup_link_order (bfd *abfd, asection *o)
        {
          s = p->u.indirect.section;
          sub = s->owner;
-         if (bfd_get_flavour (sub) == bfd_target_elf_flavour
+         if ((s->flags & SEC_LINKER_CREATED) == 0
+             && bfd_get_flavour (sub) == bfd_target_elf_flavour
              && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass
              && (elfsec = _bfd_elf_section_from_bfd_section (sub, s))
              && elfsec < elf_numsections (sub)
index a3fd84f1bd102b107e3f49801a45d74b85d9b703..ddec8c79ce362018d2d329926533d89d5062ce2b 100644 (file)
@@ -1,3 +1,10 @@
+2019-10-07  Alan Modra  <amodra@gmail.com>
+
+       * ldmisc.c (vfinfo): Save and restore bfd_error around bfd
+       function calls that might set it.
+       * testsuite/ld-elf/indirect.exp: Don't expect "nonrepresentable
+       section" message.
+
 2019-10-07  Alan Modra  <amodra@gmail.com>
 
        * testsuite/ld-powerpc/tlsexe.r: Adjust for added TLSMARK symbol.
index 848e227b0523bc610e2f1bf237632af79614ea4c..2e53d645985d7d4775c53f10361671fffcbecb00 100644 (file)
@@ -322,6 +322,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                unsigned int linenumber;
                bfd_boolean discard_last;
                bfd_boolean done;
+               bfd_error_type last_bfd_error = bfd_get_error ();
 
                abfd = args[arg_no].reladdr.abfd;
                section = args[arg_no].reladdr.sec;
@@ -406,6 +407,7 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  }
                if (!done)
                  lfinfo (fp, "(%pA+0x%v)", section, offset);
+               bfd_set_error (last_bfd_error);
 
                if (discard_last)
                  {
index 1acb556dba0529a8950c956d5cf3eb34d5ef9ed5..6f1fed34e7fbb02c25417aa741a65a72245d031b 100644 (file)
@@ -123,11 +123,10 @@ set testname "Indirect symbol 1b"
 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
 check_link_message "$cmd" [list $string1 $string] "$testname"
 
-set string ": final link failed: nonrepresentable section on output"
 set string2 ": no symbol version section for versioned symbol \`foo@FOO\'"
 set testname "Indirect symbol 2"
 set cmd "$ld -shared  -o tmpdir/indirect2.so tmpdir/indirect2.o"
-check_link_message "$cmd" [list $string2 $string] "$testname"
+check_link_message "$cmd" [list $string2] "$testname"
 
 global NOPIE_CFLAGS NOPIE_LDFLAGS
 
This page took 0.039571 seconds and 4 git commands to generate.