Closed PetarKirov closed 4 years ago
What ld linker are you using, and can you try with the others? - See https://github.com/ldc-developers/ldc/issues/3350#issuecomment-597904606.
Btw thx for letting me know it actually works; I've never tested the Termux stuff. With v1.22, Termux won't need any special patches anymore; someone else (who's actually using it) taking over Termux maintenance would be great. ;)
What ld linker are you using, and can you try with the others?
The problem is not that my code when compiled on Termux crashes, the problem is that LDC itself crashes, so I have no control over the linker - LDC has already been compiled and linked by Termux ;)
Btw thx for letting me know it actually works; I've never tested the Termux stuff.
It has been at least a year since I have built successfully LDC from source on Termux. Before I did it from the lts-master
C++ branch, and more recently (a couple of months back) by using LDC as provided by the Termux package manager.
P.S. I bought a phone with 12GB of RAM and 512GB of UFS 3.0 storage, specifically so I could natively build D code like LDC on it :P
Oh, I see now. Can you list the sections of the ldc2
executable, specifically, .tdata
and .tbss
, and post their memory address ranges?
Edit: I've checked the sections for the official Android/AArch64 package; the sections are contiguous:
> llvm-readelf --sections ldc2
[19] .tdata PROGBITS 0000000003067678 3066678 000008 00 WA 0 0 4
[20] .tbss NOBITS 0000000003067680 3066680 000160 00 WA 0 0 16
Here's what I get:
llvm-readelf --sections /data/data/com.termux/files/usr/bin/ldc2
There are 33 section headers, starting at offset 0x2ccdd90:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
[ 3] .note.gnu.property NOTE 00000000000002e8 0002e8 000060 00 A 0 0 8
[ 4] .dynsym DYNSYM 0000000000000348 000348 0d0f38 18 A 5 1 8
[ 5] .dynstr STRTAB 00000000000d1280 0d1280 26724c 00 A 0 0 1
[ 6] .gnu.hash GNU_HASH 00000000003384d0 3384d0 04a72c 00 A 4 0 8
[ 7] .gnu.version VERSYM 0000000000382bfc 382bfc 01169a 02 A 4 0 2
[ 8] .gnu.version_r VERNEED 0000000000394298 394298 000090 00 A 5 4 4
[ 9] .rela.dyn RELA 0000000000394328 394328 3a7f28 18 A 4 0 8
[10] .rela.plt RELA 000000000073c250 73c250 001e48 18 AI 4 23 8
[11] .plt PROGBITS 000000000073e098 73e098 001450 10 AX 0 0 8
[12] .text PROGBITS 000000000073f4e8 73f4e8 1a5d798 00 AX 0 0 4
[13] .gcc_except_table PROGBITS 000000000219cc80 219cc80 0044b4 00 A 0 0 4
[14] .rodata PROGBITS 00000000021a1140 21a1140 7d8b8d 00 A 0 0 16
[15] .eh_frame PROGBITS 0000000002979cd0 2979cd0 03f1a0 00 A 0 0 8
[16] .eh_frame_hdr PROGBITS 00000000029b8e70 29b8e70 01093c 00 A 0 0 4
[17] .preinit_array PREINIT_ARRAY 00000000029e2670 29d2670 000010 08 WA 0 0 8
[18] .init_array INIT_ARRAY 00000000029e2680 29d2680 000bc0 08 WA 0 0 8
[19] .fini_array FINI_ARRAY 00000000029e3240 29d3240 000010 08 WA 0 0 8
[20] .data.rel.ro PROGBITS 00000000029e3250 29d3250 2b2fc0 00 WA 0 0 16
[21] .dynamic DYNAMIC 0000000002c96210 2c86210 000250 10 WA 5 0 8
[22] .got PROGBITS 0000000002c96460 2c86460 009168 00 WA 0 0 8
[23] .got.plt PROGBITS 0000000002c9f5c8 2c8f5c8 000a30 00 WA 0 0 8
[24] .tdata PROGBITS 0000000002ca0000 2c90000 000008 00 WA 0 0 4
[25] .data PROGBITS 0000000002ca0040 2c90040 03d190 00 WA 0 0 64
[26] __minfo PROGBITS 0000000002cdd1d0 2ccd1d0 000910 00 WA 0 0 8
[27] .bss NOBITS 0000000002cddae0 2ccdae0 0658e0 00 WA 0 0 16
[28] .tcommon NOBITS 0000000002d433c0 2ccdae0 000004 00 WA 0 0 4
[29] .tbss NOBITS 0000000002d433d0 2ccdae0 000159 00 WA 0 0 16
[30] .comment PROGBITS 0000000000000000 2ccdae0 000143 01 MS 0 0 1
[31] .note.gnu.gold-version NOTE 0000000000000000 2ccdc24 00001c 00 0 0 4
[32] .shstrtab STRTAB 0000000000000000 2ccdc40 000150 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
I'll try to build master from source and see if so get something different.
Thx, so here we have the reason, the sections are quite far apart. Seems like Termux tampers with the linker scripts, as the official package is created with the default settings of Android NDK r21.
Unfortunately, there's no quick fix, as our custom TLS emulation relies on a single base address. Supporting non-contiguous ranges like here would significantly bloat the per-thread TLS data (by all regular non-TLS static data). Edit: That should be what previous LDC releases did - not being much of an issue for single-threaded LDC, but user code. Edit2: Even worse, the pre-1.21 scheme relied on .tcommon
ending up after .tbss
, which isn't the case here.
Petar, please try the official package (I haven't gotten any feedback whether that one works either yet), and try linking a little program with TLS data (zero and non-zero initialized) with different (Termux) linkers by playing with -linker=<bfd|gold|lld>
. Then output the sections and check whether there's a linker producing what we need. Hopefully one works, so that I can switch to that one in the Termux build script.
The problem is that the official ldc package (as provided by the termux) is not working, sorry if that wasn't clear. I can't do anything with it, as even ldc2 --help
fails.
These days, I'm quite busy so I wasn't actually planning on building llvm+ldc myself, as so far the official package was working fine for me.
I'm talking about the official package on GitHub (built by CI). That doesn't involve any Termux at all, and that's the one I've inspected above and so should basically work, unless there are some .so dependencies. Termux is a completely separate build, although similar (cross-compilation of LLVM + LDC from x86, but inside their special environment).
[The official package is meant to be used inside something like Termux, as it still depends on cc
for linking.]
I just finished build LLVM:
git clone --recurse-submodules --depth 100 https://github.com/ldc-developers/llvm-project
mkdir llvm-project/build && llvm-project/build
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=../../install-llvm \
-DLLVM_TARGETS_TO_BUILD='AArch64;ARM;WebAssembly' \
-DLLVM_INCLUDE_TOOLS=ON \
-DLLVM_BUILD_TOOLS=ON \
-DLLVM_BUILD_TESTS=OFF \
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_LIBEDIT=OFF \
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-S .. -B .
ninja install
# Now off to ldc:
git clone --recurse-submodules https://github.com/ldc-developers/ldc
mkdir ldc/build && cd ldc/build
...
Argh I actuall can't build LDC, because I don't have a bootstrap compiler...
I'm talking about the official package on GitHub (built by CI).
Ah ok then, I'll try it soon.
I just downloaded 1.22.0-beta2 and it compiles fine hello world betterc:
extern (C) int main()
{
import core.stdc.stdio : puts;
puts("hello world");
return 0;
}
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 -betterC hello_betterc.d
> ./hello_betterc
hello world
> size hello_betterc
text data bss dec hex filename
1082 688 8 1778 6f2 hello_betterc
> ldd ./hello_betterc
libdl.so
libm.so
libc.so
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 --betterC -v hello_betterc.d | tail -1
/data/data/com.termux/files/usr/bin/cc hello_betterc.o -o hello_betterc -L/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/../lib -Wl,--gc-sections -ldl -lm
> llvm-readelf --sections hello_betterc
llvm-readelf --sections hello_betterc 20:48:24 2020-06-07 (Sun)
There are 25 section headers, starting at offset 0x1ac8:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
[ 3] .gnu.hash GNU_HASH 00000000000002e8 0002e8 00001c 00 A 4 0 8
[ 4] .dynsym DYNSYM 0000000000000308 000308 0000a8 18 A 5 3 8
[ 5] .dynstr STRTAB 00000000000003b0 0003b0 000073 00 A 0 0 1
[ 6] .gnu.version VERSYM 0000000000000424 000424 00000e 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 0000000000000438 000438 000020 00 A 5 1 8
[ 8] .rela.dyn RELA 0000000000000458 000458 000060 18 A 4 0 8
[ 9] .rela.plt RELA 00000000000004b8 0004b8 000060 18 AI 4 19 8
[10] .plt PROGBITS 0000000000000520 000520 000060 10 AX 0 0 16
[11] .text PROGBITS 0000000000000580 000580 0000b8 00 AX 0 0 4
[12] .rodata PROGBITS 0000000000000638 000638 00000c 01 AMS 0 0 4
[13] .eh_frame_hdr PROGBITS 0000000000000644 000644 000014 00 A 0 0 4
[14] .eh_frame PROGBITS 0000000000000658 000658 000030 00 A 0 0 8
[15] .preinit_array PREINIT_ARRAY 0000000000001d50 000d50 000010 08 WA 0 0 8
[16] .init_array INIT_ARRAY 0000000000001d60 000d60 000010 08 WA 0 0 8
[17] .fini_array FINI_ARRAY 0000000000001d70 000d70 000010 08 WA 0 0 8
[18] .dynamic DYNAMIC 0000000000001d80 000d80 000220 10 WA 5 0 8
[19] .got PROGBITS 0000000000001fa0 000fa0 000060 08 WA 0 0 8
[20] .bss NOBITS 0000000000002000 001000 000008 00 WA 0 0 8
[21] .comment PROGBITS 0000000000000000 001000 000121 01 MS 0 0 1
[22] .symtab SYMTAB 0000000000000000 001128 0006c0 18 23 52 8
[23] .strtab STRTAB 0000000000000000 0017e8 0001f4 00 0 0 1
[24] .shstrtab STRTAB 0000000000000000 0019dc 0000ea 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
Phobos hello world also run well:
> cat hello.d
void main()
{
import std.stdio : writeln;
writeln("yo");
}
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 hello.d
> ./hello
yo
> size hello
text data bss dec hex filename
584244 83092 2793 670129 a39b1 hello
> ldd ./hello
libdl.so
libm.so
libc.so
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 -v hello.d | tail -1
/data/data/com.termux/files/usr/bin/cc hello.o -o hello -L/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/../lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -ldl -lm
> llvm-readelf --sections hello
There are 38 section headers, starting at offset 0x129340:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
[ 3] .gnu.hash GNU_HASH 00000000000002e8 0002e8 00001c 00 A 4 0 8
[ 4] .dynsym DYNSYM 0000000000000308 000308 000cf0 18 A 5 3 8
[ 5] .dynstr STRTAB 0000000000000ff8 000ff8 000636 00 A 0 0 1
[ 6] .gnu.version VERSYM 000000000000162e 00162e 000114 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 0000000000001748 001748 000060 00 A 5 3 8
[ 8] .rela.dyn RELA 00000000000017a8 0017a8 01b888 18 A 4 0 8
[ 9] .rela.plt RELA 000000000001d030 01d030 000c30 18 AI 4 23 8
[10] .plt PROGBITS 000000000001dc60 01dc60 000840 10 AX 0 0 16
[11] .text PROGBITS 000000000001e4a0 01e4a0 04d26c 00 AX 0 0 4
[12] .rodata PROGBITS 000000000006b710 06b710 0142f9 00 A 0 0 16
[13] .eh_frame_hdr PROGBITS 000000000007fa0c 07fa0c 00317c 00 A 0 0 4
[14] .eh_frame PROGBITS 0000000000082b88 082b88 00aafc 00 A 0 0 8
[15] .gcc_except_table PROGBITS 000000000008d684 08d684 0015fc 00 A 0 0 4
[16] .tdata PROGBITS 0000000000090c5c 08fc5c 000004 00 WAT 0 0 4
[17] .tbss NOBITS 0000000000090c60 08fc60 000159 00 WA 0 0 16
[18] .preinit_array PREINIT_ARRAY 0000000000090dc0 08fdc0 000010 08 WA 0 0 8
[19] .init_array INIT_ARRAY 0000000000090dd0 08fdd0 000030 08 WA 0 0 8
[20] .fini_array FINI_ARRAY 0000000000090e00 08fe00 000010 08 WA 0 0 8
[21] .data.rel.ro PROGBITS 0000000000090e10 08fe10 007820 00 WA 0 0 16
[22] .dynamic DYNAMIC 0000000000098630 097630 000220 10 WA 5 0 8
[23] .got PROGBITS 0000000000098850 097850 0007a8 08 WA 0 0 8
[24] .data PROGBITS 0000000000099000 098000 00bd50 00 WA 0 0 64
[25] __minfo PROGBITS 00000000000a4d50 0a3d50 000508 00 WA 0 0 8
[26] .bss NOBITS 00000000000a5260 0a4258 000990 00 WA 0 0 16
[27] .comment PROGBITS 0000000000000000 0a4258 0001fc 01 MS 0 0 1
[28] .debug_aranges PROGBITS 0000000000000000 0a4454 0003f0 00 0 0 1
[29] .debug_info PROGBITS 0000000000000000 0a4844 00a7c0 00 0 0 1
[30] .debug_abbrev PROGBITS 0000000000000000 0af004 002284 00 0 0 1
[31] .debug_line PROGBITS 0000000000000000 0b1288 003bc5 00 0 0 1
[32] .debug_str PROGBITS 0000000000000000 0b4e4d 002ca2 01 MS 0 0 1
[33] .debug_loc PROGBITS 0000000000000000 0b7aef 014020 00 0 0 1
[34] .debug_ranges PROGBITS 0000000000000000 0cbb0f 001d30 00 0 0 1
[35] .symtab SYMTAB 0000000000000000 0cd840 02c508 18 36 5275 8
[36] .strtab STRTAB 0000000000000000 0f9d48 02f478 00 0 0 1
[37] .shstrtab STRTAB 0000000000000000 1291c0 00017d 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
So I think it's safe to say that the issue is entirely related to the way Termux handles the building of the 1.21 release.
P.S. I'd happy to run any other tests on my device, if you find it useful :)
Honestly, installing ldc from Termux was just a matter of convenience for me, as the prebuilt android releases were a recent addition on your side. I'd much rather use the real "official" releases that you provide, as a I have much higher trust in you :P And also I don't like when package managers meddle with upstream software :D
All I need to do, is find time to integrate this into the dlang install.sh
script upstream ;)
So I think it's safe to say that the issue is entirely related to the way Termux handles the building of the 1.21 release. ... And also I don't like when package managers meddle with upstream software :D
Yeah, unfortunately I am playing the role of the package manager in this case (if you don't do it yourself...), flying completely blind (I just can't be bothered to try anything out on my old phone). But the official packages were completely untested from my side too, so... :] - Thanks a lot for testing, good to know the stuff actually works as it should.
I'd happy to run any other tests on my device, if you find it useful :)
Yeah, please try all available linkers and check the sections for adjacency, as mentioned earlier. If we can pinpoint it to some linker (script), the Termux build might be fixable.
Oh and a tiny little dub check would be nice as well, because of https://github.com/ldc-developers/ldc/issues/3170. It'll probably require some libcurl, would be interesting to see whether it hangs because of that etc.
Yeah, unfortunately I am playing the role of the package manager in this case (if you don't do it yourself...), flying completely blind (I just can't be bothered to try anything out on my old phone). But the official packages were completely untested from my side too, so... :]
Yeah, I remember following your PRs for Termux some time ago, though because of this msg:
Seems like Termux tampers with the linker scripts, as the official package is created with the default settings of Android NDK r21.
I thought that someone else made changes on the Termux side that you were unaware of.
Thanks a lot for testing, good to know the stuff actually works as it should.
I'm more than happy to help!
Yeah, please try all available linkers and check the sections for adjacency, as mentioned earlier. If we can pinpoint it to some linker (script), the Termux build might be fixable.
Sure, here you go:
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 --linker=lld -v hello.d | tail -1
/data/data/com.termux/files/usr/bin/cc hello.o -o hello -fuse-ld=lld -L/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/../lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -ldl -lm
> ./hello
Aborting from rt/sections_android.d(226) expected .tdata and .tbss sections to be contiguousfish: './hello' terminated by signal SIGABRT (Abort)
> llvm-readelf --sections hello
There are 40 section headers, starting at offset 0x127888:
Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 00000000000002a8 0002a8 000015 00 A 0 0 1 [ 2] .note.android.ident NOTE 00000000000002c0 0002c0 000098 00 A 0 0 4 [ 3] .dynsym DYNSYM 0000000000000358 000358 000cc0 18 A 7 1 8 [ 4] .gnu.version VERSYM 0000000000001018 001018 000110 02 A 3 0 2 [ 5] .gnu.version_r VERNEED 0000000000001128 001128 000060 00 A 7 3 4 [ 6] .gnu.hash GNU_HASH 0000000000001188 001188 00001c 00 A 3 0 8
[ 7] .dynstr STRTAB 00000000000011a4 0011a4 000653 00 A 0 0 1 [ 8] .rela.dyn RELA 00000000000017f8 0017f8 01b990 18 A 3 0 8 [ 9] .rela.plt RELA 000000000001d188 01d188 000c30 18 A 3 22 8 [10] .gcc_except_table PROGBITS 000000000001ddb8 01ddb8 002640 00 A 0 0 4 [11] .rodata PROGBITS 0000000000020400 020400 00f71d 00 AMS 0 0 16 [12] .eh_frame_hdr PROGBITS 000000000002fb20 02fb20 00317c 00 A 0 0 4 [13] .eh_frame PROGBITS 0000000000032ca0 032ca0 00b9cc 00 A 0 0 8 [14] .text PROGBITS 000000000003f000 03f000 04d1f8 00 AX 0 0 4
[15] .plt PROGBITS 000000000008c200 08c200 000840 00 AX 0 0 16
[16] .preinit_array PREINIT_ARRAY 000000000008d000 08d000 000010 08 WA 0 0 8
[17] .init_array INIT_ARRAY 000000000008d010 08d010 000030 00 WA 0 0 8
[18] .fini_array FINI_ARRAY 000000000008d040 08d040 000010 08 WA 0 0 8
[19] .data.rel.ro PROGBITS 000000000008d050 08d050 007808 00 WA 0 0 16
[20] .dynamic DYNAMIC 0000000000094858 094858 0001e0 10 WA 7 0 8
[21] .got PROGBITS 0000000000094a38 094a38 000378 00 WA 0 0 8
[22] .got.plt PROGBITS 0000000000094db0 094db0 000428 00 WA 0 0 8
[23] .bss.rel.ro NOBITS 00000000000951d8 0951d8 000000 00 WA 0 0 1
[24] .data PROGBITS 0000000000096000 096000 00bd90 00 WA 0 0 64
[25] __minfo PROGBITS 00000000000a1d90 0a1d90 000508 00 WA 0 0 8
[26] .tdata PROGBITS 00000000000a2298 0a2298 000004 00 WA 0 0 4
[27] .bss NOBITS 00000000000a22a0 0a229c 000990 00 WA 0 0 16
[28] .tbss NOBITS 00000000000a2c30 0a229c 000160 00 WA 0 0 16
[29] .comment PROGBITS 0000000000000000 0a229c 00020f 01 MS 0 0 1
[30] .debug_info PROGBITS 0000000000000000 0a24ab 00a7c0 00 0 0 1
[31] .debug_abbrev PROGBITS 0000000000000000 0acc6b 002284 00 0 0 1
[32] .debug_loc PROGBITS 0000000000000000 0aeeef 014020 00 0 0 1
[33] .debug_aranges PROGBITS 0000000000000000 0c2f0f 0003f0 00 0 0 1
[34] .debug_ranges PROGBITS 0000000000000000 0c32ff 001d30 00 0 0 1
[35] .debug_line PROGBITS 0000000000000000 0c502f 003bc5 00 0 0 1
[36] .debug_str PROGBITS 0000000000000000 0c8bf4 002e7f 01 MS 0 0 1
[37] .symtab SYMTAB 0000000000000000 0cba78 02c8e0 18 39 7220 8
[38] .shstrtab STRTAB 0000000000000000 0f8358 000197 00 0 0 1
[39] .strtab STRTAB 0000000000000000 0f84ef 02f393 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 --linker=gold -v hello.d | tail -1
/data/data/com.termux/files/usr/bin/cc hello.o -o hello -fuse-ld=gold -L/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/../lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -ldl -lm
> ./hello
Aborting from rt/sections_android.d(226) expected .tdata and .tbss sections to be contiguousfish: './hello' terminated by signal SIGABRT (Abort)
> llvm-readelf --sections hello
There are 40 section headers, starting at offset 0x12b8d8:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
[ 3] .dynsym DYNSYM 00000000000002e8 0002e8 001548 18 A 4 1 8
[ 4] .dynstr STRTAB 0000000000001830 001830 000934 00 A 0 0 1
[ 5] .gnu.hash GNU_HASH 0000000000002168 002168 00001c 00 A 3 0 8
[ 6] .gnu.version VERSYM 0000000000002184 002184 0001c6 02 A 3 0 2
[ 7] .gnu.version_r VERNEED 000000000000234c 00234c 000060 00 A 4 3 4
[ 8] .rela.dyn RELA 00000000000023b0 0023b0 01b9a8 18 A 3 0 8
[ 9] .rela.plt RELA 000000000001dd58 01dd58 000c30 18 AI 3 10 8
[10] .plt PROGBITS 000000000001e988 01e988 000840 10 AX 0 0 8
[11] .text PROGBITS 000000000001f1c8 01f1c8 04d26c 00 AX 0 0 4
[12] .gcc_except_table PROGBITS 000000000006c434 06c434 002640 00 A 0 0 4
[13] .rodata PROGBITS 000000000006ea80 06ea80 0143d1 00 A 0 0 16
[14] .eh_frame PROGBITS 0000000000082e58 082e58 00b9c8 00 A 0 0 8
[15] .eh_frame_hdr PROGBITS 000000000008e820 08e820 00317c 00 A 0 0 4
[16] .preinit_array PREINIT_ARRAY 0000000000092db0 091db0 000010 08 WA 0 0 8
[17] .init_array INIT_ARRAY 0000000000092dc0 091dc0 000030 00 WA 0 0 8
[18] .fini_array FINI_ARRAY 0000000000092df0 091df0 000010 08 WA 0 0 8
[19] .data.rel.ro PROGBITS 0000000000092e00 091e00 007820 00 WA 0 0 16
[20] .dynamic DYNAMIC 000000000009a620 099620 000230 10 WA 4 0 8
[21] .got PROGBITS 000000000009a850 099850 000380 00 WA 0 0 8
[22] .got.plt PROGBITS 000000000009abd0 099bd0 000428 00 WA 0 0 8
[23] .data PROGBITS 000000000009b000 09a000 00bd90 00 WA 0 0 64
[24] __minfo PROGBITS 00000000000a6d90 0a5d90 000508 00 WA 0 0 8
[25] .tdata PROGBITS 00000000000a7298 0a6298 000004 00 WA 0 0 4
[26] .bss NOBITS 00000000000a72a0 0a629c 000990 00 WA 0 0 16
[27] .tbss NOBITS 00000000000a7c30 0a629c 000159 00 WA 0 0 16
[28] .comment PROGBITS 0000000000000000 0a629c 0001fd 01 MS 0 0 1
[29] .debug_info PROGBITS 0000000000000000 0a6499 00a7c0 00 0 0 1
[30] .debug_abbrev PROGBITS 0000000000000000 0b0c59 002284 00 0 0 1
[31] .debug_loc PROGBITS 0000000000000000 0b2edd 014020 00 0 0 1
[32] .debug_aranges PROGBITS 0000000000000000 0c6efd 0003f0 00 0 0 1
[33] .debug_ranges PROGBITS 0000000000000000 0c72ed 001d30 00 0 0 1
[34] .debug_line PROGBITS 0000000000000000 0c901d 003bc5 00 0 0 1
[35] .debug_str PROGBITS 0000000000000000 0ccbe2 002e7f 01 MS 0 0 1
[36] .note.gnu.gold-version NOTE 0000000000000000 0cfa64 00001c 00 0 0 4
[37] .symtab SYMTAB 0000000000000000 0cfa80 02c5c8 18 38 7093 8
[38] .strtab STRTAB 0000000000000000 0fc048 02f6f3 00 0 0 1
[39] .shstrtab STRTAB 0000000000000000 12b73b 00019d 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
N ~/c/t/dlang
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 --linker=bfd hello.d
clang-9: error: invalid linker name in argument '-fuse-ld=bfd'
Error: /data/data/com.termux/files/usr/bin/cc failed with status: 1
> $REPOS/ldc2-1.22.0-beta2/bin/ldc2 --linker=ld -v hello.d | tail -1
/data/data/com.termux/files/usr/bin/cc hello.o -o hello -fuse-ld=ld -L/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/../lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -ldl -lm
> ./hello
yo
> llvm-readelf --sections hello
There are 38 section headers, starting at offset 0x129340:
Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1 [ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4 [ 3] .gnu.hash GNU_HASH 00000000000002e8 0002e8 00001c 00 A 4 0 8 [ 4] .dynsym DYNSYM 0000000000000308 000308 000cf0 18 A 5 3 8 [ 5] .dynstr STRTAB 0000000000000ff8 000ff8 000636 00 A 0 0 1 [ 6] .gnu.version VERSYM 000000000000162e 00162e 000114 02 A 4 0 2 [ 7] .gnu.version_r VERNEED 0000000000001748 001748 000060 00 A 5 3 8 [ 8] .rela.dyn RELA 00000000000017a8 0017a8 01b888 18 A 4 0 8 [ 9] .rela.plt RELA 000000000001d030 01d030 000c30 18 AI 4 23 8 [10] .plt PROGBITS 000000000001dc60 01dc60 000840 10 AX 0 0 16 [11] .text PROGBITS 000000000001e4a0 01e4a0 04d26c 00 AX 0 0 4 [12] .rodata PROGBITS 000000000006b710 06b710 0142f9 00 A 0 0 16 [13] .eh_frame_hdr PROGBITS 000000000007fa0c 07fa0c 00317c 00 A 0 0 4 [14] .eh_frame PROGBITS 0000000000082b88 082b88 00aafc 00 A 0 0 8 [15] .gcc_except_table PROGBITS 000000000008d684 08d684 0015fc 00 A 0 0 4 [16] .tdata PROGBITS 0000000000090c5c 08fc5c 000004 00 WAT 0 0 4 [17] .tbss NOBITS 0000000000090c60 08fc60 000159 00 WA 0 0 16 [18] .preinit_array PREINIT_ARRAY 0000000000090dc0 08fdc0 000010 08 WA 0 0 8 [19] .init_array INIT_ARRAY 0000000000090dd0 08fdd0 000030 08 WA 0 0 8 [20] .fini_array FINI_ARRAY 0000000000090e00 08fe00 000010 08 WA 0 0 8 [21] .data.rel.ro PROGBITS 0000000000090e10 08fe10 007820 00 WA 0 0 16 [22] .dynamic DYNAMIC 0000000000098630 097630 000220 10 WA 5 0 8 [23] .got PROGBITS 0000000000098850 097850 0007a8 08 WA 0 0 8 [24] .data PROGBITS 0000000000099000 098000 00bd50 00 WA 0 0 64 [25] __minfo PROGBITS 00000000000a4d50 0a3d50 000508 00 WA 0 0 8 [26] .bss NOBITS 00000000000a5260 0a4258 000990 00 WA 0 0 16 [27] .comment PROGBITS 0000000000000000 0a4258 0001fc 01 MS 0 0 1 [28] .debug_aranges PROGBITS 0000000000000000 0a4454 0003f0 00 0 0 1 [29] .debug_info PROGBITS 0000000000000000 0a4844 00a7c0 00 0 0 1 [30] .debug_abbrev PROGBITS 0000000000000000 0af004 002284 00 0 0 1 [31] .debug_line PROGBITS 0000000000000000 0b1288 003bc5 00 0 0 1 [32] .debug_str PROGBITS 0000000000000000 0b4e4d 002ca2 01 MS 0 0 1 [33] .debug_loc PROGBITS 0000000000000000 0b7aef 014020 00 0 0 1 [34] .debug_ranges PROGBITS 0000000000000000 0cbb0f 001d30 00 0 0 1 [35] .symtab SYMTAB 0000000000000000 0cd840 02c508 18 36 5275 8 [36] .strtab STRTAB 0000000000000000 0f9d48 02f478 00 0 0 1 [37] .shstrtab STRTAB 0000000000000000 1291c0 00017d 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), l (large) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific)
Thx for the slightly worrying results (the Android NDK aims at defaulting to LLD in future versions). They seem to contradict the results in https://github.com/ldc-developers/ldc/issues/3350#issuecomment-598079713, where gold worked fine (for code with a non-empty .bss
section, using the Android NDK r21 and cross-compiling on x86, i.e., no Termux). So I guess and hope the bfd requirement is Termux-specific.
Edit: Also, none of these section layouts match the ldc2 layout you posted above, so possibly the Termux linker scripts diverge between cross-compilation build environment on x86 and the actual Android environments...
where gold worked fine (for code with a non-empty .bss section, using the Android NDK r21 and cross-compiling on x86, i.e., no Termux).
I guess it's possible that the two versions of gold
that were different. I have the following versions installed:
> ld.lld --version
LLD 9.0.1 (compatible with GNU linkers)
> ld.gold --version
GNU gold (GNU Binutils 2.34) 1.16
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
> ld --version
GNU ld (GNU Binutils) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
so possibly the Termux linker scripts diverge between cross-compilation build environment on x86 and the actual Android environments...
Yeah, that also seems to be the case to me.
BTW, now that I have build LLVM 10 from source and I have a working LDC that I can use for bootstrapping, I could test your PRs locally, in case that help. Just ping me on the dlang Slack, as I generally can't keep up with email notifications from GitHub.
Oh and a tiny little dub check would be nice as well, because of #3170. It'll probably require some libcurl, would be interesting to see whether it hangs because of that etc.
Dub itself seems to work fine, though I have only been able to test it with dxml
as more complex packages fail to build for unrelated reasons (e.g. missing version defines, C bindings, etc.)
Edit: you find the result's of running Dub's test suite here: https://github.com/ldc-developers/ldc/issues/3170#issuecomment-640279579
> git clone https://github.com/jmdavis/dxml
cd dxml/ dub test Generating test runner configuration 'dxml-test-library' for 'library' (library). Performing "unittest" build using /data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/ldc2 for aarch64, arm_hardfloat. dxml 0.1.0+commit.80.gebee7c6: building configuration "dxml-test-library"... Linking... Running ./dxml-test-library 5 unittests passed
#!/usr/bin/env dub
/+ dub.sdl:
dependency "vibe-d" version="~>0.8.0"
+/
void main()
{
import vibe.d;
listenHTTP(":8080", (req, res) {
res.writeBody("Hello, World: " ~ req.path);
});
runApplication();
}
dub --single hello_vibe.d
Fetching botan-math 1.0.3 (getting selected version)...
Fetching vibe-core 1.9.2 (getting selected version)...
Fetching memutils 1.0.4 (getting selected version)...
Fetching taggedalgebraic 0.11.15 (getting selected version)...
Fetching vibe-d 0.8.6 (getting selected version)...
Fetching stdx-allocator 2.77.5 (getting selected version)...
Fetching botan 1.12.18 (getting selected version)...
Fetching diet-ng 1.7.2 (getting selected version)...
Fetching openssl 1.1.6+1.0.1g (getting selected version)...
Fetching eventcore 0.9.6 (getting selected version)...
Fetching mir-linux-kernel 1.0.1 (getting selected version)...
Fetching libevent 2.0.2+2.0.16 (getting selected version)...
Fetching libasync 0.8.6 (getting selected version)...
Running pre-generate commands for vibe-d:tls...
Aborting from rt/sections_android.d(226) expected .tdata and .tbss sections to be contiguousAborted
Performing "debug" build using /data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/ldc2 for aarch64, arm_hardfloat.
taggedalgebraic 0.11.15: building configuration "library"...
eventcore 0.9.6: building configuration "epoll"...
../../../../.dub/packages/eventcore-0.9.6/eventcore/source/eventcore/drivers/posix/sockets.d(115,21): Error: undefined identifier MSG_NOSIGNAL
/data/data/com.termux/files/home/code/repos/ldc2-1.22.0-beta2/bin/ldc2 failed with exit code 1.
The issue is that rdmd
executable has TLS problems. Both the version provided by the 1.22.0-beta2 GitHub archive and the that I build locally:
> $REPOS/ldc2-1.22.0-beta2/bin/rdmd --help
Aborting from rt/sections_android.d(226) expected .tdata and .tbss sections to be contiguousfish: Job 2, '$REPOS/ldc2-1.22.0-beta2/bin/rd…' terminated by signal SIGABRT (Abort)
llvm-readelf --sections $REPOS/ldc2-1.22.0-beta2/bin/rdmd
There are 40 section headers, starting at offset 0x203138:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000270 000270 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000288 000288 000098 00 A 0 0 4
[ 3] .note.gnu.property NOTE 0000000000000320 000320 000060 00 A 0 0 8
[ 4] .hash HASH 0000000000000380 000380 0008e4 04 A 6 0 8
[ 5] .gnu.hash GNU_HASH 0000000000000c68 000c68 0004ac 00 A 6 0 8
[ 6] .dynsym DYNSYM 0000000000001118 001118 001c80 18 A 7 3 8
[ 7] .dynstr STRTAB 0000000000002d98 002d98 002c97 00 A 0 0 1
[ 8] .gnu.version VERSYM 0000000000005a30 005a30 000260 02 A 6 0 2
[ 9] .gnu.version_r VERNEED 0000000000005c90 005c90 000060 00 A 7 3 8
[10] .rela.dyn RELA 0000000000005cf0 005cf0 020970 18 A 6 0 8
[11] .rela.plt RELA 0000000000026660 026660 000f48 18 AI 6 25 8
[12] .plt PROGBITS 00000000000275b0 0275b0 000a50 10 AX 0 0 16
[13] .text PROGBITS 0000000000028000 028000 0b4504 00 AX 0 0 4
[14] .rodata PROGBITS 00000000000dc510 0dc510 01bc95 00 A 0 0 16
[15] .eh_frame_hdr PROGBITS 00000000000f81a8 0f81a8 005e84 00 A 0 0 4
[16] .eh_frame PROGBITS 00000000000fe030 0fe030 0170a8 00 A 0 0 8
[17] .gcc_except_table PROGBITS 00000000001150d8 1150d8 0024a0 00 A 0 0 4
[18] .tdata PROGBITS 0000000000118bf8 117bf8 0000a4 00 WA 0 0 8
[19] .tbss NOBITS 0000000000118ca0 117c9c 0001e9 00 WA 0 0 16
[20] .preinit_array PREINIT_ARRAY 0000000000118e90 117e90 000010 08 WA 0 0 8
[21] .init_array INIT_ARRAY 0000000000118ea0 117ea0 000030 08 WA 0 0 8
[22] .fini_array FINI_ARRAY 0000000000118ed0 117ed0 000010 08 WA 0 0 8
[23] .data.rel.ro PROGBITS 0000000000118ee0 117ee0 0088a0 00 WA 0 0 16
[24] .dynamic DYNAMIC 0000000000121780 120780 000220 10 WA 7 0 8
[25] .got PROGBITS 00000000001219a0 1209a0 001658 08 WA 0 0 8
[26] .data PROGBITS 0000000000123000 122000 017210 00 WA 0 0 64
[27] __minfo PROGBITS 000000000013a210 139210 000520 00 WA 0 0 8
[28] .bss NOBITS 000000000013a730 139730 0009d0 00 WA 0 0 16
[29] .comment PROGBITS 0000000000000000 139730 0000f4 01 MS 0 0 1
[30] .debug_aranges PROGBITS 0000000000000000 139824 0003f0 00 0 0 1
[31] .debug_info PROGBITS 0000000000000000 139c14 00a7c0 00 0 0 1
[32] .debug_abbrev PROGBITS 0000000000000000 1443d4 002284 00 0 0 1
[33] .debug_line PROGBITS 0000000000000000 146658 003bc5 00 0 0 1
[34] .debug_str PROGBITS 0000000000000000 14a21d 002ca2 01 MS 0 0 1
[35] .debug_loc PROGBITS 0000000000000000 14cebf 014020 00 0 0 1
[36] .debug_ranges PROGBITS 0000000000000000 160edf 001d30 00 0 0 1
[37] .shstrtab STRTAB 0000000000000000 202fa4 000190 00 0 0 1
[38] .symtab SYMTAB 0000000000000000 162c10 0413d0 18 39 8324 8
[39] .strtab STRTAB 0000000000000000 1a3fe0 05efc4 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
> git clone https://github.com/dlang/tools
> cd tools
> ldc2 rdmd.d
> llvm-readelf --sections ./rdmd
There are 38 section headers, starting at offset 0x1ff2e0:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000000238 000238 000015 00 A 0 0 1
[ 2] .note.android.ident NOTE 0000000000000250 000250 000098 00 A 0 0 4
[ 3] .gnu.hash GNU_HASH 00000000000002e8 0002e8 00001c 00 A 4 0 8
[ 4] .dynsym DYNSYM 0000000000000308 000308 001020 18 A 5 3 8
[ 5] .dynstr STRTAB 0000000000001328 001328 000708 00 A 0 0 1
[ 6] .gnu.version VERSYM 0000000000001a30 001a30 000158 02 A 4 0 2
[ 7] .gnu.version_r VERNEED 0000000000001b88 001b88 000060 00 A 5 3 8
[ 8] .rela.dyn RELA 0000000000001be8 001be8 020958 18 A 4 0 8
[ 9] .rela.plt RELA 0000000000022540 022540 000f48 18 AI 4 23 8
[10] .plt PROGBITS 0000000000023490 023490 000a50 10 AX 0 0 16
[11] .text PROGBITS 0000000000023ee0 023ee0 0b6664 00 AX 0 0 8
[12] .rodata PROGBITS 00000000000da550 0da550 01c229 00 A 0 0 16
[13] .eh_frame_hdr PROGBITS 00000000000f677c 0f677c 005e84 00 A 0 0 4
[14] .eh_frame PROGBITS 00000000000fc600 0fc600 014c44 00 A 0 0 8
[15] .gcc_except_table PROGBITS 0000000000111244 111244 0024a0 00 A 0 0 4
[16] .tdata PROGBITS 0000000000114c08 113c08 0000a4 00 WAT 0 0 8
[17] .tbss NOBITS 0000000000114cb0 113cac 0001e9 00 WA 0 0 16
[18] .preinit_array PREINIT_ARRAY 0000000000114ea0 113ea0 000010 08 WA 0 0 8
[19] .init_array INIT_ARRAY 0000000000114eb0 113eb0 000030 08 WA 0 0 8
[20] .fini_array FINI_ARRAY 0000000000114ee0 113ee0 000010 08 WA 0 0 8
[21] .data.rel.ro PROGBITS 0000000000114ef0 113ef0 0088a0 00 WA 0 0 16
[22] .dynamic DYNAMIC 000000000011d790 11c790 000220 10 WA 5 0 8
[23] .got PROGBITS 000000000011d9b0 11c9b0 001650 08 WA 0 0 8
[24] .data PROGBITS 000000000011f000 11e000 017210 00 WA 0 0 64
[25] __minfo PROGBITS 0000000000136210 135210 000520 00 WA 0 0 8
[26] .bss NOBITS 0000000000136730 135730 0009d0 00 WA 0 0 16
[27] .comment PROGBITS 0000000000000000 135730 0001fc 01 MS 0 0 1
[28] .debug_aranges PROGBITS 0000000000000000 13592c 0003f0 00 0 0 1
[29] .debug_info PROGBITS 0000000000000000 135d1c 00a7c0 00 0 0 1
[30] .debug_abbrev PROGBITS 0000000000000000 1404dc 002284 00 0 0 1
[31] .debug_line PROGBITS 0000000000000000 142760 003bc5 00 0 0 1
[32] .debug_str PROGBITS 0000000000000000 146325 002ca2 01 MS 0 0 1
[33] .debug_loc PROGBITS 0000000000000000 148fc7 014020 00 0 0 1
[34] .debug_ranges PROGBITS 0000000000000000 15cfe7 001d30 00 0 0 1
[35] .symtab SYMTAB 0000000000000000 15ed18 041400 18 36 7974 8
[36] .strtab STRTAB 0000000000000000 1a0118 05f048 00 0 0 1
[37] .shstrtab STRTAB 0000000000000000 1ff160 00017d 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), l (large)
I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
Argh, here the reason is apparently some padding bytes inbetween, for alignment purposes. Speaking of which, the alignment would be violated by the current TLS emulation scheme, as the .tbss
range in each thread's data would be guaranteed to be 8-bytes aligned (0xA8 bytes from (IIRC malloc'd) TLS start), not the required 16 bytes. - I guess we should switch to the emutls library on Android; AFAIK, what vanilla LLVM defaults to.
I've tested the aforementioned artifact on my termux environment and it compiles, links and runs successfully my code. :+1:
Thanks for checking - could you please recheck with the latest version? https://dev.azure.com/ldc-developers/ldc/_build/results?buildId=1796&view=artifacts&type=publishedArtifacts (note: -linker=
(yes, empty) is probably required for AArch64)
[Running all executables - with -version
or whatever - should suffice.]
Yep the binaries works.
The old artifact didn't required -linker=
though.
Perfect, thank you very much - LDC v1.22 final will probably be released this evening then. :)
The Termux package was upgraded to v1.22.0 (https://github.com/termux/termux-packages/pull/5413) - please check.
Thanks, it works.
Thanks a lot @kinke I can also confirm that the 1.22 release from Termux works well. I've just tested running the DCD test suite and all of the tests pass via TCP (Unix Domain Scokets don't work for some reason, though I haven't had the chance to investigate - it's possible that they're simply not supported on Android). See:
https://asciinema.org/a/IUJZbxpHwEInNLBF6XDDMh7B5
What's notable about this is that those tests stress many parts of the toolchain: dub, rdmd, LDC, Phobos, dsymbol, msgpack-d, libdparse, stdx-allocator, emsi_containers and DCD TCP client and server.
And everything seems to be working fine out of the box!
Great, thx for the feedback.
Hi @kinke I have been using LDC 1.20 release in Termux for while without any issues. Recently I updated to LDC 1.21, and when I tried it I noticed that it doesn't work anymore.
Steps to reproduce:
pkg install ldc
ldc2 --help
(The
contiguousfish
artifact in the output is because of a missing newline and because I'm using Fish shell. But the issue is same if I use bash.)