diff mbox series

[bpf-next] samples: bpf: Fix cross-compiling error about bpftool

Message ID 20220707140811.603590-1-pulehui@huawei.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] samples: bpf: Fix cross-compiling error about bpftool | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 19 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-2 fail Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc

Commit Message

Pu Lehui July 7, 2022, 2:08 p.m. UTC
Currently, when cross compiling bpf samples, the host side
cannot use arch-specific bpftool to generate vmlinux.h or
skeleton. We need to compile the bpftool with the host
compiler.

Signed-off-by: Pu Lehui <pulehui@huawei.com>
---
 samples/bpf/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Song Liu July 7, 2022, 7:12 p.m. UTC | #1
> On Jul 7, 2022, at 7:08 AM, Pu Lehui <pulehui@huawei.com> wrote:
> 
> Currently, when cross compiling bpf samples, the host side
> cannot use arch-specific bpftool to generate vmlinux.h or
> skeleton. We need to compile the bpftool with the host
> compiler.
> 
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---
> samples/bpf/Makefile | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index 5002a5b9a7da..fe54a8c8f312 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -1,4 +1,5 @@
> # SPDX-License-Identifier: GPL-2.0
> +-include tools/scripts/Makefile.include

Why do we need the -include here? 

Thanks,
Song

> 
> BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
> TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
> BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
> BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
> BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
> 	    $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
> -		OUTPUT=$(BPFTOOL_OUTPUT)/ \
> -		LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
> -		LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
> +		ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
> +		OUTPUT=$(BPFTOOL_OUTPUT)/
> 
> $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
> 	$(call msg,MKDIR,$@)
> -- 
> 2.25.1
>
Pu Lehui July 8, 2022, 2:46 a.m. UTC | #2
On 2022/7/8 3:12, Song Liu wrote:
> 
> 
>> On Jul 7, 2022, at 7:08 AM, Pu Lehui <pulehui@huawei.com> wrote:
>>
>> Currently, when cross compiling bpf samples, the host side
>> cannot use arch-specific bpftool to generate vmlinux.h or
>> skeleton. We need to compile the bpftool with the host
>> compiler.
>>
>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>> ---
>> samples/bpf/Makefile | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
>> index 5002a5b9a7da..fe54a8c8f312 100644
>> --- a/samples/bpf/Makefile
>> +++ b/samples/bpf/Makefile
>> @@ -1,4 +1,5 @@
>> # SPDX-License-Identifier: GPL-2.0
>> +-include tools/scripts/Makefile.include
> 
> Why do we need the -include here?
> 

HOSTLD is defined in tools/scripts/Makefile.include, we need to add it.

And for -include, mainly to resolve some conflicts:
1. If workdir is kernel_src, then 'include 
tools/scripts/Makefile.include' is fine when 'make M=samples/bpf'.
2. Since the trick in samples/bpf/Makefile:

# Trick to allow make to be run from this directory
all:
	$(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR)

If workdir is samples/bpf, the compile process will first load the 
Makefile in samples/bpf, then change workdir to kernel_src and load the 
kernel_src's Makefile. So if we just add 'include 
tools/scripts/Makefile.include', then the first load will occur error 
for not found the file, so we add -include to skip the first load.

> Thanks,
> Song
> 
>>
>> BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
>> TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
>> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>> BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
>> BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
>> BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
>> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>> 	    $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
>> -		OUTPUT=$(BPFTOOL_OUTPUT)/ \
>> -		LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
>> -		LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
>> +		ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
>> +		OUTPUT=$(BPFTOOL_OUTPUT)/
>>
>> $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
>> 	$(call msg,MKDIR,$@)
>> -- 
>> 2.25.1
>>
> 
> .
>
Pu Lehui July 8, 2022, 3:12 a.m. UTC | #3
On 2022/7/8 10:46, Pu Lehui wrote:
> 
> 
> On 2022/7/8 3:12, Song Liu wrote:
>>
>>
>>> On Jul 7, 2022, at 7:08 AM, Pu Lehui <pulehui@huawei.com> wrote:
>>>
>>> Currently, when cross compiling bpf samples, the host side
>>> cannot use arch-specific bpftool to generate vmlinux.h or
>>> skeleton. We need to compile the bpftool with the host
>>> compiler.
>>>
>>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>>> ---
>>> samples/bpf/Makefile | 8 ++++----
>>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
>>> index 5002a5b9a7da..fe54a8c8f312 100644
>>> --- a/samples/bpf/Makefile
>>> +++ b/samples/bpf/Makefile
>>> @@ -1,4 +1,5 @@
>>> # SPDX-License-Identifier: GPL-2.0
>>> +-include tools/scripts/Makefile.include
>>
>> Why do we need the -include here?
>>
> 
> HOSTLD is defined in tools/scripts/Makefile.include, we need to add it.
> 
> And for -include, mainly to resolve some conflicts:
> 1. If workdir is kernel_src, then 'include 
> tools/scripts/Makefile.include' is fine when 'make M=samples/bpf'.
> 2. Since the trick in samples/bpf/Makefile:
> 
> # Trick to allow make to be run from this directory
> all:
>      $(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR)
> 
> If workdir is samples/bpf, the compile process will first load the 
> Makefile in samples/bpf, then change workdir to kernel_src and load the 
> kernel_src's Makefile. So if we just add 'include 
> tools/scripts/Makefile.include', then the first load will occur error 
> for not found the file, so we add -include to skip the first load.

