forked from OSchip/llvm-project
Add a helper for checking for weak undef. NFC.
llvm-svn: 313188
This commit is contained in:
parent
a835babef9
commit
3d9f1c032a
|
@ -194,8 +194,7 @@ bool ARM::needsThunk(RelExpr Expr, uint32_t RelocType, const InputFile *File,
|
|||
// If S is an undefined weak symbol in an executable we don't need a Thunk.
|
||||
// In a DSO calls to undefined symbols, including weak ones get PLT entries
|
||||
// which may need a thunk.
|
||||
if (S.isUndefined() && !S.isLocal() && S.symbol()->isWeak() &&
|
||||
!Config->Shared)
|
||||
if (S.isUndefWeak() && !Config->Shared)
|
||||
return false;
|
||||
// A state change from ARM to Thumb and vice versa must go through an
|
||||
// interworking thunk if the relocation type is not R_ARM_CALL or
|
||||
|
|
|
@ -560,7 +560,7 @@ static uint64_t getRelocTargetVA(uint32_t Type, int64_t A, uint64_t P,
|
|||
case R_PAGE_PC:
|
||||
case R_PLT_PAGE_PC: {
|
||||
uint64_t Dest;
|
||||
if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
|
||||
if (Body.isUndefWeak())
|
||||
Dest = getAArch64Page(A);
|
||||
else
|
||||
Dest = getAArch64Page(Body.getVA(A));
|
||||
|
@ -568,7 +568,7 @@ static uint64_t getRelocTargetVA(uint32_t Type, int64_t A, uint64_t P,
|
|||
}
|
||||
case R_PC: {
|
||||
uint64_t Dest;
|
||||
if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak()) {
|
||||
if (Body.isUndefWeak()) {
|
||||
// On ARM and AArch64 a branch to an undefined weak resolves to the
|
||||
// next instruction, otherwise the place.
|
||||
if (Config->EMachine == EM_ARM)
|
||||
|
|
|
@ -319,8 +319,8 @@ static uint32_t getMipsPairType(uint32_t Type, const SymbolBody &Sym) {
|
|||
// True if non-preemptable symbol always has the same value regardless of where
|
||||
// the DSO is loaded.
|
||||
static bool isAbsolute(const SymbolBody &Body) {
|
||||
if (Body.isUndefined())
|
||||
return !Body.isLocal() && Body.symbol()->isWeak();
|
||||
if (Body.isUndefWeak())
|
||||
return true;
|
||||
if (const auto *DR = dyn_cast<DefinedRegular>(&Body))
|
||||
return DR->Section == nullptr; // Absolute symbol.
|
||||
return false;
|
||||
|
@ -402,7 +402,7 @@ static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type,
|
|||
// between start of a function and '_gp' value and defined as absolute just
|
||||
// to simplify the code.
|
||||
assert(AbsVal && RelE);
|
||||
if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
|
||||
if (Body.isUndefWeak())
|
||||
return true;
|
||||
|
||||
error("relocation " + toString(Type) + " cannot refer to absolute symbol: " +
|
||||
|
|
|
@ -132,6 +132,12 @@ SymbolBody::SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
|
|||
IsInIgot(false), IsPreemptible(false), Type(Type), StOther(StOther),
|
||||
Name(Name) {}
|
||||
|
||||
bool SymbolBody::isUndefWeak() const {
|
||||
if (isLocal())
|
||||
return false;
|
||||
return symbol()->isWeak() && (isUndefined() || isLazy());
|
||||
}
|
||||
|
||||
InputFile *SymbolBody::getFile() const {
|
||||
if (isLocal()) {
|
||||
const SectionBase *Sec = cast<DefinedRegular>(this)->Section;
|
||||
|
@ -340,8 +346,10 @@ uint8_t Symbol::computeBinding() const {
|
|||
bool Symbol::includeInDynsym() const {
|
||||
if (computeBinding() == STB_LOCAL)
|
||||
return false;
|
||||
if (body()->isUndefined() || body()->isLazy())
|
||||
return Config->Shared || !body()->symbol()->isWeak();
|
||||
if (body()->isUndefWeak())
|
||||
return Config->Shared;
|
||||
if (!body()->isInCurrentDSO())
|
||||
return true;
|
||||
return ExportDynamic || body()->isShared();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,11 @@ public:
|
|||
return !isUndefined() && !isShared() && !isLazy();
|
||||
}
|
||||
bool isLocal() const { return IsLocal; }
|
||||
|
||||
// True is this is an undefined weak symbol. This only works once
|
||||
// all input files have been added.
|
||||
bool isUndefWeak() const;
|
||||
|
||||
InputFile *getFile() const;
|
||||
bool isPreemptible() const { return IsPreemptible; }
|
||||
StringRef getName() const { return Name; }
|
||||
|
|
Loading…
Reference in New Issue