[lld] cebb0a6 - [ELF][ARM] Improve error message for unknown relocation

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 8 12:39:13 PST 2021


Author: Fangrui Song
Date: 2021-11-08T12:39:08-08:00
New Revision: cebb0a64b431870f200bac7b7f0287149c0979a0

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

LOG: [ELF][ARM] Improve error message for unknown relocation

Like rLLD354040.

Before: `error: unrecognized relocation Unknown (254)`
Now:    `error: unknown relocation (254) against symbol foo`

Added: 
    lld/test/ELF/invalid/invalid-relocation-arm.test

Modified: 
    lld/ELF/Arch/ARM.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 557702bab671b..e64b0f231198a 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -84,6 +84,12 @@ uint32_t ARM::calcEFlags() const {
 RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
                         const uint8_t *loc) const {
   switch (type) {
+  case R_ARM_ABS32:
+  case R_ARM_MOVW_ABS_NC:
+  case R_ARM_MOVT_ABS:
+  case R_ARM_THM_MOVW_ABS_NC:
+  case R_ARM_THM_MOVT_ABS:
+    return R_ABS;
   case R_ARM_THM_JUMP11:
     return R_PC;
   case R_ARM_CALL:
@@ -156,7 +162,9 @@ RelExpr ARM::getRelExpr(RelType type, const Symbol &s,
     // not ARMv4 output, we can just ignore it.
     return R_NONE;
   default:
-    return R_ABS;
+    error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
+          ") against symbol " + toString(s));
+    return R_NONE;
   }
 }
 
@@ -702,8 +710,7 @@ void ARM::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
     break;
   }
   default:
-    error(getErrorLocation(loc) + "unrecognized relocation " +
-          toString(rel.type));
+    llvm_unreachable("unknown relocation");
   }
 }
 

diff  --git a/lld/test/ELF/invalid/invalid-relocation-arm.test b/lld/test/ELF/invalid/invalid-relocation-arm.test
new file mode 100644
index 0000000000000..d951173d1a0fc
--- /dev/null
+++ b/lld/test/ELF/invalid/invalid-relocation-arm.test
@@ -0,0 +1,29 @@
+# REQUIRES: arm
+# RUN: yaml2obj %s -o %t.o
+# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# CHECK:      error: unknown relocation (254) against symbol foo
+# CHECK-NEXT: error: unknown relocation (255) against symbol foo
+
+!ELF
+FileHeader:
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_ARM
+Sections:
+  - Name:  .text
+    Type:  SHT_PROGBITS
+    Flags: [ SHF_ALLOC ]
+  - Name:  .rela.text
+    Type:  SHT_RELA
+    Link:  .symtab
+    Info:  .text
+    Relocations:
+      - Symbol: foo
+        Type:   0xfe
+      - Symbol: foo
+        Type:   0xff
+Symbols:
+  - Name:    foo
+    Section: .text
+    Binding: STB_GLOBAL


        


More information about the llvm-commits mailing list