Skip to content

Comments

only enable emulated TLS on android compiling natively in termux#2974

Merged
lerno merged 2 commits intoc3lang:masterfrom
Book-reader:fix-android-cross-compile
Feb 23, 2026
Merged

only enable emulated TLS on android compiling natively in termux#2974
lerno merged 2 commits intoc3lang:masterfrom
Book-reader:fix-android-cross-compile

Conversation

@Book-reader
Copy link
Member

@Book-reader Book-reader commented Feb 23, 2026

sooo... turns out that the android NDK doesn't support emulated TLS, and that executables compiled with it don't have the misaligned TLS segment issue.

tlocal int x;
fn int main()
{
  return $$volatile_load(&x);
}
$ c3c compile test.c3 --target android-aarch64 --android-ndk ~/Android/Sdk/ndk/27.0.12077973/ --android-api 35 --use-stdlib=no
ld.lld: error: undefined symbol: __emutls_get_address
>>> referenced by test.c3:4
>>>               /tmp/nix-shell.e1Tb18/c3cX10fuTQ/obj/android-aarch64/test.o:(main)
Failed to create an executable: (null)

this fixes it so that both natively compiled & cross compiled executables can be compiled and will work in termux.
I am not completely certain of the reason why executables compiled in termux have a misaligned tls segment but ones compiled with the NDK don't, but apparently there is something that the android NDK does specifically to prevent the TLS alignment issues that the libraries in termux don't do.

I have verified that with this change, programs compiled both in termux and with the NDK are able to be run in termux without issue, including ones that use the stdlib and thread-locals

@lerno lerno merged commit 58022e7 into c3lang:master Feb 23, 2026
2 of 22 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