Open smokku opened 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.
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
.
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).
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?
/usr/bin/ld --version
GNU ld version 2.39-9.fc38
I have mold
built. I will try linking with it.
Linking with mold
does not help. Still crashes with SIGSEGV.
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.
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)
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.
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.
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
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)
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.
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.
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:
Built compiler crashes even on attempting to compile an empty file:
I tried to debug using gdb. The backtrace pointed to
Target::_init
ingen/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.
With this change the compiler builds and works fine. It is able to successfully complete the build.
It does not crash anymore:
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.