[lld] e3e13db - [ELF][RISCV] Improve error message for unknown relocations

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 31 16:10:03 PST 2019


Author: Fangrui Song
Date: 2019-12-31T16:09:55-08:00
New Revision: e3e13db714e0d642ae44d5d392b137ec64d93a00

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

LOG: [ELF][RISCV] Improve error message for unknown relocations

Like rLLD354040.

Added: 
    

Modified: 
    lld/ELF/Arch/RISCV.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index d4acccf80a3c..42db8e08162d 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -188,6 +188,15 @@ RelType RISCV::getDynRel(RelType type) const {
 RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
                           const uint8_t *loc) const {
   switch (type) {
+  case R_RISCV_NONE:
+    return R_NONE;
+  case R_RISCV_32:
+  case R_RISCV_64:
+  case R_RISCV_HI20:
+  case R_RISCV_LO12_I:
+  case R_RISCV_LO12_S:
+  case R_RISCV_RVC_LUI:
+    return R_ABS;
   case R_RISCV_ADD8:
   case R_RISCV_ADD16:
   case R_RISCV_ADD32:
@@ -229,9 +238,11 @@ RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,
   case R_RISCV_RELAX:
   case R_RISCV_ALIGN:
   case R_RISCV_TPREL_ADD:
-    return R_HINT;
+    return R_NONE;
   default:
-    return R_ABS;
+    error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
+          ") against symbol " + toString(s));
+    return R_NONE;
   }
 }
 
@@ -423,21 +434,9 @@ void RISCV::relocateOne(uint8_t *loc, const RelType type,
   case R_RISCV_ALIGN:
   case R_RISCV_RELAX:
     return; // Ignored (for now)
-  case R_RISCV_NONE:
-    return; // Do nothing
-
-  // These are handled by the dynamic linker
-  case R_RISCV_RELATIVE:
-  case R_RISCV_COPY:
-  case R_RISCV_JUMP_SLOT:
-  // GP-relative relocations are only produced after relaxation, which
-  // we don't support for now
-  case R_RISCV_GPREL_I:
-  case R_RISCV_GPREL_S:
+
   default:
-    error(getErrorLocation(loc) +
-          "unimplemented relocation: " + toString(type));
-    return;
+    llvm_unreachable("unknown relocation");
   }
 }
 


        


More information about the llvm-commits mailing list