[lld] r255865 - ELF: Separate NeedsCopy and OffsetInBSS.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 17:14:24 PST 2015


Author: ruiu
Date: Wed Dec 16 19:14:23 2015
New Revision: 255865

URL: http://llvm.org/viewvc/llvm-project?rev=255865&view=rev
Log:
ELF: Separate NeedsCopy and OffsetInBSS.

Previously, OffsetInBSS is -1 if it has no information about copy
relocation, 0 if it needs a copy relocation, and >0 if its offset
in BSS has been assigned. These flags were too subtle. This patch
adds a new flag, NeedsCopy, to carry information about whether
a shared symbol needs a copy relocation or not.

Modified:
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=255865&r1=255864&r2=255865&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Wed Dec 16 19:14:23 2015
@@ -795,7 +795,7 @@ typename ELFFile<ELFT>::uintX_t lld::elf
     return Out<ELFT>::Bss->getVA() + cast<DefinedCommon<ELFT>>(S).OffsetInBSS;
   case SymbolBody::SharedKind: {
     auto &SS = cast<SharedSymbol<ELFT>>(S);
-    if (SS.needsCopy())
+    if (SS.NeedsCopy)
       return Out<ELFT>::Bss->getVA() + SS.OffsetInBSS;
     return 0;
   }
@@ -1323,7 +1323,7 @@ void SymbolTableSection<ELFT>::writeGlob
       OutSec = Out<ELFT>::Bss;
       break;
     case SymbolBody::SharedKind: {
-      if (cast<SharedSymbol<ELFT>>(Body)->needsCopy())
+      if (cast<SharedSymbol<ELFT>>(Body)->NeedsCopy)
         OutSec = Out<ELFT>::Bss;
       break;
     }

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=255865&r1=255864&r2=255865&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Wed Dec 16 19:14:23 2015
@@ -299,9 +299,10 @@ public:
 
   SharedFile<ELFT> *File;
 
-  // Can have offset if requires copy relocation.
-  uintX_t OffsetInBSS = -1;
-  bool needsCopy() const { return OffsetInBSS != (uintX_t)-1; }
+  // True if the linker has to generate a copy relocation for this shared
+  // symbol. OffsetInBSS is significant only when NeedsCopy is true.
+  bool NeedsCopy = false;
+  uintX_t OffsetInBSS = 0;
 };
 
 // This class represents a symbol defined in an archive file. It is

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=255865&r1=255864&r2=255865&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Dec 16 19:14:23 2015
@@ -243,10 +243,10 @@ void Writer<ELFT>::scanRelocs(
     bool NeedsPlt = false;
     if (Body) {
       if (auto *E = dyn_cast<SharedSymbol<ELFT>>(Body)) {
-        if (E->needsCopy())
+        if (E->NeedsCopy)
           continue;
         if (Target->relocNeedsCopy(Type, *Body))
-          E->OffsetInBSS = 0;
+          E->NeedsCopy = true;
       }
       NeedsPlt = Target->relocNeedsPlt(Type, *Body);
       if (NeedsPlt) {
@@ -712,7 +712,7 @@ template <class ELFT> void Writer<ELFT>:
     if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
       CommonSymbols.push_back(C);
     if (auto *SC = dyn_cast<SharedSymbol<ELFT>>(Body))
-      if (SC->needsCopy())
+      if (SC->NeedsCopy)
         SharedCopySymbols.push_back(SC);
 
     if (!includeInSymtab<ELFT>(*Body))




More information about the llvm-commits mailing list