[PATCH] D85242: [AArch64] [Windows] Error out on some ELF style GOT relative relocations

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 13:08:41 PDT 2020


mstorsjo created this revision.
mstorsjo added reviewers: psmith, t.p.northover, compnerd, amccarth.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
Herald added a project: LLVM.
mstorsjo requested review of this revision.

These might occur in seemingly generic assembly. Previously when targeting COFF, they were silently ignored, which certainly won't give the right result. Instead clearly error out, to make it clear that the assembly needs to be adjusted for this target.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85242

Files:
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
  llvm/test/MC/AArch64/coff-relocations-diags.s


Index: llvm/test/MC/AArch64/coff-relocations-diags.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AArch64/coff-relocations-diags.s
@@ -0,0 +1,11 @@
+// RUN: not llvm-mc -triple aarch64-win32 -filetype=obj %s -o /dev/null 2>&1 | FileCheck %s
+
+  adrp x0, :got:symbol
+  // CHECK: error: unknown AArch64 symbol kind!
+  // CHECK-NEXT: adrp x0, :got:symbol
+  // CHECK-NEXT: ^
+
+  ldr x0, [x0, :got_lo12:symbol]
+  // CHECK: error: unknown AArch64 symbol kind!
+  // CHECK-NEXT: ldr x0, [x0, :got_lo12:symbol]
+  // CHECK-NEXT: ^
Index: llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
===================================================================
--- llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
+++ llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/BinaryFormat/COFF.h"
 #include "llvm/MC/MCAsmBackend.h"
+#include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCFixup.h"
 #include "llvm/MC/MCFixupKindInfo.h"
@@ -92,6 +93,8 @@
       AArch64MCExpr::VariantKind RefKind = A64E->getKind();
       if (RefKind == AArch64MCExpr::VK_SECREL_LO12)
         return COFF::IMAGE_REL_ARM64_SECREL_LOW12L;
+      if (RefKind & AArch64MCExpr::VK_GOT)
+        Ctx.reportError(Fixup.getLoc(), "unknown AArch64 symbol kind!");
     }
     return COFF::IMAGE_REL_ARM64_PAGEOFFSET_12L;
 
@@ -99,6 +102,11 @@
     return COFF::IMAGE_REL_ARM64_REL21;
 
   case AArch64::fixup_aarch64_pcrel_adrp_imm21:
+    if (const AArch64MCExpr *A64E = dyn_cast<AArch64MCExpr>(Expr)) {
+      AArch64MCExpr::VariantKind RefKind = A64E->getKind();
+      if (RefKind & AArch64MCExpr::VK_GOT)
+        Ctx.reportError(Fixup.getLoc(), "unknown AArch64 symbol kind!");
+    }
     return COFF::IMAGE_REL_ARM64_PAGEBASE_REL21;
 
   case AArch64::fixup_aarch64_pcrel_branch14:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85242.283010.patch
Type: text/x-patch
Size: 1947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200804/ec7513ea/attachment.bin>


More information about the llvm-commits mailing list