[PATCH] Fix for PR15347: PPC64: unreachable reached in PPCELFObjectWriter due to missing modifier mapping

Kai kai at redstar.de
Sun Feb 24 21:45:39 PST 2013


Hi!

While trying to port LDC to Linux/PPC64 I encountered a missing modifier 
in PPCELFObjectWriter for @tprel at l. The attached patch fixes the problem.

I still try to produce a test case because
(a) bugpoint did not deliver a useful result
(b) without an assembler it is not easy to create the required IR code 
(-O1/-O2/-O3 is required to trigger the bug.)

Please note that there is at least one version of the ELF ABI spec which 
specifies a wrong value for R_PPC64_TPREL16_LO.

Please review.

Regards
Kai
-------------- next part --------------
diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h
index bbd2955..8e6b91e 100644
--- a/include/llvm/Support/ELF.h
+++ b/include/llvm/Support/ELF.h
@@ -483,6 +483,7 @@ enum {
   R_PPC64_TOC16_DS            = 63,
   R_PPC64_TOC16_LO_DS         = 64,
   R_PPC64_TLS                 = 67,
+  R_PPC64_TPREL16_LO          = 70,
   R_PPC64_DTPREL16_LO         = 75,
   R_PPC64_DTPREL16_HA         = 77,
   R_PPC64_GOT_TLSGD16_LO      = 80,
diff --git a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
index ad41f3a..61868d4 100644
--- a/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
+++ b/lib/Target/PowerPC/MCTargetDesc/PPCELFObjectWriter.cpp
@@ -153,6 +153,9 @@ unsigned PPCELFObjectWriter::getRelocTypeInner(const MCValue &Target,
     case PPC::fixup_ppc_toc16:
       switch (Modifier) {
       default: llvm_unreachable("Unsupported Modifier");
+      case MCSymbolRefExpr::VK_PPC_TPREL16_LO:
+        Type = ELF::R_PPC64_TPREL16_LO;
+        break;
       case MCSymbolRefExpr::VK_PPC_DTPREL16_LO:
         Type = ELF::R_PPC64_DTPREL16_LO;
         break;


More information about the llvm-commits mailing list