Skip to content

Commit 3822e3d

Browse files
committed
[lld-macho] Fix bug in handling unwind info from ld -r
Two changess: - Drop assertions that all symbols are in GOT - Set allEntriesAreOmitted correctly Related bug: 50812 Differential Revision: https://reviews.llvm.org/D105364
1 parent e522010 commit 3822e3d

File tree

2 files changed

+109
-4
lines changed

2 files changed

+109
-4
lines changed

lld/MachO/UnwindInfoSection.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,14 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) {
167167
assert(target->hasAttr(r.type, RelocAttrBits::UNSIGNED));
168168

169169
if (r.offset % sizeof(CompactUnwindEntry<Ptr>) == 0) {
170-
if (auto *referentIsec = r.referent.dyn_cast<InputSection *>())
171-
if (!cast<ConcatInputSection>(referentIsec)->shouldOmitFromOutput())
172-
allEntriesAreOmitted = false;
170+
InputSection *referentIsec;
171+
if (auto *isec = r.referent.dyn_cast<InputSection *>())
172+
referentIsec = isec;
173+
else
174+
referentIsec = cast<Defined>(r.referent.dyn_cast<Symbol *>())->isec;
175+
176+
if (!cast<ConcatInputSection>(referentIsec)->shouldOmitFromOutput())
177+
allEntriesAreOmitted = false;
173178
continue;
174179
}
175180

@@ -257,7 +262,6 @@ relocateCompactUnwind(ConcatOutputSection *compactUnwindSection,
257262
uint64_t referentVA = TombstoneValue<Ptr>;
258263
if (auto *referentSym = r.referent.dyn_cast<Symbol *>()) {
259264
if (!isa<Undefined>(referentSym)) {
260-
assert(referentSym->isInGot());
261265
if (auto *defined = dyn_cast<Defined>(referentSym))
262266
checkTextSegment(defined->isec);
263267
// At this point in the link, we may not yet know the final address of
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# REQUIRES: x86
2+
## These yaml files were from an object file produced with 'ld -r', specifically:
3+
##
4+
## // foo.s
5+
## .text
6+
## .globl _main
7+
## _main:
8+
## .cfi_startproc
9+
## .cfi_def_cfa_offset 16
10+
## .cfi_endproc
11+
## nop
12+
##
13+
## llvm-mc -filetype=obj -triple=x86_64-apple-macos10.15 -o foo1.o foo.s
14+
## ld -r -o foo.o foo1.o
15+
16+
17+
# RUN: rm -rf %t; mkdir -p %t
18+
# RUN: yaml2obj %s -o %t/foo.o
19+
# RUN: %lld -o %t/a.out %t/foo.o
20+
21+
--- !mach-o
22+
FileHeader:
23+
magic: 0xFEEDFACF
24+
cputype: 0x01000007
25+
cpusubtype: 0x00000003
26+
filetype: 0x00000001
27+
ncmds: 2
28+
sizeofcmds: 384
29+
flags: 0x00000000
30+
reserved: 0x00000000
31+
LoadCommands:
32+
- cmd: LC_SEGMENT_64
33+
cmdsize: 312
34+
segname: ''
35+
vmaddr: 0
36+
vmsize: 64
37+
fileoff: 448
38+
filesize: 64
39+
maxprot: 7
40+
initprot: 7
41+
nsects: 2
42+
flags: 0
43+
Sections:
44+
- sectname: __text
45+
segname: __TEXT
46+
addr: 0x0000000000000000
47+
size: 1
48+
offset: 0x000001C0
49+
align: 0
50+
reloff: 0x00000000
51+
nreloc: 0
52+
flags: 0x80000400
53+
reserved1: 0x00000000
54+
reserved2: 0x00000000
55+
reserved3: 0x00000000
56+
content: '90'
57+
- sectname: __compact_unwind
58+
segname: __LD
59+
addr: 0x0000000000000020
60+
size: 32
61+
offset: 0x000001E0
62+
align: 3
63+
reloff: 0x00000200
64+
nreloc: 1
65+
flags: 0x02000000
66+
reserved1: 0x00000000
67+
reserved2: 0x00000000
68+
reserved3: 0x00000000
69+
content: '0000000000000000010000000000020200000000000000000000000000000000'
70+
relocations:
71+
- address: 0x00000000
72+
symbolnum: 1
73+
pcrel: false
74+
length: 3
75+
extern: true
76+
type: 0
77+
scattered: false
78+
value: 0
79+
- cmd: LC_SYMTAB
80+
cmdsize: 24
81+
symoff: 520
82+
nsyms: 2
83+
stroff: 552
84+
strsize: 24
85+
LinkEditData:
86+
NameList:
87+
- n_strx: 8
88+
n_type: 0x0E
89+
n_sect: 2
90+
n_desc: 0
91+
n_value: 8
92+
- n_strx: 2
93+
n_type: 0x0F
94+
n_sect: 1
95+
n_desc: 32
96+
n_value: 0
97+
StringTable:
98+
- ' '
99+
- _main
100+
101+
...

0 commit comments

Comments
 (0)