objdump riscv: Stop disassembling addi rd, rs, 0 with a relocation as mv rd, rs?

Maciej W. Rozycki macro@embecosm.com
Tue Feb 7 14:39:25 GMT 2023


On Mon, 6 Feb 2023, Fangrui Song wrote:

> In llvm-project, https://reviews.llvm.org/D143345 brings up the topic
> whether we should keep addi rd, rs, 0 when it is associated with a
> relocation. If it does, the relocation may resolve to a non-zero and
> `mv rd, rs` may look confusing.

 I agree, I was quite amused when I came across it a while before, and I 
can imagine people may get confused.

 However it may be quite hard to implement given how the GNU disassembler 
has been structured; most easily probably by setting the `no_aliases' flag 
temporarily for any instruction seen with a relocation attached.  This 
could have undesired consequences elsewhere though and would most likely 
make Jan unhappy who wants to see aliases in disassembly rather than 
machine instruction mnemonics with the immediate forms.

 So instead we may need another flag for the opcode table, such as 
INSN_NORELOC, which would exclude the given entry for instructions with 
any relocation attached; I think this would be the cleanest approach, 
though maybe a little bit more involving implementation-wise.

 Overall I can see it as an unfortunate side effect of choosing `ADDI rd, 
rs, 0' rather than `ADD rd, rs, x0' (why?) for the canonical MV macro 
encoding.  Though of course it's the tools that have to adapt, not the 
other way round.

 FWIW,

  Maciej


More information about the Binutils mailing list