-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lld-macho] Fix compatibility between --icf=safe_thunks and --keep-icf-stabs #116687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include "ConcatOutputSection.h" | ||
| #include "Config.h" | ||
| #include "ExportTrie.h" | ||
| #include "ICF.h" | ||
| #include "InputFiles.h" | ||
| #include "MachOStructs.h" | ||
| #include "ObjC.h" | ||
|
|
@@ -1204,6 +1205,17 @@ void SymtabSection::emitEndFunStab(Defined *defined) { | |
| stabs.emplace_back(std::move(stab)); | ||
| } | ||
|
|
||
| // Given a pointer to a function symbol, return the symbol that points to the | ||
| // actual function body that will go in the final binary. Generally this is the | ||
| // symbol itself, but if the symbol was folded using a thunk, we retrieve the | ||
| // target function body from the thunk. | ||
| Defined *SymtabSection::getFuncBodySym(Defined *originalSym) { | ||
| if (originalSym->identicalCodeFoldingKind != Symbol::ICFFoldKind::Thunk) | ||
|
||
| return originalSym; | ||
|
|
||
| return macho::getBodyForThunkFoldedSym(originalSym); | ||
| } | ||
|
|
||
| void SymtabSection::emitStabs() { | ||
| if (config->omitDebugInfo) | ||
| return; | ||
|
|
@@ -1229,20 +1241,10 @@ void SymtabSection::emitStabs() { | |
| if (defined->isAbsolute()) | ||
| continue; | ||
|
|
||
| // Never generate a STABS entry for a symbol that has been ICF'ed using a | ||
| // thunk, just as we do for fully ICF'ed functions. Otherwise, we end up | ||
| // generating invalid DWARF as dsymutil will assume the entire function | ||
| // body is at that location, when, in reality, only the thunk is | ||
| // present. This will end up causing overlapping DWARF entries. | ||
| // TODO: Find an implementation that works in combination with | ||
| // `--keep-icf-stabs`. | ||
| if (defined->identicalCodeFoldingKind == Symbol::ICFFoldKind::Thunk) | ||
| continue; | ||
|
|
||
| // Constant-folded symbols go in the executable's symbol table, but don't | ||
| // get a stabs entry unless --keep-icf-stabs flag is specified | ||
| // get a stabs entry unless --keep-icf-stabs flag is specified. | ||
| if (!config->keepICFStabs && | ||
| defined->identicalCodeFoldingKind == Symbol::ICFFoldKind::Body) | ||
| defined->identicalCodeFoldingKind != Symbol::ICFFoldKind::None) | ||
| continue; | ||
|
|
||
| ObjFile *file = defined->getObjectFile(); | ||
|
|
@@ -1251,8 +1253,8 @@ void SymtabSection::emitStabs() { | |
|
|
||
| // We use 'originalIsec' to get the file id of the symbol since 'isec()' | ||
| // might point to the merged ICF symbol's file | ||
| symbolsNeedingStabs.emplace_back(defined, | ||
| defined->originalIsec->getFile()->id); | ||
| symbolsNeedingStabs.emplace_back( | ||
| defined, getFuncBodySym(defined)->originalIsec->getFile()->id); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1269,7 +1271,8 @@ void SymtabSection::emitStabs() { | |
| Defined *defined = pair.first; | ||
| // We use 'originalIsec' of the symbol since we care about the actual origin | ||
| // of the symbol, not the canonical location returned by `isec()`. | ||
| InputSection *isec = defined->originalIsec; | ||
| Defined *funcBodySym = getFuncBodySym(defined); | ||
| InputSection *isec = funcBodySym->originalIsec; | ||
| ObjFile *file = cast<ObjFile>(isec->getFile()); | ||
|
|
||
| if (lastFile == nullptr || lastFile != file) { | ||
|
|
@@ -1284,12 +1287,12 @@ void SymtabSection::emitStabs() { | |
| StabsEntry symStab; | ||
| symStab.sect = isec->parent->index; | ||
| symStab.strx = stringTableSection.addString(defined->getName()); | ||
| symStab.value = defined->getVA(); | ||
| symStab.value = funcBodySym->getVA(); | ||
|
|
||
| if (isCodeSection(isec)) { | ||
| symStab.type = N_FUN; | ||
| stabs.emplace_back(std::move(symStab)); | ||
| emitEndFunStab(defined); | ||
| emitEndFunStab(funcBodySym); | ||
| } else { | ||
| symStab.type = defined->isExternal() ? N_GSYM : N_STSYM; | ||
| stabs.emplace_back(std::move(symStab)); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.