ldc-developers / ldc

The LLVM-based D Compiler.
http://wiki.dlang.org/LDC
Other
1.21k stars 261 forks source link

Can't cross-compile for android-x86_64 on linux #3705

Open Dadoum opened 3 years ago

Dadoum commented 3 years ago

Command:

ldc -mtriple=x86_64--linux-android ./main.d

ldc2.conf:

"x86_64-.*-linux-android":
{
    switches = [
        "-defaultlib=phobos2-ldc,druntime-ldc",
        "-link-defaultlib-shared=false",
        "-gcc=/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang", // Android NDK
    ];
    lib-dirs = [
        "/var/dlang/android/lib-x86_64", // extracted from latest ldc2 release (aarch64 contains x86_64 too)
    ];
    rpath = "";
};

Output:

/opt/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld.bfd: _D4core9exception6_storeG128v: TLS reference in main.o mismatches non-TLS definition in /var/dlang/android/lib-x86_64/libdruntime-ldc.a(exception.o) section .tbss._D4core9exception6_storeG128v

The same error occurs when using aarch64.

kinke commented 3 years ago

Looks like your LDC wasn't linked against our modded LLVM. Official releases from GitHub should do.

Dadoum commented 3 years ago

Getting this:

/usr/bin/ld.bfd: _D4core9exception6_storeG128v: TLS definition in /usr/bin/../lib/libdruntime-ldc.a(exception.o) section .tbss._D4core9exception6_storeG128v mismatches non-TLS reference in main.o

Should the clang from NDK also be patched ?

kinke commented 3 years ago

Nope, it's only used as linker driver. As the msg says, the problem is your compiled main.o compiled by LDC.

Dadoum commented 3 years ago

(The source code is the hello world in dlang.org)

Dadoum commented 3 years ago

Linux toolchain ldc2 is 1.25.1 like the android libraries, and the android ndk is the one on AUR too

kinke commented 3 years ago

Linux toolchain ldc2 is 1.25.1

Apparently not from GitHub here. We don't maintain any distro packages officially, so presumably most don't use our custom LLVM, and that comes with restrictions. This LLVM requirement for custom TLS emulation on Android is mentioned in https://wiki.dlang.org/Build_D_for_Android#Cross-compilation.

Dadoum commented 3 years ago

Yes the second error comes from the binary version downloaded from releases (I overwrote the package files)

kinke commented 3 years ago

Hmm; I don't remember anything about the TLS emulation on x86, but at least ARM (32+64 bit) should definitely link fine, as CI tests cross-building LDC itself + dub + some more tools.

Dadoum commented 3 years ago

Maybe it can help you aarch64 is also failing for another reason: (the message is repeated a lot of time:

/usr/bin/ld.bfd: main.o: Relocations in generic ELF (EM: 183)
kinke commented 3 years ago

Hmm. FWIW, CI uses Android NDK r21d or r21e, the LTS release, not r22 as currently on Arch apparently.