Skip to content

Commit c9cf7bd

Browse files
committedJun 25, 2024
aarch64: Add DT_RELR support for ILP32 ABI
Extend the 64bit DT_RELR support to work on 32bit ELF too. For this only a few changes were needed in the sizing and creation of the relr relocations.
1 parent bd54c88 commit c9cf7bd

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed
 

‎bfd/elfnn-aarch64.c

+21-16
Original file line numberDiff line numberDiff line change
@@ -9451,6 +9451,11 @@ sort_relr (struct bfd_link_info *info,
94519451
return true;
94529452
}
94539453

9454+
/* Size of a relr entry and a relocated location. */
9455+
#define RELR_SZ (ARCH_SIZE / 8)
9456+
/* Number of consecutive locations a relr bitmap entry references. */
9457+
#define RELR_N (ARCH_SIZE - 1)
9458+
94549459
/* Size .relr.dyn whenever the layout changes, the number of packed
94559460
relocs are unchanged but the packed representation can. */
94569461

@@ -9473,19 +9478,19 @@ elfNN_aarch64_size_relative_relocs (struct bfd_link_info *info,
94739478
{
94749479
bfd_vma base = addr[i];
94759480
i++;
9476-
srelrdyn->size += 8;
9477-
base += 8;
9481+
srelrdyn->size += RELR_SZ;
9482+
base += RELR_SZ;
94789483
for (;;)
94799484
{
94809485
bfd_size_type start_i = i;
94819486
while (i < htab->relr_count
9482-
&& addr[i] - base < 63 * 8
9483-
&& (addr[i] - base) % 8 == 0)
9487+
&& addr[i] - base < RELR_N * RELR_SZ
9488+
&& (addr[i] - base) % RELR_SZ == 0)
94849489
i++;
94859490
if (i == start_i)
94869491
break;
9487-
srelrdyn->size += 8;
9488-
base += 63 * 8;
9492+
srelrdyn->size += RELR_SZ;
9493+
base += RELR_N * RELR_SZ;
94899494
}
94909495
}
94919496
if (srelrdyn->size != oldsize)
@@ -9522,34 +9527,34 @@ elfNN_aarch64_finish_relative_relocs (struct bfd_link_info *info)
95229527
{
95239528
bfd_vma base = addr[i];
95249529
i++;
9525-
bfd_put_64 (dynobj, base, loc);
9526-
loc += 8;
9527-
base += 8;
9530+
bfd_put_NN (dynobj, base, loc);
9531+
loc += RELR_SZ;
9532+
base += RELR_SZ;
95289533
for (;;)
95299534
{
95309535
bfd_vma bits = 0;
95319536
while (i < htab->relr_count)
95329537
{
95339538
bfd_vma delta = addr[i] - base;
9534-
if (delta >= 63 * 8 || delta % 8 != 0)
9539+
if (delta >= RELR_N * RELR_SZ || delta % RELR_SZ != 0)
95359540
break;
9536-
bits |= (bfd_vma) 1 << (delta / 8);
9541+
bits |= (bfd_vma) 1 << (delta / RELR_SZ);
95379542
i++;
95389543
}
95399544
if (bits == 0)
95409545
break;
9541-
bfd_put_64 (dynobj, (bits << 1) | 1, loc);
9542-
loc += 8;
9543-
base += 63 * 8;
9546+
bfd_put_NN (dynobj, (bits << 1) | 1, loc);
9547+
loc += RELR_SZ;
9548+
base += RELR_N * RELR_SZ;
95449549
}
95459550
}
95469551
free (addr);
95479552
htab->relr_sorted = NULL;
95489553
/* Pad any excess with 1's, a do-nothing encoding. */
95499554
while (loc < srelrdyn->contents + srelrdyn->size)
95509555
{
9551-
bfd_put_64 (dynobj, 1, loc);
9552-
loc += 8;
9556+
bfd_put_NN (dynobj, 1, loc);
9557+
loc += RELR_SZ;
95539558
}
95549559
return true;
95559560
}

‎ld/emulparams/aarch64elf32.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
source_sh ${srcdir}/emulparams/dt-relr.sh
2+
13
ARCH="aarch64:ilp32"
24
MACHINE=
35
NOP=0x1f2003d5

‎ld/emulparams/aarch64linux32.sh

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
source_sh ${srcdir}/emulparams/dt-relr.sh
2+
13
ARCH="aarch64:ilp32"
24
MACHINE=
35
NOP=0x1f2003d5

0 commit comments

Comments
 (0)