ldc-developers / ldc

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

bin/ldc2 crashes when built using dmd #4496

Open smokku opened 11 months ago

smokku commented 11 months ago

I'm building LDC (v1.34.0 git tag) with LLVM (llvmorg-15.0.7 git tag) and DMD (dmd-2.105.2-0.fedora.x86_64.rpm).

Resulting compiler crashes when attempting to build runtime libraries during build:

[129/181] Building CXX object CMakeFiles/LDCShared.dir/gen/abi/aarch64.cpp.o
[130/181] Building CXX object CMakeFiles/LDCShared.dir/gen/aa.cpp.o
[131/181] Linking CXX static library lib/libldc.a
[132/181] Linking CXX executable bin/ldc2
[133/181] Generating objects-debug/etc/c/curl.o, objects-debug/etc/c/odbc/sql.o, objects-debug/etc/c/odbc/sqlext.o, objects-debug/etc/c/odbc/sqltypes.o, objects-debug/etc/c/odbc/sqlucode.o, objects-debug/etc/c/sqlite3.o, objects-debug/etc/c/zlib.o, objects-debug/std/algorithm/comparison.o, objects-debug/std/algorithm/internal.o, objects-debug/std/algorithm/iteration.o, objects-debug/std/algorithm/mutation.o, objects-debug/std/algorithm/package.o, objects-debug/std/algorithm/searching.o, objects-debug/std/algorithm/setops.o, objects-debug/std/algorithm/sorting.o, objects-debug/std/array.o, objects-debug/std/ascii.o, objects-debug/std/base64.o, objects-debug/std/bigint.o, objects-debug/std/bitmanip.o, objects-debug/std/checkedint.o, objects-debug/std/compiler.o, objects-debug/std/complex.o, objects-debug/std/concurrency.o, objects-debug/std/container/array.o, objects-debug/std/container/binaryheap.o, objects-debug/std/container/dlist.o, objects-debug/std/container/package.o, objects-debug/std/container/rbtree.o, objects-debug/std/container/slist.o, objects-debug/std/container/util.o, objects-debug/std/conv.o, objects-debug/std/csv.o, objects-debug/std/datetime/date.o, objects-debug/std/datetime/interval.o, objects-debug/std/datetime/package.o, objects-debug/std/datetime/stopwatch.o, objects-debug/std/datetime/systime.o, objects-debug/std/datetime/timezone.o, objects-debug/std/demangle.o, objects-debug/std/digest/crc.o, objects-debug/std/digest/hmac.o, objects-debug/std/digest/md.o, objects-debug/std/digest/murmurhash.o, objects-debug/std/digest/package.o, objects-debug/std/digest/ripemd.o, objects-debug/std/digest/sha.o, objects-debug/std/encoding.o, objects-debug/std/exception.o, objects-debug/std/experimental/allocator/building_blocks/affix_allocator.o, objects-debug/std/experimental/allocator/building_blocks/aligned_block_list.o, objects-debug/std/experimental/allocator/building_blocks/allocator_list.o, objects-debug/std/experimental/allocator/building_blocks/ascending_page_allocator.o, objects-debug/std/experimental/allocator/building_blocks/bitmapped_block.o, objects-debug/std/experimental/allocator/building_blocks/bucketizer.o, objects-debug/std/experimental/allocator/building_blocks/fallback_allocator.o, objects-debug/std/experimental/allocator/building_blocks/free_list.o, objects-debug/std/experimental/allocator/building_blocks/free_tree.o, objects-debug/std/experimental/allocator/building_blocks/kernighan_ritchie.o, objects-debug/std/experimental/allocator/building_blocks/null_allocator.o, objects-debug/std/experimental/allocator/building_blocks/package.o, objects-debug/std/experimental/allocator/building_blocks/quantizer.o, objects-debug/std/experimental/allocator/building_blocks/region.o, objects-debug/std/experimental/allocator/building_blocks/scoped_allocator.o, objects-debug/std/experimental/allocator/building_blocks/segregator.o, objects-debug/std/experimental/allocator/building_blocks/stats_collector.o, objects-debug/std/experimental/allocator/common.o, objects-debug/std/experimental/allocator/gc_allocator.o, objects-debug/std/experimental/allocator/mallocator.o, objects-debug/std/experimental/allocator/mmap_allocator.o, objects-debug/std/experimental/allocator/package.o, objects-debug/std/experimental/allocator/showcase.o, objects-debug/std/experimental/allocator/typed.o, objects-debug/std/experimental/checkedint.o, objects-debug/std/experimental/logger/core.o, objects-debug/std/experimental/logger/filelogger.o, objects-debug/std/experimental/logger/multilogger.o, objects-debug/std/experimental/logger/nulllogger.o, objects-debug/std/experimental/logger/package.o, objects-debug/std/file.o, objects-debug/std/format/internal/floats.o, objects-debug/std/format/internal/read.o, objects-debug/std/format/internal/write.o, objects-debug/std/format/package.o, objects-debug/std/format/read.o, objects-debug/std/format/spec.o, objects-debug/std/format/write.o, objects-debug/std/functional.o, objects-debug/std/getopt.o, objects-debug/std/int128.o, objects-debug/std/internal/attributes.o, objects-debug/std/internal/cstring.o, objects-debug/std/internal/digest/sha_SSSE3.o, objects-debug/std/internal/math/biguintarm.o, objects-debug/std/internal/math/biguintcore.o, objects-debug/std/internal/math/biguintnoasm.o, objects-debug/std/internal/math/biguintx86.o, objects-debug/std/internal/math/errorfunction.o, objects-debug/std/internal/math/gammafunction.o, objects-debug/std/internal/memory.o, objects-debug/std/internal/scopebuffer.o, objects-debug/std/internal/test/dummyrange.o, objects-debug/std/internal/test/range.o, objects-debug/std/internal/test/uda.o, objects-debug/std/internal/unicode_comp.o, objects-debug/std/internal/unicode_decomp.o, objects-debug/std/internal/unicode_grapheme.o, objects-debug/std/internal/unicode_norm.o, objects-debug/std/internal/unicode_tables.o, objects-debug/std/internal/windows/advapi32.o, objects-debug/std/json.o, objects-debug/std/logger/core.o, objects-debug/std/logger/filelogger.o, objects-debug/std/logger/multilogger.o, objects-debug/std/logger/nulllogger.o, objects-debug/std/logger/package.o, objects-debug/std/math/algebraic.o, objects-debug/std/math/constants.o, objects-debug/std/math/exponential.o, objects-debug/std/math/hardware.o, objects-debug/std/math/operations.o, objects-debug/std/math/package.o, objects-debug/std/math/remainder.o, objects-debug/std/math/rounding.o, objects-debug/std/math/traits.o, objects-debug/std/math/trigonometry.o, objects-debug/std/mathspecial.o, objects-debug/std/meta.o, objects-debug/std/mmfile.o, objects-debug/std/net/curl.o, objects-debug/std/net/isemail.o, objects-debug/std/numeric.o, objects-debug/std/outbuffer.o, objects-debug/std/package.o, objects-debug/std/parallelism.o, objects-debug/std/path.o, objects-debug/std/process.o, objects-debug/std/random.o, objects-debug/std/range/interfaces.o, objects-debug/std/range/package.o, objects-debug/std/range/primitives.o, objects-debug/std/regex/internal/backtracking.o, objects-debug/std/regex/internal/generator.o, objects-debug/std/regex/internal/ir.o, objects-debug/std/regex/internal/kickstart.o, objects-debug/std/regex/internal/parser.o, objects-debug/std/regex/internal/tests.o, objects-debug/std/regex/internal/tests2.o, objects-debug/std/regex/internal/thompson.o, objects-debug/std/regex/package.o, objects-debug/std/signals.o, objects-debug/std/socket.o, objects-debug/std/stdint.o, objects-debug/std/stdio.o, objects-debug/std/string.o, objects-debug/std/sumtype.o, objects-debug/std/system.o, objects-debug/std/traits.o, objects-debug/std/typecons.o, objects-debug/std/typetuple.o, objects-debug/std/uni/package.o, objects-debug/std/uri.o, objects-debug/std/utf.o, objects-debug/std/uuid.o, objects-debug/std/variant.o, objects-debug/std/zip.o, objects-debug/std/zlib.o
ninja: job terminated due to signal 11: cd /home/smoku/devel/Dos/dos/external/ldc/runtime/phobos && /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 -c --output-o -conf= -w -de -preview=dip1000 -preview=dtorfields -preview=fieldwise -g -link-defaultlib-debug -d-debug -I/home/smoku/devel/Dos/dos/external/ldc/runtime/druntime/src -I/home/smoku/devel/Dos/dos/external/ldc/runtime/phobos -od=/home/smoku/devel/Dos/dos/out/build/_host/ldc/runtime/objects-debug -op etc/c/curl.d etc/c/odbc/sql.d etc/c/odbc/sqlext.d etc/c/odbc/sqltypes.d etc/c/odbc/sqlucode.d etc/c/sqlite3.d etc/c/zlib.d std/algorithm/comparison.d std/algorithm/internal.d std/algorithm/iteration.d std/algorithm/mutation.d std/algorithm/package.d std/algorithm/searching.d std/algorithm/setops.d std/algorithm/sorting.d std/array.d std/ascii.d std/base64.d std/bigint.d std/bitmanip.d std/checkedint.d std/compiler.d std/complex.d std/concurrency.d std/container/array.d std/container/binaryheap.d std/container/dlist.d std/container/package.d std/container/rbtree.d std/container/slist.d std/container/util.d std/conv.d std/csv.d std/datetime/date.d std/datetime/interval.d std/datetime/package.d std/datetime/stopwatch.d std/datetime/systime.d std/datetime/timezone.d std/demangle.d std/digest/crc.d std/digest/hmac.d std/digest/md.d std/digest/murmurhash.d std/digest/package.d std/digest/ripemd.d std/digest/sha.d std/encoding.d std/exception.d std/experimental/allocator/building_blocks/affix_allocator.d std/experimental/allocator/building_blocks/aligned_block_list.d std/experimental/allocator/building_blocks/allocator_list.d std/experimental/allocator/building_blocks/ascending_page_allocator.d std/experimental/allocator/building_blocks/bitmapped_block.d std/experimental/allocator/building_blocks/bucketizer.d std/experimental/allocator/building_blocks/fallback_allocator.d std/experimental/allocator/building_blocks/free_list.d std/experimental/allocator/building_blocks/free_tree.d std/experimental/allocator/building_blocks/kernighan_ritchie.d std/experimental/allocator/building_blocks/null_allocator.d std/experimental/allocator/building_blocks/package.d std/experimental/allocator/building_blocks/quantizer.d std/experimental/allocator/building_blocks/region.d std/experimental/allocator/building_blocks/scoped_allocator.d std/experimental/allocator/building_blocks/segregator.d std/experimental/allocator/building_blocks/stats_collector.d std/experimental/allocator/common.d std/experimental/allocator/gc_allocator.d std/experimental/allocator/mallocator.d std/experimental/allocator/mmap_allocator.d std/experimental/allocator/package.d std/experimental/allocator/showcase.d std/experimental/allocator/typed.d std/experimental/checkedint.d std/experimental/logger/core.d std/experimental/logger/filelogger.d std/experimental/logger/multilogger.d std/experimental/logger/nulllogger.d std/experimental/logger/package.d std/file.d std/format/internal/floats.d std/format/internal/read.d std/format/internal/write.d std/format/package.d std/format/read.d std/format/spec.d std/format/write.d std/functional.d std/getopt.d std/int128.d std/internal/attributes.d std/internal/cstring.d std/internal/digest/sha_SSSE3.d std/internal/math/biguintarm.d std/internal/math/biguintcore.d std/internal/math/biguintnoasm.d std/internal/math/biguintx86.d std/internal/math/errorfunction.d std/internal/math/gammafunction.d std/internal/memory.d std/internal/scopebuffer.d std/internal/test/dummyrange.d std/internal/test/range.d std/internal/test/uda.d std/internal/unicode_comp.d std/internal/unicode_decomp.d std/internal/unicode_grapheme.d std/internal/unicode_norm.d std/internal/unicode_tables.d std/internal/windows/advapi32.d std/json.d std/logger/core.d std/logger/filelogger.d std/logger/multilogger.d std/logger/nulllogger.d std/logger/package.d std/math/algebraic.d std/math/constants.d std/math/exponential.d std/math/hardware.d std/math/operations.d std/math/package.d std/math/remainder.d std/math/rounding.d std/math/traits.d std/math/trigonometry.d std/mathspecial.d std/meta.d std/mmfile.d std/net/curl.d std/net/isemail.d std/numeric.d std/outbuffer.d std/package.d std/parallelism.d std/path.d std/process.d std/random.d std/range/interfaces.d std/range/package.d std/range/primitives.d std/regex/internal/backtracking.d std/regex/internal/generator.d std/regex/internal/ir.d std/regex/internal/kickstart.d std/regex/internal/parser.d std/regex/internal/tests.d std/regex/internal/tests2.d std/regex/internal/thompson.d std/regex/package.d std/signals.d std/socket.d std/stdint.d std/stdio.d std/string.d std/sumtype.d std/system.d std/traits.d std/typecons.d std/typetuple.d std/uni/package.d std/uri.d std/utf.d std/uuid.d std/variant.d std/zip.d std/zlib.d
 #0 0x000055c1525e06d4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x31006d4)
 #1 0x000055c1525de61c llvm::sys::RunSignalHandlers() (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x30fe61c)
 #2 0x000055c1525e0a38 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f47e525fbb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
 #4 0x000055c150262c6a Target::_init(Param const&) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xd82c6a)
 #5 0x000055c1500dc177 mars_mainBody(Param&, Array<char const*>&, Array<char const*>&) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xbfc177)
 #6 0x000055c1502bbbc5 cppmain() (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xddbbc5)
 #7 0x000055c1501f8be1 D main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xd18be1)
 #8 0x000055c15261108f _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZ9__lambda2MFZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x313108f)
 #9 0x000055c152610f3e _D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130f3e)
