diff options
author | 2022-06-24 13:25:45 +0930 | |
---|---|---|
committer | 2022-06-27 12:28:59 +0930 | |
commit | 648f6099d4dcadf446f3f00790ad4b16dd4042f6 (patch) | |
tree | f806f1f5fa08ad7937c657b8f5107c05afbfee97 /ld/ldexp.c | |
parent | Automatic date update in version.in (diff) | |
download | binutils-gdb-648f6099d4dcadf446f3f00790ad4b16dd4042f6.tar.gz binutils-gdb-648f6099d4dcadf446f3f00790ad4b16dd4042f6.tar.bz2 binutils-gdb-648f6099d4dcadf446f3f00790ad4b16dd4042f6.zip |
-z relro relaxation and ld script SIZEOF
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.
Diffstat (limited to 'ld/ldexp.c')
-rw-r--r-- | ld/ldexp.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ld/ldexp.c b/ld/ldexp.c index c18b8284ca5..d4d8706968d 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -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; |