Skip to content

Commit f9f92f1

Browse files
committed
[DWARFLinker][Reland] Handle DW_OP_GNU_push_tls_address while check for variable location.
The D147066 changed the way how DWARF location expressions are handled. Now expressions are parsed and their operands are analysed. New handling misses the DW_OP_GNU_push_tls_address extention. This patch adds handling DW_OP_GNU_push_tls_address while checking for addresses. Differential Revision: https://reviews.llvm.org/D153010
1 parent 65305ae commit f9f92f1

File tree

2 files changed

+199
-2
lines changed

2 files changed

+199
-2
lines changed

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@ void DWARFLinker::cleanupAuxiliarryData(LinkContext &Context) {
420420
DIEAlloc.Reset();
421421
}
422422

423+
static bool isTlsAddressCode(uint8_t DW_OP_Code) {
424+
return DW_OP_Code == dwarf::DW_OP_form_tls_address ||
425+
DW_OP_Code == dwarf::DW_OP_GNU_push_tls_address;
426+
}
427+
423428
std::optional<int64_t>
424429
DWARFLinker::getVariableRelocAdjustment(AddressesMap &RelocMgr,
425430
const DWARFDie &DIE) {
@@ -471,8 +476,7 @@ DWARFLinker::getVariableRelocAdjustment(AddressesMap &RelocMgr,
471476
case dwarf::DW_OP_const8u:
472477
case dwarf::DW_OP_const4s:
473478
case dwarf::DW_OP_const8s:
474-
if (NextIt == Expression.end() ||
475-
NextIt->getCode() != dwarf::DW_OP_form_tls_address)
479+
if (NextIt == Expression.end() || !isTlsAddressCode(NextIt->getCode()))
476480
break;
477481
[[fallthrough]];
478482
case dwarf::DW_OP_addr: {
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
## This test checks that thread local storage variables
2+
## are preserved.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
# RUN: echo '---' > %t2.map
6+
# RUN: echo "triple: 'x86_64-apple-darwin'" >> %t2.map
7+
# RUN: echo 'objects:' >> %t2.map
8+
# RUN: echo " - filename: '%t.o'" >> %t2.map
9+
# RUN: echo ' symbols:' >> %t2.map
10+
# RUN: echo ' - { sym: __Z3foov, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }' >> %t2.map
11+
# RUN: echo '...' >> %t2.map
12+
# RUN: dsymutil -y %t2.map --keep-function-for-static -f -o - | llvm-dwarfdump -a - | FileCheck %s
13+
14+
# CHECK: file format Mach-O 64-bit x86-64
15+
# CHECK: .debug_info contents:
16+
# CHECK: Compile Unit:
17+
# CHECK: DW_TAG_compile_unit
18+
# CHECK: DW_AT_name{{.*}}"CU1"
19+
# CHECK: DW_TAG_subprogram
20+
# CHECK: DW_AT_name{{.*}}"foo"
21+
# CHECK: DW_TAG_variable
22+
# CHECK: DW_AT_name{{.*}}"var1"
23+
# CHECK: DW_AT_location (DW_OP_const8u 0x{{.*}}, DW_OP_GNU_push_tls_address)
24+
# CHECK: DW_AT_name{{.*}}"var2"
25+
# CHECK: DW_AT_location (DW_OP_const8u 0x{{.*}}, DW_OP_form_tls_address)
26+
27+
--- !mach-o
28+
FileHeader:
29+
magic: 0xFEEDFACF
30+
cputype: 0x01000007
31+
cpusubtype: 0x00000003
32+
filetype: 0x00000001
33+
ncmds: 2
34+
sizeofcmds: 376
35+
flags: 0x00002000
36+
reserved: 0x00000000
37+
LoadCommands:
38+
- cmd: LC_SEGMENT_64
39+
cmdsize: 232
40+
segname: ''
41+
vmaddr: 0x00
42+
vmsize: 0x300
43+
fileoff: 0x300
44+
filesize: 0x300
45+
maxprot: 7
46+
initprot: 7
47+
nsects: 2
48+
flags: 0
49+
Sections:
50+
- sectname: __debug_abbrev
51+
segname: __DWARF
52+
addr: 0x000000000000000F
53+
size: 0x27
54+
offset: 0x00000380
55+
align: 0
56+
reloff: 0x00000000
57+
nreloc: 0
58+
flags: 0x02000000
59+
reserved1: 0x00000000
60+
reserved2: 0x00000000
61+
reserved3: 0x00000000
62+
- sectname: __debug_info
63+
segname: __DWARF
64+
addr: 0x000000000000100
65+
size: 0x54
66+
offset: 0x00000410
67+
align: 0
68+
reloff: 0x00000600
69+
nreloc: 2
70+
flags: 0x02000000
71+
reserved1: 0x00000000
72+
reserved2: 0x00000000
73+
reserved3: 0x00000000
74+
relocations:
75+
- address: 0x32
76+
symbolnum: 1
77+
pcrel: true
78+
length: 3
79+
extern: true
80+
type: 0
81+
scattered: false
82+
value: 0
83+
- address: 0x47
84+
symbolnum: 1
85+
pcrel: true
86+
length: 3
87+
extern: true
88+
type: 0
89+
scattered: false
90+
value: 0
91+
- cmd: LC_SYMTAB
92+
cmdsize: 24
93+
symoff: 0x700
94+
nsyms: 2
95+
stroff: 0x720
96+
strsize: 10
97+
LinkEditData:
98+
NameList:
99+
- n_strx: 1
100+
n_type: 0x0F
101+
n_sect: 1
102+
n_desc: 0
103+
n_value: 0
104+
- n_strx: 1
105+
n_type: 0x0F
106+
n_sect: 1
107+
n_desc: 0
108+
n_value: 0
109+
StringTable:
110+
- ''
111+
- '__Z3foov'
112+
- ''
113+
DWARF:
114+
debug_abbrev:
115+
- Table:
116+
- Tag: DW_TAG_compile_unit
117+
Children: DW_CHILDREN_yes
118+
Attributes:
119+
- Attribute: DW_AT_producer
120+
Form: DW_FORM_string
121+
- Attribute: DW_AT_language
122+
Form: DW_FORM_data2
123+
- Attribute: DW_AT_name
124+
Form: DW_FORM_string
125+
- Tag: DW_TAG_subprogram
126+
Children: DW_CHILDREN_yes
127+
Attributes:
128+
- Attribute: DW_AT_name
129+
Form: DW_FORM_string
130+
- Attribute: DW_AT_type
131+
Form: DW_FORM_ref4
132+
- Tag: DW_TAG_variable
133+
Children: DW_CHILDREN_no
134+
Attributes:
135+
- Attribute: DW_AT_name
136+
Form: DW_FORM_string
137+
- Attribute: DW_AT_type
138+
Form: DW_FORM_ref4
139+
- Attribute: DW_AT_location
140+
Form: DW_FORM_exprloc
141+
- Tag: DW_TAG_base_type
142+
Children: DW_CHILDREN_no
143+
Attributes:
144+
- Attribute: DW_AT_name
145+
Form: DW_FORM_string
146+
debug_info:
147+
- Version: 4
148+
Entries:
149+
- AbbrCode: 1
150+
Values:
151+
- CStr: by_hand
152+
- Value: 0x04
153+
- CStr: CU1
154+
- AbbrCode: 4
155+
Values:
156+
- CStr: int
157+
- AbbrCode: 2
158+
Values:
159+
- CStr: foo
160+
- Value: 0x1a
161+
- AbbrCode: 3
162+
Values:
163+
- CStr: var1
164+
- Value: 0x0000001a
165+
- BlockData:
166+
- 0x0e
167+
- 0x00
168+
- 0x00
169+
- 0x01
170+
- 0x00
171+
- 0x00
172+
- 0x00
173+
- 0x00
174+
- 0x00
175+
- 0xe0
176+
- AbbrCode: 3
177+
Values:
178+
- CStr: var2
179+
- Value: 0x0000001a
180+
- BlockData:
181+
- 0x0e
182+
- 0x00
183+
- 0x00
184+
- 0x01
185+
- 0x00
186+
- 0x00
187+
- 0x00
188+
- 0x00
189+
- 0x00
190+
- 0x9b
191+
- AbbrCode: 0
192+
- AbbrCode: 0
193+
...

0 commit comments

Comments
 (0)