[PATCH] D102985: [lld][ELF][SPARC] Fix GOT-relative relocations

LemonBoy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 20 08:59:50 PDT 2021


LemonBoy added a comment.

In D102985#2827315 <https://reviews.llvm.org/D102985#2827315>, @MaskRay wrote:

> Is dynamic linking fully functional?

Sort of. I managed to link and run (under Qemu) a dynamically-linked PIE executable after applying a few more touch-ups, the idea is to turn this patchset into one targeting GOT/PLT support, as you suggested.
No updated patch was uploaded because I've hit a problem with (I think) how LLD handles GOT entries and how SPARC GOTDATA <https://binutils.sourceware.narkive.com/zsExLDV1/patch-sparc-gotdata-optimizations> relocations are supposed to work. At the moment the plan is to avoid implementing the GOTDATA optimizations and treat them as regular GOT-relative relocations instead.
Below you can find the set of relocations emitted by GCC for a small hello-world program, the six GOTDATA triplets reference six different objects in the `.rodata` sections ... by means of a `STT_SECTION` reference with non-zero addend. Since all the six relocations point to the same symbol LLD generates a single GOT entry (every call to `isInGot` returns true) and that generates binaries that are crashing at runtime.

As you can see the code sequence for this kind of relocation expects a single GOT entry for each relocation w/ different addends:

  sethi %gdop_hix22(symbol), %l1
  xor   %l1, %gdop_lox10(symbol), %l1
  ld    [%l7 + %l1], %l2, %gdop(symbol)

I'm open to suggestions on how to overcome this problem, of course relaxing this relocation kind solves the problem at hand (even though that opens another can of worms, `RelExpr` already has 64 elements and `RelExprMaskBuilder` requires some work to accommodate more entries) but I wonder if that'd be only papering over a bigger problem.

  Section (3) .rela.text {
    0x4 R_SPARC_PC22 _GLOBAL_OFFSET_TABLE_ 0xFFFFFFFFFFFFFFF8
    0x8 R_SPARC_PC10 _GLOBAL_OFFSET_TABLE_ 0xFFFFFFFFFFFFFFFC
    0xC R_SPARC_WPLT30 __sparc_get_pc_thunk.l7 0x0
    0x24 R_SPARC_GOTDATA_OP_HIX22 .rodata 0x0
    0x28 R_SPARC_GOTDATA_OP_LOX10 .rodata 0x0
    0x2C R_SPARC_GOTDATA_OP .rodata 0x0
    0x34 R_SPARC_WPLT30 puts 0x0
    0x3C R_SPARC_GOTDATA_OP_HIX22 .rodata 0x10
    0x40 R_SPARC_GOTDATA_OP_LOX10 .rodata 0x10
    0x44 R_SPARC_GOTDATA_OP .rodata 0x10
    0x4C R_SPARC_GOTDATA_OP_HIX22 .rodata 0x18
    0x50 R_SPARC_GOTDATA_OP_LOX10 .rodata 0x18
    0x54 R_SPARC_GOTDATA_OP .rodata 0x18
    0x5C R_SPARC_WPLT30 fopen 0x0
    0x74 R_SPARC_GOTDATA_OP_HIX22 .rodata 0x28
    0x78 R_SPARC_GOTDATA_OP_LOX10 .rodata 0x28
    0x7C R_SPARC_GOTDATA_OP .rodata 0x28
    0x84 R_SPARC_WPLT30 puts 0x0
    0x98 R_SPARC_GOTDATA_OP_HIX22 .rodata 0x30
    0x9C R_SPARC_GOTDATA_OP_LOX10 .rodata 0x30
    0xA0 R_SPARC_GOTDATA_OP .rodata 0x30
    0xA8 R_SPARC_WPLT30 fwrite 0x0
    0xB4 R_SPARC_WPLT30 fclose 0x0
    0xBC R_SPARC_GOTDATA_OP_HIX22 .rodata 0x38
    0xC0 R_SPARC_GOTDATA_OP_LOX10 .rodata 0x38
    0xC4 R_SPARC_GOTDATA_OP .rodata 0x38
    0xCC R_SPARC_WPLT30 puts 0x0
  }


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102985/new/

https://reviews.llvm.org/D102985



More information about the llvm-commits mailing list