Page MenuHomePhabricator

[ELF][PPC32] Implement IPLT code sequence for non-preemptible IFUNC
ClosedPublic

Authored by MaskRay on Dec 17 2019, 11:23 AM.

Details

Summary

Similar to D71509 (EM_PPC64), on EM_PPC, the IPLT code sequence should
be similar to a PLT call stub. Unlike EM_PPC64, EM_PPC -msecure-plt has
small/large PIC model differences.

  • -fpic/-fpie: R_PPC_PLTREL24 r_addend=0. The call stub loads an address relative to _GLOBAL_OFFSET_TABLE_.
  • -fPIC/-fPIE: R_PPC_PLTREL24 r_addend=0x8000. (A partial linked object file may have an addend larger than 0x8000.) The call stub loads an address relative to .got2+0x8000.

Just assume large PIC model for now. This patch makes:

// clang -fuse-ld=lld -fno-pie -no-pie a.c
// clang -fuse-ld=lld -fPIE -pie a.c
#include <stdio.h>
static void impl(void) { puts("meow"); }
void thefunc(void) __attribute__((ifunc("resolver")));
void *resolver(void) { return &impl; }
int main(void) {
  thefunc();
  void (*theptr)(void) = &thefunc;
  theptr();
}

work. -fpie will crash.

Diff Detail

Event Timeline

MaskRay created this revision.Dec 17 2019, 11:23 AM
MaskRay updated this revision to Diff 234390.Dec 17 2019, 2:30 PM

Make -fPIE -pie work

MaskRay updated this revision to Diff 234399.Dec 17 2019, 3:02 PM

Properly rebase on top of D71509

MaskRay updated this revision to Diff 234409.Dec 17 2019, 3:51 PM
MaskRay edited the summary of this revision. (Show Details)
MaskRay added reviewers: Restricted Project, Bdragon28, sfertile, ruiu.
MaskRay removed a subscriber: wuzish.

Add tests

MaskRay edited the summary of this revision. (Show Details)Dec 17 2019, 3:53 PM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 29 2019, 10:53 PM
This revision was automatically updated to reflect the committed changes.