Skip to content

Commit 9408b75

Browse files
committed
[lld-macho][nfc] Hoist out creation of Section in parseSections()
Simplifies the code slightly. Reviewed By: #lld-macho, thakis Differential Revision: https://reviews.llvm.org/D118796
1 parent 0e9a3d3 commit 9408b75

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

lld/MachO/InputFiles.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,16 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
277277
ArrayRef<uint8_t> data = {isZeroFill(sec.flags) ? nullptr
278278
: buf + sec.offset,
279279
static_cast<size_t>(sec.size)};
280+
sections.push_back(sec.addr);
280281
if (sec.align >= 32) {
281282
error("alignment " + std::to_string(sec.align) + " of section " + name +
282283
" is too large");
283-
sections.push_back(sec.addr);
284284
continue;
285285
}
286286
uint32_t align = 1 << sec.align;
287287
uint32_t flags = sec.flags;
288288

289289
auto splitRecords = [&](int recordSize) -> void {
290-
sections.push_back(sec.addr);
291290
if (data.empty())
292291
return;
293292
Subsections &subsections = sections.back().subsections;
@@ -321,7 +320,6 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
321320
isec = make<WordLiteralInputSection>(segname, name, this, data, align,
322321
flags);
323322
}
324-
sections.push_back(sec.addr);
325323
sections.back().subsections.push_back({0, isec});
326324
} else if (auto recordSize = getRecordSize(segname, name)) {
327325
splitRecords(*recordSize);
@@ -350,23 +348,19 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
350348
// ld64 does not appear to emit contents from sections within the __LLVM
351349
// segment. Symbols within those sections point to bitcode metadata
352350
// instead of actual symbols. Global symbols within those sections could
353-
// have the same name without causing duplicate symbol errors. Push an
354-
// empty entry to ensure indices line up for the remaining sections.
351+
// have the same name without causing duplicate symbol errors. To avoid
352+
// spurious duplicate symbol errors, we do not parse these sections.
355353
// TODO: Evaluate whether the bitcode metadata is needed.
356-
sections.push_back(sec.addr);
357354
} else {
358355
auto *isec =
359356
make<ConcatInputSection>(segname, name, this, data, align, flags);
360357
if (isDebugSection(isec->getFlags()) &&
361358
isec->getSegName() == segment_names::dwarf) {
362359
// Instead of emitting DWARF sections, we emit STABS symbols to the
363360
// object files that contain them. We filter them out early to avoid
364-
// parsing their relocations unnecessarily. But we must still push an
365-
// empty entry to ensure the indices line up for the remaining sections.
366-
sections.push_back(sec.addr);
361+
// parsing their relocations unnecessarily.
367362
debugSections.push_back(isec);
368363
} else {
369-
sections.push_back(sec.addr);
370364
sections.back().subsections.push_back({0, isec});
371365
}
372366
}

0 commit comments

Comments
 (0)