#10 0x000055c152611017 _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3131017)
#11 0x000055c152610f3e _D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130f3e)
#12 0x000055c152610ea7 _d_run_main2 (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130ea7)
#13 0x000055c152610c90 _d_run_main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130c90)
#14 0x000055c1502b9d94 main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xdd9d94)
#15 0x00007f47e5249b8a __libc_start_call_main /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#16 0x00007f47e5249c4b /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../csu/libc-start.c:128:20
#17 0x00007f47e5249c4b __libc_start_main@GLIBC_2.2.5 /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../csu/libc-start.c:347:5
#18 0x000055c14fe8ff45 _start (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x9aff45)
ninja: subcommand failed
make: *** [Makefile:88: /home/smoku/devel/Dos/dos/out/host/bin/ldc] Error 1

Built compiler crashes even on attempting to compile an empty file:

> /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 --version

LDC - the LLVM D compiler (1.34.0):
  based on DMD v2.104.2 and LLVM 15.0.7
  built with DMD64 D Compiler v2.105.2
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3

> touch ~/test.d
> /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 ~/test.d

 #0 0x000055714483e6d4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x31006d4)
 #1 0x000055714483c61c llvm::sys::RunSignalHandlers() (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x30fe61c)
 #2 0x000055714483ea38 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f294d05fbb0 __restore_rt (/lib64/libc.so.6+0x3dbb0)
 #4 0x00005571424c0c6a Target::_init(Param const&) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xd82c6a)
 #5 0x000055714233a177 mars_mainBody(Param&, Array<char const*>&, Array<char const*>&) (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xbfc177)
 #6 0x0000557142519bc5 cppmain() (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xddbbc5)
 #7 0x0000557142456be1 D main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xd18be1)
 #8 0x000055714486f08f _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZ9__lambda2MFZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x313108f)
 #9 0x000055714486ef3e _D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130f3e)
