ldc-developers / ldc

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

No stack trace when llvm fails #3335

Open etcimon opened 4 years ago

etcimon commented 4 years ago

I'm compiling Botan for iOS and there's about 500,000 LOC. I get the following output from LDC:

botan 1.12.18+commit.2.gd2e766e: building configuration "botan-test-full"...
Enhanced memory security is enabled.
Memory debugger enabled
error: couldn't allocate output register for constraint '{eax}'
ldc2 failed with exit code 1.

The issue is that LLVM failures should be caught and a stack trace generated in order to be useful

etcimon commented 4 years ago

Posted a $300 bounty https://www.bountysource.com/issues/88985269-no-stack-trace-when-llvm-fails

JohanEngelen commented 4 years ago

What you need here is not a stacktrace, because LLVM is not crashing. It is reporting the error (error: couldn't allocate output register for constraint '{eax}') and what you need here is source location, for example the function in which that asm output constraint was found.

kinke commented 4 years ago

I'm compiling Botan for iOS

I assume no x86 target, but AArch64, so any inline asm using the x86 eax register cannot work. So this might mean revising all existing inline asm.

kinke commented 4 years ago

clang does support this (https://cpp.godbolt.org/z/vfYQ-n), apparently by attaching some srcloc IR metadata.

kinke commented 4 years ago

I've quickly looked into this; srcloc (+ custom InlineAsmDiagnosticHandler for LLVMContext) would indeed be helpful for errors in the template string, additionally displaying the LOC of the D expression/statement. Validation (in terms of valid codes) for inline asm constraint strings isn't part of that; clang does it all in the frontend, with clang-specific TargetInfo classes validating register names etc (validateOutputConstraint()...). So these LLVM errors (wrt. wrong register names in constraints) unfortunately don't pass through InlineAsmDiagnosticHandler, and so the IR metadata isn't available.

kinke commented 4 years ago

The actual inline asm diagnostics have been extended in #3339. Manual validation of the constraints isn't feasible / not worth the cost IMO. If you don't expect a lot of these errors and just want to locate them, there are little tricks that can help, like running dub with -v for the failing cmdline, then outputting the textual IR (only) via -output-ll (possibly adding -disable-verify to skip LLVM validation passes), and finally grepping the generated .ll file for the problematic constraint string.