]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
-z relro relaxation and ld script SIZEOF
authorAlan Modra <amodra@gmail.com>
Fri, 24 Jun 2022 03:55:45 +0000 (13:25 +0930)
committerAlan Modra <amodra@gmail.com>
Mon, 27 Jun 2022 02:58:59 +0000 (12:28 +0930)
A number of targets use assignments like:
. = DATA_SEGMENT_RELRO_END (SIZEOF (.got.plt) >= 12 ? 12 : 0, .);
(from i386) in linker scripts to put the end of the relro segment past
the header in .got.plt.  Examination of testcases like those edited by
this patch instead sees the end of the relro segment being placed at
the start of .got.plt.  For the i386 pie1 test:

  [ 9] .got.plt          PROGBITS        00002000 001000 00000c 04  WA  0   0  4

  GNU_RELRO      0x000f90 0x00001f90 0x00001f90 0x00070 0x00070 R   0x1

A map file shows:

.dynamic        0x0000000000001f90       0x70
 *(.dynamic)
 .dynamic       0x0000000000001f90       0x70 tmpdir/pie1.o
                0x0000000000001f90                _DYNAMIC

.got            0x0000000000002000        0x0
 *(.got)
 .got           0x0000000000002000        0x0 tmpdir/pie1.o
 *(.igot)
                0x0000000000002ff4                . = DATA_SEGMENT_RELRO_END (., (SIZEOF (.got.plt) >= 0xc)?0xc:0x0)

.got.plt        0x0000000000002000        0xc
 *(.got.plt)
 .got.plt       0x0000000000002000        0xc tmpdir/pie1.o
                0x0000000000002000                _GLOBAL_OFFSET_TABLE_

The DATA_SEGMENT_RELRO_END value in the map file is weird too.  All of
this is triggered by SIZEOF (.got.plt) being evaluated wrongly as
zero.  Fix it by taking into account the action of
lang_reset_memory_regions during relaxation.

* ldexp.c (fold_name <SIZEOF>): Use rawsize if size has been reset.
* ldlang.c (lang_size_sections_1): Don't reset processed_vma here.
* testsuite/ld-i386/pie1.d: Adjust to suit.
* testsuite/ld-x86-64/pr20830a.d: Likewise.
* testsuite/ld-x86-64/pr20830b.d: Likewise.
* testsuite/ld-x86-64/pr21038a.d: Likewise.
* testsuite/ld-x86-64/pr21038b.d: Likewise.
* testsuite/ld-x86-64/pr21038c.d: Likewise.

ld/ldexp.c
ld/ldlang.c
ld/testsuite/ld-i386/pie1.d
ld/testsuite/ld-x86-64/pr20830a.d
ld/testsuite/ld-x86-64/pr20830b.d
ld/testsuite/ld-x86-64/pr21038a.d
ld/testsuite/ld-x86-64/pr21038b.d
ld/testsuite/ld-x86-64/pr21038c.d

index c18b8284ca513830ed7ab198ae1ca4cffee14f04..d4d8706968dc74770f776e3d2bb8eab050028fc4 100644 (file)
@@ -864,9 +864,17 @@ fold_name (etree_type *tree)
              bfd_vma val;
 
              if (tree->type.node_code == SIZEOF)
-               val = (os->bfd_section->size
-                      / bfd_octets_per_byte (link_info.output_bfd,
-                                             os->bfd_section));
+               {
+                 if (os->processed_vma)
+                   val = os->bfd_section->size;
+                 else
+                   /* If we've just called lang_reset_memory_regions,
+                      size will be zero and a previous estimate of
+                      size will be in rawsize.  */
+                   val = os->bfd_section->rawsize;
+                 val /= bfd_octets_per_byte (link_info.output_bfd,
+                                             os->bfd_section);
+               }
              else
                val = (bfd_vma)1 << os->bfd_section->alignment_power;
 
