[lld] r350827 - [PPC64] Fix RelType in checkInt and checkAlignment diagnsotics.

Sean Fertile via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 10 07:08:02 PST 2019


Author: sfertile
Date: Thu Jan 10 07:08:02 2019
New Revision: 350827

URL: http://llvm.org/viewvc/llvm-project?rev=350827&view=rev
Log:
[PPC64] Fix RelType in checkInt and checkAlignment diagnsotics.

In the PPC64 target we map toc-relative relocations, dynamic thread pointer
relative relocations, and got relocations into a corresponding ADDR16 relocation
type for handling in relocateOne. This patch saves the orignal RelType before
mapping to an ADDR16 relocation so that any diagnostic messages will not
mistakenly use the mapped type.

Differential Revision: https://reviews.llvm.org/D56448

Modified:
    lld/trunk/ELF/Arch/PPC64.cpp
    lld/trunk/test/ELF/ppc64-error-missaligned-dq.s
    lld/trunk/test/ELF/ppc64-error-missaligned-ds.s

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=350827&r1=350826&r2=350827&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Thu Jan 10 07:08:02 2019
@@ -611,11 +611,13 @@ static bool isTocOptType(RelType Type) {
 }
 
 void PPC64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {
-  // We need to save the original relocation type to determine if we should
-  // toc-optimize the instructions being relocated.
+  // We need to save the original relocation type to use in diagnostics, and
+  // use the original type to determine if we should toc-optimize the
+  // instructions being relocated.
+  RelType OriginalType = Type;
   bool ShouldTocOptimize =  isTocOptType(Type);
-  // For TOC-relative and GOT-indirect relocations, proceed in terms of the
-  // corresponding ADDR16 relocation type.
+  // For dynamic thread pointer relative, toc-relative, and got-indirect
+  // relocations, proceed in terms of the corresponding ADDR16 relocation type.
   std::tie(Type, Val) = toAddr16Rel(Type, Val);
 
   switch (Type) {
@@ -628,16 +630,16 @@ void PPC64::relocateOne(uint8_t *Loc, Re
   }
   case R_PPC64_ADDR16:
   case R_PPC64_TPREL16:
-    checkInt(Loc, Val, 16, Type);
+    checkInt(Loc, Val, 16, OriginalType);
     write16(Loc, Val);
     break;
   case R_PPC64_ADDR16_DS:
   case R_PPC64_TPREL16_DS: {
-    checkInt(Loc, Val, 16, Type);
+    checkInt(Loc, Val, 16, OriginalType);
     // DQ-form instructions use bits 28-31 as part of the instruction encoding
     // DS-form instructions only use bits 30-31.
     uint16_t Mask = isDQFormInstruction(readInstrFromHalf16(Loc)) ? 0xF : 0x3;
-    checkAlignment(Loc, lo(Val), Mask + 1, Type);
+    checkAlignment(Loc, lo(Val), Mask + 1, OriginalType);
     write16(Loc, (read16(Loc) & Mask) | lo(Val));
   } break;
   case R_PPC64_ADDR16_HA:
@@ -692,7 +694,7 @@ void PPC64::relocateOne(uint8_t *Loc, Re
     // DS-form instructions only use bits 30-31.
     uint32_t Inst = readInstrFromHalf16(Loc);
     uint16_t Mask = isDQFormInstruction(Inst) ? 0xF : 0x3;
-    checkAlignment(Loc, lo(Val), Mask + 1, Type);
+    checkAlignment(Loc, lo(Val), Mask + 1, OriginalType);
     if (Config->TocOptimize && ShouldTocOptimize && ha(Val) == 0) {
       // When the high-adjusted part of a toc relocation evalutes to 0, it is
       // changed into a nop. The lo part then needs to be updated to use the toc

Modified: lld/trunk/test/ELF/ppc64-error-missaligned-dq.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-error-missaligned-dq.s?rev=350827&r1=350826&r2=350827&view=diff
==============================================================================
--- lld/trunk/test/ELF/ppc64-error-missaligned-dq.s (original)
+++ lld/trunk/test/ELF/ppc64-error-missaligned-dq.s Thu Jan 10 07:08:02 2019
@@ -6,7 +6,7 @@
 # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
 # RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
 
-# CHECK: improper alignment for relocation R_PPC64_ADDR16_LO_DS: 0x8001 is not aligned to 16 bytes
+# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8001 is not aligned to 16 bytes
 
         .global test
         .p2align        4

Modified: lld/trunk/test/ELF/ppc64-error-missaligned-ds.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-error-missaligned-ds.s?rev=350827&r1=350826&r2=350827&view=diff
==============================================================================
--- lld/trunk/test/ELF/ppc64-error-missaligned-ds.s (original)
+++ lld/trunk/test/ELF/ppc64-error-missaligned-ds.s Thu Jan 10 07:08:02 2019
@@ -6,7 +6,7 @@
 # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
 # RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
 
-# CHECK: improper alignment for relocation R_PPC64_ADDR16_LO_DS: 0x8001 is not aligned to 4 bytes
+# CHECK: improper alignment for relocation R_PPC64_TOC16_LO_DS: 0x8001 is not aligned to 4 bytes
 
         .global test
         .p2align        4




More information about the llvm-commits mailing list