Skip to content

[XCOFF] Display branch-absolute targets in hex. #72532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lld/test/ELF/ppc32-reloc-addr.s
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
.section .R_PPC_ADDR24,"ax",@progbits
ba a
# CHECK-LABEL: section .R_PPC_ADDR24:
# CHECK: ba 4660
# CHECK: ba 0x1234

.section .R_PPC_ADDR32,"a",@progbits
.long a
Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Target/PowerPC/MCTargetDesc/PPCInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,10 @@ void PPCInstPrinter::printAbsBranchOperand(const MCInst *MI, unsigned OpNo,
if (!MI->getOperand(OpNo).isImm())
return printOperand(MI, OpNo, STI, O);

O << SignExtend32<32>((unsigned)MI->getOperand(OpNo).getImm() << 2);
uint64_t Imm = MI->getOperand(OpNo).getImm() << 2;
if (!TT.isPPC64())
Imm = static_cast<uint32_t>(Imm);
O << formatHex(Imm);
}

void PPCInstPrinter::printcrbitm(const MCInst *MI, unsigned OpNo,
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/PowerPC/PPCRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ def directbrtarget : Operand<OtherVT> {
def absdirectbrtarget : Operand<OtherVT> {
let PrintMethod = "printAbsBranchOperand";
let EncoderMethod = "getAbsDirectBrEncoding";
let DecoderMethod = "decodeDirectBrTarget";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bug related to branch instruction decode?
Normally we need another patch to fix this as the fix here is not same with this patch's purpose.
Since this change is quite small, let's put them together.

let ParserMatchClass = PPCDirectBrAsmOperand;
}
def PPCCondBrAsmOperand : AsmOperandClass {
Expand All @@ -814,6 +815,7 @@ def condbrtarget : Operand<OtherVT> {
def abscondbrtarget : Operand<OtherVT> {
let PrintMethod = "printAbsBranchOperand";
let EncoderMethod = "getAbsCondBrEncoding";
let DecoderMethod = "decodeCondBrTarget";
let ParserMatchClass = PPCCondBrAsmOperand;
}
def calltarget : Operand<iPTR> {
Expand All @@ -826,6 +828,7 @@ def calltarget : Operand<iPTR> {
def abscalltarget : Operand<iPTR> {
let PrintMethod = "printAbsBranchOperand";
let EncoderMethod = "getAbsDirectBrEncoding";
let DecoderMethod = "decodeDirectBrTarget";
let ParserMatchClass = PPCDirectBrAsmOperand;
}
def PPCCRBitMaskOperand : AsmOperandClass {
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/MC/Disassembler/PowerPC/ppc64-operands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@
# CHECK: b .+1024
0x48 0x00 0x04 0x00

# CHECK: ba 1024
# CHECK: ba 0x400
0x48 0x00 0x04 0x02

# FIXME: decode as beq 0, .+1024
# CHECK: bt 2, .+1024
0x41 0x82 0x04 0x00

# FIXME: decode as beqa 0, 1024
# CHECK: bta 2, 1024
# CHECK: bta 2, 0x400
0x41 0x82 0x04 0x02

8 changes: 6 additions & 2 deletions llvm/test/MC/PowerPC/ppc32-ba.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# RUN: llvm-mc -triple powerpc-unknown-unknown --show-encoding %s | FileCheck %s

# Check that large immediates in 32bit mode are accepted.
# Check that large and/or negative immediates in 32-bit mode are accepted.

# CHECK: ba -33554432 # encoding: [0x4a,0x00,0x00,0x02]
# CHECK: ba 0xfe000000 # encoding: [0x4a,0x00,0x00,0x02]
# CHECK-NEXT: ba 0xfe000000 # encoding: [0x4a,0x00,0x00,0x02]
# CHECK-NEXT: ba 0xfffffc00 # encoding: [0x4b,0xff,0xfc,0x02]
ba 0xfe000000
ba (-33554432)
ba (-1024)
8 changes: 4 additions & 4 deletions llvm/test/MC/PowerPC/ppc64-operands.s
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@
# CHECK-LE: b .+1024 # encoding: [0x00,0x04,0x00,0x48]
b 1024

# CHECK-BE: ba 1024 # encoding: [0x48,0x00,0x04,0x02]
# CHECK-LE: ba 1024 # encoding: [0x02,0x04,0x00,0x48]
# CHECK-BE: ba 0x400 # encoding: [0x48,0x00,0x04,0x02]
# CHECK-LE: ba 0x400 # encoding: [0x02,0x04,0x00,0x48]
ba 1024

# CHECK-BE: beq 0, .+1024 # encoding: [0x41,0x82,0x04,0x00]
# CHECK-LE: beq 0, .+1024 # encoding: [0x00,0x04,0x82,0x41]
beq 1024

# CHECK-BE: beqa 0, 1024 # encoding: [0x41,0x82,0x04,0x02]
# CHECK-LE: beqa 0, 1024 # encoding: [0x02,0x04,0x82,0x41]
# CHECK-BE: beqa 0, 0x400 # encoding: [0x41,0x82,0x04,0x02]
# CHECK-LE: beqa 0, 0x400 # encoding: [0x02,0x04,0x82,0x41]
beqa 1024

# CHECK-BE: # encoding: [0x42,0x9f,A,0bAAAAAA01]
Expand Down
158 changes: 158 additions & 0 deletions llvm/test/tools/llvm-objdump/XCOFF/disassemble-abs.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
## Object files assembled on AIX from the following source:
## .csect [PR]
##.main:
## .globl .main
## .extern .function
## bla .function
## btla .function
## ba 0x1234
## ba -32
## bta 0x2348
## bta -256
#
# RUN: yaml2obj %s --docnum=1 -o %t32.o
# RUN: llvm-objdump -d %t32.o | FileCheck %s
#
# CHECK: : file format aixcoff-rs6000
# CHECK: Disassembly of section .text:
# CHECK: 00000000 <.main>:
# CHECK: 0: 48 00 00 03 bla 0x0
# CHECK-NEXT: 4: 41 80 00 03 btla 0, 0x0
# CHECK-NEXT: 8: 48 00 12 36 ba 0x1234
# CHECK-NEXT: c: 4b ff ff e2 ba 0xffffffe0
# CHECK-NEXT: 10: 41 80 23 4a bta 0, 0x2348
# CHECK-NEXT: 14: 41 80 ff 02 bta 0, 0xffffff00

--- !XCOFF
FileHeader:
MagicNumber: 0x1DF
NumberOfSections: 1
CreationTime: 1700148622
OffsetToSymbolTable: 0x68
EntriesInSymbolTable: 8
AuxiliaryHeaderSize: 0
Flags: 0x0
Sections:
- Name: .text
Address: 0x0
Size: 0x18
FileOffsetToData: 0x3C
FileOffsetToRelocations: 0x54
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x2
NumberOfLineNumbers: 0x0
Flags: [ STYP_TEXT ]
SectionData: 4800000341800003480012364BFFFFE24180234A4180FF02
Relocations:
- Address: 0x0
Symbol: 0x2
Info: 0x99
Type: 0x18
- Address: 0x6
Symbol: 0x2
Info: 0x8F
Type: 0x18
Symbols:
- Name: .file
Value: 0x0
Section: N_DEBUG
Type: 0xC03
StorageClass: C_FILE
NumberOfAuxEntries: 1
- Name: .function
Value: 0x0
Section: N_UNDEF
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
- Name: ''
Value: 0x0
Section: .text
Type: 0x0
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
- Name: .main
Value: 0x0
Section: .text
Type: 0x0
StorageClass: C_EXT
NumberOfAuxEntries: 1
StringTable: {}
...

# RUN: yaml2obj %s --docnum=2 -o %t64.o
# RUN: llvm-objdump -d %t64.o | FileCheck --check-prefixes=CHECK64 %s
#

# CHECK64: : file format aix5coff64-rs6000
# CHECK64: Disassembly of section .text:
# CHECK64: 0000000000000000 <.main>:
# CHECK64-NEXT: 0: 48 00 00 03 bla 0x0
# CHECK64-NEXT: 4: 41 80 00 03 btla 0, 0x0
# CHECK64-NEXT: 8: 48 00 12 36 ba 0x1234
# CHECK64-NEXT: c: 4b ff ff e2 ba 0xffffffffffffffe0
# CHECK64-NEXT: 10: 41 80 23 4a bta 0, 0x2348
# CHECK64-NEXT: 14: 41 80 ff 02 bta 0, 0xffffffffffffff00
#
--- !XCOFF
FileHeader:
MagicNumber: 0x1F7
NumberOfSections: 1
CreationTime: 1701859282
AuxiliaryHeaderSize: 0
Flags: 0x0
Sections:
- Name: .text
Address: 0x0
Size: 0x18
FileOffsetToData: 0x60
FileOffsetToRelocations: 0x78
FileOffsetToLineNumbers: 0x0
NumberOfRelocations: 0x2
NumberOfLineNumbers: 0x0
Flags: [ STYP_TEXT ]
SectionData: 4800000341800003480012364BFFFFE24180234A4180FF02
Relocations:
- Address: 0x0
Symbol: 0x1
Info: 0x99
Type: 0x18
- Address: 0x6
Symbol: 0x1
Info: 0x8F
Type: 0x18
Symbols:
- Name: .file
Section: N_DEBUG
StorageClass: C_FILE
NumberOfAuxEntries: 0
- Name: .function
Section: N_UNDEF
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
StorageMappingClass: XMC_PR
SymbolAlignmentAndType: 0
- Name: ''
Section: .text
StorageClass: C_HIDEXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
StorageMappingClass: XMC_PR
SymbolAlignmentAndType: 1
- Name: .main
Section: .text
StorageClass: C_EXT
NumberOfAuxEntries: 1
AuxEntries:
- Type: AUX_CSECT
StorageMappingClass: XMC_PR
SymbolAlignmentAndType: 2
StringTable:
Strings:
- .file
- .function
- .text
- .main