[PPC] Fix PR24686 by failing assembly for an invalid relocation
authorBill Schmidt <wschmidt@linux.vnet.ibm.com>
Thu, 22 Oct 2015 15:53:44 +0000 (15:53 +0000)
committerBill Schmidt <wschmidt@linux.vnet.ibm.com>
Thu, 22 Oct 2015 15:53:44 +0000 (15:53 +0000)
PR24686 identifies a problem where a relocation expression is invalid
when not all of the symbols in the expression can be locally
resolved.  This causes the compiler to request a PC-relative half16ds
relocation, which is nonsensical for PowerPC.  This patch recognizes
this situation and ensures we fail the assembly cleanly.

Test case provided by Anton Blanchard.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@251027 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
test/MC/PowerPC/pr24686.s [new file with mode: 0644]

index ebcea9af27940a4f4e9a1f058f47be1d7e08efce..75ba12b5a83b235e225ce41da0cbcc507cfb46f1 100644 (file)
@@ -113,6 +113,13 @@ unsigned PPCELFObjectWriter::GetRelocType(const MCValue &Target,
         break;
       }
       break;
+    case PPC::fixup_ppc_half16ds: {
+      raw_ostream &OS = *(new raw_fd_ostream(2, false));
+      Target.print(OS);
+      OS << "\n";
+      report_fatal_error("Invalid PC-relative half16ds relocation");
+      break;
+    }
     case FK_Data_4:
     case FK_PCRel_4:
       Type = ELF::R_PPC_REL32;
diff --git a/test/MC/PowerPC/pr24686.s b/test/MC/PowerPC/pr24686.s
new file mode 100644 (file)
index 0000000..28cba23
--- /dev/null
@@ -0,0 +1,7 @@
+# RUN: not llvm-mc -triple=powerpc64le-unknown-linux-gnu -filetype=obj %s \
+# RUN: 2>&1 | FileCheck %s
+        
+_stext:
+ld %r5, p_end - _stext(%r5)
+
+# CHECK: LLVM ERROR: Invalid PC-relative half16ds relocation