From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 69-171-232-181.mail-mxout.facebook.com (69-171-232-181.mail-mxout.facebook.com [69.171.232.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 951CF3F4829 for ; Thu, 17 Sep 2026 05:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=69.171.232.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789624703; cv=none; b=Tic3gw4sdaHf+auT3sFoD8SzFGe9JWyMPT+yqHNQI3w7nfStxFsTIO6HjPjh8jg3rCDWk2ku1eT4XdkCzAPpVDataSnIQq7QFc1aVrU8nDY8lsWJrNfO1XPnpEu841TnNeTn1yR02rN+akdKfjqS6smC1oJTiEF9mY1Q1SChP+M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789624703; c=relaxed/simple; bh=JWLjsvgmBYPsGRwQxCtTi1RqXu9bhQwRfisLcbtQGyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCdt0WrBuJCSLlGJE2+f30+3wvQ3SJazAUaQjujKl9gbgkCNo0pWMPSjYWFaNIJmurq2DJx2Kq4rhIuUO4wqrRubBTBnSU8NmqajOTJy464KwIVfKg9ayXm0BLh93kZlijbcwANZPWvUyXdD+HHWhZW9s18P3F5SDFTaTeEflJg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev; spf=fail smtp.mailfrom=linux.dev; arc=none smtp.client-ip=69.171.232.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=linux.dev Received: by devvm16039.vll0.facebook.com (Postfix, from userid 128203) id DD2792B48B28CB; Wed, 16 Sep 2026 22:58:12 -0700 (PDT) From: Yonghong Song To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Eduard Zingerman , kernel-team@fb.com Subject: [PATCH bpf-next 17/20] libbpf: Let the static linker carry .bpf_cleanup relocations Date: Wed, 16 Sep 2026 22:58:12 -0700 Message-ID: <20260917055812.3934611-1-yonghong.song@linux.dev> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260917055645.3926444-1-yonghong.song@linux.dev> References: <20260917055645.3926444-1-yonghong.song@linux.dev> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable An object that carries a compiler-emitted exception cleanup table cannot = be linked today. The table's fields are byte offsets into a code section, materialised by a 32-bit relocation against that section's symbol with th= e offset itself as the implicit addend, and the linker rejects both halves = of that: the relocation type is not in the list it accepts, and a relocation against an STT_SECTION symbol from a non-executable section is an outrigh= t error. Both spellings of that relocation have to be taken. LLVM emits R_BPF_64_NODYLD32 for a .long against a section symbol; GNU as emits R_BPF_64_ABS32, which is what bpf_reloc_type_lookup() maps BFD_RELOC_32 t= o. They describe the same value, and the selftests are built with both compilers. Signed-off-by: Yonghong Song --- tools/lib/bpf/linker.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 78f92c39290a..e5c06023cb5b 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -1036,7 +1036,8 @@ static int linker_sanity_check_elf_relos(struct src= _obj *obj, struct src_sec *se size_t sym_type =3D ELF64_R_TYPE(relo->r_info); =20 if (sym_type !=3D R_BPF_64_64 && sym_type !=3D R_BPF_64_32 && - sym_type !=3D R_BPF_64_ABS64 && sym_type !=3D R_BPF_64_ABS32) { + sym_type !=3D R_BPF_64_ABS64 && sym_type !=3D R_BPF_64_ABS32 && + sym_type !=3D R_BPF_64_NODYLD32) { pr_warn("ELF relo #%d in section #%zu has unexpected type %zu in %s\n= ", i, sec->sec_idx, sym_type, obj->filename); return -EINVAL; @@ -2274,6 +2275,22 @@ static int linker_append_elf_relos(struct bpf_link= er *linker, struct src_obj *ob insn->imm +=3D sec->dst_off / sizeof(struct bpf_insn); else insn->imm +=3D sec->dst_off; + } else if (sym_type =3D=3D R_BPF_64_NODYLD32 || + sym_type =3D=3D R_BPF_64_ABS32) { + __u32 *val; + + /* Two spellings of the one thing: LLVM + * emits NODYLD32 for a .long against a + * section symbol, GNU as emits ABS32 + * (bpf_reloc_type_lookup() maps + * BFD_RELOC_32 to it), and the value + * they describe is the same. + */ + val =3D dst_linked_sec->raw_data + dst_rel->r_offset; + if (linker->swapped_endian) + *val =3D bswap_32(bswap_32(*val) + sec->dst_off); + else + *val +=3D sec->dst_off; } else { pr_warn("relocation against STT_SECTION in non-exec section is not = supported!\n"); return -EINVAL; --=20 2.53.0-Meta