index 839535bdb7342b3f9b18c7811ce442837cbe6514..e640380e90181de6e68145d41a7133c797d18557 100644 (file)
@@ -5778,7 +5778,6 @@ lang_size_sections_1
              os->addr_tree = exp_intop (0);
            if (os->addr_tree != NULL)
              {
-               os->processed_vma = false;
                exp_fold_tree (os->addr_tree, bfd_abs_section_ptr, &dot);
 
                if (expld.result.valid_p)
index 338d05784d0384509c9972224c1f797a5ec83e23..fdc65b101f6f8c817603f31245d13f8b79313fcf 100644 (file)
@@ -6,11 +6,11 @@
 
 SYMBOL TABLE:
 #...
-0+2000 l     O .got.plt        0+ _GLOBAL_OFFSET_TABLE_
+0+1ff4 l     O .got.plt        0+ _GLOBAL_OFFSET_TABLE_
 #...
 
 Disassembly of section .text:
 
 .* <_start>:
-.*:    8d 80 00 e0 ff ff       lea    -0x2000\(%eax\),%eax
+.*:    8d 80 0c e0 ff ff       lea    -0x1ff4\(%eax\),%eax
 #pass
index 2c47a51b19d60cb9c4a329f97845fe5f7151a769..1d92b10ba7142f792ea144207bb119da5737d0a8 100644 (file)
@@ -50,19 +50,19 @@ Contents of the .eh_frame section:
 Disassembly of section .plt:
 
 0+1b0 <.plt>:
- +[a-f0-9]+:   ff 35 52 fe 3f 00       push   0x3ffe52\(%rip\)        # 400008 <_GLOBAL_OFFSET_TABLE_\+0x8>
- +[a-f0-9]+:   ff 25 54 fe 3f 00       jmp    \*0x3ffe54\(%rip\)        # 400010 <_GLOBAL_OFFSET_TABLE_\+0x10>
+ +[a-f0-9]+:   ff 35 3a fe 3f 00       push   0x3ffe3a\(%rip\)        # 3ffff0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+ +[a-f0-9]+:   ff 25 3c fe 3f 00       jmp    \*0x3ffe3c\(%rip\)        # 3ffff8 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 40 00             nopl   0x0\(%rax\)
 
 Disassembly of section .plt.got:
 
 0+1c0 <func@plt>:
- +[a-f0-9]+:   ff 25 32 fe 3f 00       jmp    \*0x3ffe32\(%rip\)        # 3ffff8 <func>
+ +[a-f0-9]+:   ff 25 1a fe 3f 00       jmp    \*0x3ffe1a\(%rip\)        # 3fffe0 <func>
  +[a-f0-9]+:   66 90                   xchg   %ax,%ax
 
 Disassembly of section .text:
 
 0+1c8 <foo>:
  +[a-f0-9]+:   e8 f3 ff ff ff          call   1c0 <func@plt>
- +[a-f0-9]+:   48 8b 05 24 fe 3f 00    mov    0x3ffe24\(%rip\),%rax        # 3ffff8 <func>
+ +[a-f0-9]+:   48 8b 05 0c fe 3f 00    mov    0x3ffe0c\(%rip\),%rax        # 3fffe0 <func>
 #pass
index 047adc174608fd56d391f33565c736b65496c42f..303a0242573e8c567f897513ed214c72072896b3 100644 (file)
@@ -42,19 +42,19 @@ Contents of the .eh_frame section:
 Disassembly of section .plt:
 
 0+120 <.plt>:
- +[a-f0-9]+:   ff 35 e2 fe 3f 00       push   0x3ffee2\(%rip\)        # 400008 <_GLOBAL_OFFSET_TABLE_\+0x8>
- +[a-f0-9]+:   ff 25 e4 fe 3f 00       jmp    \*0x3ffee4\(%rip\)        # 400010 <_GLOBAL_OFFSET_TABLE_\+0x10>
+ +[a-f0-9]+:   ff 35 ca fe 3f 00       push   0x3ffeca\(%rip\)        # 3ffff0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+ +[a-f0-9]+:   ff 25 cc fe 3f 00       jmp    \*0x3ffecc\(%rip\)        # 3ffff8 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 40 00             nopl   0x0\(%rax\)
 
 Disassembly of section .plt.got:
 
 0+130 <func@plt>:
- +[a-f0-9]+:   ff 25 c2 fe 3f 00       jmp    \*0x3ffec2\(%rip\)        # 3ffff8 <func>
+ +[a-f0-9]+:   ff 25 aa fe 3f 00       jmp    \*0x3ffeaa\(%rip\)        # 3fffe0 <func>
  +[a-f0-9]+:   66 90                   xchg   %ax,%ax
 
 Disassembly of section .text:
 
 0+138 <foo>:
  +[a-f0-9]+:   e8 f3 ff ff ff          call   130 <func@plt>
- +[a-f0-9]+:   48 8b 05 b4 fe 3f 00    mov    0x3ffeb4\(%rip\),%rax        # 3ffff8 <func>
+ +[a-f0-9]+:   48 8b 05 9c fe 3f 00    mov    0x3ffe9c\(%rip\),%rax        # 3fffe0 <func>
 #pass
index 070d37e5bcc824d00933a76cf77f2ec9db32bbe6..06e504ec9562d39fd2e26e9733d01a2db4758335 100644 (file)
@@ -49,19 +49,19 @@ Contents of the .eh_frame section:
 Disassembly of section .plt:
 
 0+1b0 <.plt>:
- +[a-f0-9]+:   ff 35 52 fe 3f 00       push   0x3ffe52\(%rip\)        # 400008 <_GLOBAL_OFFSET_TABLE_\+0x8>
- +[a-f0-9]+:   f2 ff 25 53 fe 3f 00    bnd jmp \*0x3ffe53\(%rip\)        # 400010 <_GLOBAL_OFFSET_TABLE_\+0x10>
+ +[a-f0-9]+:   ff 35 3a fe 3f 00       push   0x3ffe3a\(%rip\)        # 3ffff0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+ +[a-f0-9]+:   f2 ff 25 3b fe 3f 00    bnd jmp \*0x3ffe3b\(%rip\)        # 3ffff8 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 00                nopl   \(%rax\)
 
 Disassembly of section .plt.got:
 
 0+1c0 <func@plt>:
- +[a-f0-9]+:   f2 ff 25 31 fe 3f 00    bnd jmp \*0x3ffe31\(%rip\)        # 3ffff8 <func>
+ +[a-f0-9]+:   f2 ff 25 19 fe 3f 00    bnd jmp \*0x3ffe19\(%rip\)        # 3fffe0 <func>
  +[a-f0-9]+:   90                      nop
 
 Disassembly of section .text:
 
 0+1c8 <foo>:
  +[a-f0-9]+:   e8 f3 ff ff ff          call   1c0 <func@plt>
- +[a-f0-9]+:   48 8b 05 24 fe 3f 00    mov    0x3ffe24\(%rip\),%rax        # 3ffff8 <func>
+ +[a-f0-9]+:   48 8b 05 0c fe 3f 00    mov    0x3ffe0c\(%rip\),%rax        # 3fffe0 <func>
 #pass
index d6a9567364df0e83cb8c2a077239b2b71b139343..0e77d2c89d7aac1db1a551cff09f4abec73e0767 100644 (file)
@@ -49,8 +49,8 @@ Contents of the .eh_frame section:
 Disassembly of section .plt:
 
 0+1b0 <.plt>:
- +[a-f0-9]+:   ff 35 52 fe 3f 00       push   0x3ffe52\(%rip\)        # 400008 <_GLOBAL_OFFSET_TABLE_\+0x8>
- +[a-f0-9]+:   f2 ff 25 53 fe 3f 00    bnd jmp \*0x3ffe53\(%rip\)        # 400010 <_GLOBAL_OFFSET_TABLE_\+0x10>
+ +[a-f0-9]+:   ff 35 3a fe 3f 00       push   0x3ffe3a\(%rip\)        # 3ffff0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+ +[a-f0-9]+:   f2 ff 25 3b fe 3f 00    bnd jmp \*0x3ffe3b\(%rip\)        # 3ffff8 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 00                nopl   \(%rax\)
  +[a-f0-9]+:   68 00 00 00 00          push   \$0x0
  +[a-f0-9]+:   f2 e9 e5 ff ff ff       bnd jmp 1b0 <func@plt-0x20>
@@ -59,7 +59,7 @@ Disassembly of section .plt:
 Disassembly of section .plt.sec:
 
 0+1d0 <func@plt>:
- +[a-f0-9]+:   f2 ff 25 41 fe 3f 00    bnd jmp \*0x3ffe41\(%rip\)        # 400018 <func>
+ +[a-f0-9]+:   f2 ff 25 29 fe 3f 00    bnd jmp \*0x3ffe29\(%rip\)        # 400000 <func>
  +[a-f0-9]+:   90                      nop
 
 Disassembly of section .text:
index 6784d336a536d392f4be6f2e74bb8d8ca3160892..afbdb56086cd4b86e8dc81d2e2d61fe338277ddf 100644 (file)
@@ -58,8 +58,8 @@ Contents of the .eh_frame section:
 Disassembly of section .plt:
 
 0+1f0 <.plt>:
- +[a-f0-9]+:   ff 35 12 fe 3f 00       push   0x3ffe12\(%rip\)        # 400008 <_GLOBAL_OFFSET_TABLE_\+0x8>
- +[a-f0-9]+:   f2 ff 25 13 fe 3f 00    bnd jmp \*0x3ffe13\(%rip\)        # 400010 <_GLOBAL_OFFSET_TABLE_\+0x10>
+ +[a-f0-9]+:   ff 35 fa fd 3f 00       push   0x3ffdfa\(%rip\)        # 3ffff0 <_GLOBAL_OFFSET_TABLE_\+0x8>
+ +[a-f0-9]+:   f2 ff 25 fb fd 3f 00    bnd jmp \*0x3ffdfb\(%rip\)        # 3ffff8 <_GLOBAL_OFFSET_TABLE_\+0x10>
  +[a-f0-9]+:   0f 1f 00                nopl   \(%rax\)
  +[a-f0-9]+:   68 00 00 00 00          push   \$0x0
  +[a-f0-9]+:   f2 e9 e5 ff ff ff       bnd jmp 1f0 <func1@plt-0x20>
@@ -68,13 +68,13 @@ Disassembly of section .plt:
 Disassembly of section .plt.got:
 
 0+210 <func1@plt>:
- +[a-f0-9]+:   f2 ff 25 e1 fd 3f 00    bnd jmp \*0x3ffde1\(%rip\)        # 3ffff8 <func1>
+ +[a-f0-9]+:   f2 ff 25 c9 fd 3f 00    bnd jmp \*0x3ffdc9\(%rip\)        # 3fffe0 <func1>
  +[a-f0-9]+:   90                      nop
 
 Disassembly of section .plt.sec:
 
 0+218 <func2@plt>:
- +[a-f0-9]+:   f2 ff 25 f9 fd 3f 00    bnd jmp \*0x3ffdf9\(%rip\)        # 400018 <func2>
+ +[a-f0-9]+:   f2 ff 25 e1 fd 3f 00    bnd jmp \*0x3ffde1\(%rip\)        # 400000 <func2>
  +[a-f0-9]+:   90                      nop
 
 Disassembly of section .text:
@@ -82,5 +82,5 @@ Disassembly of section .text:
 0+220 <foo>:
  +[a-f0-9]+:   e8 eb ff ff ff          call   210 <func1@plt>
  +[a-f0-9]+:   e8 ee ff ff ff          call   218 <func2@plt>
- +[a-f0-9]+:   48 8b 05 c7 fd 3f 00    mov    0x3ffdc7\(%rip\),%rax        # 3ffff8 <func1>
+ +[a-f0-9]+:   48 8b 05 af fd 3f 00    mov    0x3ffdaf\(%rip\),%rax        # 3fffe0 <func1>
 #pass