Skip to content

[SPARC64] PLT relocations might point to the wrong place when linking #1529

@koachan

Description

@koachan

This is another case I found when building LLVM. I found that PLT relocations might end up pointing somewhere else after linking.
For example, in this snippet:

  88:   f8 5e 00 00     ldx  [ %i0 ], %i4
  8c:   c2 5f a6 97     ldx  [ %fp + 0x697 ], %g1
  90:   fa 5d c0 01     ldx  [ %l7 + %g1 ], %i5
                        90: R_SPARC_GOTDATA_OP  TLS init function for llvm::parallel::threadIndex
  94:   02 c7 40 04     brz,pn   %i5, a4 <(anonymous namespace)::ConcurrentHashTableTest_AddStringMultiplueEntriesWithResize_Test::TestBody()::{lambda()#1}::operator()() const+0xa4>
  98:   01 00 00 00     nop 
  9c:   40 00 00 00     call  9c <(anonymous namespace)::ConcurrentHashTableTest_AddStringMultiplueEntriesWithResize_Test::TestBody()::{lambda()#1}::operator()() const+0x9c>
                        9c: R_SPARC_WPLT30      TLS init function for llvm::parallel::threadIndex
  a0:   01 00 00 00     nop 
  a4:   40 00 00 00     call  a4 <(anonymous namespace)::ConcurrentHashTableTest_AddStringMultiplueEntriesWithResize_Test::TestBody()::{lambda()#1}::operator()() const+0xa4>
                        a4: R_SPARC_TLS_GD_CALL llvm::parallel::threadIndex
  a8:   d0 5f a6 9f     ldx  [ %fp + 0x69f ], %o0
  ac:   c2 02 00 00     ld  [ %o0 ], %g1

After linking with mold, the R_SPARC_WPLT30 call points to another place, causing crashes during runtime:

  488000:       f8 5e 00 00     ldx  [ %i0 ], %i4
  488004:       c2 5f a6 97     ldx  [ %fp + 0x697 ], %g1
  488008:       01 00 00 00     nop 
  48800c:       02 c7 40 04     brz,pn   %i5, 48801c <(anonymous namespace)::ConcurrentHashTableTest_AddStringMultiplueEntriesWithResize_Test::TestBody()::{lambda()#1}::operator()() const+0xa4>
  488010:       01 00 00 00     nop 
  488014:       7f ed df fb     call  0 <SmallSetTest_Grow_Test::~SmallSetTest_Grow_Test()>
  488018:       01 00 00 00     nop 
  48801c:       90 01 c0 08     add  %g7, %o0, %o0
  488020:       d0 5f a6 9f     ldx  [ %fp + 0x69f ], %o0
  488024:       c2 02 00 00     ld  [ %o0 ], %g1

For comparison this is the same code after linking with GNU ld, with the call pointing to the symbol's entry in the PLT:

  4101e0:       f8 5e 00 00     ldx  [ %i0 ], %i4
  4101e4:       c2 5f a6 97     ldx  [ %fp + 0x697 ], %g1
  4101e8:       fa 5d c0 01     ldx  [ %l7 + %g1 ], %i5
  4101ec:       02 c7 40 04     brz,pn   %i5, 4101fc <(anonymous namespace)::ConcurrentHashTableTest_AddStringMultiplueEntriesWithResize_Test::TestBody()::{lambda()#1}::operator()() const+0xa4>
  4101f0:       01 00 00 00     nop 
  4101f4:       40 1f c2 fb     call  c00de0 <TLS init function for llvm::parallel::threadIndex@plt>
  4101f8:       01 00 00 00     nop 
  4101fc:       01 00 00 00     nop 
  410200:       d0 5f a6 9f     ldx  [ %fp + 0x69f ], %o0
  410204:       c2 02 00 00     ld  [ %o0 ], %g1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions