Skip to content

luajit2: fix build and runtime on powerpc - #30280

Merged
BKPepe merged 1 commit into
openwrt:masterfrom
BKPepe:luajit2-powerpc-fixes
Aug 15, 2026
Merged

luajit2: fix build and runtime on powerpc#30280
BKPepe merged 1 commit into
openwrt:masterfrom
BKPepe:luajit2-powerpc-fixes

Conversation

@BKPepe

@BKPepe BKPepe commented Aug 15, 2026

Copy link
Copy Markdown
Member

📦 Package Details

Maintainer: @jmarcet

Description:

luajit2 cannot currently be built for powerpc — the link of libluajit.so fails with:

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

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. lang/lua/luajit has carried it as 060-ppc-musl.patch since 2019, extended with the soft-float helpers that the 2.1 branch needs in the GOT. luajit2 never got either version. Patch 050 ports it and keeps Clint Bland as the author of the commit.

With the package building again, two iteration paths turn out to be broken on 32-bit big-endian soft-float. Patches 030 and 040 fix those. Both are regressions introduced by openresty/luajit2@2763a421 and do not affect upstream LuaJIT.

The runtime fixes were verified with small Lua programs exercising both iteration functions:

local sum = 0
for _, v in ipairs({10, 20, 30}) do
    sum = sum + v
end
assert(sum == 60)
local expected = {7, 8, 9}
local i = 0
for k, v in pairs(expected) do
    i = i + 1
    assert(k == i and v == expected[i])
end
assert(i == 3)

Before the fixes, the ipairs() test produces -42 instead of 60, while pairs() yields an extra nil nil entry. With the fixes, both tests pass.

Test Before After
ipairs({10,20,30}) sum -42 60
pairs({7,8,9}) extra nil nil row correct
dynamically linked binary crashes at startup runs

Possibly related: openresty/luajit2#118 reports a powerpc startup crash. I could not reproduce that one — its backtrace is inside the glibc loader before main(), whereas the crash fixed by patch 050 happens after the loader has finished. Linking it here in case it turns out to be the same thing for the reporter.

The three patches will be submitted to openresty/luajit2 in parallel.


🧪 Run Testing Details

  • OpenWrt Version: installed the CI-built luajit2-2.1.2026.02.27-r2.apk on the device and ran the tests above — ipairs returns 60, pairs iterates cleanly, math.sin/math.sqrt are correct and the JIT is enabled. Since this is a BUILDMODE=dynamic package, it also confirms the PLT fix in the real packaging configuration.
  • OpenWrt Target/Subtarget: mpc85xx / p2020 (powerpc_8548)
  • OpenWrt Device: Turris 1.0 / 1.1 (e500v2, big-endian, musl, soft-float)

Tested on real hardware, not only as a cross-compile/CI build. The same ipairs() misbehaviour was also confirmed against TurrisOS 9.1 on the same device, where the distro's upstream LuaJIT (luajit 2.1.0-beta3-r7) returns the correct results — which is what pinned these down as luajit2-only regressions.


✅ Formalities

  • I have reviewed the CONTRIBUTING.md file for detailed contributing guidelines.

If your PR contains a patch:

  • It can be applied using git am
  • It has been refreshed to avoid offsets, fuzzes, etc., using
    make package/<your-package>/refresh V=s
  • It is structured in a way that it is potentially upstreamable

Draft — opened to get a powerpc_8548 CI build and a package to test on real hardware before submitting the patches upstream.

@BKPepe
BKPepe force-pushed the luajit2-powerpc-fixes branch from dc3279c to 278d80b Compare August 15, 2026 07:13
@BKPepe
BKPepe force-pushed the luajit2-powerpc-fixes branch from 278d80b to 8ea5f7d Compare August 15, 2026 07:30
@BKPepe
BKPepe marked this pull request as ready for review August 15, 2026 09:05
Copilot AI lite review requested due to automatic review settings August 15, 2026 09:05

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.

luajit2 currently fails to link for powerpc: lj_vm.o emits PLT calls
that force BSS-PLT, which the inline-PLT relocations emitted by GCC 12
and newer do not support. Add the same GOT-based fix that
lang/lua/luajit has carried as 060-ppc-musl.patch since 2019.

With that in place the package builds, but ipairs() and pairs() turn
out to be broken on 32-bit big-endian soft-float targets. Both are
regressions in luajit2's PPC64 patch and do not affect upstream
LuaJIT. To be submitted to openresty/luajit2 as well.

Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
@BKPepe
BKPepe force-pushed the luajit2-powerpc-fixes branch from 8ea5f7d to 475ad1b Compare August 15, 2026 09:21
@BKPepe
BKPepe merged commit a6b248d into openwrt:master Aug 15, 2026
12 of 14 checks passed
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.

2 participants