[lld] r315673 - Make it explicit that we are writing addends to target sections if REL.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 22:58:54 PDT 2017


Author: ruiu
Date: Thu Oct 12 22:58:54 2017
New Revision: 315673

URL: http://llvm.org/viewvc/llvm-project?rev=315673&view=rev
Log:
Make it explicit that we are writing addends to target sections if REL.

Relocations.cpp is still head-scratching. Even though relocations are
processed by multiple functions, the functions are effectively one
gigantic function with lots of local and global shared states, because
they are really tightly coupled. It is really hard to predict whether
a change to a function will or will not affect other functions behaviors.

What I'm trying to do is to rewrite the code without breaking the
existing tests so that the code can tolerate a more aggressive
refactoring (i.e. splitting it to logically separated steps).

Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=315673&r1=315672&r2=315673&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Oct 12 22:58:54 2017
@@ -1010,20 +1010,28 @@ static void scanRelocs(InputSectionBase
     if (Expr == R_SIZE)
       Addend += Body.getSize<ELFT>();
 
+    // If the produced value is a constant, we just remember to write it
+    // when outputting this section. We also have to do it if the format
+    // uses Elf_Rel, since in that case the written value is the addend.
+    if (IsConstant) {
+      Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
+      continue;
+    }
+
     // If the output being produced is position independent, the final value
     // is still not known. In that case we still need some help from the
     // dynamic linker. We can however do better than just copying the incoming
     // relocation. We can process some of it and and just ask the dynamic
     // linker to add the load address.
-    if (!IsConstant)
+    if (Config->IsRela) {
       In<ELFT>::RelaDyn->addReloc(
           {Target->RelativeRel, &Sec, Offset, true, &Body, Addend});
-
-    // If the produced value is a constant, we just remember to write it
-    // when outputting this section. We also have to do it if the format
-    // uses Elf_Rel, since in that case the written value is the addend.
-    if (IsConstant || !RelTy::IsRela)
+    } else {
+      // In REL, addends are stored to the target section.
+      In<ELFT>::RelaDyn->addReloc(
+          {Target->RelativeRel, &Sec, Offset, true, &Body, 0});
       Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
+    }
   }
 }
 




More information about the llvm-commits mailing list