Skip to content

Commit

Permalink
bpfilter: switch to CC from HOSTCC
Browse files Browse the repository at this point in the history
check that CC can build executables and use that compiler instead of HOSTCC

Suggested-by: Arnd Bergmann <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Alexei Starovoitov authored and davem330 committed Jun 5, 2018
1 parent 47a6ca3 commit 819dd92
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $
KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
endif

ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/cc-can-link.sh $(CC)), y)
CC_CAN_LINK := y
export CC_CAN_LINK
endif

ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
Expand Down
4 changes: 4 additions & 0 deletions net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ obj-$(CONFIG_TLS) += tls/
obj-$(CONFIG_XFRM) += xfrm/
obj-$(CONFIG_UNIX) += unix/
obj-$(CONFIG_NET) += ipv6/
ifneq ($(CC_CAN_LINK),y)
$(warning CC cannot link executables. Skipping bpfilter.)
else
obj-$(CONFIG_BPFILTER) += bpfilter/
endif
obj-$(CONFIG_PACKET) += packet/
obj-$(CONFIG_NET_KEY) += key/
obj-$(CONFIG_BRIDGE) += bridge/
Expand Down
2 changes: 2 additions & 0 deletions net/bpfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
hostprogs-y := bpfilter_umh
bpfilter_umh-objs := main.o
HOSTCFLAGS += -I. -Itools/include/ -Itools/include/uapi
HOSTCC := $(CC)

ifeq ($(CONFIG_BPFILTER_UMH), y)
# builtin bpfilter_umh should be compiled with -static
# since rootfs isn't mounted at the time of __init
Expand Down
11 changes: 11 additions & 0 deletions scripts/cc-can-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0

cat << "END" | $@ -x c - -o /dev/null >/dev/null 2>&1 && echo "y"
#include <stdio.h>
int main(void)
{
printf("");
return 0;
}
END

0 comments on commit 819dd92

Please sign in to comment.