[lld] r313188 - Add a helper for checking for weak undef. NFC.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 13:43:04 PDT 2017


Author: rafael
Date: Wed Sep 13 13:43:04 2017
New Revision: 313188

URL: http://llvm.org/viewvc/llvm-project?rev=313188&view=rev
Log:
Add a helper for checking for weak undef. NFC.

Modified:
    lld/trunk/ELF/Arch/ARM.cpp
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/Arch/ARM.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/ARM.cpp?rev=313188&r1=313187&r2=313188&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/ARM.cpp (original)
+++ lld/trunk/ELF/Arch/ARM.cpp Wed Sep 13 13:43:04 2017
@@ -194,8 +194,7 @@ bool ARM::needsThunk(RelExpr Expr, uint3
   // 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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=313188&r1=313187&r2=313188&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed Sep 13 13:43:04 2017
@@ -560,7 +560,7 @@ static uint64_t getRelocTargetVA(uint32_
   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_
   }
   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)

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=313188&r1=313187&r2=313188&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Sep 13 13:43:04 2017
@@ -319,8 +319,8 @@ static uint32_t getMipsPairType(uint32_t
 // 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(Rel
   // 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: " +

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=313188&r1=313187&r2=313188&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Sep 13 13:43:04 2017
@@ -132,6 +132,12 @@ SymbolBody::SymbolBody(Kind K, StringRef
       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();
 }
 

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=313188&r1=313187&r2=313188&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Sep 13 13:43:04 2017
@@ -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; }




More information about the llvm-commits mailing list