Skip to content

Commit 8f4b2cd

Browse files
author
Alex B
committed
Address feedback Nr.1
1 parent b24f4fa commit 8f4b2cd

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

lld/MachO/ConcatOutputSection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class TextOutputSection : public ConcatOutputSection {
7272
void finalizeContents() override {}
7373
void finalize() override;
7474
bool needsThunks() const;
75-
const std::vector<ConcatInputSection *> &getThunks() const { return thunks; }
75+
ArrayRef<ConcatInputSection *> getThunks() const { return thunks; }
7676
void writeTo(uint8_t *buf) const override;
7777

7878
static bool classof(const OutputSection *sec) {

lld/MachO/MapFile.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -203,42 +203,32 @@ void macho::writeMapFile() {
203203
seg->name.str().c_str(), osec->name.str().c_str());
204204
}
205205

206+
// Helper lambda that prints all symbols from one ConcatInputSection.
207+
auto printOne = [&](const ConcatInputSection *isec) {
208+
for (Defined *sym : isec->symbols) {
209+
if (!(isPrivateLabel(sym->getName()) && getSymSizeForMap(sym) == 0)) {
210+
os << format("0x%08llX\t0x%08llX\t[%3u] %s\n", sym->getVA(),
211+
getSymSizeForMap(sym),
212+
readerToFileOrdinal.lookup(sym->getFile()),
213+
sym->getName().str().data());
214+
}
215+
}
216+
};
206217
// Shared function to print one or two arrays of ConcatInputSection in
207218
// ascending outSecOff order. The second array is optional; if provided, we
208219
// interleave the printing in sorted order without allocating a merged temp
209220
// array.
210-
auto printIsecArrSyms = [&](const std::vector<ConcatInputSection *> &arr1,
211-
const std::vector<ConcatInputSection *> *arr2 =
212-
nullptr) {
213-
// Helper lambda that prints all symbols from one ConcatInputSection.
214-
auto printOne = [&](const ConcatInputSection *isec) {
215-
for (Defined *sym : isec->symbols) {
216-
if (!(isPrivateLabel(sym->getName()) && getSymSizeForMap(sym) == 0)) {
217-
os << format("0x%08llX\t0x%08llX\t[%3u] %s\n", sym->getVA(),
218-
getSymSizeForMap(sym),
219-
readerToFileOrdinal.lookup(sym->getFile()),
220-
sym->getName().str().data());
221-
}
222-
}
223-
};
224-
225-
// If there is only one array, print all symbols from it and return.
226-
// This simplifies the logic for the merge case below.
227-
if (!arr2) {
228-
for (const ConcatInputSection *isec : arr1)
229-
printOne(isec);
230-
return;
231-
}
232-
221+
auto printIsecArrSyms = [&](ArrayRef<ConcatInputSection *> arr1,
222+
ArrayRef<ConcatInputSection *> arr2 = {}) {
233223
size_t i = 0, j = 0;
234224
size_t size1 = arr1.size();
235-
size_t size2 = arr2->size();
225+
size_t size2 = arr2.size();
236226
while (i < size1 || j < size2) {
237227
if (i < size1 &&
238-
(j >= size2 || arr1[i]->outSecOff <= (*arr2)[j]->outSecOff)) {
228+
(j >= size2 || arr1[i]->outSecOff <= arr2[j]->outSecOff)) {
239229
printOne(arr1[i++]);
240230
} else if (j < size2) {
241-
printOne((*arr2)[j++]);
231+
printOne(arr2[j++]);
242232
}
243233
}
244234
};
@@ -248,7 +238,7 @@ void macho::writeMapFile() {
248238
for (const OutputSegment *seg : outputSegments) {
249239
for (const OutputSection *osec : seg->getSections()) {
250240
if (auto *textOsec = dyn_cast<TextOutputSection>(osec)) {
251-
printIsecArrSyms(textOsec->inputs, &textOsec->getThunks());
241+
printIsecArrSyms(textOsec->inputs, textOsec->getThunks());
252242
} else if (auto *concatOsec = dyn_cast<ConcatOutputSection>(osec)) {
253243
printIsecArrSyms(concatOsec->inputs);
254244
} else if (osec == in.cStringSection || osec == in.objcMethnameSection) {

lld/test/MachO/arm64-thunks.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ _main:
337337
# linker will create a symbol for every '0' in the section, leading to
338338
# dramatic memory usage and a huge linker map file
339339
.space 0x4000000, 'A'
340+
.byte 0
340341

341342

342343
.section __TEXT,__lcxx_override,regular,pure_instructions

0 commit comments

Comments
 (0)