mirror of
https://github.com/frida/tinycc
synced 2024-11-28 02:29:38 +03:00
Add __builtin_return_address.
Implementation is mostly shared with __builtin_frame_address. It seems to work on arm64, i386 and x86_64. It may need to be adapted for other targets.
This commit is contained in:
parent
8764993c0d
commit
238e760a29
14
tccgen.c
14
tccgen.c
@ -3874,13 +3874,18 @@ ST_FUNC void unary(void)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TOK_builtin_frame_address:
|
case TOK_builtin_frame_address:
|
||||||
|
case TOK_builtin_return_address:
|
||||||
{
|
{
|
||||||
|
int tok1 = tok;
|
||||||
int level;
|
int level;
|
||||||
CType type;
|
CType type;
|
||||||
next();
|
next();
|
||||||
skip('(');
|
skip('(');
|
||||||
if (tok != TOK_CINT || tokc.i < 0) {
|
if (tok != TOK_CINT || tokc.i < 0) {
|
||||||
tcc_error("__builtin_frame_address only takes positive integers");
|
tcc_error("%s only takes positive integers",
|
||||||
|
tok1 == TOK_builtin_return_address ?
|
||||||
|
"__builtin_return_address" :
|
||||||
|
"__builtin_frame_address");
|
||||||
}
|
}
|
||||||
level = tokc.i;
|
level = tokc.i;
|
||||||
next();
|
next();
|
||||||
@ -3892,6 +3897,13 @@ ST_FUNC void unary(void)
|
|||||||
mk_pointer(&vtop->type);
|
mk_pointer(&vtop->type);
|
||||||
indir(); /* -> parent frame */
|
indir(); /* -> parent frame */
|
||||||
}
|
}
|
||||||
|
if (tok1 == TOK_builtin_return_address) {
|
||||||
|
// assume return address is just above frame pointer on stack
|
||||||
|
vpushi(PTR_SIZE);
|
||||||
|
gen_op('+');
|
||||||
|
mk_pointer(&vtop->type);
|
||||||
|
indir();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
|
1
tcctok.h
1
tcctok.h
@ -130,6 +130,7 @@
|
|||||||
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
|
DEF(TOK_builtin_types_compatible_p, "__builtin_types_compatible_p")
|
||||||
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
|
DEF(TOK_builtin_constant_p, "__builtin_constant_p")
|
||||||
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
|
DEF(TOK_builtin_frame_address, "__builtin_frame_address")
|
||||||
|
DEF(TOK_builtin_return_address, "__builtin_return_address")
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
DEF(TOK_builtin_va_start, "__builtin_va_start")
|
||||||
|
Loading…
Reference in New Issue
Block a user