From: Xu Kuohai The follow up patch introduces bpf SDT probe macros that emit per-probe metadata into a new data section named .bpf_sdt_notes. Each entry begins with a ___sdt_jt_* symbol and contains an R_BPF_64_ABS64 relocation referencing the probe site address in the bpf prog. Prepare the linker for this by treating .bpf_sdt_notes like .jumptables. Bypass the section-type check when appending ___sdt_jt_* symbols so they can survive from linking, and relocate to real address inside each entry. Signed-off-by: Xu Kuohai --- tools/lib/bpf/libbpf_internal.h | 1 + tools/lib/bpf/linker.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h index 04cd303fb5a8..ed7a587a61ca 100644 --- a/tools/lib/bpf/libbpf_internal.h +++ b/tools/lib/bpf/libbpf_internal.h @@ -75,6 +75,7 @@ #endif #define JUMPTABLES_SEC ".jumptables" +#define SDT_NOTES_SEC ".bpf_sdt_notes" #define BTF_INFO_ENC(kind, kind_flag, vlen) \ ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN)) diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 78f92c39290a..3a72276244c7 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -2028,6 +2028,8 @@ static int linker_append_elf_sym(struct bpf_linker *linker, struct src_obj *obj, if (strcmp(src_sec->sec_name, JUMPTABLES_SEC) == 0) goto add_sym; + if (strcmp(src_sec->sec_name, SDT_NOTES_SEC) == 0) + goto add_sym; } if (sym_bind == STB_LOCAL) @@ -2274,6 +2276,13 @@ static int linker_append_elf_relos(struct bpf_linker *linker, struct src_obj *ob insn->imm += sec->dst_off / sizeof(struct bpf_insn); else insn->imm += sec->dst_off; + } else if (strcmp(src_linked_sec->sec_name, SDT_NOTES_SEC) == 0) { + /* .bpf_sdt_notes contains R_BPF_64_ABS64 relocations + * referencing code section symbols. Adjust the 64-bit + * address by dst_off. + */ + __u64 *addr = dst_linked_sec->raw_data + dst_rel->r_offset; + *addr += sec->dst_off; } else { pr_warn("relocation against STT_SECTION in non-exec section is not supported!\n"); return -EINVAL; -- 2.47.3