Skip to content

[CMAKE] Disable PIE when fixing Box64 load address - #4362

Merged
ptitSeb merged 1 commit into
ptitSeb:mainfrom
VoltrexKeyva:addnopie
Sep 6, 2026
Merged

[CMAKE] Disable PIE when fixing Box64 load address#4362
ptitSeb merged 1 commit into
ptitSeb:mainfrom
VoltrexKeyva:addnopie

Conversation

@VoltrexKeyva

@VoltrexKeyva VoltrexKeyva commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

When Box64 is built with Clang on distributions where PIE is enabled by default, the current CMake configuration can produce a PIE executable even though Box64 is linked with --image-base=0x34800000.

--image-base does not disable PIE with Clang/LLD, so the resulting ET_DYN executable can be relocated to a high address at runtime.

This breaks Box32 because some Box32 data structures must be addressable through 32-bit pointers. For example, wrappedlibc converts the address of its ctype tables with to_ptrv(), which rejects host pointers above 32 bits and aborts.

For reproduction I tested on Debian 13 Arm64 with Clang/LLD:

Both Box64 v0.4.4 branch and latest main branch with
-DARM_DYNAREC=ON -DBOX32=ON -DBOX32_BINFMT=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo

and the resulting executable is Type: DYN (Shared object file) with a preferred load address of 0x34800000, but is relocated to a high 0xaaaa... address at runtime. Box32 then aborts during wrappedlibc_init32():

[BOX32] Warning, pointer 0xaaaa... is not a 32bits value

The failure was localized with LLDB to:

box64_abort
-> to_ptrv()
-> ctSetup()
-> wrappedlibc_init32()


Adding -no-pie to the link flags changes the executable to Type: EXEC (Executable file) and keeps it at the intended 0x34800000 load address, SteamCMD then starts successfully.

So pass -no-pie whenever the Clang/mold link path uses the fixed Box64 image base. NOLOADADDR=ON remains an explicit opt-out, so builds that request an unfixed load address are unaffected.

Android is explicitly excluded because Android 5.0 and later require position-independent executables. The existing --image-base option remains unchanged for Android builds.

Verified as working with Clang/LLD and GCC + ld (GNU ld part is unchanged).

@ptitSeb

ptitSeb commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Android builds are broken, because they need PIE...

@VoltrexKeyva

Copy link
Copy Markdown
Contributor Author

Android builds are broken, because they need PIE...

Added a condition to keep PIE when targeting Android.

--image-base does not disable PIE with Clang/LLD, allowing Box64 to
be relocated above the 32-bit address range used by Box32.

Pass -no-pie whenever the fixed Box64 image base is used unless the
target is Android.
@ptitSeb
ptitSeb merged commit b5697f4 into ptitSeb:main Sep 6, 2026
28 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