From 9be9af7a9f528ae5df1b8efbc6efe763509d0d06 Mon Sep 17 00:00:00 2001 From: "Shang-Wen Wang (Sam Wang)" Date: Mon, 2 May 2022 16:35:03 -0400 Subject: [PATCH] fix: support bpf_core_type_exists() In the previous version, when no target is found in BTF, coreCalculateFixups() will mark its relocation as poison and cause failure when verified by Linux verifier. This issue is fixed by using right fixup for "checksForExistence" type of relocations. Signed-off-by: Shang-Wen Wang (Sam Wang) --- internal/btf/core.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/btf/core.go b/internal/btf/core.go index 417f1e8ff..86bab5c6a 100644 --- a/internal/btf/core.go +++ b/internal/btf/core.go @@ -313,10 +313,16 @@ func coreCalculateFixups(byteOrder binary.ByteOrder, local Type, targets []Type, if bestFixups == nil { // Nothing at all matched, probably because there are no suitable - // targets at all. Poison everything! + // targets at all. + // + // Poison everything except checksForExistence. bestFixups = make([]COREFixup, len(relos)) for i, relo := range relos { - bestFixups[i] = COREFixup{kind: relo.kind, poison: true} + if relo.kind.checksForExistence() { + bestFixups[i] = COREFixup{kind: relo.kind, local: 1, target: 0} + } else { + bestFixups[i] = COREFixup{kind: relo.kind, poison: true} + } } }