[MC][ARM] Fix redundant errors for .quad/.8byte relocations on ELF
authorFangrui Song <i@maskray.me>
Mon, 8 May 2023 04:41:38 +0000 (21:41 -0700)
committerFangrui Song <i@maskray.me>
Mon, 8 May 2023 04:41:38 +0000 (21:41 -0700)
For a .quad/.8byte directive that needs a relocation, Mach-O emits one error
while ELF emits two. Emit just one for ELF and change the diagnostic to match
other ports.

llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
llvm/test/MC/ARM/arm-memory-instructions-immediate.s
llvm/test/MC/ARM/quad-relocation.s
llvm/test/MC/ARM/t2-modified-immediate-fixup-error1.s
llvm/test/MC/ARM/thumb1-relax-adr.s
llvm/test/MC/ARM/thumb1-relax-bcc.s
llvm/test/MC/ARM/thumb1-relax-br.s
llvm/test/MC/ARM/thumb1-relax-ldrlit.s

index 0bd7156..df142b8 100644 (file)
@@ -448,7 +448,6 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
 
   switch (Kind) {
   default:
-    Ctx.reportError(Fixup.getLoc(), "bad relocation fixup type");
     return 0;
   case FK_Data_1:
   case FK_Data_2:
index df8f54d..2a6bda6 100644 (file)
@@ -87,7 +87,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
   if (IsPCRel) {
     switch (Fixup.getTargetKind()) {
     default:
-      Ctx.reportError(Fixup.getLoc(), "unsupported relocation on symbol");
+      Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
       return ELF::R_ARM_NONE;
     case FK_Data_4:
       switch (Modifier) {
@@ -159,7 +159,7 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
   }
   switch (Kind) {
   default:
-    Ctx.reportError(Fixup.getLoc(), "unsupported relocation on symbol");
+    Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
     return ELF::R_ARM_NONE;
   case FK_Data_1:
     switch (Modifier) {
index b267730..6f81205 100644 (file)
@@ -79,7 +79,7 @@ static bool getARMFixupKindMachOInfo(unsigned Kind, unsigned &RelocType,
     return true;
   case FK_Data_8:
     Log2Size = llvm::Log2_32(8);
-    return true;
+    return false;
 
     // These fixups are expected to always be resolvable at assembly time and
     // have no relocations supported.
@@ -386,8 +386,7 @@ void ARMMachObjectWriter::recordRelocation(MachObjectWriter *Writer,
     // relocation type for the fixup kind. This happens when it's a fixup that's
     // expected to always be resolvable at assembly time and not have any
     // relocations needed.
-    Asm.getContext().reportError(Fixup.getLoc(),
-                                 "unsupported relocation on symbol");
+    Asm.getContext().reportError(Fixup.getLoc(), "unsupported relocation type");
     return;
   }
 
index 04b2b9e..d72028e 100644 (file)
@@ -21,5 +21,5 @@ foo:
 // CHECK-NEXT: strb r0, [r1, #1024]
 .ifdef ERR
     str r0, [r1, 1b]
-// ERR:[[#@LINE-1]]:5: error: unsupported relocation on symbol
+// ERR:[[#@LINE-1]]:5: error: unsupported relocation type
 .endif
index 34de182..50d8d82 100644 (file)
@@ -1,9 +1,9 @@
-@ RUN: not llvm-mc -triple arm-arm-none-eabi -filetype obj < %s -o /dev/null 2>&1 | FileCheck %s
+@ RUN: not llvm-mc -triple=arm -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
+@ RUN: not llvm-mc -triple=arm-apple-darwin -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s --implicit-check-not=error:
 
        .align 3
 symbol:
-  .quad(symbol)
-
-@ CHECK: error: unsupported relocation on symbol
-@ CHECK-NEXT:   .quad(symbol)
-@ CHECK-NEXT:        ^
+@ CHECK:      :[[#@LINE+1]]:6: error: unsupported relocation type
+.quad(symbol)
+@ CHECK:      :[[#@LINE+1]]:8: error: unsupported relocation type
+.8byte symbol
index f5113a6..6424840 100644 (file)
@@ -10,4 +10,4 @@
     .equ sym0, 0x01abcdef
 .L2:
     mov r0, .L2
-@ CHECK: error: unsupported relocation on symbol
+@ CHECK: :[[#@LINE-1]]:5: error: unsupported relocation type
index 3eb2a02..fc5c7c3 100644 (file)
@@ -5,4 +5,4 @@
         .global func1
 _func1:
         adr r0, _func2
-@ CHECK-ERROR: unsupported relocation on symbol
+@ CHECK-ERROR: :[[#@LINE-1]]:9: error: unsupported relocation type
index 0d73a00..78f3477 100644 (file)
@@ -5,7 +5,7 @@
 
         .global func1
 _func1:
-@ CHECK-ERROR: :[[#@LINE+1]]:9: error: unsupported relocation on symbol
+@ CHECK-ERROR: :[[#@LINE+1]]:9: error: unsupported relocation type
         bne _func2
 
 @ CHECK-ELF: f47f affe          bne.w {{.+}} @ imm = #-4
index 5652073..b58dd6c 100644 (file)
@@ -9,8 +9,7 @@ _func1:
         @ There is no MachO relocation for Thumb1's unconditional branch, so
         @ this is unrepresentable. FIXME: I think ELF could represent this.
         b _func2
-
-@ CHECK-ERROR: unsupported relocation on symbol
+@ CHECK-ERROR: :[[#@LINE-1]]:9: error: unsupported relocation type
 
 @ CHECK-MACHO: f7ff bffe          b.w {{.+}} @ imm = #-4
 @ CHECK-MACHO-NEXT: ARM_THUMB_RELOC_BR22
index 31a9759..5cba369 100644 (file)
@@ -4,5 +4,5 @@
 
         .global func1
 _func1:
-@ CHECK-ERROR: :[[#@LINE+1]]:9: error: unsupported relocation on symbol
+@ CHECK-ERROR: :[[#@LINE+1]]:9: error: unsupported relocation type
         ldr r0, _func2