#10 0x000055714486f017 _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3131017)
#11 0x000055714486ef3e _D2rt6dmain212_d_run_main2UAAamPUQgZiZ7tryExecMFMDFZvZv (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130f3e)
#12 0x000055714486eea7 _d_run_main2 (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130ea7)
#13 0x000055714486ec90 _d_run_main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x3130c90)
#14 0x0000557142517d94 main (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0xdd9d94)
#15 0x00007f294d049b8a __libc_start_call_main /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#16 0x00007f294d049c4b /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../csu/libc-start.c:128:20
#17 0x00007f294d049c4b __libc_start_main@GLIBC_2.2.5 /usr/src/debug/glibc-2.37-5.fc38.x86_64/csu/../csu/libc-start.c:347:5
#18 0x00005571420edf45 _start (/home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2+0x9aff45)
fish: Job 1, '/home/smoku/devel/Dos/dos/out/b…' terminated by signal SIGSEGV (Address boundary error)

I tried to debug using gdb. The backtrace pointed to Target::_init in gen/target.cpp, but the line was inconclusive.

So I sprinkled the whole function with printf() every second line to get the exact place of the crash and the problem disappeared. Compiler started working fine.

I was able to narrow it down to single printf line.

diff --git a/gen/target.cpp b/gen/target.cpp
index 8b81afe12e..00783089cb 100644
--- a/gen/target.cpp
+++ b/gen/target.cpp
@@ -177,6 +177,7 @@ void Target::_init(const Param &params) {
     RealProperties.min_normal = CTFloat::parse("0x1p-16382", isOutOfRange);
     RealProperties.epsilon = CTFloat::parse("0x1p-63", isOutOfRange);
     RealProperties.dig = 18;
+    printf(" ");
     RealProperties.mant_dig = 64;
     RealProperties.max_exp = 16384;
     RealProperties.min_exp = -16381;

With this change the compiler builds and works fine. It is able to successfully complete the build.

It does not crash anymore:

> /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 ~/test.d

/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/13/../../../../lib64/crt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
collect2: error: ld returned 1 exit status
Error: /usr/bin/cc failed with status: 1

I know it looks bizarre, but if I move this printf() one line up or down, the crash is not gone. Only this specific line fixes the crash.

The printf-patched compiler works fine, as it is able to properly build itself, when used instead DMD.

Also, building with this ldc2 does not require printf-patch. Compiler builds as-is.

> /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 --version                                                            śro, 20 wrz 2023, 10:48:57
LDC - the LLVM D compiler (1.34.0):
  based on DMD v2.104.2 and LLVM 15.0.7
  built with LDC - the LLVM D compiler (1.34.0)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
kinke commented 11 months ago

This sounds bizarre indeed - hacking a printf into the C++ source makes the built compiler work when compiling totally unrelated D parts with DMD?! Anyway, if this is a genuine reproducible issue, it's almost certainly a DMD issue, not an LDC one.

Our CI tests DMD as host compiler too (on Linux and Mac), and those jobs are green - the latest master pipeline was using DMD v2.105.1-beta.1.

smokku commented 11 months ago

This is 100% reproducible on my machine. I've compiled ldc many times during debugging. Several times more when I found it, as I could not believe it.

I have a suspicion that there might be some ABI incompatibility between D objects generated by DMD and C++ objects of LLVM. This is due to the fact, when LDC is generating D object files (via LLVM), the crash is not present.

If you wish to try my build env, check-out "ldc" branch of https://github.com/D-os/dos/tree/ldc and make ldc.

JohanEngelen commented 11 months ago

I have a suspicion that there might be some ABI incompatibility between D objects generated by DMD and C++ objects of LLVM. This is due to the fact, when LDC is generating D object files (via LLVM), the crash is not present.

This is why kinke said that it is probably a DMD bug (so the bug belongs in DMD's bug tracker, not LDC).

kinke commented 11 months ago

The printf doesn't affect the ABI, and as said, it works for CI (I doubt this is a DMD v2.105.2 regression). What linker are you using, and can you try different ones?

smokku commented 11 months ago
/usr/bin/ld --version
GNU ld version 2.39-9.fc38

I have mold built. I will try linking with it.

smokku commented 11 months ago

Linking with mold does not help. Still crashes with SIGSEGV.

kinke commented 11 months ago

Yeah well I wouldn't consider mold to be an extremely stable linker to be used as a reference. I'd definitely try gold and (recent) lld.

smokku commented 11 months ago

Unfortunately no change with gold nor lld. Still crashes.

GNU gold (version 2.39-9.fc38) 1.16
LLD 16.0.6 (compatible with GNU linkers)
kinke commented 11 months ago

Hmm then I'm out of ideas - bizarre. Btw any good reason for using a DMD host compiler? DMD's own release builds are built with LDC, because it's ~50% faster then.

smokku commented 11 months ago

Not really… I wanted to go with "official" compiler in my build instructions. ¯\(ツ)

Go to https://dlang.org/download.html and download a build for your distribution.

That's what I did. I just clicked the proper button and had the compiler installed in few seconds.

image

smokku commented 11 months ago

I've just tried ldc packaged by Fedora.

[35/181] Linking CXX executable bin/FileCheck
ninja: job failed: : && /home/smoku/devel/Dos/dos/out/host/bin/clang++ -DDMDV2 -O3 -DNDEBUG  obj/ldmd2.o -o bin/ldmd2  lib/libldmd.a  -llldMinGW  -llldCOFF  -llldELF  -llldMachO  -llldWasm  -llldCommon  -lLLVMSymbolize  -lLLVMWindowsManifest  -lLLVMWindowsDriver  -lLLVMLTO  -lLLVMExtensions  -lPolly  -lPollyISL  -lLLVMPasses  -lLLVMObjCARCOpts  -lLLVMCoroutines  -lLLVMLibDriver  -lLLVMOption  -lLLVMipo  -lLLVMVectorize  -lLLVMLinker  -lLLVMIRReader  -lLLVMFrontendOpenMP  -lLLVMAsmParser  -lLLVMX86TargetMCA  -lLLVMMCA  -lLLVMX86Disassembler  -lLLVMX86AsmParser  -lLLVMX86CodeGen  -lLLVMX86Desc  -lLLVMX86Info  -lLLVMInstrumentation  -lLLVMAArch64Disassembler  -lLLVMMCDisassembler  -lLLVMAArch64AsmParser  -lLLVMAArch64CodeGen  -lLLVMCFGuard  -lLLVMGlobalISel  -lLLVMSelectionDAG  -lLLVMAsmPrinter  -lLLVMCodeGen  -lLLVMTarget  -lLLVMScalarOpts  -lLLVMInstCombine  -lLLVMAggressiveInstCombine  -lLLVMTransformUtils  -lLLVMBitWriter  -lLLVMAnalysis  -lLLVMProfileData  -lLLVMSymbolize  -lLLVMDebugInfoPDB  -lLLVMDebugInfoMSF  -lLLVMDebugInfoDWARF  -lLLVMObject  -lLLVMTextAPI  -lLLVMMCParser  -lLLVMBitReader  -lLLVMCore  -lLLVMRemarks  -lLLVMBitstreamReader  -lLLVMAArch64Desc  -lLLVMAArch64Utils  -lLLVMAArch64Info  -lLLVMMC  -lLLVMDebugInfoCodeView  -lLLVMBinaryFormat  -lLLVMSupport  -lLLVMDemangle  -L/home/smoku/devel/Dos/dos/out/host/lib  -lrt  -ldl  -lm  -lz  -lzstd  -lxml2  -Wl,--export-dynamic  /usr/lib64/ldc_rt.dso.o  -L/usr/lib64  -lphobos2-ldc-shared  -ldruntime-ldc-shared  -Wl,--gc-sections  -lrt  -ldl  -lpthread  -lm  -m64  -lLLVMWindowsManifest  -lLLVMWindowsDriver  -lLLVMLTO  -lLLVMExtensions  -lPolly  -lPollyISL  -lLLVMPasses  -lLLVMObjCARCOpts  -lLLVMCoroutines  -lLLVMLibDriver  -lLLVMOption  -lLLVMipo  -lLLVMVectorize  -lLLVMLinker  -lLLVMIRReader  -lLLVMFrontendOpenMP  -lLLVMAsmParser  -lLLVMX86TargetMCA  -lLLVMMCA  -lLLVMX86Disassembler  -lLLVMX86AsmParser  -lLLVMX86CodeGen  -lLLVMX86Desc  -lLLVMX86Info  -lLLVMInstrumentation  -lLLVMAArch64Disassembler  -lLLVMMCDisassembler  -lLLVMAArch64AsmParser  -lLLVMAArch64CodeGen  -lLLVMCFGuard  -lLLVMGlobalISel  -lLLVMSelectionDAG  -lLLVMAsmPrinter  -lLLVMCodeGen  -lLLVMTarget  -lLLVMScalarOpts  -lLLVMInstCombine  -lLLVMAggressiveInstCombine  -lLLVMTransformUtils  -lLLVMBitWriter  -lLLVMAnalysis  -lLLVMProfileData  -lLLVMDebugInfoPDB  -lLLVMDebugInfoMSF  -lLLVMDebugInfoDWARF  -lLLVMObject  -lLLVMTextAPI  -lLLVMMCParser  -lLLVMBitReader  -lLLVMCore  -lLLVMRemarks  -lLLVMBitstreamReader  -lLLVMAArch64Desc  -lLLVMAArch64Utils  -lLLVMAArch64Info  -lLLVMMC  -lLLVMDebugInfoCodeView  -lLLVMBinaryFormat  -lLLVMSupport  -lLLVMDemangle  -lrt  -ldl  -lm  -lz  -lzstd  -lxml2  /usr/lib64/ldc_rt.dso.o  -lphobos2-ldc-shared  -ldruntime-ldc-shared  -lpthread  -lrt  -ldl  -lm  -lz  -lzstd  -lxml2  /usr/lib64/ldc_rt.dso.o  -lphobos2-ldc-shared  -ldruntime-ldc-shared  -lpthread && :
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o: in function `_D2rt3dso12register_dsoFZv':
dso.d:(.text._D2rt3dso12register_dsoFZv+0x0): multiple definition of `_D2rt3dso12register_dsoFZv'; /usr/lib64/ldc_rt.dso.o:dso.d:(.text._D2rt3dso12register_dsoFZv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData+0x0): multiple definition of `_D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData'; /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoSlotPv+0x0): multiple definition of `_D2rt3dso7dsoSlotPv'; /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoSlotPv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o: in function `_D2rt3dso14unregister_dsoFZv':
dso.d:(.text._D2rt3dso14unregister_dsoFZv+0x0): multiple definition of `_D2rt3dso14unregister_dsoFZv'; /usr/lib64/ldc_rt.dso.o:dso.d:(.text._D2rt3dso14unregister_dsoFZv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss.__rt_dso_ref+0x0): multiple definition of `__rt_dso_ref'; /usr/lib64/ldc_rt.dso.o:(.bss.__rt_dso_ref+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o: in function `_D2rt3dso12register_dsoFZv':
dso.d:(.text._D2rt3dso12register_dsoFZv+0x0): multiple definition of `_D2rt3dso12register_dsoFZv'; /usr/lib64/ldc_rt.dso.o:dso.d:(.text._D2rt3dso12register_dsoFZv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData+0x0): multiple definition of `_D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData'; /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoDataSQq19sections_elf_shared15CompilerDSOData+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoSlotPv+0x0): multiple definition of `_D2rt3dso7dsoSlotPv'; /usr/lib64/ldc_rt.dso.o:(.bss._D2rt3dso7dsoSlotPv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o: in function `_D2rt3dso14unregister_dsoFZv':
dso.d:(.text._D2rt3dso14unregister_dsoFZv+0x0): multiple definition of `_D2rt3dso14unregister_dsoFZv'; /usr/lib64/ldc_rt.dso.o:dso.d:(.text._D2rt3dso14unregister_dsoFZv+0x0): first defined here
/usr/bin/ld: /usr/lib64/ldc_rt.dso.o:(.bss.__rt_dso_ref+0x0): multiple definition of `__rt_dso_ref'; /usr/lib64/ldc_rt.dso.o:(.bss.__rt_dso_ref+0x0): first defined here
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
> rpm -qf /usr/lib64/ldc_rt.dso.o
ldc-1.32.2-1.fc38.x86_64
smokku commented 11 months ago

With gdc (+ gdmd wrapper) build fails with:

ninja: job failed: : && /home/smoku/devel/Dos/dos/out/host/bin/clang++ -DDMDV2 -O3 -DNDEBUG  obj/ldmd2.o -o bin/ldmd2  lib/libldmd.a  -llldMinGW  -llldCOFF  -llldELF  -llldMachO  -llldWasm  -llldCommon  -lLLVMSymbolize  -lLLVMWindowsManifest  -lLLVMWindowsDriver  -lLLVMLTO  -lLLVMExtensions  -lPolly  -lPollyISL  -lLLVMPasses  -lLLVMObjCARCOpts  -lLLVMCoroutines  -lLLVMLibDriver  -lLLVMOption  -lLLVMipo  -lLLVMVectorize  -lLLVMLinker  -lLLVMIRReader  -lLLVMFrontendOpenMP  -lLLVMAsmParser  -lLLVMX86TargetMCA  -lLLVMMCA  -lLLVMX86Disassembler  -lLLVMX86AsmParser  -lLLVMX86CodeGen  -lLLVMX86Desc  -lLLVMX86Info  -lLLVMInstrumentation  -lLLVMAArch64Disassembler  -lLLVMMCDisassembler  -lLLVMAArch64AsmParser  -lLLVMAArch64CodeGen  -lLLVMCFGuard  -lLLVMGlobalISel  -lLLVMSelectionDAG  -lLLVMAsmPrinter  -lLLVMCodeGen  -lLLVMTarget  -lLLVMScalarOpts  -lLLVMInstCombine  -lLLVMAggressiveInstCombine  -lLLVMTransformUtils  -lLLVMBitWriter  -lLLVMAnalysis  -lLLVMProfileData  -lLLVMSymbolize  -lLLVMDebugInfoPDB  -lLLVMDebugInfoMSF  -lLLVMDebugInfoDWARF  -lLLVMObject  -lLLVMTextAPI  -lLLVMMCParser  -lLLVMBitReader  -lLLVMCore  -lLLVMRemarks  -lLLVMBitstreamReader  -lLLVMAArch64Desc  -lLLVMAArch64Utils  -lLLVMAArch64Info  -lLLVMMC  -lLLVMDebugInfoCodeView  -lLLVMBinaryFormat  -lLLVMSupport  -lLLVMDemangle  -L/home/smoku/devel/Dos/dos/out/host/lib  -lrt  -ldl  -lm  -lz  -lzstd  -lxml2  -Wl,--export-dynamic  -L/usr/lib/gcc/x86_64-redhat-linux/13  -L/usr/lib/gcc/x86_64-redhat-linux/13/../../../../lib64  -L/lib/../lib64  -L/usr/lib/../lib64  -L/usr/lib/gcc/x86_64-redhat-linux/13/../../..  -lgphobos  -lgcc_s  -lgcc  -lm  -lc  -lgcc_s  -lgcc  -lLLVMWindowsManifest  -lLLVMWindowsDriver  -lLLVMLTO  -lLLVMExtensions  -lPolly  -lPollyISL  -lLLVMPasses  -lLLVMObjCARCOpts  -lLLVMCoroutines  -lLLVMLibDriver  -lLLVMOption  -lLLVMipo  -lLLVMVectorize  -lLLVMLinker  -lLLVMIRReader  -lLLVMFrontendOpenMP  -lLLVMAsmParser  -lLLVMX86TargetMCA  -lLLVMMCA  -lLLVMX86Disassembler  -lLLVMX86AsmParser  -lLLVMX86CodeGen  -lLLVMX86Desc  -lLLVMX86Info  -lLLVMInstrumentation  -lLLVMAArch64Disassembler  -lLLVMMCDisassembler  -lLLVMAArch64AsmParser  -lLLVMAArch64CodeGen  -lLLVMCFGuard  -lLLVMGlobalISel  -lLLVMSelectionDAG  -lLLVMAsmPrinter  -lLLVMCodeGen  -lLLVMTarget  -lLLVMScalarOpts  -lLLVMInstCombine  -lLLVMAggressiveInstCombine  -lLLVMTransformUtils  -lLLVMBitWriter  -lLLVMAnalysis  -lLLVMProfileData  -lLLVMDebugInfoPDB  -lLLVMDebugInfoMSF  -lLLVMDebugInfoDWARF  -lLLVMObject  -lLLVMTextAPI  -lLLVMMCParser  -lLLVMBitReader  -lLLVMCore  -lLLVMRemarks  -lLLVMBitstreamReader  -lLLVMAArch64Desc  -lLLVMAArch64Utils  -lLLVMAArch64Info  -lLLVMMC  -lLLVMDebugInfoCodeView  -lLLVMBinaryFormat  -lLLVMSupport  -lLLVMDemangle  -lrt  -ldl  -lm  -lz  -lzstd  -lxml2  -lgphobos  -lgcc_s  -lgcc  -lc  -lm  -lz  -lzstd  -lxml2  -lgphobos  -lgcc_s  -lgcc  -lc && :
/usr/bin/ld: obj/ldmd2.o: relocation R_X86_64_32 against `.rodata' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: failed to set dynamic section sizes: bad value
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: subcommand failed
> gdmd --version
gdc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)
smokku commented 11 months ago

Adding -DD_COMPILER_FLAGS="-fPIC" to cmake call fixes compilation with gdmd.

> /home/smoku/devel/Dos/dos/out/build/_host/ldc/bin/ldc2 --version

LDC - the LLVM D compiler (1.34.0):
  based on DMD v2.104.2 and LLVM 15.0.7
  built with gdc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3
  http://dlang.org - http://wiki.dlang.org/LDC

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64

Built compiler works fine.

kalev commented 11 months ago

This is all bizarre because the ldc compiler as packaged in Fedora certainly can compile itself and other packages in Fedora. I think it may be something to do with using clang vs gcc - the Fedora-packaged ldc is built using gcc.