Commit 6d5e323
brianph
fix(loader): patch kfunc calls in .text subroutines, not just xdp section
Alpha.18 emits verify_ping_token and verify_session_header as #[inline(never)]
BPF subroutines, placing them in the .text section with their kfunc calls
relocated via .rel.text. The previous loader only walked .relxdp and patched
the xdp section, so kfunc calls inside .text retained src_reg=1 (BPF_PSEUDO_CALL)
with imm=-1. aya-obj's relocate_calls() then treated them as BPF-to-BPF calls
with self-referential pc-relative targets, causing:
error relocating verify_ping_token
function 0x18 not found while relocating ...
(0x18 = 24 = byte offset of the first call instruction in the function.)
Fix:
- code_relocation_tables(): new helper enumerating every code section (xdp,
.text, .text.*) and its sibling .rel<section> table. patch_elf_skip_kfuncs,
patch_elf_bpf_helpers, and patch_elf_map_fds now iterate all of them.
- patch_elf_skip_kfuncs: in addition to flipping src_reg 1->2, encodes the
kfunc index (position in RELAY_MODULE_KFUNCS) into the imm field.
- patch_kfunc_instructions: identifies each src_reg=2 call by reading imm
back as the kfunc index, instead of zipping by ELF byte offset against
positional ordering. Robust against aya inlining .text subroutines after
the xdp program (which invalidates the previous offset-sorted assumption).
- collect_kfunc_offsets: returns Vec<(section_name, offset, name)> across
all code sections for diagnostic logging.
Verified against relay_xdp_rust.o: .rel.text contains 3 bpf_relay_sha256
relocations (0x18 + 0xb0 in verify_ping_token, 0x128 in verify_session_header),
all of which are now patched. Binary builds and clippy clean for relay-xdp.
Pre-existing relay-backend warnings unrelated.1 parent c07a9d4 commit 6d5e323
2 files changed
Lines changed: 361 additions & 252 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
110 | 113 | | |
111 | 114 | | |
112 | 115 | | |
113 | | - | |
| 116 | + | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
117 | | - | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
| 159 | + | |
| 160 | + | |
157 | 161 | | |
158 | 162 | | |
159 | | - | |
| 163 | + | |
160 | 164 | | |
161 | | - | |
| 165 | + | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| |||
0 commit comments