PPC: call libm helpers via private GOT to fix linking with GCC 12+ - #271
Open
BKPepe wants to merge 1 commit into
Open
PPC: call libm helpers via private GOT to fix linking with GCC 12+#271BKPepe wants to merge 1 commit into
BKPepe wants to merge 1 commit into
Conversation
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
force-pushed
the
ppc-got-instead-of-plt
branch
from
August 15, 2026 09:17
908fad0 to
3bc16e0
Compare
Author
|
@glaubitz You might be interested in this one. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
bl sym@pltcall emitted by the VM assembler produces anR_PPC_PLTREL24relocation 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 linkinglibluajit.sofails outright:This currently prevents
luajit2from 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@pltand 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 upstreamluajitpackage as060-ppc-musl.patchsince 2022 (openwrt/packages#18793), extended with the soft-float helpers that the 2.1 branch needs in the GOT.luajit2never 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. NoR_PPC_PLTREL24relocations 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 thepowerpc_8548package builds and was installed and tested on the device.