summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorSean Fertile <sfertile@ca.ibm.com>2019-01-10 15:08:02 +0000
committerSean Fertile <sfertile@ca.ibm.com>2019-01-10 15:08:02 +0000
commit2964123c3d993af781cbe58336b15764a7904794 (patch)
treeb6ca4952771cb2fb2b87a3157de7166b7da9f033 /lld
parente332d9be2bc0b21200d85a41df3d9cf6a20e5cc0 (diff)
[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
Diffstat (limited to 'lld')
-rw-r--r--lld/ELF/Arch/PPC64.cpp18
-rw-r--r--lld/test/ELF/ppc64-error-missaligned-dq.s2
-rw-r--r--lld/test/ELF/ppc64-error-missaligned-ds.s2
3 files changed, 12 insertions, 10 deletions
diff --git a/lld/ELF/Arch/PPC64.cpp b/lld/ELF/Arch/PPC64.cpp
index 94e98a31813..8a320c9a4e9 100644
--- a/lld/ELF/Arch/PPC64.cpp
+++ b/lld/ELF/Arch/PPC64.cpp
@@ -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, RelType Type, uint64_t Val) const {
}
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, RelType Type, uint64_t Val) const {
// 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
diff --git a/lld/test/ELF/ppc64-error-missaligned-dq.s b/lld/test/ELF/ppc64-error-missaligned-dq.s
index ea30ab88fb8..68ad2e5c46f 100644
--- a/lld/test/ELF/ppc64-error-missaligned-dq.s
+++ b/lld/test/ELF/ppc64-error-missaligned-dq.s
@@ -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
diff --git a/lld/test/ELF/ppc64-error-missaligned-ds.s b/lld/test/ELF/ppc64-error-missaligned-ds.s
index 99a2c08bc99..deee8f9caa1 100644
--- a/lld/test/ELF/ppc64-error-missaligned-ds.s
+++ b/lld/test/ELF/ppc64-error-missaligned-ds.s
@@ -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