I'm learning RISCV(64) and implementing a simulator. I compile the following simple code and disassemble the generated elf with riscv64-unknown-linux-gnu-objdump
. I have two problems totally.
int main() {
return 0;
}
- If I use
riscv64-unknown-linux-gnu-objdump -d ./xxx.elf
, the asm codes are like this.
Disassembly of section .text:
0000000080000000 <_start>:
80000000: 00000413 li s0,0
80000004: 00009117 auipc sp,0x9
80000008: ffc10113 add sp,sp,-4 # 80009000 <_end>
8000000c: 00c000ef jal 80000018 <_trm_init>
0000000080000010 <main>:
80000010: 00000513 li a0,0
80000014: 00008067 ret
0000000080000018 <_trm_init>:
80000018: ff010113 add sp,sp,-16
8000001c: 00000517 auipc a0,0x0
80000020: 01c50513 add a0,a0,28 # 80000038 <_etext>
80000024: 00113423 sd ra,8(sp)
80000028: fe9ff0ef jal 80000010 <main>
8000002c: 00050513 mv a0,a0
80000030: 00100073 ebreak
80000034: 0000006f j 80000034 <_trm_init+0x1c>
If -M no-aliases
option is added, the asm codes are like this.
Disassembly of section .text:
0000000080000000 <_start>:
80000000: 00000413 addi s0,zero,0
80000004: 00009117 auipc sp,0x9
80000008: ffc10113 addi sp,sp,-4 # 80009000 <_end>
8000000c: 00c000ef jal ra,80000018 <_trm_init>
0000000080000010 <main>:
80000010: 00000513 addi a0,zero,0
80000014: 00008067 jalr zero,0(ra)
0000000080000018 <_trm_init>:
80000018: ff010113 addi sp,sp,-16
8000001c: 00000517 auipc a0,0x0
80000020: 01c50513 addi a0,a0,28 # 80000038 <_etext>
80000024: 00113423 sd ra,8(sp)
80000028: fe9ff0ef jal ra,80000010 <main>
8000002c: 00050513 addi a0,a0,0
80000030: 00100073 ebreak
80000034: 0000006f jal zero,80000034 <_trm_init+0x1c>
Therefore, addi
and add
are all disassembled as add
instruction. From the RISCV spec, I know li
, j
, ret
, mv
these are pseudo-instructions. But addi
and add
are all real instrucions, why are they all translated into add
? Is alias-instruction
different with pseudo-instruction
? Is there a standard manual about this alias-instruction
? Even if it is tool-related, I want to see the accurate statements.
- See the second piece of asm codes above, the
immediate address offset of jal instrcution
(like jal ra,80000018) isabsolute address
rather thanpc-relative address
. So How to make riscv-objdump use pc-relative address rather than absolute address?
My Environment:
Machine:
x86_64
OS:
Ubuntu 22.04(VMWare Virtual Machine)
riscv64-unknown-linux-gnu-objdump -v
: GNU objdump (GNU Binutils) 2.40.0.20230214
Thanks in advance!