[lld] r259467 - ELF: Move copy relocation handler to one place. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 1 22:08:08 PST 2016


Author: ruiu
Date: Tue Feb  2 00:08:08 2016
New Revision: 259467

URL: http://llvm.org/viewvc/llvm-project?rev=259467&view=rev
Log:
ELF: Move copy relocation handler to one place. NFC.

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259467&r1=259466&r2=259467&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Feb  2 00:08:08 2016
@@ -293,16 +293,23 @@ void Writer<ELFT>::scanRelocs(
       continue;
     }
 
+    // If a symbol in a DSO is referenced directly instead of through GOT,
+    // we need to create a copy relocation for the symbol.
+    if (auto *B = dyn_cast_or_null<SharedSymbol<ELFT>>(Body)) {
+      if (B->NeedsCopy)
+        continue;
+      if (Target->needsCopyRel(Type, *B)) {
+        B->NeedsCopy = true;
+        B->setUsedInDynamicReloc();
+        Out<ELFT>::RelaDyn->addReloc({&C, &RI});
+        continue;
+      }
+    }
+
     bool NeedsGot = false;
     bool NeedsPlt = false;
 
     if (Body) {
-      if (auto *E = dyn_cast<SharedSymbol<ELFT>>(Body)) {
-        if (E->NeedsCopy)
-          continue;
-        if (Target->needsCopyRel(Type, *Body))
-          E->NeedsCopy = true;
-      }
       NeedsPlt = Target->needsPlt(Type, *Body);
       if (NeedsPlt) {
         if (Body->isInPlt())




More information about the llvm-commits mailing list