Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang: Executable's TLS segment is underaligned #8273

Closed
Kyliekyler opened this issue Dec 18, 2021 · 9 comments
Closed

Clang: Executable's TLS segment is underaligned #8273

Kyliekyler opened this issue Dec 18, 2021 · 9 comments
Labels
bug report Something is not working properly

Comments

@Kyliekyler
Copy link

Problem description

I've been using clang for quite a while now and using dynamic binaries, and now as I've tried compiling using -static flag it throws me this error on binary execution

executable's TLS segment is underaligned: alignment is 8, needs to be at least 32 for ARM Bionic

What steps will reproduce the bug?

Compile binaries statically and run on an Android 12 device.

What is the expected behavior?

No response

System information

termux-info:

Termux Version: 0.117 (F-Droid)
System Information: AOSP Android 12 (Arm64-v8a)
Device Information: POCO X3 NFC
@Kyliekyler Kyliekyler added the bug report Something is not working properly label Dec 18, 2021
@Grimler91
Copy link
Member

Please provide the full output of termux-info.

I can reproduce it on aarch64, and also when cross-compiling with ndk r23, so we should open an issue in the android/ndk repo as well

@Kyliekyler
Copy link
Author

Please provide the full output of termux-info.

I can reproduce it on aarch64, and also when cross-compiling with ndk r23, so we should open an issue in the android/ndk repo as well

Oh my bad I didn't knew it was a command, heres the output

Application version:
0.117
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://grimler.se/termux-packages-24/ stable main
# game-repo (sources.list.d/game.list)
deb https://packages.termux.org/apt/termux-games games stable
# science-repo (sources.list.d/science.list)
deb https://packages.termux.org/apt/termux-science science stable
# sources.list.d/pointless.list
deb https://its-pointless.github.io/files/24 termux extras
# root-repo (sources.list.d/root.list)
deb https://packages.termux.org/apt/termux-root root stable
Updatable packages:
All packages up to date
Android version:
12
Kernel build information:
Linux localhost 4.14.190-QuicksilveR-perf-surya/e12ec1c9 #3 SMP PREEMPT Sun Nov 28 17:37:12 IST 2021 aarch64 Android
Device manufacturer:
Xiaomi
Device model:
M2007J20CG

And yes I was cross-compiling, thanks and I'll give them a bugreport too :)

@Grimler91
Copy link
Member

And yes I was cross-compiling

Arm64-v8a combined with at least 32 for ARM Bionic seemed weird, so that explains that.

Cross-compiling with the ndk and testing on arm, or compiling on arm, gives the same error. This could be, or probably is, a limitation of the static libc used, as @xeffyr discussed here

@lzhiyong
Copy link

lzhiyong commented Dec 19, 2021

static compilation for Android api level < 29 (api>=29 should works, the termux default api level is 24)

Way 1

Way 2

  • use align_fix.py(only arm/arm64), execute the command align_fix.py your executable file

@Kyliekyler
Copy link
Author

And yes I was cross-compiling

Arm64-v8a combined with at least 32 for ARM Bionic seemed weird, so that explains that.

Cross-compiling with the ndk and testing on arm, or compiling on arm, gives the same error. This could be, or probably is, a limitation of the static libc used, as @xeffyr discussed here

Yeah it was weird that I also compiles for 32bit whereas most phones this day running on 64bit at this Android 12. Though I need it for older Android versions to work too down to Android Lollipop. Anyway thanks for such a fast response, cheers 🥂

@Kyliekyler
Copy link
Author

static compilation for Android api level < 29 (api>=29 should works, the termux default api level is 24)

Way 1

* use ndk-r21e sysroot, specify `--sysroot=/path/to/ndk-r21e/**/sysroot` flags, download the Ndk from https://developer.android.com/ndk/downloads

Way 2

* use [align_fix.py](https://github.com/Lzhiyong/termux-ndk/blob/master/patches/align_fix.py)(only arm/arm64), execute the command `align_fix.py your executable file`

Im not in using the way 1 but so I ended up using way 2 and it works! Thanks and now Ill close this issue, cheers 🥂

@zorro
Copy link
Contributor

zorro commented May 22, 2022

Adding -ffunction-sections -fdata-sections -Wl,--gc-sections after the -static flag worked for me

@Kyliekyler
Copy link
Author

Adding -ffunction-sections -fdata-sections -Wl,--gc-sections after the -static flag worked for me

Well, I dont have that issue now. Glad it worked for you that way.

@T-3B
Copy link

T-3B commented Jun 26, 2022

static compilation for Android api level < 29 (api>=29 should works, the termux default api level is 24)

Unfortunately I am on Android 11 (api level 30) and static binaries don't work immediately (I got alignement 8 instead of 64 for ARM64).

I used your python script and now they work like a charm, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something is not working properly
Projects
None yet
Development

No branches or pull requests

5 participants