BPF List
 help / color / mirror / Atom feed
From: Yikai Lin <yikai.lin@vivo.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
	Jiri Olsa <jolsa@kernel.org>, Mykola Lysenko <mykolal@fb.com>,
	Shuah Khan <shuah@kernel.org>, Nick Terrell <terrelln@fb.com>,
	bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org, opensource.kernel@vivo.com,
	Yikai Lin <yikai.lin@vivo.com>
Subject: Re: [PATCH bpf-next v1 2/2] selftests/bpf: Fix cross-compile issue for some files and a static compile issue for "-lzstd"
Date: Wed, 28 Aug 2024 17:54:51 +0800	[thread overview]
Message-ID: <72d7f850-2143-4287-b2cf-96da367b8941@vivo.com> (raw)
In-Reply-To: <CAEf4BzZXL9=pOkt=GbrYG2DpDGtXNLS7AHH5rL3adHd50zMKmQ@mail.gmail.com>

On 2024/8/28 06:49:18, Lin Yikai reply:

> [Some people who received this message don't often get email from andrii.nakryiko@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> On Tue, Aug 27, 2024 at 6:40 AM Lin Yikai <yikai.lin@vivo.com> wrote:
>>
>> 1. Fix cross-compile issue for some files:
>> [Issue]
>> When cross-compiling bpf selftests for arm64 on x86_64 host, the following error occurs:
>> progs/loop2.c:20:7: error: incomplete definition of type 'struct user_pt_regs'
>>     20 |                 if (PT_REGS_RC(ctx) & 1)
>>        |                     ^~~~~~~~~~~~~~~
>>
>> There are same error in files: loop1.c, loop2.c, loop3.c, loop6.c ???
>>
>> [Reason]
>> On arm64, in file bpf_tracing.h, we use userspace's user_pt_regs,
>> which is defined in "linux/ptrace.h".
>> We include the header file by adding "-idirafter /usr/include" for "CLANG_CFLAGS".
>>
>> However, during cross-compiling, "linux/ptrace.h" is based on x86_64
>> and has no definition of "struct user_pt_regs".
>>
>> [Fix]
>> Thus, to fix this issue, we include the Linux source tree's header file directory.
>>
> 
> Hm.. Not sure that's the right fix. Note -D__TARGET_ARCH_$(SRCARCH) in
> BPF_CFLAGS, that __TARGET_ARCH has to match actual target
> architecture, so please check that first.
> 

Hi, Andrii, thanks for your advice.

After searching, I find needed "user_pt_regs" is defined as below:
   bpf-next$ find ./ -name "ptrace.h" | xargs grep -rni "user_pt_regs"
   ./arch/arm64/include/uapi/asm/ptrace.h:88:struct user_pt_regs {

So we can directly add it into include directory
by below approach without "make header_install".

   +ifneq ($(CROSS_COMPILE),)
   +src_uapi_dir := $(srctree)/arch/$(SRCARCH)/include/uapi
   +BPF_CFLAGS += -I$(src_uapi_dir)
   +endif

I'll test it and send a v2 patch.

> pw-bot: cr
> 
>> 2. Fix static compile issue for "-lzstd":
>> [Issue]
>> By running the command "LDLIBS=-static LDFLAGS=--sysroot=/aarch64-linux-gnu/libc ./vmtest.sh -s -- ./test_progs",
>> during static cross-compiling, an error occurs:
>> /aarch64-linux-gnu/bin/ld: aarch64-linux-gnu/libc/usr/lib/libelf.a(elf_compress.o): in function `__libelf_compress':
>> (.text+0xec): undefined reference to `ZSTD_createCCtx'
>> /aarch64-linux-gnu/bin/ld: (.text+0xf0): undefined reference to `ZSTD_createCCtx'
>> ...
>>
>> [Fix]
>> For static compile, add "LDLIBS += -lzstd".
> 
> we can probably just add it unconditionally, no? But please send it as
> a separate change in its own patch
> 
Thanks, I'll try it for v2 patch.

>>
>> Signed-off-by: Lin Yikai <yikai.lin@vivo.com>
>> ---
>>   tools/testing/selftests/bpf/Makefile | 12 +++++++++++-
>>   1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
>> index ec7d425c4022..5b725bc890d2 100644
>> --- a/tools/testing/selftests/bpf/Makefile
>> +++ b/tools/testing/selftests/bpf/Makefile
>> @@ -48,6 +48,10 @@ CFLAGS += -g $(OPT_FLAGS) -rdynamic                                  \
>>   LDFLAGS += $(SAN_LDFLAGS)
>>   LDLIBS += $(LIBELF_LIBS) -lz -lrt -lpthread
>>
>> +ifneq (,$(findstring -static,$(LDLIBS)))
>> +LDLIBS += -lzstd
>> +endif
>> +
>>   LDLIBS += $(shell $(PKG_CONFIG) --libs libpcap 2>/dev/null)
>>   CFLAGS += $(shell $(PKG_CONFIG) --cflags libpcap 2>/dev/null)
>>   CFLAGS += $(shell $(PKG_CONFIG) --exists libpcap 2>/dev/null && echo "-DTRAFFIC_MONITOR=1")
>> @@ -443,13 +447,19 @@ CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
>>   endif
>>
>>   CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
>> +CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
>> +
>>   BPF_CFLAGS = -g -Wall -Werror -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN)    \
>>               -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR)                   \
>>               -I$(abspath $(OUTPUT)/../usr/include)                      \
>>               -Wno-compare-distinct-pointer-types
>>   # TODO: enable me -Wsign-compare
>>
>> -CLANG_CFLAGS = $(CLANG_SYS_INCLUDES)
>> +#"make headers_install" at first
>> +ifneq ($(CROSS_COMPILE),)
>> +src_uapi_dir := $(srctree)/usr/include
>> +BPF_CFLAGS += -I$(src_uapi_dir)
>> +endif
>>
>>   $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
>>   $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
>> --
>> 2.34.1
>>


      reply	other threads:[~2024-08-28  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-27 13:39 [PATCH bpf-next v1 0/2] Enable vmtest for cross-compile arm64 on x86_64 host, and fix some related issues Lin Yikai
2024-08-27 13:39 ` [PATCH bpf-next v1 1/2] selftests/bpf: Update "vmtest.sh" for cross-compile arm64 on x86_64 host Lin Yikai
2024-08-27 14:05   ` Pu Lehui
2024-08-28  3:11     ` yikai.lin
2024-08-27 13:39 ` [PATCH bpf-next v1 2/2] selftests/bpf: Fix cross-compile issue for some files and a static compile issue for "-lzstd" Lin Yikai
2024-08-27 22:49   ` Andrii Nakryiko
2024-08-28  9:54     ` Yikai Lin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=72d7f850-2143-4287-b2cf-96da367b8941@vivo.com \
    --to=yikai.lin@vivo.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=opensource.kernel@vivo.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=terrelln@fb.com \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox