From 72c3b1ed1d405d445ebad0ba8f179075ca33b211 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 14 Feb 2019 19:33:26 +0000 Subject: [PATCH] Move a function from .h to .cpp and use a shorter name. NFC. llvm-svn: 354054 --- lld/ELF/Relocations.cpp | 80 +++++++++++++++++++++++++++++++++---------------- lld/ELF/Relocations.h | 30 ------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index ab2113b..5d0d84d 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -93,6 +93,38 @@ static std::string getLocation(InputSectionBase &S, const Symbol &Sym, return Msg + S.getObjMsg(Off); } +namespace { +// Build a bitmask with one bit set for each RelExpr. +// +// Constexpr function arguments can't be used in static asserts, so we +// use template arguments to build the mask. +// But function template partial specializations don't exist (needed +// for base case of the recursion), so we need a dummy struct. +template struct RelExprMaskBuilder { + static inline uint64_t build() { return 0; } +}; + +// Specialization for recursive case. +template +struct RelExprMaskBuilder { + static inline uint64_t build() { + static_assert(0 <= Head && Head < 64, + "RelExpr is too large for 64-bit mask!"); + return (uint64_t(1) << Head) | RelExprMaskBuilder::build(); + } +}; +} // namespace + +// Return true if `Expr` is one of `Exprs`. +// There are fewer than 64 RelExpr's, so we can represent any set of +// RelExpr's as a constant bit mask and test for membership with a +// couple cheap bitwise operations. +template bool oneof(RelExpr Expr) { + assert(0 <= Expr && (int)Expr < 64 && + "RelExpr is too large for 64-bit mask!"); + return (uint64_t(1) << Expr) & RelExprMaskBuilder::build(); +} + // This function is similar to the `handleTlsRelocation`. MIPS does not // support any relaxations for TLS relocations so by factoring out MIPS // handling in to the separate function we can simplify the code and do not @@ -186,7 +218,7 @@ handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C, if (Config->EMachine == EM_MIPS) return handleMipsTlsRelocation(Type, Sym, C, Offset, Addend, Expr); - if (isRelExprOneOf(Expr) && + if (oneof(Expr) && Config->Shared) { if (In.Got->addDynTlsEntry(Sym)) { uint64_t Off = In.Got->getGlobalDynOffset(Sym); @@ -198,8 +230,8 @@ handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C, return 1; } - if (isRelExprOneOf(Expr)) { + if (oneof( + Expr)) { // Local-Dynamic relocs can be relaxed to Local-Exec. if (!Config->Shared) { C.Relocations.push_back( @@ -242,8 +274,8 @@ handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C, return 1; } - if (isRelExprOneOf(Expr)) { + if (oneof(Expr)) { if (Config->Shared) { if (In.Got->addDynTlsEntry(Sym)) { uint64_t Off = In.Got->getGlobalDynOffset(Sym); @@ -283,8 +315,8 @@ handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C, // Initial-Exec relocs can be relaxed to Local-Exec if the symbol is locally // defined. - if (isRelExprOneOf(Expr) && + if (oneof(Expr) && !Config->Shared && !Sym.IsPreemptible) { C.Relocations.push_back({R_RELAX_TLS_IE_TO_LE, Type, Offset, Addend, &Sym}); return 1; @@ -336,24 +368,23 @@ static bool isAbsoluteValue(const Symbol &Sym) { // Returns true if Expr refers a PLT entry. static bool needsPlt(RelExpr Expr) { - return isRelExprOneOf(Expr); + return oneof(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(Expr); + return oneof(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) { - return isRelExprOneOf(Expr); + return oneof(Expr); } // Returns true if a given relocation can be computed at link-time. @@ -368,14 +399,13 @@ static bool isRelExpr(RelExpr Expr) { static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym, InputSectionBase &S, uint64_t RelOff) { // These expressions always compute a constant - if (isRelExprOneOf(E)) + if (oneof(E)) return true; // These never do, except if the entire file is position dependent or if @@ -991,7 +1021,7 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I, RelExpr Expr = Target->getRelExpr(Type, Sym, RelocatedAddr); // Ignore "hint" relocations because they are only markers for relaxation. - if (isRelExprOneOf(Expr)) + if (oneof(Expr)) return; // We can separate the small code model relocations into 2 categories: @@ -1032,8 +1062,8 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I, // This relocation does not require got entry, but it is relative to got and // needs it to be created. Here we request for that. - if (isRelExprOneOf(Expr)) + if (oneof(Expr)) In.Got->HasGotOffRel = true; // Read an addend. diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h index 3298bfc..fbb96b8 100644 --- a/lld/ELF/Relocations.h +++ b/lld/ELF/Relocations.h @@ -95,36 +95,6 @@ enum RelExpr { R_RISCV_PC_INDIRECT, }; -// Build a bitmask with one bit set for each RelExpr. -// -// Constexpr function arguments can't be used in static asserts, so we -// use template arguments to build the mask. -// But function template partial specializations don't exist (needed -// for base case of the recursion), so we need a dummy struct. -template struct RelExprMaskBuilder { - static inline uint64_t build() { return 0; } -}; - -// Specialization for recursive case. -template -struct RelExprMaskBuilder { - static inline uint64_t build() { - static_assert(0 <= Head && Head < 64, - "RelExpr is too large for 64-bit mask!"); - return (uint64_t(1) << Head) | RelExprMaskBuilder::build(); - } -}; - -// Return true if `Expr` is one of `Exprs`. -// There are fewer than 64 RelExpr's, so we can represent any set of -// RelExpr's as a constant bit mask and test for membership with a -// couple cheap bitwise operations. -template bool isRelExprOneOf(RelExpr Expr) { - assert(0 <= Expr && (int)Expr < 64 && - "RelExpr is too large for 64-bit mask!"); - return (uint64_t(1) << Expr) & RelExprMaskBuilder::build(); -} - // Architecture-neutral representation of relocation. struct Relocation { RelExpr Expr; -- 2.7.4