Closed quantrpeter closed 4 years ago
Branches and jumps are not fully assembled until link time.
Also, branch and jump arguments are not offsets in the assembler syntax. 0x12 will be interpreted as an absolute address. If you want to jump 0x12 bytes forward, put a label there and jump to the label.
On Sat, May 9, 2020 at 12:15 PM Peter notifications@github.com wrote:
hi Gas assemble jal x2,0x12 as 0000016f, i think it is wrong. May be gas is try to optimizing the output bytes, possible to turn this feature off? thanks
.section .text .globl _start _start: jal x2,0x12
a.out: file format elf64-littleriscv
Contents of section .text: 0000 6f010000 o... Contents of section .riscv.attributes: 0000 412d0000 00726973 63760001 23000000 A-...riscv..#... 0010 05727636 34693270 305f6d32 70305f61 .rv64i2p0_m2p0_a 0020 3270305f 66327030 5f643270 3000 2p0_f2p0_d2p0.
Disassembly of section .text:
0000000000000000 <_start>: 0: 0000016f jal sp,0 <_start>
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/riscv/riscv-asm-manual/issues/31, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH3XQQNJFL5QXPAOV3YTXTRQWTWLANCNFSM4M45NWWA .
thanks, your solution works
You should use -dr when disassembling object files to see the relocations. With objdump -dr I get 00000000 <_start>: 0: 0000016f jal sp,0 <_start> 0: R_RISCV_JAL ABS+0x12 The relocation gets resolved at link time to modify the branch to jump to an absolute address of 0x12.
hi Gas assemble jal x2,0x12 as 0000016f, i think it is wrong. May be gas is try to optimizing the output bytes, possible to turn this feature off? thanks