Skip to content

Commit 5ab6075

Browse files
author
Alex B
committed
Address feedback nr.1
1 parent 474d9a2 commit 5ab6075

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lld/MachO/ICF.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ Defined *macho::getBodyForThunkFoldedSym(Defined *foldedSym) {
507507
}
508508

509509
llvm_unreachable("could not find body symbol for ICF-generated thunk");
510-
return nullptr;
511510
}
512511
void macho::foldIdenticalSections(bool onlyCfStrings) {
513512
TimeTraceScope timeScope("Fold Identical Code Sections");

lld/MachO/SyntheticSections.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,11 @@ void SymtabSection::emitEndFunStab(Defined *defined) {
12051205
stabs.emplace_back(std::move(stab));
12061206
}
12071207

1208+
// Given a pointer to a function symbol, return the symbol that points to the
1209+
// actual function body that will go in the final binary. Generally this is the
1210+
// symbol itself, but if the symbol was folded using a thunk, we retrieve the
1211+
// target function body from the thunk.
12081212
Defined *SymtabSection::getFuncBodySym(Defined *originalSym) {
1209-
// If the Defined is not a thunk, we can use it directly
12101213
if (originalSym->identicalCodeFoldingKind != Symbol::ICFFoldKind::Thunk)
12111214
return originalSym;
12121215

@@ -1226,8 +1229,6 @@ void SymtabSection::emitStabs() {
12261229
struct SymbolStabInfo {
12271230
Defined *originalSym; // Original Defined symbol - this may be an ICF thunk
12281231
int fileId; // File ID associated with the STABS symbol
1229-
Defined *mainBodySym; // Symbol that consists of the full function body -
1230-
// use this for the STABS entry
12311232
};
12321233

12331234
std::vector<SymbolStabInfo> symbolsNeedingStabs;
@@ -1256,8 +1257,8 @@ void SymtabSection::emitStabs() {
12561257
// We use 'originalIsec' to get the file id of the symbol since 'isec()'
12571258
// might point to the merged ICF symbol's file
12581259
Defined *funcBodySym = getFuncBodySym(defined);
1259-
symbolsNeedingStabs.emplace_back(SymbolStabInfo{
1260-
defined, funcBodySym->originalIsec->getFile()->id, funcBodySym});
1260+
symbolsNeedingStabs.emplace_back(
1261+
SymbolStabInfo{defined, funcBodySym->originalIsec->getFile()->id});
12611262
}
12621263
}
12631264

@@ -1273,7 +1274,8 @@ void SymtabSection::emitStabs() {
12731274
for (const SymbolStabInfo &info : symbolsNeedingStabs) {
12741275
// We use 'originalIsec' of the symbol since we care about the actual origin
12751276
// of the symbol, not the canonical location returned by `isec()`.
1276-
InputSection *bodyIsec = info.mainBodySym->originalIsec;
1277+
Defined *funcBodySym = getFuncBodySym(info.originalSym);
1278+
InputSection *bodyIsec = funcBodySym->originalIsec;
12771279
ObjFile *file = cast<ObjFile>(bodyIsec->getFile());
12781280

12791281
if (lastFile == nullptr || lastFile != file) {
@@ -1288,12 +1290,12 @@ void SymtabSection::emitStabs() {
12881290
StabsEntry symStab;
12891291
symStab.sect = bodyIsec->parent->index;
12901292
symStab.strx = stringTableSection.addString(info.originalSym->getName());
1291-
symStab.value = info.mainBodySym->getVA();
1293+
symStab.value = funcBodySym->getVA();
12921294

12931295
if (isCodeSection(bodyIsec)) {
12941296
symStab.type = N_FUN;
12951297
stabs.emplace_back(std::move(symStab));
1296-
emitEndFunStab(info.mainBodySym);
1298+
emitEndFunStab(funcBodySym);
12971299
} else {
12981300
symStab.type = info.originalSym->isExternal() ? N_GSYM : N_STSYM;
12991301
stabs.emplace_back(std::move(symStab));

0 commit comments

Comments
 (0)