From 6d8e7251125ec411fab09005db787b1a06873173 Mon Sep 17 00:00:00 2001 From: Bryce Kahle Date: Mon, 2 Dec 2024 14:16:01 -0800 Subject: [PATCH] fix helper call removal --- pkg/ebpf/perf/event.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/ebpf/perf/event.go b/pkg/ebpf/perf/event.go index 043bb3af8c252..c0832a5735bfc 100644 --- a/pkg/ebpf/perf/event.go +++ b/pkg/ebpf/perf/event.go @@ -189,6 +189,7 @@ func (e *EventHandler) BeforeInit(mgr *manager.Manager, moduleName names.ModuleN e.initRingBuffer(mgr) return nil } + defer e.removeRingBufferHelperCalls(mgr, moduleName, mgrOpts) if e.opts.mode == perfBufferOnly { if ms.Type != ebpf.PerfEventArray { @@ -212,13 +213,20 @@ func (e *EventHandler) BeforeInit(mgr *manager.Manager, moduleName names.ModuleN } e.initPerfBuffer(mgr) - // add helper call remover because ring buffers are not available - return ddebpf.NewHelperCallRemover(asm.FnRingbufOutput).BeforeInit(mgr, moduleName, mgrOpts) + return nil } return fmt.Errorf("unsupported EventHandlerMode %d", e.opts.mode) } +func (e *EventHandler) removeRingBufferHelperCalls(mgr *manager.Manager, moduleName names.ModuleName, mgrOpts *manager.Options) { + if features.HaveMapType(ebpf.RingBuf) == nil { + return + } + // add helper call remover because ring buffers are not available + _ = ddebpf.NewHelperCallRemover(asm.FnRingbufOutput).BeforeInit(mgr, moduleName, mgrOpts) +} + func (e *EventHandler) setupConstant(mgrOpts *manager.Options) { if e.opts.ringBufferConstantName == "" || e.f == nil { return