Changing the code to something like this
void f(void) __attribute__((__weak__));
void _start(void)
{
void (*g)(void) = f;
if (g != 0) {
(*g)();
}
}
doesn't work either, since this is optimized to
.option nopic
.text
.align 1
.globl _start
.type _start, @function
_start:
lla a5,f
beqz a5,.L1
tail f
.L1:
ret
.size _start, .-_start
.weak f
Why doesn't the RISC-V generate a trampoline code to call far functions?
The non-optimized example code with "tail f" replaced by "jalr a5" links
well:
.option nopic
.text
.align 1
.globl _start
.type _start, @function
_start:
addi sp,sp,-32
sd ra,24(sp)
sd s0,16(sp)
addi s0,sp,32
lla a5,f
sd a5,-24(s0)
ld a5,-24(s0)
beqz a5,.L3
ld a5,-24(s0)
jalr a5
.L3:
nop
ld ra,24(sp)
ld s0,16(sp)
addi sp,sp,32
jr ra
.size _start, .-_start
.weak f
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.