Skip to content

Instantly share code, notes, and snippets.

@MaskRay
Created February 24, 2024 02:47
Show Gist options
  • Save MaskRay/11f33f43f8d2a94949f687d9042c0ffd to your computer and use it in GitHub Desktop.
Save MaskRay/11f33f43f8d2a94949f687d9042c0ffd to your computer and use it in GitHub Desktop.
FDPIC -fno-plt
void f0(void);
void f1(void);
void f2(void);
void g() { f0(); f1(); f2(); }
g:
  push    {r4, lr}
  mov     r4, r9
  bl      f(PLT)
  mov     r9, r4
  bl      f(PLT)
  mov     r9, r4
  pop     {r4, lr}
  b       f(PLT)

If GCC implements -fno-plt, it can use the following code sequence:

g:
  push    {r4, lr}
  mov     r4, r9
  // call f0
  ldr     r12, .L0
  add     r12, r12, r4
  ldr     r9, [r12, #4]
  ldr     pc, [r12]
  // call f1
  ldr     r12, .L1
  add     r12, r12, r4
  ldr     r9, [r12, #4]
  ldr     pc, [r12]
  // tail call f2
  ldr     r12, .L2
  add     r12, r12, r4
  ldr     r9, [r12, #4]
  pop     {r4, lr}
  ldr     pc, [r12]

.L0: .word f0(GOTOFFFUNCDESC)
.L1: .word f1(GOTOFFFUNCDESC)
.L2: .word f2(GOTOFFFUNCDESC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment