[lld] r315669 - Destructure a boolean expression and add comment.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 21:04:10 PDT 2017


Author: ruiu
Date: Thu Oct 12 21:04:10 2017
New Revision: 315669

URL: http://llvm.org/viewvc/llvm-project?rev=315669&view=rev
Log:
Destructure a boolean expression and add comment.

"IsWrite" variable didn't make sense and was misleading because
it became true even if a section is not writable.

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=315669&r1=315668&r2=315669&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Oct 12 21:04:10 2017
@@ -556,8 +556,19 @@ static void errorOrWarn(const Twine &Msg
 template <class ELFT>
 static RelExpr adjustExpr(SymbolBody &Body, RelExpr Expr, RelType Type,
                           InputSectionBase &S, uint64_t RelOff) {
-  bool IsWrite = !Config->ZText || (S.Flags & SHF_WRITE);
-  if (IsWrite || isStaticLinkTimeConstant<ELFT>(Expr, Type, Body, S, RelOff))
+  // We can create any dynamic relocation if a section is simply writable.
+  if (S.Flags & SHF_WRITE)
+    return Expr;
+
+  // Or, if we are allowed to create dynamic relocations against
+  // read-only sections (i.e. unless "-z notext" is given),
+  // we can create a dynamic relocation as we want, too.
+  if (!Config->ZText)
+    return Expr;
+
+  // If a relocation can be applied at link-time, we don't need to
+  // create a dynamic relocation in the first place.
+  if (isStaticLinkTimeConstant<ELFT>(Expr, Type, Body, S, RelOff))
     return Expr;
 
   // If we got here we know that this relocation would require the dynamic




More information about the llvm-commits mailing list