0

I use tail pseudoinstruction to call an external function, and the function is in the range of jalr instruction. But two instructions auipc and jr are generated from this with GCC version 10.2.1. Won't linker relaxation feature replace these two instructions by jr itself? By the way, call pseudoinstruction will be replaced by a single jalr instruction.

My source code:

tail main

Generated instructions from disassembly

174           tail main    
000000a2:   auipc   t1,0x0
000000a6:   jr      886(t1) # 0x418 <main>
Wanghz
  • 305
  • 2
  • 12
  • Try to read this https://stackoverflow.com/questions/310974/what-is-tail-call-optimization. According to ISA manual, `tail` is a pseudoinstruction that convert into `auipc` + `jr`. – Alexy Khilaev Nov 01 '21 at 11:01
  • @АлексейХилаев I don't think the post you mentioned is the same question as mine. It explained what's the tail call optimization, not the linker relaxation in RISC-V. From RISC-V ISA manual, yes, `tail` will be converted into `auipc` + `jr`. But I think that's before linker relaxation. Just like `call` will be converted to `auipc` + `jalr` from ISA manual, but actually it will be relaxed to a single `jalr` if the target symbol is in the range of it. – Wanghz Nov 02 '21 at 01:56

0 Answers0