Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit bb804ee

Browse files
committed
Emit DWARF3 call frame information when DWARF3+ debug info is requested
Currently, llvm always emits a DWARF CIE with a version of 1, even when emitting DWARF 3 or 4, which both support CIE version 3. This patch makes it emit the newer CIE version when we are emitting DWARF 3 or 4. This will not reduce compatibility, as we already emit other DWARF3/4 features, and is worth doing as the DWARF3 spec removed some ambiguities in the interpretation of call frame information. It also fixes a minor bug where the "return address" field of the CIE was encoded as a ULEB128, which is only valid when the CIE version is 3. There are no test changes for this, because (as far as I can tell) none of the platforms that we test have a return address register with a DWARF register number >127. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211272 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7e40983 commit bb804ee

29 files changed

+132
-74
lines changed

include/llvm/Support/Dwarf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ enum LLVMConstants : uint32_t {
5757
DW_TAG_user_base = 0x1000, // Recommended base for user tags.
5858

5959
DWARF_VERSION = 4, // Default dwarf version we output.
60-
DW_CIE_VERSION = 1, // Common frame information version.
6160
DW_PUBTYPES_VERSION = 2, // Section version number for .debug_pubtypes.
6261
DW_PUBNAMES_VERSION = 2, // Section version number for .debug_pubnames.
6362
DW_ARANGES_VERSION = 2 // Section version number for .debug_aranges.

lib/CodeGen/AsmPrinter/DwarfDebug.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
209209
DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber
210210
: MMI->getModule()->getDwarfVersion();
211211

212+
Asm->OutStreamer.getContext().setDwarfVersion(DwarfVersion);
213+
212214
{
213215
NamedRegionTimer T(DbgTimerName, DWARFGroupName, TimePassesIsEnabled);
214216
beginModule();

lib/MC/MCDwarf.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,10 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCObjectStreamer &streamer,
12701270

12711271
// Version
12721272
if (verboseAsm) streamer.AddComment("DW_CIE_VERSION");
1273-
streamer.EmitIntValue(dwarf::DW_CIE_VERSION, 1);
1273+
// For DWARF2, we use CIE version 1
1274+
// For DWARF3+, we use CIE version 3
1275+
uint8_t CIEVersion = context.getDwarfVersion() <= 2 ? 1 : 3;
1276+
streamer.EmitIntValue(CIEVersion, 1);
12741277

12751278
// Augmentation String
12761279
SmallString<8> Augmentation;
@@ -1298,7 +1301,14 @@ const MCSymbol &FrameEmitterImpl::EmitCIE(MCObjectStreamer &streamer,
12981301

12991302
// Return Address Register
13001303
if (verboseAsm) streamer.AddComment("CIE Return Address Column");
1301-
streamer.EmitULEB128IntValue(MRI->getDwarfRegNum(MRI->getRARegister(), true));
1304+
if (CIEVersion == 1) {
1305+
assert(MRI->getRARegister() <= 255 &&
1306+
"DWARF 2 encodes return_address_register in one byte");
1307+
streamer.EmitIntValue(MRI->getDwarfRegNum(MRI->getRARegister(), true), 1);
1308+
} else {
1309+
streamer.EmitULEB128IntValue(
1310+
MRI->getDwarfRegNum(MRI->getRARegister(), true));
1311+
}
13021312

13031313
// Augmentation Data Length (optional)
13041314

test/DebugInfo/AArch64/eh_frame.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ foo:
1717
// Output is:
1818

1919
// CHECK: Contents of section .eh_frame:
20-
// CHECK-NEXT: 0000 10000000 00000000 017a5200 017c1e01 .........zR..|..
20+
// CHECK-NEXT: 0000 10000000 00000000 037a5200 017c1e01 .........zR..|..
2121
// CHECK-NEXT: 0010 1b0c1f00 10000000 18000000 00000000 ................
2222

2323

@@ -30,7 +30,7 @@ foo:
3030
// -------------------
3131
// 10000000: length of first CIE = 0x10
3232
// 00000000: This is a CIE
33-
// 01: version = 0x1
33+
// 03: version = 0x3
3434
// 7a 52 00: augmentation string "zR" -- pointer format is specified
3535
// 01: code alignment factor 1
3636
// 7c: data alignment factor -4

test/DebugInfo/AArch64/eh_frame_personality.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ clean:
1616
}
1717

1818
; CHECK: Contents of section .eh_frame:
19-
; CHECK: 0000 1c000000 00000000 017a504c 5200017c .........zPLR..|
19+
; CHECK: 0000 1c000000 00000000 037a504c 5200017c .........zPLR..|
2020
; CHECK: 0010 1e0b0000 00000000 00000000 1b0c1f00 ................
2121

2222
; Don't really care about the rest:
@@ -33,7 +33,7 @@ clean:
3333
; ----------
3434
; 1c000000: Length = 0x1c
3535
; 00000000: This is a CIE
36-
; 01: Version 1
36+
; 03: Version 3
3737
; 7a 50 4c 52 00: Augmentation string "zPLR" (personality routine, language-specific data, pointer format)
3838
; 01: Code alignment factor 1
3939
; 78: Data alignment factor: -8

test/DebugInfo/SystemZ/eh_frame.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ check_largest_class:
2323
# Contents of the .eh_frame section:
2424
#
2525
# 00000000 0000001c 00000000 CIE
26-
# Version: 1
26+
# Version: 3
2727
# Augmentation: "zR"
2828
# Code alignment factor: 1
2929
# Data alignment factor: -8
@@ -48,7 +48,7 @@ check_largest_class:
4848
# DW_CFA_nop
4949
#
5050
# CHECK: Contents of section .eh_frame:
51-
# CHECK-NEXT: 0000 00000014 00000000 017a5200 01780e01 .........zR..x..
51+
# CHECK-NEXT: 0000 00000014 00000000 037a5200 01780e01 .........zR..x..
5252
# CHECK-NEXT: 0010 1b0c0fa0 01000000 0000001c 0000001c ................
5353
# CHECK-NEXT: 0020 00000000 00000012 00468d07 8e068f05 .........F......
5454
# CHECK-NEXT: 0030 440ec002 00000000 D.......

test/DebugInfo/SystemZ/eh_frame_personality.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DW.ref.__gxx_personality_v0:
3737
# Contents of the .eh_frame section:
3838
#
3939
# 00000000 0000001c 00000000 CIE
40-
# Version: 1
40+
# Version: 3
4141
# Augmentation: "zPLR"
4242
# Code alignment factor: 1
4343
# Data alignment factor: -8
@@ -61,7 +61,7 @@ DW.ref.__gxx_personality_v0:
6161
# DW_CFA_nop
6262
#
6363
# CHECK: Contents of section .eh_frame:
64-
# CHECK-NEXT: 0000 0000001c 00000000 017a504c 52000178 .........zPLR..x
64+
# CHECK-NEXT: 0000 0000001c 00000000 037a504c 52000178 .........zPLR..x
6565
# CHECK-NEXT: 0010 0e079b00 0000001b 1b0c0fa0 01000000 ................
6666
# CHECK-NEXT: 0020 0000001c 00000024 00000000 00000012 .......$........
6767
# CHECK-NEXT: 0030 04000000 00468e06 8f05440e c0020000 .....F....D.....

test/MC/ELF/cfi-adjust-cfa-offset.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ f:
2828
// CHECK-NEXT: Relocations [
2929
// CHECK-NEXT: ]
3030
// CHECK-NEXT: SectionData (
31-
// CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001
31+
// CHECK-NEXT: 0000: 14000000 00000000 037A5200 01781001
3232
// CHECK-NEXT: 0010: 1B0C0708 90010000 1C000000 1C000000
3333
// CHECK-NEXT: 0020: 00000000 0A000000 00440E10 410E1444
3434
// CHECK-NEXT: 0030: 0E080000 00000000

test/MC/ELF/cfi-advance-loc2.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ f:
2626
// CHECK-NEXT: Relocations [
2727
// CHECK-NEXT: ]
2828
// CHECK-NEXT: SectionData (
29-
// CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001
29+
// CHECK-NEXT: 0000: 14000000 00000000 037A5200 01781001
3030
// CHECK-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000
3131
// CHECK-NEXT: 0020: 00000000 01010000 00030001 0E080000
3232
// CHECK-NEXT: )

test/MC/ELF/cfi-def-cfa-offset.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ f:
2727
// CHECK-NEXT: Relocations [
2828
// CHECK-NEXT: ]
2929
// CHECK-NEXT: SectionData (
30-
// CHECK-NEXT: 0000: 14000000 00000000 017A5200 01781001
30+
// CHECK-NEXT: 0000: 14000000 00000000 037A5200 01781001
3131
// CHECK-NEXT: 0010: 1B0C0708 90010000 14000000 1C000000
3232
// CHECK-NEXT: 0020: 00000000 0A000000 00440E10 450E0800
3333
// CHECK-NEXT: )

0 commit comments

Comments
 (0)