Skip to content

Commit 56d75f4

Browse files
author
Alex B
committed
Address Feedbak Nr.2
1 parent 5ab6075 commit 56d75f4

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

lld/MachO/SyntheticSections.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,9 @@ void SymtabSection::emitStabs() {
12261226
stabs.emplace_back(std::move(astStab));
12271227
}
12281228

1229-
struct SymbolStabInfo {
1230-
Defined *originalSym; // Original Defined symbol - this may be an ICF thunk
1231-
int fileId; // File ID associated with the STABS symbol
1232-
};
1233-
1234-
std::vector<SymbolStabInfo> symbolsNeedingStabs;
1229+
// Cache the file ID for each symbol in an std::pair for faster sorting.
1230+
using SortingPair = std::pair<Defined *, int>;
1231+
std::vector<SortingPair> symbolsNeedingStabs;
12351232
for (const SymtabEntry &entry :
12361233
concat<SymtabEntry>(localSymbols, externalSymbols)) {
12371234
Symbol *sym = entry.sym;
@@ -1256,27 +1253,27 @@ void SymtabSection::emitStabs() {
12561253

12571254
// We use 'originalIsec' to get the file id of the symbol since 'isec()'
12581255
// might point to the merged ICF symbol's file
1259-
Defined *funcBodySym = getFuncBodySym(defined);
12601256
symbolsNeedingStabs.emplace_back(
1261-
SymbolStabInfo{defined, funcBodySym->originalIsec->getFile()->id});
1257+
defined, getFuncBodySym(defined)->originalIsec->getFile()->id);
12621258
}
12631259
}
12641260

12651261
llvm::stable_sort(symbolsNeedingStabs,
1266-
[&](const SymbolStabInfo &a, const SymbolStabInfo &b) {
1267-
return a.fileId < b.fileId;
1262+
[&](const SortingPair &a, const SortingPair &b) {
1263+
return a.second < b.second;
12681264
});
12691265

12701266
// Emit STABS symbols so that dsymutil and/or the debugger can map address
12711267
// regions in the final binary to the source and object files from which they
12721268
// originated.
12731269
InputFile *lastFile = nullptr;
1274-
for (const SymbolStabInfo &info : symbolsNeedingStabs) {
1270+
for (SortingPair &pair : symbolsNeedingStabs) {
1271+
Defined *defined = pair.first;
12751272
// We use 'originalIsec' of the symbol since we care about the actual origin
12761273
// of the symbol, not the canonical location returned by `isec()`.
1277-
Defined *funcBodySym = getFuncBodySym(info.originalSym);
1278-
InputSection *bodyIsec = funcBodySym->originalIsec;
1279-
ObjFile *file = cast<ObjFile>(bodyIsec->getFile());
1274+
Defined *funcBodySym = getFuncBodySym(defined);
1275+
InputSection *isec = funcBodySym->originalIsec;
1276+
ObjFile *file = cast<ObjFile>(isec->getFile());
12801277

12811278
if (lastFile == nullptr || lastFile != file) {
12821279
if (lastFile != nullptr)
@@ -1288,16 +1285,16 @@ void SymtabSection::emitStabs() {
12881285
}
12891286

12901287
StabsEntry symStab;
1291-
symStab.sect = bodyIsec->parent->index;
1292-
symStab.strx = stringTableSection.addString(info.originalSym->getName());
1288+
symStab.sect = isec->parent->index;
1289+
symStab.strx = stringTableSection.addString(defined->getName());
12931290
symStab.value = funcBodySym->getVA();
12941291

1295-
if (isCodeSection(bodyIsec)) {
1292+
if (isCodeSection(isec)) {
12961293
symStab.type = N_FUN;
12971294
stabs.emplace_back(std::move(symStab));
12981295
emitEndFunStab(funcBodySym);
12991296
} else {
1300-
symStab.type = info.originalSym->isExternal() ? N_GSYM : N_STSYM;
1297+
symStab.type = defined->isExternal() ? N_GSYM : N_STSYM;
13011298
stabs.emplace_back(std::move(symStab));
13021299
}
13031300
}

0 commit comments

Comments
 (0)