Skip to content

Commit 9eb71a5

Browse files
committed
x86-64: Allocate input section memory if needed
When --no-keep-memory is used, the input section memory may not be cached. Allocate input section memory for -z pack-relative-relocs if needed. bfd/ PR ld/29939 * elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Allocate input section memory if needed. ld/ PR ld/29939 * testsuite/ld-elf/dt-relr-2i.d: New test.
1 parent 767e2da commit 9eb71a5

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

bfd/elfxx-x86.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,12 +1541,33 @@ elf_x86_size_or_finish_relative_reloc
15411541
}
15421542
else
15431543
{
1544+
bfd_byte *contents;
1545+
15441546
if (rel.r_offset >= sec->size)
15451547
abort ();
1548+
1549+
if (elf_section_data (sec)->this_hdr.contents
1550+
!= NULL)
1551+
contents
1552+
= elf_section_data (sec)->this_hdr.contents;
1553+
else
1554+
{
1555+
if (!bfd_malloc_and_get_section (sec->owner,
1556+
sec,
1557+
&contents))
1558+
info->callbacks->einfo
1559+
/* xgettext:c-format */
1560+
(_("%F%P: %pB: failed to allocate memory for section `%pA'\n"),
1561+
info->output_bfd, sec);
1562+
1563+
/* Cache the section contents for
1564+
elf_link_input_bfd. */
1565+
elf_section_data (sec)->this_hdr.contents
1566+
= contents;
1567+
}
15461568
htab->elf_write_addend
15471569
(info->output_bfd, outrel->r_addend,
1548-
(elf_section_data (sec)->this_hdr.contents
1549-
+ rel.r_offset));
1570+
contents + rel.r_offset);
15501571
}
15511572
}
15521573
}

ld/testsuite/ld-elf/dt-relr-2i.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#source: dt-relr-2.s
2+
#ld: -e _start -pie --no-keep-memory $DT_RELR_LDFLAGS
3+
#readelf: -rW -d
4+
#target: [supports_dt_relr]
5+
6+
#...
7+
0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+
8+
0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\)
9+
0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\)
10+
#...
11+
Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry:
12+
#...
13+
[0-9a-f]+ +[0-9a-f]+ +R_.*_(RELATIVE|UADDR.*) .*
14+
#...
15+
Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries:
16+
4 offsets
17+
#pass

0 commit comments

Comments
 (0)