https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98896
--- Comment #6 from Stas Sergeev <stsp at users dot sourceforge.net> ---
(In reply to Jakub Jelinek from comment #5)
> I think Andrew meant asm goto, which you haven't tried.
You are right.
Thanks for mentioning that.
But it doesn't work as well:
---
int main(void)
{
__label__ cont;
asm volatile goto (
"push %l[cont]\n"
"ret\n"
::::cont);
cont:
return 0;
}
---
$ LC_ALL=C cc -Wall -ggdb3 -O2 -o jmpret2 jmpret2.c -pie -fPIE
/usr/bin/ld: /tmp/cc1UoxnD.o: relocation R_X86_64_32S against `.text.startup'
can not be used when making a PIE object; recompile with -fPIE
And in an asm file we see:
---
#APP
# 4 "jmpret2.c" 1
push .L2 #
ret
---
Please compare this to the following:
---
int main(void)
{
__label__ cont;
asm volatile (
"push %0\n"
"ret\n"
::"r"(&&cont));
cont:
return 0;
}
---
And its asm:
---
.L2:
.loc 1 4 5 view .LVU1
leaq .L2(%rip), %rax #, tmp83
#APP
# 4 "jmpret3.c" 1
push %rax # tmp83
ret
---
So... it seems, only the second case can work,
and indeed does with clang?