Skip to content

Commit ede827f

Browse files
committed
[DWARFLinker][DWARFv5] add support for DW_FORM_implicit_const form.
This patch adds handling of DW_FORM_implicit_const form. Differential Revision: https://reviews.llvm.org/D146047
1 parent 6bc5aa5 commit ede827f

File tree

4 files changed

+146
-3
lines changed

4 files changed

+146
-3
lines changed

llvm/include/llvm/CodeGen/DIE.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class DIEAbbrev : public FoldingSetNode {
115115
Data.push_back(DIEAbbrevData(Attribute, Value));
116116
}
117117

118+
/// Adds another set of attribute information to the abbreviation.
119+
void AddAttribute(const DIEAbbrevData &AbbrevData) {
120+
Data.push_back(AbbrevData);
121+
}
122+
118123
/// Used to gather unique data for the abbreviation folding set.
119124
void Profile(FoldingSetNodeID &ID) const;
120125

llvm/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include "llvm/ADT/SmallVector.h"
1313
#include "llvm/ADT/iterator_range.h"
1414
#include "llvm/BinaryFormat/Dwarf.h"
15+
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1516
#include <cassert>
1617
#include <cstddef>
1718
#include <cstdint>
1819

1920
namespace llvm {
2021

2122
class DataExtractor;
22-
class DWARFFormValue;
2323
class DWARFUnit;
2424
class raw_ostream;
2525

@@ -39,6 +39,13 @@ class DWARFAbbreviationDeclaration {
3939
this->ByteSize.ByteSize = *ByteSize;
4040
}
4141

42+
DWARFFormValue getFormValue() const {
43+
if (Form == dwarf::DW_FORM_implicit_const)
44+
return DWARFFormValue::createFromSValue(Form, getImplicitConstValue());
45+
46+
return DWARFFormValue(Form);
47+
}
48+
4249
dwarf::Attribute Attr;
4350
dwarf::Form Form;
4451

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ void DWARFLinker::assignAbbrev(DIEAbbrev &Abbrev) {
928928
Abbreviations.push_back(
929929
std::make_unique<DIEAbbrev>(Abbrev.getTag(), Abbrev.hasChildren()));
930930
for (const auto &Attr : Abbrev.getData())
931-
Abbreviations.back()->AddAttribute(Attr.getAttribute(), Attr.getForm());
931+
Abbreviations.back()->AddAttribute(Attr);
932932
AbbreviationsSet.InsertNode(Abbreviations.back().get(), InsertToken);
933933
// Assign the unique abbreviation number.
934934
Abbrev.setNumber(Abbreviations.size());
@@ -1408,6 +1408,7 @@ unsigned DWARFLinker::DIECloner::cloneAttribute(
14081408
case dwarf::DW_FORM_flag_present:
14091409
case dwarf::DW_FORM_rnglistx:
14101410
case dwarf::DW_FORM_loclistx:
1411+
case dwarf::DW_FORM_implicit_const:
14111412
return cloneScalarAttribute(Die, InputDIE, File, Unit, AttrSpec, Val,
14121413
AttrSize, Info);
14131414
default:
@@ -1596,7 +1597,7 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
15961597
continue;
15971598
}
15981599

1599-
DWARFFormValue Val(AttrSpec.Form);
1600+
DWARFFormValue Val = AttrSpec.getFormValue();
16001601
uint64_t AttrSize = Offset;
16011602
Val.extractValue(Data, &Offset, U.getFormParams(), &U);
16021603
AttrSize = Offset - AttrSize;
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
## Test that DWARFv5 DW_FORM_implicit_const is correctly recognized
2+
## and copied into the result.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil %t.o %t1
7+
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s --check-prefix VERIFY-CHECK
8+
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s
9+
#
10+
# RUN: llvm-dwarfutil --no-garbage-collection %t.o %t1
11+
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s --check-prefix VERIFY-CHECK
12+
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s
13+
#
14+
# RUN: llvm-dwarfutil --no-garbage-collection --build-accelerator=DWARF %t.o %t1
15+
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s --check-prefix VERIFY-CHECK
16+
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s
17+
18+
#VERIFY-CHECK: No errors.
19+
20+
#CHECK: .debug_abbrev
21+
#CHECK: DW_TAG_compile_unit
22+
#CHECK: DW_TAG_subprogram
23+
#CHECK: DW_TAG_base_type
24+
#CHECK: DW_TAG_variable
25+
#CHECK: DW_AT_name
26+
#CHECK: DW_AT_const_value DW_FORM_implicit_const 33
27+
#CHECK: DW_AT_type
28+
#CHECK: DW_TAG_compile_unit
29+
#CHECK: DW_AT_name {{.*}}"CU1"
30+
#CHECK: DW_AT_low_pc
31+
#CHECK: DW_AT_high_pc
32+
#CHECK: DW_TAG_subprogram
33+
#CHECK: DW_AT_name {{.*}}"foo1"
34+
#CHECK: DW_AT_low_pc
35+
#CHECK: DW_AT_high_pc
36+
#CHECK: DW_TAG_variable
37+
#CHECK: DW_AT_name {{.*}}"var1"
38+
#CHECK: DW_AT_const_value [DW_FORM_implicit_const] (33)
39+
#CHECK: DW_AT_type {{.*}}"int"
40+
41+
--- !ELF
42+
FileHeader:
43+
Class: ELFCLASS64
44+
Data: ELFDATA2LSB
45+
Type: ET_REL
46+
Machine: EM_X86_64
47+
Sections:
48+
- Name: .text
49+
Type: SHT_PROGBITS
50+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
51+
Address: 0x1130
52+
Size: 0x60
53+
DWARF:
54+
debug_abbrev:
55+
- Table:
56+
- Tag: DW_TAG_compile_unit
57+
Children: DW_CHILDREN_yes
58+
Attributes:
59+
- Attribute: DW_AT_producer
60+
Form: DW_FORM_string
61+
- Attribute: DW_AT_language
62+
Form: DW_FORM_data2
63+
- Attribute: DW_AT_name
64+
Form: DW_FORM_string
65+
- Attribute: DW_AT_low_pc
66+
Form: DW_FORM_addrx
67+
- Attribute: DW_AT_high_pc
68+
Form: DW_FORM_data8
69+
- Attribute: DW_AT_addr_base
70+
Form: DW_FORM_sec_offset
71+
- Tag: DW_TAG_subprogram
72+
Children: DW_CHILDREN_yes
73+
Attributes:
74+
- Attribute: DW_AT_name
75+
Form: DW_FORM_string
76+
- Attribute: DW_AT_low_pc
77+
Form: DW_FORM_addrx
78+
- Attribute: DW_AT_high_pc
79+
Form: DW_FORM_data8
80+
- Attribute: DW_AT_type
81+
Form: DW_FORM_ref4
82+
- Tag: DW_TAG_base_type
83+
Children: DW_CHILDREN_no
84+
Attributes:
85+
- Attribute: DW_AT_name
86+
Form: DW_FORM_string
87+
- Tag: DW_TAG_variable
88+
Children: DW_CHILDREN_no
89+
Attributes:
90+
- Attribute: DW_AT_name
91+
Form: DW_FORM_string
92+
- Attribute: DW_AT_const_value
93+
Form: DW_FORM_implicit_const
94+
Value: 33
95+
- Attribute: DW_AT_type
96+
Form: DW_FORM_ref4
97+
debug_info:
98+
- Version: 5
99+
UnitType: DW_UT_compile
100+
Entries:
101+
- AbbrCode: 1
102+
Values:
103+
- CStr: by_hand
104+
- Value: 0x04
105+
- CStr: CU1
106+
- Value: 0x0
107+
- Value: 0x10
108+
- Value: 0x8
109+
- AbbrCode: 2
110+
Values:
111+
- CStr: foo1
112+
- Value: 0x0
113+
- Value: 0x10
114+
- Value: 0x3c
115+
- AbbrCode: 0
116+
- AbbrCode: 3
117+
Values:
118+
- CStr: int
119+
- AbbrCode: 4
120+
Values:
121+
- CStr: var1
122+
- Value: 0x00000000
123+
- Value: 0x0000003c
124+
- AbbrCode: 0
125+
debug_addr:
126+
- Version: 5
127+
AddressSize: 0x08
128+
Entries:
129+
- Address: 0x1130
130+
...

0 commit comments

Comments
 (0)