ldc-developers / ldc

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

Android/Termux: build failure #3153

Open kettes-leulhetsz opened 5 years ago

kettes-leulhetsz commented 5 years ago

All packages are termux-latest.


~/l/l/build> cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=~/bin -GNinja -DCOMPILE_D_MODULES_SEPARATELY=ON
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/cc
-- Check for working C compiler: /data/data/com.termux/files/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++
-- Check for working CXX compiler: /data/data/com.termux/files/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found host D compiler /data/data/com.termux/files/usr/bin/ldmd2, with default flags ''
-- Host D compiler ID: LDMD
-- Host D compiler version: LDC - the LLVM D compiler (1.17.0)
-- Host D compiler front-end version: 2087
-- Found LLVM: /data/data/com.termux/files/usr (found suitable version "8.0.1", minimum required is "3.9")
-- Found PkgConfig: /data/data/com.termux/files/usr/bin/pkg-config (found version "0.29.2")
-- Checking for module 'LLVMSPIRVLib'
--   No package 'LLVMSPIRVLib' found
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- LDC version identifier: 1.17.0-git-a9b9097
-- Building LDC with dynamic compilation support: True (LDC_DYNAMIC_COMPILE=True)
-- Building LDC with integrated LLD: ON (LDC_WITH_LLD=ON)
-- Performing Test LINKER_ACCEPTS_EXPORT_DYNAMIC_FLAG
-- Performing Test LINKER_ACCEPTS_EXPORT_DYNAMIC_FLAG - Success
-- Building LDC with plugin support: ON (LDC_ENABLE_PLUGINS=ON)
-- Host D compiler linker program: /data/data/com.termux/files/usr/bin/cc
-- Host D compiler linker flags: -L/data/data/com.termux/files/usr/bin/../lib;-lphobos2-ldc;-ldruntime-ldc;-Wl,--gc-sections;-ldl;-lm
-- Looking for _SC_ARG_MAX
-- Looking for _SC_ARG_MAX - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Using path for Intrinsics.td: /data/data/com.termux/files/usr/include
-- The ASM compiler identification is Clang
-- Found assembler: /data/data/com.termux/files/usr/bin/cc
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Performing Test LINKER_ACCEPTS_EXCLUDE_LIBS_ALL
-- Performing Test LINKER_ACCEPTS_EXCLUDE_LIBS_ALL - Success
-- GDB 8.3 detected
-- LDC_HOST_ARCH: AArch64
-- Configuring done
-- Generating done
-- Build files have been written to: /data/data/com.termux/files/home/ldc/ldc/build
~/l/l/build> ninja -j4                                                                                 [86/355] Building CXX object CMakeFiles/LDCShared.dir/gen/toir.cpp.o
../gen/toir.cpp:1123:28: warning: lambda capture 'e' is not used [-Wunused-lambda-capture]
    auto getBasePointer = [e, v, etype]() {
                           ^~
1 warning generated.
[245/355] Generating objects/core/atomic.o, object.../bionic/string.o, objects/core/sys/bionic/unistd.
FAILED: runtime/objects/core/atomic.o runtime/objects/core/attribute.o runtime/objects/core/bitop.o <snip> runtime/objects/core/sys/bionic/unistd.o
cd /data/data/com.termux/files/home/ldc/ldc/runtime/druntime/src && /data/data/com.termux/files/home/ldc/ldc/build/bin/ldc2 -c --output-o -conf= -w -O3 -release -I/data/data/com.termux/files/home/ldc/ldc/runtime/druntime/src -od=/data/data/com.termux/files/home/ldc/ldc/build/runtime/objects -op core/atomic.d core/attribute.d core/bitop.d <snip> core/sys/bionic/unistd.d
Warning: unknown target OS: android
Warning: Assuming critical section size = 40 bytes
core/stdc/time.d(151): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(151): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(153): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(153): Error: undefined identifier `tm`
core/stdc/time.d(155): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(155): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(158): Error: undefined identifier `tm`
core/stdc/time.d(160): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(162): Error: undefined identifier `tm`
core/stdc/time.d(162): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(164): Error: undefined identifier `tm`
core/stdc/time.d(164): Error: undefined identifier `time_t`, did you mean function `time`?
core/stdc/time.d(166): Error: undefined identifier `tm`
core/stdc/wchar_.d(125): Error: undefined identifier `wchar_t`, did you mean `dchar`?
core/stdc/wchar_.d(128): Error: undefined identifier `wchar_t`, did you mean `dchar`?
core/stdc/wchar_.d(131): Error: undefined identifier `FILE`
core/stdc/wchar_.d(131): Error: undefined identifier `wchar_t`, did you mean `dchar`?
core/stdc/wchar_.d(133): Error: undefined identifier `FILE`
core/stdc/wchar_.d(133): Error: undefined identifier `wchar_t`, did you mean `dchar`?
core/stdc/wchar_.d(135): Error: undefined identifier `wchar_t`, did you mean `dchar`?
[248/355] Building CXX object runtime/CMakeFiles/ldc-jit-rt-so.dir/jit-rt/cpp-so/compile.cpp.o
ninja: build stopped: subcommand failed.
``
kinke commented 5 years ago
  1. druntime v1.17 doesn't compile without this: https://github.com/dlang/druntime/pull/2779
  2. Found LLVM: /data/data/com.termux/files/usr (found suitable version "8.0.1", minimum required is "3.9") - is that our fork? It won't work without it (custom TLS emulation...).
  3. The missing symbols you get when compiling druntime with the fresh native build of LDC weren't an issue when cross-compiling, so I assume it has something to do with your LLVM's default triple, as LDC seems not to predefine Posix or CRuntime_Bionic. Use bin/ldc2 --version to output the default triple of your native LDC and compare it to the cross-compiled termux-ldc.
  4. You'll at least need an additional -DTARGET_SYSTEM='Android;Linux;UNIX' in the CMake cmdline, as CMake doesn't detect Android (or at least used not to).
kettes-leulhetsz commented 5 years ago

LLVM is stock libllvm-static from termux-stable. Default targets are the same though:

~/l/l/build> bin/ldc2 --version | grep Default
  Default target: aarch64-linux-android
~/l/l/build> ldc2 --version | grep Default
  Default target: aarch64--linux-android
kinke commented 5 years ago

The triples are not the same:

So setting env variable DFLAGS='-mtriple=aarch64--linux-android' should get you somewhat further with stock LLVM. [The default triple can be customized in the LLVM CMake command line, see the Wiki.]

kettes-leulhetsz commented 5 years ago

Tried building ldc-llvm with:

cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_ENABLE_CXX1Y=OFF -DLLVM_PARALLEL_LINK_JOBS=5 -DLLVM_TARGETS_TO_BUILD="AArch64" -DLLVM_LINK_LLVM_DYLIB=ON -GNinja -DCMAKE_INSTALL_PREFIX=$PREFIX -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_ENABLE_LTO=Thin
/data/data/com.termux/files/usr/bin/aarch64-linux-android-ld: lib/libLLVMSupport.a: error adding symbols: archive has no index; run ranlib to add one
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Thin LTO would've been nice for linker memory usage. Retrying without it.

Apparently there's UserLAnd which seems to be a Termux fork that runs full distros under proot, but ldc isn't packaged for its Ubuntu yet. I can't think of a use case where Termux comes out on top in comparison if this takes off.

kinke commented 5 years ago

Thin LTO would've been nice for linker memory usage.

Code generation at link time consumes less memory than linking machine-code objects and libraries? CMAKE_BUILD_TYPE=Release probably helps with linker memory requirements.

kettes-leulhetsz commented 5 years ago

Yes, it does. I've had it peak at 500 Mb on Chromium builds. The article also claims build times comparable to non-LTO builds due to parallel linking.

kinke commented 5 years ago

Yes, it does.

I don't see any mention of that in the linked article.

kettes-leulhetsz commented 5 years ago

It's this picture, with the text

On the memory consumption side, the improvements are significant. Over the last two years, FullLTO was significantly improved, as shown on the chart below, but our measurement shows that ThinLTO keeps a large advantage.

That large advantage is an advantage over regular linking, too, for a large enough project.

kinke commented 5 years ago

That large advantage is an advantage over regular linking, too, for a large enough project.

Yeah but that's exactly what the article doesn't mention at all. ;)

kinke commented 5 years ago

How's it going, were you able to build LDC and the libraries successfully with termux-ldc?

kettes-leulhetsz commented 5 years ago

Yeah but that's exactly what the article doesn't mention at all. ;)

That's why you need to run a source-based distro on underpowered hardware for a decade. You'll pick up these things :P

I do have a sneaking suspicion that rustc's parallelism and low memory usage was heavily influenced by ThinLTO. I'm seeing absurdly low mem usage even when it hogs all the CPUs and/or cargo builds all the things in parallel. Pouring a million man hours into a bad design can make it tolerable, who would've thought.

As for building ldc, I think I'll need to scale back on my ambitions for now. (You know you've picked the wrong hobby when bootstrapping an Exherbo in Arch in UserLAnd in Android seems like a reasonable idea...) Currently blocked on a bfd assert with no replacement linker. Should I keep this open?

kinke commented 5 years ago

Currently blocked on a bfd assert with no replacement linker.

Our Ubuntu-aarch64 CI is flooded with gold warnings: Erratum 843419 found and fixed at ... Maybe you need --fix-cortex-a53-843419 as additional linker flag?