sorry, correct the reply, so we add -include to skip the 
'tools/scripts/Makefile.include' file on the fisrt load.

> 
>> Thanks,
>> Song
>>
>>>
>>> BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
>>> TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
>>> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] 
>>> $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>>> BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
>>> BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
>>> BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
>>> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] 
>>> $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>>> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) 
>>> | $(BPFTOOL_OUTPUT)
>>>         $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
>>> -        OUTPUT=$(BPFTOOL_OUTPUT)/ \
>>> -        LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
>>> -        LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
>>> +        ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
>>> +        OUTPUT=$(BPFTOOL_OUTPUT)/
>>>
>>> $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
>>>     $(call msg,MKDIR,$@)
>>> -- 
>>> 2.25.1
>>>
>>
>> .
>>
> .
Song Liu July 8, 2022, 4:53 a.m. UTC | #4
> On Jul 7, 2022, at 8:12 PM, Pu Lehui <pulehui@huawei.com> wrote:
> 
> 
> 
> On 2022/7/8 10:46, Pu Lehui wrote:
>> On 2022/7/8 3:12, Song Liu wrote:
>>> 
>>> 
>>>> On Jul 7, 2022, at 7:08 AM, Pu Lehui <pulehui@huawei.com> wrote:
>>>> 
>>>> Currently, when cross compiling bpf samples, the host side
>>>> cannot use arch-specific bpftool to generate vmlinux.h or
>>>> skeleton. We need to compile the bpftool with the host
>>>> compiler.
>>>> 
>>>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>>>> ---
>>>> samples/bpf/Makefile | 8 ++++----
>>>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>>> 
>>>> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
>>>> index 5002a5b9a7da..fe54a8c8f312 100644
>>>> --- a/samples/bpf/Makefile
>>>> +++ b/samples/bpf/Makefile
>>>> @@ -1,4 +1,5 @@
>>>> # SPDX-License-Identifier: GPL-2.0
>>>> +-include tools/scripts/Makefile.include
>>> 
>>> Why do we need the -include here?
>>> 
>> HOSTLD is defined in tools/scripts/Makefile.include, we need to add it.
>> And for -include, mainly to resolve some conflicts:
>> 1. If workdir is kernel_src, then 'include tools/scripts/Makefile.include' is fine when 'make M=samples/bpf'.
>> 2. Since the trick in samples/bpf/Makefile:
>> # Trick to allow make to be run from this directory
>> all:
>> $(MAKE) -C ../../ M=$(CURDIR) BPF_SAMPLES_PATH=$(CURDIR)
>> If workdir is samples/bpf, the compile process will first load the Makefile in samples/bpf, then change workdir to kernel_src and load the kernel_src's Makefile. So if we just add 'include tools/scripts/Makefile.include', then the first load will occur error for not found the file, so we add -include to skip the first load.
> 
> sorry, correct the reply, so we add -include to skip the 'tools/scripts/Makefile.include' file on the fisrt load.


Thanks for the explanation. 

Acked-by: Song Liu <song@kernel.org>

> 
>>> Thanks,
>>> Song
>>> 
>>>> 
>>>> BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
>>>> TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
>>>> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>>>> BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
>>>> BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
>>>> BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
>>>> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>>>> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>>>> $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
>>>> -  OUTPUT=$(BPFTOOL_OUTPUT)/ \
>>>> -  LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
>>>> -  LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
>>>> +  ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
>>>> +  OUTPUT=$(BPFTOOL_OUTPUT)/
>>>> 
>>>> $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
>>>> $(call msg,MKDIR,$@)
>>>> -- 
>>>> 2.25.1
>>>> 
>>> 
>>> .
>>> 
>> .
Andrii Nakryiko July 8, 2022, 10:42 p.m. UTC | #5
On Thu, Jul 7, 2022 at 6:37 AM Pu Lehui <pulehui@huawei.com> wrote:
>
> Currently, when cross compiling bpf samples, the host side
> cannot use arch-specific bpftool to generate vmlinux.h or
> skeleton. We need to compile the bpftool with the host
> compiler.
>
> Signed-off-by: Pu Lehui <pulehui@huawei.com>
> ---

