Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpfilter: Allow to build bpfilter_umh as a module without static library

Originally, bpfilter_umh was linked with -static only when
CONFIG_BPFILTER_UMH=y.

Commit 8a2cc0505cc4 ("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 b1183b6dca3e ("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: 8a2cc0505cc4 ("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

authored by

Masahiro Yamada and committed by
Alexei Starovoitov
9326e0f8 a4fa4589

+8 -4
+6 -4
net/bpfilter/Kconfig
··· 9 9 if BPFILTER 10 10 config BPFILTER_UMH 11 11 tristate "bpfilter kernel module with user mode helper" 12 - depends on CC_CAN_LINK_STATIC 12 + depends on CC_CAN_LINK 13 + depends on m || CC_CAN_LINK_STATIC 13 14 default m 14 15 help 15 16 This builds bpfilter kernel module with embedded user mode helper 16 17 17 - Note: your toolchain must support building static binaries, since 18 - rootfs isn't mounted at the time when __init functions are called 19 - and do_execv won't be able to find the elf interpreter. 18 + Note: To compile this as built-in, your toolchain must support 19 + building static binaries, since rootfs isn't mounted at the time 20 + when __init functions are called and do_execv won't be able to find 21 + the elf interpreter. 20 22 endif
+2
net/bpfilter/Makefile
··· 7 7 bpfilter_umh-objs := main.o 8 8 userccflags += -I $(srctree)/tools/include/ -I $(srctree)/tools/include/uapi 9 9 10 + ifeq ($(CONFIG_BPFILTER_UMH), y) 10 11 # builtin bpfilter_umh should be linked with -static 11 12 # since rootfs isn't mounted at the time of __init 12 13 # function is called and do_execv won't find elf interpreter 13 14 userldflags += -static 15 + endif 14 16 15 17 $(obj)/bpfilter_umh_blob.o: $(obj)/bpfilter_umh 16 18