diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst --- a/llvm/docs/CommandGuide/llvm-objdump.rst +++ b/llvm/docs/CommandGuide/llvm-objdump.rst @@ -226,7 +226,7 @@ When printing a PC-relative global symbol reference, print it as an offset from the leading symbol. - Only works with PowerPC objects or X86 linked images. + Only works with PowerPC or RISC-V objects or X86 linked images. Example: A non-symbolized branch instruction with a local target and pc-relative memory access like diff --git a/llvm/test/tools/llvm-objdump/ELF/RISCV/branches.s b/llvm/test/tools/llvm-objdump/ELF/RISCV/branches.s --- a/llvm/test/tools/llvm-objdump/ELF/RISCV/branches.s +++ b/llvm/test/tools/llvm-objdump/ELF/RISCV/branches.s @@ -1,80 +1,94 @@ -# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s \ -# RUN: | llvm-objdump -d -M no-aliases --no-show-raw-insn - \ -# RUN: | FileCheck --match-full-lines %s +# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c < %s -o %t +# RUN: llvm-objdump %t -d -M no-aliases --no-show-raw-insn \ +# RUN: | FileCheck -check-prefixes=CHECK-NOSYMBOLIZE,CHECK-COMMON --match-full-lines %s +# RUN: llvm-objdump %t -d -M no-aliases --no-show-raw-insn --symbolize-operands \ +# RUN: | FileCheck -check-prefixes=CHECK-SYMBOLIZE,CHECK-COMMON --match-full-lines %s -# CHECK: 00000000 : +# CHECK-COMMON: 00000000 : foo: -# CHECK: 0: beq t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: 0: beq t0, t1, 0x58 +# CHECK-SYMBOLIZE: 0: beq t0, t1, 0x58 beq t0, t1, .Llocal -# CHECK: 4: bne t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: 4: bne t0, t1, 0x58 +# CHECK-SYMBOLIZE: 4: bne t0, t1, 0x58 bne t0, t1, .Llocal -# CHECK: 8: blt t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: 8: blt t0, t1, 0x58 +# CHECK-SYMBOLIZE: 8: blt t0, t1, 0x58 blt t0, t1, .Llocal -# CHECK: c: bge t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: c: bge t0, t1, 0x58 +# CHECK-SYMBOLIZE: c: bge t0, t1, 0x58 bge t0, t1, .Llocal -# CHECK: 10: bltu t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: 10: bltu t0, t1, 0x58 +# CHECK-SYMBOLIZE: 10: bltu t0, t1, 0x58 bltu t0, t1, .Llocal -# CHECK: 14: bgeu t0, t1, 0x58 +# CHECK-NOSYMBOLIZE: 14: bgeu t0, t1, 0x58 +# CHECK-SYMBOLIZE: 14: bgeu t0, t1, 0x58 bgeu t0, t1, .Llocal -# CHECK: 18: c.beqz a0, 0x58 +# CHECK-NOSYMBOLIZE: 18: c.beqz a0, 0x58 +# CHECK-SYMBOLIZE: 18: c.beqz a0, 0x58 beq a0, zero, .Llocal -# CHECK: 1a: c.bnez a0, 0x58 +# CHECK-NOSYMBOLIZE: 1a: c.bnez a0, 0x58 +# CHECK-SYMBOLIZE: 1a: c.bnez a0, 0x58 bne a0, zero, .Llocal -# CHECK: 1c: beq t0, t1, 0x60 +# CHECK-COMMON: 1c: beq t0, t1, 0x60 beq t0, t1, bar -# CHECK: 20: bne t0, t1, 0x60 +# CHECK-COMMON: 20: bne t0, t1, 0x60 bne t0, t1, bar -# CHECK: 24: blt t0, t1, 0x60 +# CHECK-COMMON: 24: blt t0, t1, 0x60 blt t0, t1, bar -# CHECK: 28: bge t0, t1, 0x60 +# CHECK-COMMON: 28: bge t0, t1, 0x60 bge t0, t1, bar -# CHECK: 2c: bltu t0, t1, 0x60 +# CHECK-COMMON: 2c: bltu t0, t1, 0x60 bltu t0, t1, bar -# CHECK: 30: bgeu t0, t1, 0x60 +# CHECK-COMMON: 30: bgeu t0, t1, 0x60 bgeu t0, t1, bar -# CHECK: 34: c.beqz a0, 0x60 +# CHECK-COMMON: 34: c.beqz a0, 0x60 beq a0, zero, bar -# CHECK: 36: c.bnez a0, 0x60 +# CHECK-COMMON: 36: c.bnez a0, 0x60 bne a0, zero, bar -# CHECK: 38: jal t0, 0x58 +# CHECK-NOSYMBOLIZE: 38: jal t0, 0x58 +# CHECK-SYMBOLIZE: 38: jal t0, 0x58 jal t0, .Llocal -# CHECK: 3c: c.jal 0x58 +# CHECK-NOSYMBOLIZE: 3c: c.jal 0x58 +# CHECK-SYMBOLIZE: 3c: c.jal 0x58 c.jal .Llocal -# CHECK: 3e: c.j 0x58 +# CHECK-NOSYMBOLIZE: 3e: c.j 0x58 +# CHECK-SYMBOLIZE: 3e: c.j 0x58 c.j .Llocal -# CHECK: 40: jal t0, 0x60 +# CHECK-COMMON: 40: jal t0, 0x60 jal t0, bar -# CHECK: 44: c.jal 0x60 +# CHECK-COMMON: 44: c.jal 0x60 c.jal bar -# CHECK: 46: c.j 0x60 +# CHECK-COMMON: 46: c.j 0x60 c.j bar -# CHECK: 48: auipc ra, 0 -# CHECK: 4c: jalr ra, 16(ra) +# CHECK-COMMON: 48: auipc ra, 0 +# CHECK-NOSYMBOLIZE: 4c: jalr ra, 16(ra) +# CHECK-SYMBOLIZE: 4c: jalr ra, 16(ra) call .Llocal -# CHECK: 50: auipc ra, 0 -# CHECK: 54: jalr ra, 16(ra) +# CHECK-COMMON: 50: auipc ra, 0 +# CHECK-COMMON: 54: jalr ra, 16(ra) call bar .Llocal: -# CHECK: 58: c.nop -# CHECK: 5a: c.nop -# CHECK: 5c: c.nop -# CHECK: 5e: c.nop +# CHECK-COMMON: 58: c.nop +# CHECK-COMMON: 5a: c.nop +# CHECK-COMMON: 5c: c.nop +# CHECK-COMMON: 5e: c.nop nop nop nop nop -# CHECK: 00000060 : +# CHECK-COMMON: 00000060 : bar: -# CHECK: 60: c.nop +# CHECK-COMMON: 60: c.nop nop diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -978,8 +978,9 @@ const MCSubtargetInfo *STI, uint64_t SectionAddr, uint64_t Start, uint64_t End, std::unordered_map &Labels) { - // So far only supports PowerPC and X86. - if (!STI->getTargetTriple().isPPC() && !STI->getTargetTriple().isX86()) + // So far only supports PowerPC, RISC-V, and X86. + if (!STI->getTargetTriple().isPPC() && !STI->getTargetTriple().isRISCV() && + !STI->getTargetTriple().isX86()) return; Labels.clear();