6f3ead0ae16deb9f0004b275e29a276c9712ee3c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From 6f3ead0ae16deb9f0004b275e29a276c9712ee3c Mon Sep 17 00:00:00 2001
  2. From: Rich Felker <dalias@aerifal.cx>
  3. Date: Mon, 12 Sep 2022 08:30:36 -0400
  4. Subject: process DT_RELR relocations in ldso-startup/static-pie
  5. commit d32dadd60efb9d3b255351a3b532f8e4c3dd0db1 added DT_RELR
  6. processing for programs and shared libraries processed by the dynamic
  7. linker, but left them unsupported in the dynamic linker itseld and in
  8. static pie binaries, which self-relocate via code in dlstart.c.
  9. add the equivalent processing to this code path so that there are not
  10. arbitrary restrictions on where the new packed relative relocation
  11. form can be used.
  12. ---
  13. ldso/dlstart.c | 15 +++++++++++++++
  14. 1 file changed, 15 insertions(+)
  15. diff --git a/ldso/dlstart.c b/ldso/dlstart.c
  16. index 20d50f2c..259f5e18 100644
  17. --- a/ldso/dlstart.c
  18. +++ b/ldso/dlstart.c
  19. @@ -140,6 +140,21 @@ hidden void _dlstart_c(size_t *sp, size_t *dynv)
  20. size_t *rel_addr = (void *)(base + rel[0]);
  21. *rel_addr = base + rel[2];
  22. }
  23. +
  24. + rel = (void *)(base+dyn[DT_RELR]);
  25. + rel_size = dyn[DT_RELRSZ];
  26. + size_t *relr_addr = 0;
  27. + for (; rel_size; rel++, rel_size-=sizeof(size_t)) {
  28. + if ((rel[0]&1) == 0) {
  29. + relr_addr = (void *)(base + rel[0]);
  30. + *relr_addr++ += base;
  31. + } else {
  32. + for (size_t i=0, bitmap=rel[0]; bitmap>>=1; i++)
  33. + if (bitmap&1)
  34. + relr_addr[i] += base;
  35. + relr_addr += 8*sizeof(size_t)-1;
  36. + }
  37. + }
  38. #endif
  39. stage2_func dls2;
  40. --
  41. cgit v1.2.1