Changeset View
Changeset View
Standalone View
Standalone View
lld/ELF/SymbolTable.cpp
Show All 33 Lines | void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { | ||||
// Redirect __real_foo to the original foo and foo to the original __wrap_foo. | // Redirect __real_foo to the original foo and foo to the original __wrap_foo. | ||||
int &idx1 = symMap[CachedHashStringRef(sym->getName())]; | int &idx1 = symMap[CachedHashStringRef(sym->getName())]; | ||||
int &idx2 = symMap[CachedHashStringRef(real->getName())]; | int &idx2 = symMap[CachedHashStringRef(real->getName())]; | ||||
int &idx3 = symMap[CachedHashStringRef(wrap->getName())]; | int &idx3 = symMap[CachedHashStringRef(wrap->getName())]; | ||||
idx2 = idx1; | idx2 = idx1; | ||||
idx1 = idx3; | idx1 = idx3; | ||||
if (!real->isUsedInRegularObj && sym->isUndefined()) | // Propagate symbol usage information to the redirected symbols. | ||||
if (sym->isUsedInRegularObj) | |||||
wrap->isUsedInRegularObj = true; | |||||
if (real->isUsedInRegularObj) | |||||
sym->isUsedInRegularObj = true; | |||||
else if (sym->isUndefined()) | |||||
MaskRay: It will be good to have a comment for the `if (sym->isUndefined())` condition. | |||||
smeenai: Note that I'm tightening the condition further in D124065, which is a follow-up to this diff. | |||||
Ah adding the comment to D124065 will be good. Are you splitting the two patches for easy bisection? I.e. in case the second patch breaks something? MaskRay: Ah adding the comment to D124065 will be good.
Are you splitting the two patches for easy… | |||||
Yup, I wanted to keep the changes isolated so that each patch was an individual behavior change (i.e. this one only fixes the wrapping behavior and doesn't change any existing tests, and the next one changes symbol retention and needs an existing test to be modified). smeenai: Yup, I wanted to keep the changes isolated so that each patch was an individual behavior change… | |||||
sym->isUsedInRegularObj = false; | sym->isUsedInRegularObj = false; | ||||
// Now renaming is complete, and no one refers to real. We drop real from | // Now renaming is complete, and no one refers to real. We drop real from | ||||
// .symtab and .dynsym. If real is undefined, it is important that we don't | // .symtab and .dynsym. If real is undefined, it is important that we don't | ||||
// leave it in .dynsym, because otherwise it might lead to an undefined symbol | // leave it in .dynsym, because otherwise it might lead to an undefined symbol | ||||
// error in a subsequent link. If real is defined, we could emit real as an | // error in a subsequent link. If real is defined, we could emit real as an | ||||
// alias for sym, but that could degrade the user experience of some tools | // alias for sym, but that could degrade the user experience of some tools | ||||
// that can print out only one symbol for each location: sym is a preferred | // that can print out only one symbol for each location: sym is a preferred | ||||
▲ Show 20 Lines • Show All 289 Lines • Show Last 20 Lines |
It will be good to have a comment for the if (sym->isUndefined()) condition.