As discussed on the llvm-commits list [1], for platforms which default to emitting DWARF2, such as *BSD, Darwin and Solaris, clang can output an incorrect CIE version field in object files, depending on whether -g is used or not. This behavior was introduced by r211272. A simple demonstration (as already shown on the mailing list): $ cat build-config-test.c int f (void) { return 0; } $ ~/obj/llvm-r211272/bin/clang -c build-config-test.c -o test-r211272-without-g.o $ ~/obj/llvm-r211272/bin/clang -c -g build-config-test.c -o test-r211272-with-g.o $ strip test-r211272-without-g.o $ strip test-r211272-with-g.o $ dwarfdump -v -F test-r211272-without-g.o .eh_frame fde: < 0><0x00000020:0x0000002b><><fde offset 0x00000018 length: 0x0000001c><eh aug data len 0x0> 0x00000020: <off cfa=08(r7) > <off r16=-8(cfa) > 0x00000021: <off cfa=16(r7) > <off r6=-16(cfa) > <off r16=-8(cfa) > 0x00000024: <off cfa=16(r6) > <off r6=-16(cfa) > <off r16=-8(cfa) > cie: < 0> version 3 cie section offset 0 0x00000000 augmentation zR code_alignment_factor 1 data_alignment_factor -8 return_address_register 16 eh aug data len 0x1 bytes 0x1b bytes of initial instructions 7 cie length 20 initial instructions 0 DW_CFA_def_cfa r7 8 3 DW_CFA_offset r16 -8 (1 * -8) 5 DW_CFA_nop 6 DW_CFA_nop $ dwarfdump -v -F test-r211272-with-g.o .eh_frame fde: < 0><0x00000020:0x0000002b><><fde offset 0x00000018 length: 0x0000001c><eh aug data len 0x0> 0x00000020: <off cfa=08(r7) > <off r16=-8(cfa) > 0x00000021: <off cfa=16(r7) > <off r6=-16(cfa) > <off r16=-8(cfa) > 0x00000024: <off cfa=16(r6) > <off r6=-16(cfa) > <off r16=-8(cfa) > cie: < 0> version 1 cie section offset 0 0x00000000 augmentation zR code_alignment_factor 1 data_alignment_factor -8 return_address_register 16 eh aug data len 0x1 bytes 0x1b bytes of initial instructions 7 cie length 20 initial instructions 0 DW_CFA_def_cfa r7 8 3 DW_CFA_offset r16 -8 (1 * -8) 5 DW_CFA_nop 6 DW_CFA_nop E.g., without the -g option, the CIE version is incorrectly set to 3, while with the -g option, the CIE version is correctly set to 1. This still reproduces on trunk r224901, as of 2014-12-28. [1] http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20141222/250134.html
*** Bug 23192 has been marked as a duplicate of this bug. ***
Using the test from my report of... echo "int f (void) { return 0; }" > conftest.c clang-3.7 -emit-llvm -g -c conftest.c it see the following walk in lldb... % lldb /sw/opt/llvm-3.7.0/bin/llc (lldb) target create "/sw/opt/llvm-3.7.0/bin/llc" Current executable set to '/sw/opt/llvm-3.7.0/bin/llc' (x86_64). (lldb) b Module.cpp:460 Breakpoint 1: where = llc`llvm::Module::getDwarfVersion() const + 68 at Module.cpp:460, address = 0x0000000100bd47c4 (lldb) r conftest.bc Process 47262 launched: '/sw/opt/llvm-3.7.0/bin/llc' (x86_64) Process 47262 stopped * thread #1: tid = 0xe183d1, 0x0000000100bd47c4 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100bd47c4 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460 457 458 unsigned Module::getDwarfVersion() const { 459 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version")); -> 460 if (!Val) 461 return dwarf::DWARF_VERSION; 462 return cast<ConstantInt>(Val->getValue())->getZExtValue(); 463 } (lldb) s Process 47262 stopped * thread #1: tid = 0xe183d1, 0x0000000100bd47de llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 94 at Module.cpp:462, queue = 'com.apple.main-thread', stop reason = step in frame #0: 0x0000000100bd47de llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 94 at Module.cpp:462 459 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version")); 460 if (!Val) 461 return dwarf::DWARF_VERSION; -> 462 return cast<ConstantInt>(Val->getValue())->getZExtValue(); 463 } 464 465 Comdat *Module::getOrInsertComdat(StringRef Name) { whereas for... clang-3.7 -emit-llvm -c conftest.c lldb /sw/opt/llvm-3.7.0/bin/llc (lldb) target create "/sw/opt/llvm-3.7.0/bin/llc" Current executable set to '/sw/opt/llvm-3.7.0/bin/llc' (x86_64). (lldb) b Module.cpp:460 Breakpoint 1: where = llc`llvm::Module::getDwarfVersion() const + 68 at Module.cpp:460, address = 0x0000000100bd47c4 (lldb) r conftest.bc Process 47413 launched: '/sw/opt/llvm-3.7.0/bin/llc' (x86_64) Process 47413 stopped * thread #1: tid = 0xe18ba1, 0x0000000100bd47c4 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #0: 0x0000000100bd47c4 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460 457 458 unsigned Module::getDwarfVersion() const { 459 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version")); -> 460 if (!Val) 461 return dwarf::DWARF_VERSION; 462 return cast<ConstantInt>(Val->getValue())->getZExtValue(); 463 } (lldb) s Process 47413 stopped * thread #1: tid = 0xe18ba1, 0x0000000100bd47d2 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 82 at Module.cpp:461, queue = 'com.apple.main-thread', stop reason = step in frame #0: 0x0000000100bd47d2 llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 82 at Module.cpp:461 458 unsigned Module::getDwarfVersion() const { 459 auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("Dwarf Version")); 460 if (!Val) -> 461 return dwarf::DWARF_VERSION; 462 return cast<ConstantInt>(Val->getValue())->getZExtValue(); 463 } 464 (lldb) s Process 47413 stopped * thread #1: tid = 0xe18ba1, 0x0000000100bd47fc llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 124 at Module.cpp:463, queue = 'com.apple.main-thread', stop reason = step in frame #0: 0x0000000100bd47fc llc`llvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 124 at Module.cpp:463 460 if (!Val) 461 return dwarf::DWARF_VERSION; 462 return cast<ConstantInt>(Val->getValue())->getZExtValue(); -> 463 } 464 465 Comdat *Module::getOrInsertComdat(StringRef Name) { 466 auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;
Any idea how to get lldb to display the value of the returned dwarf::DWARF_VERSION in the case with -g?