bfd: strip symbols not representable in COFF/PE symbol table
authorJan Beulich <jbeulich@suse.com>
Wed, 10 Mar 2021 07:12:37 +0000 (08:12 +0100)
committerJan Beulich <jbeulich@suse.com>
Wed, 10 Mar 2021 07:12:37 +0000 (08:12 +0100)
The offset-within-section field in the symbol table entry is only 32
bits wide, so rather than emitting bogus entries omit them, and issue
a diagnostic identifying the issue.

This requires adjusting the PR/22267 test to no longer produce symbols
with out of range values on 64-bit BFD. This also depends on
adjustments to testsuite/ld-scripts/map-address.* made by an earlier
patch. The purpose of the test can very well be achieved nevertheless.

bfd/ChangeLog
bfd/cofflink.c
ld/ChangeLog
ld/scripttempl/mcorepe.sc
ld/testsuite/ld-scripts/pr22267.d
ld/testsuite/ld-scripts/pr22267.t

index fe3808596bb6575767d78f717daffb36ffdee19d..d3c1d403529b26a84850c205f508aeb09f7da476 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-10  Jan Beulich  <jbeulich@suse.com>
+
+       * cofflink.c (_bfd_coff_write_global_sym): Range-check symbol
+       offset.
+
 2021-03-10  Alan Modra  <amodra@gmail.com>
            Jan Beulich  <jbeulich@suse.com>
 
index 4b0aab2a4ce491edab43557f7194d8ad8460322a..874354a70d00c06579072cb9dfa3e689228c9e1e 100644 (file)
@@ -2602,6 +2602,17 @@ _bfd_coff_write_global_sym (struct bfd_hash_entry *bh, void *data)
                        + h->root.u.def.section->output_offset);
        if (! obj_pe (flaginfo->output_bfd))
          isym.n_value += sec->vma;
+#ifdef BFD64
+       if (isym.n_value > (bfd_vma) 0xffffffff)
+         {
+           if (! h->root.linker_def)
+             _bfd_error_handler
+               (_("%pB: stripping non-representable symbol '%s' (value "
+                  "%" BFD_VMA_FMT "x)"),
+                output_bfd, h->root.root.string, isym.n_value);
+           return TRUE;
+         }
+#endif
       }
       break;
 
index c51332ad5c67a6e3417c8f7bc308404ba2c4c9f3..ec7854163fa72c6a9f7b1246e7076162dab203f8 100644 (file)
@@ -1,3 +1,11 @@
+2021-03-10  Jan Beulich  <jbeulich@suse.com>
+
+       * testsuite/ld-scripts/pr22267.t: Avoid symbol value with more
+       than 32 set bits.
+       * testsuite/ld-scripts/pr22267.d: Adjust expectation and drop
+       comment.
+       * scripttempl/mcorepe.sc: Use PROVIDE() for _stack.
+
 2021-03-09  Jan Beulich  <jbeulich@suse.com>
 
        * testsuite/ld-pe/reloc.s: Add entry point symbols. Increase
index 1cdbac282cccbcaac99d7b7d9c4f6e31e6febe9a..20fa6f954650dd760b2a448edf252939758ae38b 100644 (file)
@@ -168,7 +168,7 @@ SECTIONS
 
   .stack 0x80000 :
   {
-    _stack = .;
+    PROVIDE(_stack = .);
     *(.stack)
   }
 }
index b0bd18ed564f32b618449ed69ccd760d35057641..b46fec3ee7376a7905f4444b86f885b4892e60b2 100644 (file)
@@ -2,7 +2,6 @@
 #nm: -n
 #xfail: bfin-*-linux* frv-*-linux*
 
-# Some targets may zero-extend 32-bit address to 64 bits.
 #...
-0*f+00 A foo
+0*ff A foo
 #pass
index a0754058e5983e08b0493fe3a7595bf88f2d800a..004934594d5ae3e98aa9ff88568f2e87fd34de21 100644 (file)
@@ -1,4 +1,4 @@
 SECTIONS
 {
-  foo = ~0xFF;
+  foo = ~~0xFF;
 }
This page took 0.030186 seconds and 4 git commands to generate.