[lld] e983109 - [ELF] Move R_TPREL/R_TPREL_NEG check into handleTlsRelocation

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 16 12:20:06 PDT 2022


Author: Fangrui Song
Date: 2022-10-16T12:19:58-07:00
New Revision: e98310987691aeaf92821331724c9d865994efaa

URL: https://github.com/llvm/llvm-project/commit/e98310987691aeaf92821331724c9d865994efaa
DIFF: https://github.com/llvm/llvm-project/commit/e98310987691aeaf92821331724c9d865994efaa.diff

LOG: [ELF] Move R_TPREL/R_TPREL_NEG check into handleTlsRelocation

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index aa930e2df2f0..8264e3728a55 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1189,8 +1189,14 @@ static unsigned handleMipsTlsRelocation(RelType type, Symbol &sym,
 static unsigned handleTlsRelocation(RelType type, Symbol &sym,
                                     InputSectionBase &c, uint64_t offset,
                                     int64_t addend, RelExpr expr) {
-  if (!sym.isTls())
+  if (expr == R_TPREL || expr == R_TPREL_NEG) {
+    if (config->shared) {
+      errorOrWarn("relocation " + toString(type) + " against " + toString(sym) +
+                  " cannot be used with -shared" + getLocation(c, sym, offset));
+      return 1;
+    }
     return 0;
+  }
 
   if (config->emachine == EM_MIPS)
     return handleMipsTlsRelocation(type, sym, c, offset, addend, expr);
@@ -1386,17 +1392,12 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
 
   // Process TLS relocations, including relaxing TLS relocations. Note that
   // R_TPREL and R_TPREL_NEG relocations are resolved in processAux.
-  if (expr == R_TPREL || expr == R_TPREL_NEG) {
-    if (config->shared) {
-      errorOrWarn("relocation " + toString(type) + " against " + toString(sym) +
-                  " cannot be used with -shared" +
-                  getLocation(*sec, sym, offset));
+  if (sym.isTls()) {
+    if (unsigned processed =
+            handleTlsRelocation(type, sym, *sec, offset, addend, expr)) {
+      i += processed - 1;
       return;
     }
-  } else if (unsigned processed =
-                 handleTlsRelocation(type, sym, *sec, offset, addend, expr)) {
-    i += (processed - 1);
-    return;
   }
 
   // Relax relocations.


        


More information about the llvm-commits mailing list