aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <tstellar@redhat.com>2019-05-30 00:31:30 +0000
committerTom Stellard <tstellar@redhat.com>2019-05-30 00:31:30 +0000
commite3dc222bd3ce1060e82ab2a8f2802a18abac834c (patch)
tree2bd47dec1156b5e8344dad05612bdf235367d1c2
parentf0bd598148675a650b0778f085c90bf442370248 (diff)
downloadllvm-e3dc222bd3ce1060e82ab2a8f2802a18abac834c.zip
llvm-e3dc222bd3ce1060e82ab2a8f2802a18abac834c.tar.gz
llvm-e3dc222bd3ce1060e82ab2a8f2802a18abac834c.tar.bz2
Merging r353865, r353866, and r353874:
------------------------------------------------------------------------ r353865 | sfertile | 2019-02-12 09:48:22 -0800 (Tue, 12 Feb 2019) | 1 line [PowerPC] Fix printing of negative offsets in call instruction dissasembly. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r353866 | sfertile | 2019-02-12 09:49:04 -0800 (Tue, 12 Feb 2019) | 4 lines [PPC64] Update tests to reflect change in printing of call operand. [NFC] The printing of branch operands for call instructions was changed to properly handle negative offsets. Updating the tests to reflect that. ------------------------------------------------------------------------ ------------------------------------------------------------------------ r353874 | sfertile | 2019-02-12 12:03:04 -0800 (Tue, 12 Feb 2019) | 5 lines Fix undefined behaviour in PPCInstPrinter::printBranchOperand. Fix the undefined behaviour introduced by my previous patch r353865 (left shifting a potentially negative value), which was caught by the bots that run UBSan. ------------------------------------------------------------------------ llvm-svn: 362043
-rw-r--r--lld/test/ELF/ppc64-bsymbolic-toc-restore.s2
-rw-r--r--lld/test/ELF/ppc64-call-reach.s4
-rw-r--r--lld/test/ELF/ppc64-ifunc.s4
-rw-r--r--lld/test/ELF/ppc64-local-dynamic.s2
-rw-r--r--lld/test/ELF/ppc64-plt-stub.s2
-rw-r--r--lld/test/ELF/ppc64-rel-calls.s5
-rw-r--r--lld/test/ELF/ppc64-toc-restore-recursive-call.s2
-rw-r--r--lld/test/ELF/ppc64-toc-restore.s6
-rw-r--r--llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp8
-rw-r--r--llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp7
-rw-r--r--llvm/lib/Target/PowerPC/PPCInstrInfo.td2
-rw-r--r--llvm/test/tools/llvm-objdump/PowerPC/branch-offset.s43
-rw-r--r--llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg2
13 files changed, 73 insertions, 16 deletions
diff --git a/lld/test/ELF/ppc64-bsymbolic-toc-restore.s b/lld/test/ELF/ppc64-bsymbolic-toc-restore.s
index 49d347c..b7d9edd 100644
--- a/lld/test/ELF/ppc64-bsymbolic-toc-restore.s
+++ b/lld/test/ELF/ppc64-bsymbolic-toc-restore.s
@@ -53,7 +53,7 @@ caller:
# CHECK-LABEL: caller
# CHECK: bl .+44
# CHECK-NEXT: mr 31, 3
-# CHECK-NEXT: bl .+67108816
+# CHECK-NEXT: bl .-48
# CHECK-NEXT: ld 2, 24(1)
# CHECK-NEXT: add 3, 3, 31
# CHECK-NEXT: addi 1, 1, 32
diff --git a/lld/test/ELF/ppc64-call-reach.s b/lld/test/ELF/ppc64-call-reach.s
index a02bfa8..e32497b 100644
--- a/lld/test/ELF/ppc64-call-reach.s
+++ b/lld/test/ELF/ppc64-call-reach.s
@@ -62,7 +62,7 @@ test:
# CHECK: 10010024: {{.*}} b .+33554428
# NEGOFFSET-LABEL: test
-# NEGOFFSET: 10010014: {{.*}} bl .+33554432
+# NEGOFFSET: 10010014: {{.*}} bl .-33554432
# NEGOFFSET: 10010024: {{.*}} b .+33554432
# .branch_lt[0]
@@ -83,7 +83,7 @@ test:
# the offset is interpreted as a signed 26 bit value so 67108812 is actually
# -52.
# THUNK-LABEL: test:
-# THUNK: 10010034: {{.*}} bl .+67108812
+# THUNK: 10010034: {{.*}} bl .-52
# THUNK: 10010044: {{.*}} b .+67108812
# The offset from the TOC to the .branch_lt section is (-1 << 16) - 32768.
diff --git a/lld/test/ELF/ppc64-ifunc.s b/lld/test/ELF/ppc64-ifunc.s
index 6f2d331..bd7f761 100644
--- a/lld/test/ELF/ppc64-ifunc.s
+++ b/lld/test/ELF/ppc64-ifunc.s
@@ -42,9 +42,9 @@
# CHECK: _start:
# CHECK-NEXT: addis 2, 12, 2
# CHECK-NEXT: addi 2, 2, -32588
-# CHECK-NEXT: bl .+67108812
+# CHECK-NEXT: bl .-52
# CHECK-NEXT: ld 2, 24(1)
-# CHECK-NEXT: bl .+67108824
+# CHECK-NEXT: bl .-40
# CHECK-NEXT: ld 2, 24(1)
# Check tocbase
diff --git a/lld/test/ELF/ppc64-local-dynamic.s b/lld/test/ELF/ppc64-local-dynamic.s
index 6ed3b0f..8a23863 100644
--- a/lld/test/ELF/ppc64-local-dynamic.s
+++ b/lld/test/ELF/ppc64-local-dynamic.s
@@ -113,7 +113,7 @@ k:
// Dis: test:
// Dis: addis 3, 2, 0
// Dis-NEXT: addi 3, 3, -32760
-// Dis-NEXT: bl .+67108804
+// Dis-NEXT: bl .-60
// Dis-NEXT: ld 2, 24(1)
// Dis-NEXT: addis 3, 3, 0
// Dis-NEXT: lwa 3, -32768(3)
diff --git a/lld/test/ELF/ppc64-plt-stub.s b/lld/test/ELF/ppc64-plt-stub.s
index a644f48..95e28a5 100644
--- a/lld/test/ELF/ppc64-plt-stub.s
+++ b/lld/test/ELF/ppc64-plt-stub.s
@@ -22,7 +22,7 @@
// CHECK: _start:
-// CHECK: bl .+67108824
+// CHECK: bl .-40
.text
.abiversion 2
.globl _start
diff --git a/lld/test/ELF/ppc64-rel-calls.s b/lld/test/ELF/ppc64-rel-calls.s
index 4c79498d..8423eb4 100644
--- a/lld/test/ELF/ppc64-rel-calls.s
+++ b/lld/test/ELF/ppc64-rel-calls.s
@@ -30,9 +30,8 @@ bar:
nop
blr
-# FIXME: The printing here is misleading, the branch offset here is negative.
-# CHECK: 1001000c: {{.*}} bl .+67108852
+# CHECK: 1001000c: {{.*}} bl .-12
# CHECK: 10010010: {{.*}} nop
-# CHECK: 10010014: {{.*}} bl .+67108844
+# CHECK: 10010014: {{.*}} bl .-20
# CHECK: 10010018: {{.*}} nop
# CHECK: 1001001c: {{.*}} blr
diff --git a/lld/test/ELF/ppc64-toc-restore-recursive-call.s b/lld/test/ELF/ppc64-toc-restore-recursive-call.s
index 4bedcfe..d194ada 100644
--- a/lld/test/ELF/ppc64-toc-restore-recursive-call.s
+++ b/lld/test/ELF/ppc64-toc-restore-recursive-call.s
@@ -18,7 +18,7 @@
# CHECK-NEXT: 10000:
# CHECK-LABEL: recursive_func
# CHECK-NEXT: 10014:
-# CHECK: 1003c: {{[0-9a-fA-F ]+}} bl .+67108804
+# CHECK: 1003c: {{.*}} bl .-60
# CHECK-NEXT: ld 2, 24(1)
.abiversion 2
diff --git a/lld/test/ELF/ppc64-toc-restore.s b/lld/test/ELF/ppc64-toc-restore.s
index d9e06ca..8c26207 100644
--- a/lld/test/ELF/ppc64-toc-restore.s
+++ b/lld/test/ELF/ppc64-toc-restore.s
@@ -32,10 +32,10 @@ _start:
// CHECK: Disassembly of section .text:
// CHECK: _start:
-// CHECK: 1001001c: {{.*}} bl .+67108836
+// CHECK: 1001001c: {{.*}} bl .-28
// CHECK-NOT: 10010020: {{.*}} nop
// CHECK: 10010020: {{.*}} ld 2, 24(1)
-// CHECK: 10010024: {{.*}} bl .+67108848
+// CHECK: 10010024: {{.*}} bl .-16
// CHECK-NOT: 10010028: {{.*}} nop
// CHECK-NOT: 10010028: {{.*}} ld 2, 24(1)
@@ -68,5 +68,5 @@ last:
bl foo
nop
// CHECK: last:
-// CHECK: 10010038: {{.*}} bl .+67108808
+// CHECK: 10010038: {{.*}} bl .-56
// CHECK-NEXT: 1001003c: {{.*}} ld 2, 24(1)
diff --git a/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp b/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
index 26869f2..cce239ca 100644
--- a/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
+++ b/llvm/lib/Target/PowerPC/Disassembler/PPCDisassembler.cpp
@@ -61,6 +61,14 @@ extern "C" void LLVMInitializePowerPCDisassembler() {
createPPCLEDisassembler);
}
+static DecodeStatus DecodePCRel24BranchTarget(MCInst &Inst, unsigned Imm,
+ uint64_t Addr,
+ const void *Decoder) {
+ int32_t Offset = SignExtend32<24>(Imm);
+ Inst.addOperand(MCOperand::createImm(Offset));
+ return MCDisassembler::Success;
+}
+
// FIXME: These can be generated by TableGen from the existing register
// encoding values!
diff --git a/llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp b/llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
index fc29e4e..6824168 100644
--- a/llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
@@ -382,8 +382,11 @@ void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
// Branches can take an immediate operand. This is used by the branch
// selection pass to print .+8, an eight byte displacement from the PC.
- O << ".+";
- printAbsBranchOperand(MI, OpNo, O);
+ O << ".";
+ int32_t Imm = SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2);
+ if (Imm >= 0)
+ O << "+";
+ O << Imm;
}
void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo,
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.td b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
index dd3f1ac..77aa4fe 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.td
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.td
@@ -737,7 +737,9 @@ def abscondbrtarget : Operand<OtherVT> {
def calltarget : Operand<iPTR> {
let PrintMethod = "printBranchOperand";
let EncoderMethod = "getDirectBrEncoding";
+ let DecoderMethod = "DecodePCRel24BranchTarget";
let ParserMatchClass = PPCDirectBrAsmOperand;
+ let OperandType = "OPERAND_PCREL";
}
def abscalltarget : Operand<iPTR> {
let PrintMethod = "printAbsBranchOperand";
diff --git a/llvm/test/tools/llvm-objdump/PowerPC/branch-offset.s b/llvm/test/tools/llvm-objdump/PowerPC/branch-offset.s
new file mode 100644
index 0000000..b0b3f05
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/PowerPC/branch-offset.s
@@ -0,0 +1,43 @@
+# RUN: llvm-mc -triple=powerpc64le-unknown-linux -filetype=obj %s -o %t.o
+# RUN: llvm-objdump -d %t.o | FileCheck %s
+
+# RUN: llvm-mc -triple=powerpc64-unknown-linux -filetype=obj %s -o %t.o
+# RUN: llvm-objdump -d %t.o | FileCheck %s
+
+# RUN: llvm-mc -triple=powerpc-unknown-linux -filetype=obj %s -o %t.o
+# RUN: llvm-objdump -d %t.o | FileCheck %s
+
+# CHECK: 0000000000000000 callee_back:
+# CHECK: 18: {{.*}} bl .-24
+# CHECK: 20: {{.*}} bl .+16
+# CHECK: 0000000000000030 callee_forward:
+
+ .text
+ .global caller
+ .type caller,@function
+ .type callee_forward,@function
+ .type callee_back,@function
+
+ .p2align 4
+callee_back:
+ li 3, 55
+ blr
+
+ .p2align 4
+caller:
+.Lgep:
+ addis 2, 12, .TOC.-.Lgep@ha
+ addi 2, 2, .TOC.-.Lgep@l
+.Llep:
+ .localentry caller, .Llep-.Lgep
+ bl callee_back
+ mr 31, 3
+ bl callee_forward
+ add 3, 3, 31
+ blr
+
+ .p2align 4
+callee_forward:
+ li 3, 66
+ blr
+
diff --git a/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg b/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg
new file mode 100644
index 0000000..b775107
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/PowerPC/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'PowerPC' in config.root.targets:
+ config.unsupported = True