[lld] bb1e3df - SparcInstPrinter: Support llvm-objdump --print-imm-hex
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat May 3 16:57:57 PDT 2025
Author: Fangrui Song
Date: 2025-05-03T16:57:52-07:00
New Revision: bb1e3df7009af1bf4b60e1ff4ddb5b7f94d6bff9
URL: https://github.com/llvm/llvm-project/commit/bb1e3df7009af1bf4b60e1ff4ddb5b7f94d6bff9
DIFF: https://github.com/llvm/llvm-project/commit/bb1e3df7009af1bf4b60e1ff4ddb5b7f94d6bff9.diff
LOG: SparcInstPrinter: Support llvm-objdump --print-imm-hex
... to align with other targets, e.g., https://reviews.llvm.org/D77853
(AArch64) and https://reviews.llvm.org/D83634 (AVR).
binutils's sparc port uses %d when imm<=9, diverging from other ports.
We do not follow the binutils sparc port behavior.
Added:
Modified:
lld/test/ELF/sparcv9-reloc.s
lld/test/ELF/sparcv9-tls-le.s
llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp
llvm/test/MC/Sparc/sparc-assembly-exprs.s
llvm/test/MC/Sparc/sparc-fixups.s
llvm/test/MC/Sparc/sparc-little-endian.s
llvm/test/MC/Sparc/sparc-tls-relocations.s
llvm/test/MC/Sparc/sparc64-bpr-offset.s
Removed:
################################################################################
diff --git a/lld/test/ELF/sparcv9-reloc.s b/lld/test/ELF/sparcv9-reloc.s
index ec9abd6dc3bb5..2b1d133252527 100644
--- a/lld/test/ELF/sparcv9-reloc.s
+++ b/lld/test/ELF/sparcv9-reloc.s
@@ -1,7 +1,7 @@
# REQUIRES: sparc
# RUN: llvm-mc -filetype=obj -triple=sparcv9 %s -o %t.o
# RUN: ld.lld %t.o --defsym=a=0x0123456789ABCDEF --defsym=b=0x0123456789A --defsym=c=0x01234567 -o %t
-# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
+# RUN: llvm-objdump -d --no-show-raw-insn --no-print-imm-hex %t | FileCheck %s
# RUN: llvm-objdump -s %t | FileCheck --check-prefix=HEX %s
## R_SPARC_HH22, R_SPARC_HM10
diff --git a/lld/test/ELF/sparcv9-tls-le.s b/lld/test/ELF/sparcv9-tls-le.s
index 2d4fec9ccc8d8..731d954cea9ad 100644
--- a/lld/test/ELF/sparcv9-tls-le.s
+++ b/lld/test/ELF/sparcv9-tls-le.s
@@ -5,8 +5,8 @@
## %hix(@tpoff(a)) = ~(st_value(a) - 1026) >> 10 = 1
## %lo(@tpoff(a)) = (st_value(a) - 1026) & 0x3ff | 0x1c00 = -2 (0x1ffe)
-# LE: sethi 1, %o0
-# LE-NEXT: xor %o0, -2, %o0
+# LE: sethi 0x1, %o0
+# LE-NEXT: xor %o0, -0x2, %o0
sethi %tle_hix22(a), %o0
xor %o0, %tle_lox10(a), %o0
diff --git a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp
index f2a61c95fefb5..ed52e0c5714e8 100644
--- a/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp
+++ b/llvm/lib/Target/Sparc/MCTargetDesc/SparcInstPrinter.cpp
@@ -126,7 +126,7 @@ void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
if (MO.isImm()) {
switch (MI->getOpcode()) {
default:
- O << (int)MO.getImm();
+ markup(O, Markup::Immediate) << formatImm(int32_t(MO.getImm()));
return;
case SP::TICCri: // Fall through
diff --git a/llvm/test/MC/Sparc/sparc-assembly-exprs.s b/llvm/test/MC/Sparc/sparc-assembly-exprs.s
index e2b877ac93e5b..c69199ffe72f5 100644
--- a/llvm/test/MC/Sparc/sparc-assembly-exprs.s
+++ b/llvm/test/MC/Sparc/sparc-assembly-exprs.s
@@ -1,4 +1,4 @@
-! RUN: llvm-mc %s -triple=sparc -show-encoding | FileCheck %s
+! RUN: llvm-mc %s -triple=sparc -show-encoding | FileCheck %s
! RUN: llvm-mc %s -triple=sparc -filetype=obj | llvm-objdump -r -d - | FileCheck %s --check-prefix=OBJDUMP
! CHECK: mov 1033, %o1 ! encoding: [0x92,0x10,0x24,0x09]
@@ -7,12 +7,12 @@
mov ((12+3)<<2), %o2
! CHECK: ba symStart+4 ! encoding: [0x10,0b10AAAAAA,A,A]
- ! OBJDUMP: ba 1
+ ! OBJDUMP: ba 0x1
symStart:
b symStart + 4
! CHECK: mov symEnd-symStart, %g1 ! encoding: [0x82,0x10,0b001AAAAA,A]
- ! OBJDUMP: mov 24, %g1
+ ! OBJDUMP: mov 0x18, %g1
mov symEnd - symStart, %g1
! CHECK: sethi %hi(sym+10), %g2 ! encoding: [0x05,0b00AAAAAA,A,A]
diff --git a/llvm/test/MC/Sparc/sparc-fixups.s b/llvm/test/MC/Sparc/sparc-fixups.s
index 5f5bf6a330392..18224d699fe28 100644
--- a/llvm/test/MC/Sparc/sparc-fixups.s
+++ b/llvm/test/MC/Sparc/sparc-fixups.s
@@ -5,26 +5,30 @@
.set sym, 0xfedcba98
-! CHECK: sethi 4175662, %o0
+! CHECK: sethi 0x3fb72e, %o0
+! CHECK-NEXT: xor %o0, 0x298, %o0
+! CHECK-NEXT: sethi 0x3b72ea, %o1
+! CHECK-NEXT: xor %o0, 0x188, %o1
sethi %hi(sym), %o0
-! CHECK: xor %o0, 664, %o0
xor %o0, %lo(sym), %o0
+sethi %hi(-0x12345678), %o1
+xor %o0, %lo(-0x12345678), %o1
-! CHECK: sethi 1019, %o0
+! CHECK: sethi 0x3fb, %o0
+! CHECK-NEXT: or %o0, 0x1cb, %o0
+! CHECK-NEXT: ld [%o0+0xa98], %o0
sethi %h44(sym), %o0
-! CHECK: or %o0, 459, %o0
or %o0, %m44(sym), %o0
-! CHECK: ld [%o0+2712], %o0
ld [%o0 + %l44(sym)], %o0
-! CHECK: sethi 0, %o0
+! CHECK: sethi 0x0, %o0
+! CHECK-NEXT: sethi 0x3fb72e, %o0
+! CHECK-NEXT: or %o0, 0x0, %o0
sethi %hh(sym), %o0
-! CHECK: sethi 4175662, %o0
sethi %lm(sym), %o0
-! CHECK: or %o0, 0, %o0
or %o0, %hm(sym), %o0
-! CHECK: sethi 18641, %o0
+! CHECK: sethi 0x48d1, %o0
+! CHECK-NEXT: xor %o0, -0x168, %o0
sethi %hix(sym), %o0
-! CHECK: xor %o0, -360, %o0
xor %o0, %lox(sym), %o0
diff --git a/llvm/test/MC/Sparc/sparc-little-endian.s b/llvm/test/MC/Sparc/sparc-little-endian.s
index b0f650bfef9e7..d02dfd40d195b 100644
--- a/llvm/test/MC/Sparc/sparc-little-endian.s
+++ b/llvm/test/MC/Sparc/sparc-little-endian.s
@@ -13,5 +13,5 @@
! ...and that fixups are applied to the correct bytes.
! CHECK: ba .BB0 ! encoding: [A,A,0b10AAAAAA,0x10]
- ! CHECK-OBJ: 4: ff ff bf 10 ba 4194303
+ ! CHECK-OBJ: 4: ff ff bf 10 ba 0x3fffff
ba .BB0
diff --git a/llvm/test/MC/Sparc/sparc-tls-relocations.s b/llvm/test/MC/Sparc/sparc-tls-relocations.s
index 8dc6e62baef5e..94f2148ceffd4 100644
--- a/llvm/test/MC/Sparc/sparc-tls-relocations.s
+++ b/llvm/test/MC/Sparc/sparc-tls-relocations.s
@@ -28,12 +28,12 @@ foo:
! Sequence for Local Executable model:
! LE_HIX22/LE_LOX10
-! OBJDUMP: {{[0-9,a-f]+}}: 31 00 00 00 sethi 0, %i0
+! OBJDUMP: {{[0-9,a-f]+}}: 31 00 00 00 sethi 0x0, %i0
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_HIX22 Local
! ASM: sethi %tle_hix22(Local), %i0 ! encoding: [0x31,0x00,0x00,0x00]
sethi %tle_hix22(Local), %i0
-! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 20 00 xor %i0, 0, %i0
+! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 20 00 xor %i0, 0x0, %i0
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LE_LOX10 Local
! ASM: xor %i0, %tle_lox10(Local), %i0 ! encoding: [0xb0,0x1e,0x20,0x00]
xor %i0, %tle_lox10(Local), %i0
@@ -43,17 +43,17 @@ foo:
! Local Dynamic model:
! LDO_HIX22/LDO_LOX10/LDO_ADD/LDM_HI22/LDM_LO10/LDM_ADD/LDM_CALL
-! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
+! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_HIX22 Local
! ASM: sethi %tldo_hix22(Local), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
sethi %tldo_hix22(Local), %i1
-! OBJDUMP: {{[0-9,a-f]+}}: 35 00 00 00 sethi 0, %i2
+! OBJDUMP: {{[0-9,a-f]+}}: 35 00 00 00 sethi 0x0, %i2
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_HI22 Local
! ASM: sethi %tldm_hi22(Local), %i2 ! encoding: [0x35,0b00AAAAAA,A,A]
sethi %tldm_hi22(Local), %i2
-! OBJDUMP: {{[0-9,a-f]+}}: b4 06 a0 00 add %i2, 0, %i2
+! OBJDUMP: {{[0-9,a-f]+}}: b4 06 a0 00 add %i2, 0x0, %i2
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDM_LO10 Local
! ASM: add %i2, %tldm_lo10(Local), %i2 ! encoding: [0xb4,0x06,0b101000AA,A]
add %i2, %tldm_lo10(Local), %i2
@@ -63,7 +63,7 @@ foo:
! ASM: add %i0, %i2, %o0, %tldm_add(Local) ! encoding: [0x90,0x06,0x00,0x1a]
add %i0, %i2, %o0, %tldm_add(Local)
-! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 60 00 xor %i1, 0, %i0
+! OBJDUMP: {{[0-9,a-f]+}}: b0 1e 60 00 xor %i1, 0x0, %i0
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_LDO_LOX10 Local
! ASM: xor %i1, %tldo_lox10(Local), %i0 ! encoding: [0xb0,0x1e,0b011000AA,A]
xor %i1, %tldo_lox10(Local), %i0
@@ -83,12 +83,12 @@ foo:
! Initial Executable model:
! IE_HI22/IE_LO10/IE_LD (or IE_LDX)/IE_ADD
-! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
+! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_IE_HI22 Extern
! ASM: sethi %tie_hi22(Extern), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
sethi %tie_hi22(Extern), %i1
-! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0, %i1
+! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0x0, %i1
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_IE_LO10 Extern
! ASM: add %i1, %tie_lo10(Extern), %i1 ! encoding: [0xb2,0x06,0b011000AA,A]
add %i1, %tie_lo10(Extern), %i1
@@ -111,12 +111,12 @@ foo:
! General Dynamic model
! GD_HI22/GD_LO10/GD_ADD/GD_CALL
-! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0, %i1
+! OBJDUMP: {{[0-9,a-f]+}}: 33 00 00 00 sethi 0x0, %i1
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_GD_HI22 Extern
! ASM: sethi %tgd_hi22(Extern), %i1 ! encoding: [0x33,0b00AAAAAA,A,A]
sethi %tgd_hi22(Extern), %i1
-! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0, %i1
+! OBJDUMP: {{[0-9,a-f]+}}: b2 06 60 00 add %i1, 0x0, %i1
! OBJDUMP: {{[0-9,a-f]+}}: R_SPARC_TLS_GD_LO10 Extern
! ASM: add %i1, %tgd_lo10(Extern), %i1 ! encoding: [0xb2,0x06,0b011000AA,A]
add %i1, %tgd_lo10(Extern), %i1
diff --git a/llvm/test/MC/Sparc/sparc64-bpr-offset.s b/llvm/test/MC/Sparc/sparc64-bpr-offset.s
index c9d3821dea3e4..37453567924f3 100644
--- a/llvm/test/MC/Sparc/sparc64-bpr-offset.s
+++ b/llvm/test/MC/Sparc/sparc64-bpr-offset.s
@@ -1,4 +1,4 @@
-! RUN: llvm-mc -triple=sparcv9 -filetype=obj %s | llvm-objdump -d - | FileCheck %s --check-prefix=BIN
+! RUN: llvm-mc -triple=sparcv9 -filetype=obj %s | llvm-objdump -d --no-print-imm-hex - | FileCheck %s --check-prefix=BIN
!! SPARCv9/SPARC64 BPr branches have
diff erent offset encoding from the others,
!! make sure that our offset bits don't trample on other fields.
More information about the llvm-commits
mailing list