Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are "retainedNodes" in LLVMs debug metadata?

Using the LLVM 8.0.1 library, I try to create the debug info for a function with the following code:

DIFile *Unit = DebugBuilder->createFile(CompileUnit->getFilename(), CompileUnit->getDirectory());
DIScope *FContext(Unit);

DISubprogram *SP = DebugBuilder->createFunction(
    FContext, def->Name, def->Name, Unit, LineNo,
    CreateFunctionType(ft, CompileUnit->getFile()), 0);

func->setSubprogram(SP);

This, however, results in IR like the following:

define i32 @main(i32 %y) !dbg !3 {
entry:
  ret i32 2
}
    ; ...
!3 = !DISubprogram(name: "main", linkageName: "main", scope: !2, file: !2, type: !4, spFlags: 0, retainedNodes: !7)
    ; ...
!7 = <temporary!> !{}

Which, upon calling DebugBuilder->finalize(), throws Assertion failed: !N->isTemporary() && "Expected all forward declarations to be resolved"

I have not found a description of the retainedNodes field in the official reference nor other tutorials, and web searches only lead to uncommented sections of the LLVM source. What is the meaning or purpose of this field? How is a temporary node created there?

like image 451
Tau Avatar asked Nov 25 '25 05:11

Tau


1 Answers

I found this solved by adding, before generating the DebugBuilder,

TheModule->addModuleFlag(llvm::Module::Warning, "CodeView", 1);

... as explained apparently nowhere in the official documentation.

like image 188
Tau Avatar answered Nov 28 '25 16:11

Tau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!