Skip to content

Commit

Permalink
bpfilter: Allow to build bpfilter_umh as a module without static library
Browse files Browse the repository at this point in the history
Originally, bpfilter_umh was linked with -static only when
CONFIG_BPFILTER_UMH=y.

Commit 8a2cc05 ("bpfilter: use 'userprogs' syntax to build
bpfilter_umh") silently, accidentally dropped the CONFIG_BPFILTER_UMH=y
test in the Makefile. Revive it in order to link it dynamically when
CONFIG_BPFILTER_UMH=m.

Since commit b1183b6 ("bpfilter: check if $(CC) can link static
libc in Kconfig"), the compiler must be capable of static linking to
enable CONFIG_BPFILTER_UMH, but it requires more than needed.

To loosen the compiler requirement, I changed the dependency as follows:

    depends on CC_CAN_LINK
    depends on m || CC_CAN_LINK_STATIC

If CONFIG_CC_CAN_LINK_STATIC in unset, CONFIG_BPFILTER_UMH is restricted
to 'm' or 'n'.

In theory, CONFIG_CC_CAN_LINK is not required for CONFIG_BPFILTER_UMH=y,
but I did not come up with a good way to describe it.

Fixes: 8a2cc05 ("bpfilter: use 'userprogs' syntax to build bpfilter_umh")
Reported-by: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Michal Kubecek <mkubecek@suse.cz>
Link: https://lore.kernel.org/bpf/20200701092644.762234-1-masahiroy@kernel.org
  • Loading branch information
Masahiro Yamada authored and Alexei Starovoitov committed Jul 14, 2020
1 parent a4fa458 commit 9326e0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions net/bpfilter/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ menuconfig BPFILTER
if BPFILTER
config BPFILTER_UMH
tristate "bpfilter kernel module with user mode helper"
depends on CC_CAN_LINK_STATIC
depends on CC_CAN_LINK
depends on m || CC_CAN_LINK_STATIC
default m
help
This builds bpfilter kernel module with embedded user mode helper

Note: your toolchain must support building static binaries, since
rootfs isn't mounted at the time when __init functions are called
and do_execv won't be able to find the elf interpreter.
Note: To compile this as built-in, your toolchain must support
building static binaries, since rootfs isn't mounted at the time
when __init functions are called and do_execv won't be able to find
the elf interpreter.
endif
2 changes: 2 additions & 0 deletions net/bpfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ userprogs := bpfilter_umh
bpfilter_umh-objs := main.o
userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi

ifeq ($(CONFIG_BPFILTER_UMH), y)
# builtin bpfilter_umh should be linked with -static
# since rootfs isn't mounted at the time of __init
# function is called and do_execv won't find elf interpreter
userldflags += -static
endif

$(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh

Expand Down

0 comments on commit 9326e0f

Please sign in to comment.