Skip to content

Commit

Permalink
tetragon: Allow to build llvm IR objects
Browse files Browse the repository at this point in the history
Allowing to build llvm IR objects with:

  $ make -C bpf objs/bpf_generic_kprobe_v61.ll

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Nov 29, 2024
1 parent 7eedba6 commit 32eb721
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions bpf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
# following variable:
#
# CFLAGS_<object.o> (example: CFLAGS_bpf_enforcer.o = -D__BPF_OVERRIDE_RETURN)
#
# It's possible to make .ll file for any object, like:
#
# $ make -C bpf objs/bpf_generic_kprobe_v61.ll

.PHONY: all clean
.SUFFIXES:
Expand Down Expand Up @@ -114,13 +118,17 @@ CFLAGS_bpf_generic_lsm_core.o = -D__LARGE_BPF_PROG
CFLAGS_bpf_generic_lsm_output.o = -D__LARGE_BPF_PROG

# Rules
MTARGET = $(patsubst $(DEPSDIR)%.d,$(OBJSDIR)%.o,$@)
MTARGET_o = $(patsubst $(DEPSDIR)%.d,$(OBJSDIR)%.o,$@)
MTARGET_ll = $(patsubst $(DEPSDIR)%.d,$(OBJSDIR)%.ll,$@)

rule_d_CFLAGS = $(CFLAGS_$(notdir $(MTARGET)))
rule_o_CFLAGS = $(CFLAGS_$(notdir $@))
rule_d_CFLAGS = $(CFLAGS_$(notdir $(MTARGET_o)))
rule_o_CFLAGS = $(CFLAGS_$(notdir $@))
rule_ll_CFLAGS = $(CFLAGS_$(notdir $(patsubst %.ll,%.o,$@)))

rule_d = $(CLANG) $(CLANG_FLAGS) $(rule_d_CFLAGS) $1 -MM -MP -MT $(MTARGET) $< > $@
rule_o = $(CLANG) $(CLANG_FLAGS) $(rule_o_CFLAGS) $1 -c $< -o $@
rule_d = $(CLANG) $(CLANG_FLAGS) $(rule_d_CFLAGS) $1 -MM -MP -MT $(MTARGET_o) $< > $@ && \
$(CLANG) $(CLANG_FLAGS) $(rule_d_CFLAGS) $1 -MM -MP -MT $(MTARGET_ll) $< >> $@
rule_o = $(CLANG) $(CLANG_FLAGS) $(rule_o_CFLAGS) $1 -c $< -o $@
rule_ll = $(CLANG) $(CLANG_FLAGS) $(rule_ll_CFLAGS) -emit-llvm $1 -c $< -o $@

VARIANT_CFLAGS = $$(CFLAGS_$1)

Expand All @@ -141,6 +149,9 @@ $(DEPSDIR)bpf_multi_uprobe_$$(VAR).d: $(PROCESSDIR)bpf_generic_uprobe.c
$(OBJSDIR)%_$$(VAR).o:
$$(call rule_o,$(VARIANT_CFLAGS))

$(OBJSDIR)%_$$(VAR).ll:
$$(call rule_ll,$(VARIANT_CFLAGS))

# Generic dependency files for VARIANT objects
$(DEPSDIR)%_$$(VAR).d: $(PROCESSDIR)%.c
$$(call rule_d,$(VARIANT_CFLAGS))
Expand All @@ -162,6 +173,9 @@ $(eval $(call DEFINE_VARIANT,v61))
objs/%.o:
$(rule_o)

objs/%.ll:
$(rule_ll)

# Generic dependency files
$(DEPSDIR)%.d: $(ALIGNCHECKERDIR)%.c
$(rule_d)
Expand Down

0 comments on commit 32eb721

Please sign in to comment.