Skip to content

PPC: call libm helpers via private GOT to fix linking with GCC 12+ - #271

Open
BKPepe wants to merge 1 commit into
openresty:v2.1-agentzhfrom
BKPepe:ppc-got-instead-of-plt
Open

PPC: call libm helpers via private GOT to fix linking with GCC 12+#271
BKPepe wants to merge 1 commit into
openresty:v2.1-agentzhfrom
BKPepe:ppc-got-instead-of-plt

Conversation

@BKPepe

@BKPepe BKPepe commented Aug 15, 2026

Copy link
Copy Markdown

A bl sym@plt call emitted by the VM assembler produces an R_PPC_PLTREL24 relocation with addend 0, which forces the linker to use BSS-PLT for the entire link. GCC 12 and newer emit inline-PLT relocations (R_PPC_PLTSEQ, R_PPC_PLTCALL, R_PPC_PLT16_*) that have no BSS-PLT equivalent, so linking libluajit.so fails outright:

ld: bss-plt forced due to lj_vm.o
ld: crtstuff.c:(.text+0x46): R_PPC_PLT16_HA relocation unsupported for bss-plt

This currently prevents luajit2 from linking for powerpc in the OpenWrt package build.

The same root cause has a second, quieter manifestation on older toolchains. With GCC 11 the link succeeds and only warns (bss-plt forced due to lj_vm.o), but the resulting dynamically linked binary crashes during startup on this target. A static build of the same tree is unaffected. Both the link failure and the startup crash go away with this patch.

Provenance

Upstream LuaJIT has the same bl extern target@plt and is affected too. Clint Bland proposed this fix upstream in LuaJIT/LuaJIT#486, made against 2.0 and addressing LuaJIT/LuaJIT#481, and it was closed without being merged. OpenWrt has carried it for the upstream luajit package as 060-ppc-musl.patch since 2022 (openwrt/packages#18793), extended with the soft-float helpers that the 2.1 branch needs in the GOT. luajit2 never got either version.

This is that patch, adapted for luajit2. The commit keeps Clint Bland as its author.

Verification

Tested on Turris 1.x (e500v2, musl, soft-float) with BUILDMODE=dynamic. No R_PPC_PLTREL24 relocations remain and the resulting binary runs correctly, including all libm calls now routed through the new GOT. The fix is also carried in openwrt/packages#30280, where the powerpc_8548 package builds and was installed and tested on the device.

Copilot AI lite review requested due to automatic review settings August 15, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

A bl sym@plt call emitted by the VM assembler produces an
R_PPC_PLTREL24 relocation with addend 0, which forces the linker to
use BSS-PLT for the entire link. GCC 12 and newer emit inline-PLT
relocations (R_PPC_PLTSEQ, R_PPC_PLTCALL, R_PPC_PLT16_*) that have no
BSS-PLT equivalent, so linking libluajit.so fails outright:

  ld: bss-plt forced due to lj_vm.o
  ld: crtstuff.c:(.text+0x46): R_PPC_PLT16_HA relocation unsupported
      for bss-plt

Route these calls through a private GOT stored in GG_State, the way
the MIPS port already does. No PLT relocation is emitted, the linker
selects secure-PLT and the link succeeds.

Originally submitted upstream as LuaJIT/LuaJIT#486, against 2.0 and
addressing LuaJIT/LuaJIT#481, and closed without being merged. OpenWrt
has carried it for the upstream luajit package as 060-ppc-musl.patch
since 2019, extended with the soft-float helpers the 2.1 branch needs
in the GOT. Adapted here for luajit2 and verified on OpenWrt.

Tested on Turris 1.x (e500v2, 32-bit big-endian, musl, soft-float)
with BUILDMODE=dynamic. No R_PPC_PLTREL24 relocations remain, and the
resulting binary runs correctly, including all libm calls routed
through the new GOT. The previously produced dynamic binary crashed
during startup.

Co-authored-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
@BKPepe
BKPepe force-pushed the ppc-got-instead-of-plt branch from 908fad0 to 3bc16e0 Compare August 15, 2026 09:17
@BKPepe

BKPepe commented Aug 15, 2026

Copy link
Copy Markdown
Author

@glaubitz You might be interested in this one. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants