-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AArch64 first argument passing problem #781
Comments
@namhyung Could you please explain the problem and how to avoid it? |
It's to pass the address of parent function to |
It may not be guaranteed but it seems that
We have to determine the address of |
The encoding of
It will be interpreted as The bit-masking for this is Reference: https://static.docs.arm.com/ddi0596/a/DDI_0596_ARM_a64_instruction_set_architecture.pdf |
It's aarch64 $ cat gcc/config/aarch64/aarch64.h
...
#define MCOUNT_NAME "_mcount"
#define NO_PROFILE_COUNTERS 1
/* Emit rtl for profiling. Output assembler code to FILE
to call "_mcount" for profiling a function entry. */
#define PROFILE_HOOK(LABEL) \
{ \
rtx fun, lr; \
lr = get_hard_reg_initial_val (Pmode, LR_REGNUM); \
fun = gen_rtx_SYMBOL_REF (Pmode, MCOUNT_NAME); \
emit_library_call (fun, LCT_NORMAL, VOIDmode, lr, Pmode); \
}
/* All the work done in PROFILE_HOOK, but still required. */
#define FUNCTION_PROFILER(STREAM, LABELNO) do { } while (0)
... $ cat gcc/function.c
...
/*
`expand_function_start' is called at the beginning of a function,
before the function body is parsed, and `expand_function_end' is
called after parsing the body.
*/
...
void expand_function_start (tree subr)
{
...
if (crtl->profile)
{
#ifdef PROFILE_HOOK
PROFILE_HOOK (current_function_funcdef_no);
#endif
}
...
}
... $ cat gcc/cfgexpand.c
...
unsigned int
pass_expand::execute (function *fun)
{
...
/* Set up parameters and prepare for return, for the function. */
expand_function_start (current_function_decl);
...
}
... |
There is another case that 00000000009308b0 <node::Init(...)>:
9308b0: a9b37bfd stp x29, x30, [sp,#-208]!
9308b4: 910003fd mov x29, sp
9308b8: a90153f3 stp x19, x20, [sp,#16]
9308bc: a9025bf5 stp x21, x22, [sp,#32]
9308c0: a90363f7 stp x23, x24, [sp,#48]
9308c4: a9046bf9 stp x25, x26, [sp,#64]
9308c8: a90573fb stp x27, x28, [sp,#80]
9308cc: aa0003f8 mov x24, x0
9308d0: aa1e03e0 mov x0, x30
9308d4: aa0103f9 mov x25, x1
9308d8: b000bf56 adrp x22, 2119000 <v8::platform::tracing::g_category_groups+0x510>
9308dc: d000bf55 adrp x21, 211a000 <node::Environment::set_debug_categories(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)::available_category+0x18>
9308e0: 97fed818 bl 8e6940 <_mcount@plt>
9308e4: 9111e2b3 add x19, x21, #0x478
... In this case, the original |
maybe we can use callee-saved register instead use parameter registers. https://developer.arm.com/documentation/102374/0101/Procedure-Call-Standard risc-v & arm64 results instructions generated like this: mov w20, w1
mov w21, w2
mov w22, w3
mov w19, w0
mov x0, x30
bl _mcount but it is depends on opt level. when you put 0 in str w0, [sp, 28]
str w1, [sp, 24]
str w2, [sp, 20]
str w3, [sp, 16]
mov x30, x4
hint 7 // xpaclri
mov x0, x30
bl _mcount so, I think it require tricky tweak for that. |
@ParkHanbum Your explanation doesn’t look clear to me but yes, there is no problem accessing the first argument in dynamic tracing. |
GNU gprof requires two arguments (
It depends on CPU/psABI how to pass those arguments. IIRC x86 can pass them on stack, but AArch64 uses LR for |
As I wrote in #777 #778, there is a problem passing the first argument in AArch64.
The test result of running fibonacci example in both x86_64 and aarch64 is as follows.
1. x86_64
2. aarch64
It shows the arguments incorrectly unlike x86_64.
I just compiled and dumped for both original
s-fibonacci.c
and its-pg
compiled version as follows:For better comparison, I just modified some offset labels in
s-fibonacci.o.asm
and its diff result is as follows:I'm not sure why
x0
is overwritten by other registers in both functions.The text was updated successfully, but these errors were encountered: