Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect CIE version 3 in object files for platforms defaulting to DWARF2 #22420

Open
DimitryAndric opened this issue Dec 28, 2014 · 4 comments
Labels
bugzilla Issues migrated from bugzilla

Comments

@DimitryAndric
Copy link
Collaborator

Bugzilla Link 22046
Version trunk
OS All
CC @emaste,@pogo59

Extended Description

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:
0x00000021:
0x00000024:

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:
0x00000021:
0x00000024:

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

@DimitryAndric
Copy link
Collaborator Author

*** Bug llvm/llvm-bugzilla-archive#23192 has been marked as a duplicate of this bug. ***

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 12, 2015

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 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #&#8203;0: 0x0000000100bd47c4 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460
    457
    458 unsigned Module::getDwarfVersion() const {
    459 auto *Val = cast_or_null(getModuleFlag("Dwarf Version"));
    -> 460 if (!Val)
    461 return dwarf::DWARF_VERSION;
    462 return cast(Val->getValue())->getZExtValue();
    463 }
    (lldb) s
    Process 47262 stopped
  • thread #​1: tid = 0xe183d1, 0x0000000100bd47de llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 94 at Module.cpp:462, queue = 'com.apple.main-thread', stop reason = step in frame #&#8203;0: 0x0000000100bd47de llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 94 at Module.cpp:462
    459 auto *Val = cast_or_null(getModuleFlag("Dwarf Version"));
    460 if (!Val)
    461 return dwarf::DWARF_VERSION;
    -> 462 return cast(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 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 frame #&#8203;0: 0x0000000100bd47c4 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 68 at Module.cpp:460
    457
    458 unsigned Module::getDwarfVersion() const {
    459 auto *Val = cast_or_null(getModuleFlag("Dwarf Version"));
    -> 460 if (!Val)
    461 return dwarf::DWARF_VERSION;
    462 return cast(Val->getValue())->getZExtValue();
    463 }
    (lldb) s
    Process 47413 stopped
  • thread #​1: tid = 0xe18ba1, 0x0000000100bd47d2 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 82 at Module.cpp:461, queue = 'com.apple.main-thread', stop reason = step in frame #&#8203;0: 0x0000000100bd47d2 llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 82 at Module.cpp:461
    458 unsigned Module::getDwarfVersion() const {
    459 auto *Val = cast_or_null(getModuleFlag("Dwarf Version"));
    460 if (!Val)
    -> 461 return dwarf::DWARF_VERSION;
    462 return cast(Val->getValue())->getZExtValue();
    463 }
    464
    (lldb) s
    Process 47413 stopped
  • thread #​1: tid = 0xe18ba1, 0x0000000100bd47fc llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 124 at Module.cpp:463, queue = 'com.apple.main-thread', stop reason = step in frame #&#8203;0: 0x0000000100bd47fc llcllvm::Module::getDwarfVersion(this=0x0000000102c0a960) const + 124 at Module.cpp:463
    460 if (!Val)
    461 return dwarf::DWARF_VERSION;
    462 return cast(Val->getValue())->getZExtValue();
    -> 463 }
    464
    465 Comdat *Module::getOrInsertComdat(StringRef Name) {
    466 auto &Entry = *ComdatSymTab.insert(std::make_pair(Name, Comdat())).first;

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 12, 2015

Any idea how to get lldb to display the value of the returned dwarf::DWARF_VERSION in the case with -g?

@DimitryAndric
Copy link
Collaborator Author

mentioned in issue llvm/llvm-bugzilla-archive#23192

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla
Projects
None yet
Development

No branches or pull requests

2 participants