llvm/llvm-project

a missing `type` field in `DISubprogram` does not give a warning but a Segmentation fault

Open

#59.471 aberto em 12 de dez. de 2022

Ver no GitHub
 (21 comments) (0 reactions) (2 assignees)C++ (10.782 forks)batch import
crashdebuginfogood first issue

Métricas do repositório

Stars
 (26.378 stars)
Métricas de merge de PR
 (Mesclagem média 1d 2h) (1.000 fundiu PRs em 30d)

Description

hello there :wave: :yum:

i've followed your contributing guidelines to the "Crashing bugs" section, however i cannot go further in the bug report flow, i get an error which is not mentionned in the section :open_mouth: when i add -emit-llvm as given in the section, i get

> clang-15 -emit-llvm foo.main.ll foo.ll -o foo.elf
clang-15: error: -emit-llvm cannot be used when linking

i've tried to be as concise as possible, given the sizes of the files i manipulate, with simple examples, but also as complete as possible... i hope this is not too large nor to small :relieved: please fell free to ask anything :wink:

a tiny bit of context

i am writing a compiler for the Oberon language :+1: this is a work in progres, but it is already able to take some oberon input, translate it to llvm IR and finally use clang to optimize the IR and generate some machine code binary for the host target :ok_hand:

EDIT

i've changed the example for an even simpler one

my issue

i have the following oberon source file

; foo.obn
MODULE foo;
    VAR k: INTEGER;
BEGIN
    k := 0
END foo.

the compiler turns it into the two following IR files, thanks to a new -g option i'm currently working on! i.e. the command is here ./oberon -g compile foo.obn

; foo.main.ll
target triple = "x86_64-unknown-linux-gnu"

declare i32 @foo.__main()

define i32 @main() {
  call i32 @foo.__main()
  ret i32 0
}

and

; foo.ll
target triple = "x86_64-unknown-linux-gnu"

!0 = !DIFile(
  filename: "foo.obn",
  directory: "/home/amtoine/.local/share/ghq/github.com/oberonforall/compiler",
  checksumkind: CSK_MD5,
  checksum: "f4e60ed3f396da2f9a168da6602e890c"
)

!2 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!3 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!4 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_float)
!5 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_signed)

!6 = distinct !DIGlobalVariable(name: "k", scope: !1, file: !0, line: 2, type: !5, isLocal: false, isDefinition: true)
!7 = distinct !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
@foo.k = dso_local global i32 0, align 4, !dbg !7

!8 = !{!7}

!1 = distinct !DICompileUnit(
  language: DW_LANG_C99,
  file: !0,
  producer: "clang version 15.0.5",
  isOptimized: false,
  runtimeVersion: 0,
  emissionKind: FullDebug,
  globals: !8,
  splitDebugInlining: false,
  nameTableKind: None
)
;!9 = !DISubroutineType()

!10 = distinct !DISubprogram(
  name: "main",
  scope: !0,
  file: !0,
  line: 3,
  scopeLine: 3,
  flags: DIFlagPrototyped,
  spFlags: DISPFlagDefinition,
  unit: !1,
  retainedNodes: !{}
)

define dso_local i32 @foo.__main() !dbg !10 {
  store i32 0, i32* @foo.k, align 4, !dbg !DILocation(line: 5, column: 3, scope: !10)

  ret i32 0, !dbg !DILocation(line: 5, column: 9, scope: !10)
}

!llvm.dbg.cu = !{!1}

!11 = !{i32 2, !"Debug Info Version", i32 3}
!llvm.module.flags = !{!11}

NOTE: all of the above is generated dynamically by the compiler :warning:

finally, the error i get is the following

> clang-15 foo.main.ll foo.ll -o foo.elf | clip
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/amtoine/.local/share/clang-15/bin/clang-15 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name foo.ll -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -fcoverage-compilation-dir=/home/amtoine/.local/share/ghq/github.com/oberonforall/compiler -resource-dir /home/amtoine/.local/share/clang-15/lib/clang/15.0.5 -fdebug-compilation-dir=/home/amtoine/.local/share/ghq/github.com/oberonforall/compiler -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/foo-3d58f3.o -x ir foo.ll
1.	Code generation
2.	Running pass 'Function Pass Manager' on module 'foo.ll'.
3.	Running pass 'X86 Assembly Printer' on function '@foo.__main'
 #0 0x0000561dea8042d3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x5a942d3)
 #1 0x0000561dea80223e llvm::sys::RunSignalHandlers() (/home/amtoine/.local/share/clang-15/bin/clang-15+0x5a9223e)
 #2 0x0000561dea80466f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f6820651a00 (/usr/lib/libc.so.6+0x38a00)
 #4 0x0000561deb540a5c llvm::DwarfCompileUnit::constructSubprogramScopeDIE(llvm::DISubprogram const*, llvm::LexicalScope*) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x67d0a5c)
 #5 0x0000561deb528ce5 llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x67b8ce5)
 #6 0x0000561deb5112f1 llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x67a12f1)
 #7 0x0000561deb4ffc08 llvm::AsmPrinter::emitFunctionBody() (/home/amtoine/.local/share/clang-15/bin/clang-15+0x678fc08)
 #8 0x0000561de977e920 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) X86AsmPrinter.cpp:0:0
 #9 0x0000561de9db21cc llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x50421cc)
#10 0x0000561dea17a43b llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x540a43b)
#11 0x0000561dea181663 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x5411663)
#12 0x0000561dea17affa llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x540affa)
#13 0x0000561deaeeef83 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x617ef83)
#14 0x0000561deb2b0ffe clang::CodeGenAction::ExecuteAction() (/home/amtoine/.local/share/clang-15/bin/clang-15+0x6540ffe)
#15 0x0000561deb1f4e29 clang::FrontendAction::Execute() (/home/amtoine/.local/share/clang-15/bin/clang-15+0x6484e29)
#16 0x0000561deb16c2f6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x63fc2f6)
#17 0x0000561deb2aca9a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x653ca9a)
#18 0x0000561de8a782d2 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x3d082d2)
#19 0x0000561de8a7664a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#20 0x0000561de8a76451 clang_main(int, char**) (/home/amtoine/.local/share/clang-15/bin/clang-15+0x3d06451)
#21 0x00007f682063c290 (/usr/lib/libc.so.6+0x23290)
#22 0x00007f682063c34a __libc_start_main (/usr/lib/libc.so.6+0x2334a)
#23 0x0000561de8a72dba _start (/home/amtoine/.local/share/clang-15/bin/clang-15+0x3d02dba)
clang-15: error: unable to execute command: Segmentation fault (core dumped)
clang-15: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 15.0.5
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/amtoine/.local/share/clang-15/bin
clang-15: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.

additional context

compiling without debugging information

a simpler ./oberon compile foo.obn gives me

; foo.main.ll
target triple = "x86_64-unknown-linux-gnu"

declare i32 @foo.__main()

define i32 @main() {
  call i32 @foo.__main()
  ret i32 0
}

and

target triple = "x86_64-unknown-linux-gnu"

@foo.k = dso_local global i32 0, align 4

define dso_local i32 @foo.__main() {
  store i32 0, i32* @foo.k, align 4

  ret i32 0
}

and

> clang-15 foo.main.ll foo.ll -o foo.elf
> ./foo.elf

works just fine :yum:

clang installation

i've installed the latest available precompiled binary from here, inside my ~/.local/share/ directory and the version is

> clang-15 --version
clang version 15.0.5
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/amtoine/.local/share/clang-15/bin

:ok_hand:

Guia do colaborador