libbpf-bootstrap icon indicating copy to clipboard operation
libbpf-bootstrap copied to clipboard

xmake cross build error

Open idersan opened this issue 3 years ago • 1 comments

$ uname -a
    Linux idersan 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ xmake f -p cross --sdk=~/aarch64-linux-musl-cross
$ xmake

output:

generating ../../libbpf/src/bpf_helper_defs.h ... cache
[ 43%]: compiling.bpf uprobe.bpf.c
error: In file included from uprobe.bpf.c:4:
In file included from /usr/src/linux-headers-5.15.0-48-generic/include/linux/ptrace.h:5:
/usr/src/linux-headers-5.15.0-48-generic/include/linux/compiler.h:255:10: fatal error: 'asm/rwonce.h' file not found
#include <asm/rwonce.h>
         ^~~~~~~~~~~~~~
Stack dump:
0.      Program arguments: /usr/bin/clang -c -Qunused-arguments -m64 -fvisibility=hidden -O3 -I../../vmlinux -Ibuild/.gens/uprobe/linux/x86_64/release/rules/bpf -I../../libbpf/include/uapi -Ibuild -isystem /usr/src/linux-headers-5.15.0-48-generic/include -DNDEBUG -target bpf -g -O2 -D__TARGET_ARCH_x86 -o build/.gens/uprobe/linux/x86_64/release/rules/bpf/uprobe.bpf.o uprobe.bpf.c 
1.      <eof> parser at end of file
 #0 0x00007f89680d54ff llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x9814ff)
 #1 0x00007f89680d37b0 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x97f7b0)
 #2 0x00007f89680d4c4d llvm::sys::CleanupOnSignal(unsigned long) (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x980c4d)
 #3 0x00007f896802ae60 (/lib/x86_64-linux-gnu/libLLVM-10.so.1+0x8d6e60)

when add a commnts at uprobe in xmake.lua, have a another error output:

[ 77%]: cache compiling.release minimal_legacy.c
error: /usr/src/linux-headers-5.15.0-48-generic/include/linux/stddef.h:11:2: error: expected identifier
        false   = 0,
        ^
/usr/lib/llvm-10/lib/clang/10.0.0/include/stdbool.h:17:15: note: expanded from macro 'false'
#define false 0
              ^
In file included from minimal_legacy.c:5:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
In file included from /usr/src/linux-headers-5.15.0-48-generic/include/linux/types.h:6:
In file included from /usr/src/linux-headers-5.15.0-48-generic/include/uapi/linux/types.h:14:
In file included from /usr/include/linux/posix_types.h:5:
/usr/src/linux-headers-5.15.0-48-generic/include/linux/stddef.h:12:2: error: expected identifier
        true    = 1
        ^
/usr/lib/llvm-10/lib/clang/10.0.0/include/stdbool.h:16:14: note: expanded from macro 'true'
#define true 1
  > in minimal_legacy.c

idersan avatar Sep 27 '22 11:09 idersan

This looks like xmake doesn't give the proper parameters to clang. In a typical case, xmake downloads a copy of linux-headers, uncompresses the file, and uses the directory as an include path. But, here, xmake doesn't do it. We should forward this issue to xmake as well! They may have a better idea of what is going on.

ThinkerYzu1 avatar Sep 27 '22 22:09 ThinkerYzu1

@waruqi can you please take a look when you get a chance?

anakryiko avatar Nov 15 '22 05:11 anakryiko

xmake f -p cross --sdk=~/aarch64-linux-musl-cross /usr/bin/clang -c -Qunused-arguments

It seems that you intend to cross-compile the bpf program, but xmake still uses clang instead of aarch64-linux-musl-cross

Can you pass -vD and let me see verbose logs? and please show me your aarch64-linux-musl-cross structure.

xmake f -p cross --sdk=~/aarch64-linux-musl-cross -c -vD
xmake -rvD
ls ~/aarch64-linux-musl-cross
find ~/aarch64-linux-musl-cross  -name "*gcc*" 

and you need pass -a [arm|arm64|mips64|ppc] arguments to set arch. it will define __TARGET_ARCH_xxx when compiling bpf code.

xmake f -p cross --sdk=~/aarch64-linux-musl-cross -a arm64 -c -vD
        if target:is_arch("x86_64", "i386") then
            targetarch = "__TARGET_ARCH_x86"
        elseif target:is_arch("arm64", "arm64-v8a") then
            targetarch = "__TARGET_ARCH_arm64"
        elseif target:is_arch("arm.*") then
            targetarch = "__TARGET_ARCH_arm"
        elseif target:is_arch("mips64", "mips") then
            targetarch = "__TARGET_ARCH_mips"
        elseif target:is_arch("ppc64", "ppc") then
            targetarch = "__TARGET_ARCH_powerpc"
        end

waruqi avatar Nov 15 '22 06:11 waruqi