Skip to content

Commit 3bcbecf

Browse files
committed
[luajit] Fix G-finding heuristic on aarch64 (#236)
I can't figure out why at some point we thought that r7 holds the dispatch table on ARM, but as far as I can tell, that's not the case. What is, however, the case, is that r22 holds G; see here: https://github.com/LuaJIT/LuaJIT/blob/659a61693aa3b87661864ad0f12eee14c865cd7f/src/lj_target_arm64.h#L41 And this is the register we load `g` from, e.g. when entering `lj_gc_step_jit`.
1 parent 9592cfa commit 3bcbecf

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

support/ebpf/luajit_tracer.ebpf.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ struct luajit_procs_t {
2727
// The number of LuaJIT frames to unwind per frame-unwinding eBPF program.
2828
#define FRAMES_PER_WALK_LUAJIT_STACK 15
2929

30-
#if defined(__x86_64__)
31-
#define DISPATCH r14
32-
#elif defined(__aarch64__)
33-
#define DISPATCH r7
34-
#endif
35-
3630
// Non error checking bpf read, used sparingly for reading sections of the stack after
3731
// we've established we can read neighboring memory.
3832
#define deref(o) \
@@ -517,7 +511,11 @@ find_context(struct pt_regs *ctx, PerCPURecord *record, const LuaJITProcInfo *in
517511
// but once we propagate G to the HA text_section_bias will be set to the G pointer and we can
518512
// pull cur_L from that. So this is just a bootstrap crutch that just has to work once (or
519513
// never because G also gets picked up from interpreter hits).
520-
G_ptr = (char *)state->DISPATCH - info->g2dispatch;
514+
#if defined(__x86_64__)
515+
G_ptr = (char *)state->r14 - info->g2dispatch;
516+
#elif defined(__aarch64__)
517+
G_ptr = (char *)state->r22;
518+
#endif
521519
reportG = true;
522520
} else {
523521
G_ptr = (void *)state->text_section_bias;

support/ebpf/tracer.ebpf.amd64

-8 Bytes
Binary file not shown.

support/ebpf/tracer.ebpf.arm64

-152 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)