Skip to content

Commit

Permalink
process DT_RELR relocations in ldso-startup/static-pie
Browse files Browse the repository at this point in the history
commit d32dadd added DT_RELR
processing for programs and shared libraries processed by the dynamic
linker, but left them unsupported in the dynamic linker itseld and in
static pie binaries, which self-relocate via code in dlstart.c.

add the equivalent processing to this code path so that there are not
arbitrary restrictions on where the new packed relative relocation
form can be used.
  • Loading branch information
richfelker committed Sep 12, 2022
1 parent 25085c8 commit 6f3ead0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ldso/dlstart.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ hidden void _dlstart_c(size_t *sp, size_t *dynv)
size_t *rel_addr = (void *)(base + rel[0]);
*rel_addr = base + rel[2];
}

rel = (void *)(base+dyn[DT_RELR]);
rel_size = dyn[DT_RELRSZ];
size_t *relr_addr = 0;
for (; rel_size; rel++, rel_size-=sizeof(size_t)) {
if ((rel[0]&1) == 0) {
relr_addr = (void *)(base + rel[0]);
*relr_addr++ += base;
} else {
for (size_t i=0, bitmap=rel[0]; bitmap>>=1; i++)
if (bitmap&1)
relr_addr[i] += base;
relr_addr += 8*sizeof(size_t)-1;
}
}
#endif

stage2_func dls2;
Expand Down

0 comments on commit 6f3ead0

Please sign in to comment.