samples/bpf use bpftool for vmlinux.h, skeleton, and static linking
only. All that is supported by lightweight "bootstrap" bpftool
version, so we can build just that. It will be faster, and bootstrap
version should be always host-native even during cross compilation.
See [0] for what I did in libbpf-bootstrap.

Also please cc Quention for bpftool-related changes. Thanks!

   [0] https://github.com/libbpf/libbpf-bootstrap/commit/fc28424eb3f0e39cfb5959296b070389b9a8bd8f

>  samples/bpf/Makefile | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
> index 5002a5b9a7da..fe54a8c8f312 100644
> --- a/samples/bpf/Makefile
> +++ b/samples/bpf/Makefile
> @@ -1,4 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0
> +-include tools/scripts/Makefile.include
>
>  BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
>  TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>  BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
>  BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
>  BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>             $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
> -               OUTPUT=$(BPFTOOL_OUTPUT)/ \
> -               LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
> -               LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
> +               ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
> +               OUTPUT=$(BPFTOOL_OUTPUT)/
>
>  $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
>         $(call msg,MKDIR,$@)
> --
> 2.25.1
>
Pu Lehui July 9, 2022, 7:31 a.m. UTC | #6
On 2022/7/9 6:42, Andrii Nakryiko wrote:
> On Thu, Jul 7, 2022 at 6:37 AM Pu Lehui <pulehui@huawei.com> wrote:
>>
>> Currently, when cross compiling bpf samples, the host side
>> cannot use arch-specific bpftool to generate vmlinux.h or
>> skeleton. We need to compile the bpftool with the host
>> compiler.
>>
>> Signed-off-by: Pu Lehui <pulehui@huawei.com>
>> ---
> 
> samples/bpf use bpftool for vmlinux.h, skeleton, and static linking
> only. All that is supported by lightweight "bootstrap" bpftool
> version, so we can build just that. It will be faster, and bootstrap
> version should be always host-native even during cross compilation.
> See [0] for what I did in libbpf-bootstrap.
> 
> Also please cc Quention for bpftool-related changes. Thanks!
> 
>     [0] https://github.com/libbpf/libbpf-bootstrap/commit/fc28424eb3f0e39cfb5959296b070389b9a8bd8f
> 

so brilliant,we can take it to other places where rely on bpftool.
thanks.

>>   samples/bpf/Makefile | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
>> index 5002a5b9a7da..fe54a8c8f312 100644
>> --- a/samples/bpf/Makefile
>> +++ b/samples/bpf/Makefile
>> @@ -1,4 +1,5 @@
>>   # SPDX-License-Identifier: GPL-2.0
>> +-include tools/scripts/Makefile.include
>>
>>   BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
>>   TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
>> @@ -283,11 +284,10 @@ $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
>>   BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
>>   BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
>>   BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
>> -$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>> +$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
>>              $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
>> -               OUTPUT=$(BPFTOOL_OUTPUT)/ \
>> -               LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
>> -               LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
>> +               ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
>> +               OUTPUT=$(BPFTOOL_OUTPUT)/
>>
>>   $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
>>          $(call msg,MKDIR,$@)
>> --
>> 2.25.1
>>
> .
>
diff mbox series

Patch

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 5002a5b9a7da..fe54a8c8f312 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -1,4 +1,5 @@ 
 # SPDX-License-Identifier: GPL-2.0
+-include tools/scripts/Makefile.include
 
 BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
 TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
@@ -283,11 +284,10 @@  $(LIBBPF): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
 BPFTOOLDIR := $(TOOLS_PATH)/bpf/bpftool
 BPFTOOL_OUTPUT := $(abspath $(BPF_SAMPLES_PATH))/bpftool
 BPFTOOL := $(BPFTOOL_OUTPUT)/bpftool
-$(BPFTOOL): $(LIBBPF) $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
+$(BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) | $(BPFTOOL_OUTPUT)
 	    $(MAKE) -C $(BPFTOOLDIR) srctree=$(BPF_SAMPLES_PATH)/../../ \
-		OUTPUT=$(BPFTOOL_OUTPUT)/ \
-		LIBBPF_OUTPUT=$(LIBBPF_OUTPUT)/ \
-		LIBBPF_DESTDIR=$(LIBBPF_DESTDIR)/
+		ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
+		OUTPUT=$(BPFTOOL_OUTPUT)/
 
 $(LIBBPF_OUTPUT) $(BPFTOOL_OUTPUT):
 	$(call msg,MKDIR,$@)