Zig Version
0.17.0-dev.93+76174e1bc
Steps to Reproduce and Observed Behavior
Android's dynamic linker imposes restrictions on the alignment of the tls segment header of an elf file on arm and arm64. These restrictions can be seen here.
On arm64, the minimum tls alignment is (MAX_TLS_SLOT+1)*sizeof(void*) = (7+1)*8 = 64. On arm, the minimum alignment is 8*4 = 32. By default, the elf files produces by zig might not satisfy these two requirements.
As an example, consider the following:
// test1.zigpubfnmain()void{}
// test2.zigthreadlocalvarx:u8align(64)=0;pubfnmain()void{x+=1;}
I complied these two source files on an arm64 android device:
zig build-exe -target aarch64-linux-android -femit-bin=test1-arm64 test1.zig /system/lib64/libc.so
zig build-exe -target aarch64-linux-android -femit-bin=test2-arm64 test2.zig /system/lib64/libc.so
Then used read-elf -l [executable path] to see the alignment of each executable's tls segment:
test1-arm64 | tls alignment = 0x8 = 8
test2-arm64 | tls alignment = 0x40 = 64
Executing test2-arm64 works fine, but executing test1-arm64 gives the following error from the dynamic linker (located at /system/bin/linker64):
error: "./test1-arm64": executable's TLS segment is underaligned: alignment is 8 (skew 0), needs to be at least 64 for ARM64 Bionic
Expected Behavior
The elf files produced by zig should have a default minimum tls segment alignment of 64 when targeting aarch64-linux-android. The minimum should be 32 when targeting arm-linux-android.
### Zig Version
0.17.0-dev.93+76174e1bc
### Steps to Reproduce and Observed Behavior
Android's dynamic linker imposes restrictions on the alignment of the tls segment header of an elf file on arm and arm64. These restrictions can be seen [here](https://cs.android.com/android/platform/superproject/+/android-latest-release:bionic/libc/bionic/bionic_elf_tls.cpp?q=%22is%20underaligned%22&ss=android%2Fplatform%2Fsuperproject).
On arm64, the minimum tls alignment is `(MAX_TLS_SLOT+1)*sizeof(void*) = (7+1)*8 = 64`. On arm, the minimum alignment is `8*4 = 32`. By default, the elf files produces by zig might not satisfy these two requirements.
As an example, consider the following:
```zig
// test1.zig
pub fn main() void {}
```
```zig
// test2.zig
threadlocal var x: u8 align(64) = 0;
pub fn main() void {
x += 1;
}
```
I complied these two source files on an arm64 android device:
```
zig build-exe -target aarch64-linux-android -femit-bin=test1-arm64 test1.zig /system/lib64/libc.so
zig build-exe -target aarch64-linux-android -femit-bin=test2-arm64 test2.zig /system/lib64/libc.so
```
Then used `read-elf -l [executable path]` to see the alignment of each executable's tls segment:
```
test1-arm64 | tls alignment = 0x8 = 8
test2-arm64 | tls alignment = 0x40 = 64
```
Executing `test2-arm64` works fine, but executing `test1-arm64` gives the following error from the dynamic linker (located at `/system/bin/linker64`):
```
error: "./test1-arm64": executable's TLS segment is underaligned: alignment is 8 (skew 0), needs to be at least 64 for ARM64 Bionic
```
### Expected Behavior
The elf files produced by zig should have a default minimum tls segment alignment of 64 when targeting `aarch64-linux-android`. The minimum should be 32 when targeting `arm-linux-android`.