Skip to content

Commit 67e7f61

Browse files
committed
refactor
Signed-off-by: Peter Rong <[email protected]>
1 parent 2c43e32 commit 67e7f61

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

lld/MachO/BPSectionOrderer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ getRelocHash(const Reloc &reloc,
6464
static uint64_t getUnwindInfoEncodingHash(const InputSection *isec) {
6565
for (Symbol *sym : isec->symbols) {
6666
if (auto *d = dyn_cast_or_null<Defined>(sym)) {
67-
if (auto *ue = d->unwindEntry()) {
68-
CompactUnwindEntry cu;
69-
cu.relocateOneCompactUnwindEntry(d);
70-
if (cu.lsda)
71-
return xxHash64("HAS LSDA");
72-
StringRef name = cu.personality ? cu.personality->getName().empty()
73-
? "<unnamed>"
74-
: cu.personality->getName()
75-
: "<none>";
76-
return xxHash64((name + ";" + Twine::utohexstr(cu.encoding)).str());
77-
}
67+
if (!d->unwindEntry())
68+
continue;
69+
CompactUnwindEntry cu;
70+
cu.relocateOneCompactUnwindEntry(d);
71+
if (cu.lsda)
72+
return xxHash64("HAS LSDA");
73+
StringRef name = (cu.personality == nullptr) ? "<none>"
74+
: cu.personality->getName().empty()
75+
? "<unnamed>"
76+
: cu.personality->getName();
77+
return xxHash64((name + ";" + Twine::utohexstr(cu.encoding)).str());
7878
}
7979
}
8080
return 0;

lld/MachO/UnwindInfoSection.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ CREATE_LAYOUT_CLASS(CompactUnwind, FOR_EACH_CU_FIELD);
111111

112112
void lld::macho::CompactUnwindEntry::relocateOneCompactUnwindEntry(
113113
const Defined *d) {
114+
functionAddress = d->getVA();
115+
114116
ConcatInputSection *unwindEntry = d->unwindEntry();
115-
assert(unwindEntry);
117+
if (!unwindEntry)
118+
return;
116119

117-
functionAddress = d->getVA();
118120
// If we have DWARF unwind info, create a slimmed-down CU entry that points
119121
// to it.
120122
if (unwindEntry->getName() == section_names::ehFrame) {
@@ -126,12 +128,11 @@ void lld::macho::CompactUnwindEntry::relocateOneCompactUnwindEntry(
126128
// would instead encode the largest possible offset to a valid CFI record,
127129
// but since we don't keep track of that, just encode zero -- the start of
128130
// the section is always the start of a CFI record.
129-
uint64_t dwarfOffsetHint =
130-
d->unwindEntry()->outSecOff <= DWARF_SECTION_OFFSET
131-
? d->unwindEntry()->outSecOff
132-
: 0;
131+
uint64_t dwarfOffsetHint = unwindEntry->outSecOff <= DWARF_SECTION_OFFSET
132+
? unwindEntry->outSecOff
133+
: 0;
133134
encoding = target->modeDwarfEncoding | dwarfOffsetHint;
134-
const FDE &fde = cast<ObjFile>(d->getFile())->fdes[d->unwindEntry()];
135+
const FDE &fde = cast<ObjFile>(d->getFile())->fdes[unwindEntry];
135136
functionLength = fde.funcLength;
136137
// Omit the DWARF personality from compact-unwind entry so that we
137138
// don't need to encode it.
@@ -388,13 +389,7 @@ Symbol *UnwindInfoSectionImpl::canonicalizePersonality(Symbol *personality) {
388389
void UnwindInfoSectionImpl::relocateCompactUnwind(
389390
std::vector<CompactUnwindEntry> &cuEntries) {
390391
parallelFor(0, symbolsVec.size(), [&](size_t i) {
391-
CompactUnwindEntry &cu = cuEntries[i];
392-
const Defined *d = symbolsVec[i].second;
393-
cu.functionAddress = d->getVA();
394-
if (!d->unwindEntry())
395-
return;
396-
397-
cu.relocateOneCompactUnwindEntry(d);
392+
cuEntries[i].relocateOneCompactUnwindEntry(symbolsVec[i].second);
398393
});
399394
}
400395

0 commit comments

Comments
 (0)