Skip to content

Commit

Permalink
Rename refersToGotEntry needsGot and add comments.
Browse files Browse the repository at this point in the history
This patch addresses a post-commit review comment for r299615.

Differential Revision: https://reviews.llvm.org/D31792

llvm-svn: 299722
  • Loading branch information
rui314 committed Apr 6, 2017
1 parent a633ee6 commit 5eb8ea8
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lld/ELF/Relocations.cpp
Expand Up @@ -79,12 +79,6 @@ static std::string getLocation(InputSectionBase &S, const SymbolBody &Sym,
return Msg + S.getObjMsg<ELFT>(Off);
}

static bool refersToGotEntry(RelExpr Expr) {
return isRelExprOneOf<R_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF,
R_MIPS_GOT_OFF32, R_GOT_PAGE_PC, R_GOT_PC,
R_GOT_FROM_END>(Expr);
}

static bool isPreemptible(const SymbolBody &Body, uint32_t Type) {
// In case of MIPS GP-relative relocations always resolve to a definition
// in a regular input file, ignoring the one-definition rule. So we,
Expand Down Expand Up @@ -284,10 +278,20 @@ static bool isAbsoluteValue(const SymbolBody &Body) {
return isAbsolute(Body) || Body.isTls();
}

// Returns true if Expr refers a PLT entry.
static bool needsPlt(RelExpr Expr) {
return isRelExprOneOf<R_PLT_PC, R_PPC_PLT_OPD, R_PLT, R_PLT_PAGE_PC>(Expr);
}

// Returns true if Expr refers a GOT entry. Note that this function
// returns false for TLS variables even though they need GOT, because
// TLS variables uses GOT differently than the regular variables.
static bool needsGot(RelExpr Expr) {
return isRelExprOneOf<R_GOT, R_GOT_OFF, R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOT_OFF,
R_MIPS_GOT_OFF32, R_GOT_PAGE_PC, R_GOT_PC,
R_GOT_FROM_END>(Expr);
}

// True if this expression is of the form Sym - X, where X is a position in the
// file (PC, or GOT for example).
static bool isRelExpr(RelExpr Expr) {
Expand Down Expand Up @@ -843,7 +847,7 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
}

// Create a GOT slot if a relocation needs GOT.
if (refersToGotEntry(Expr)) {
if (needsGot(Expr)) {
if (Config->EMachine == EM_MIPS) {
// MIPS ABI has special rules to process GOT entries and doesn't
// require relocation entries for them. A special case is TLS
Expand All @@ -861,8 +865,7 @@ static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
}
}

if (!needsPlt(Expr) && !refersToGotEntry(Expr) &&
isPreemptible(Body, Type)) {
if (!needsPlt(Expr) && !needsGot(Expr) && isPreemptible(Body, Type)) {
// We don't know anything about the finaly symbol. Just ask the dynamic
// linker to handle the relocation for us.
if (!Target->isPicRel(Type))
Expand Down

0 comments on commit 5eb8ea8

Please sign in to comment.