Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译bpf-bootstrap失败 #4207

Closed
lyg4795 opened this issue Sep 16, 2023 · 2 comments
Closed

编译bpf-bootstrap失败 #4207

lyg4795 opened this issue Sep 16, 2023 · 2 comments

Comments

@lyg4795
Copy link

lyg4795 commented Sep 16, 2023

Xmake 版本

v2.8.2+20230916

操作系统版本和架构

Linux lin 5.19.0-45-generic #46~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Jun 7 15:06:04 UTC 20 x86_64 x86_64 x86_64 GNU/Linux

描述问题

编译失败 不知道怎么解决

期待的结果

能编译minimal

工程配置

xmake f --require-bpftool=y
xmake

下面是lua配置
xmake.lua

add_rules("platform.linux.bpf")
set_license("GPL-2.0")

if xmake.version():satisfies(">=2.5.7 <=2.5.9") then
    on_load(function (target)
        raise("xmake(%s) has a bug preventing BPF source code compilation. Please run `xmake update -f 2.5.6` to revert to v2.5.6 version or upgrade to xmake v2.6.1 that fixed the issue.", xmake.version())
    end)
end

option("system-libbpf",      {showmenu = true, default = false, description = "Use system-installed libbpf"})
option("require-bpftool",    {showmenu = true, default = false, description = "Require bpftool package"})

add_requires("elfutils", "zlib")
if is_plat("android") then
    add_requires("ndk >=22.x", "argp-standalone")
    set_toolchains("@ndk", {sdkver = "23"})
else
    add_requires("llvm >=10.x")
    set_toolchains("@llvm")
    add_requires("linux-headers")
end

add_includedirs("../../vmlinux")

-- we can run `xmake f --require-bpftool=y` to pull bpftool from xmake-repo repository
if has_config("require-bpftool") then
    add_requires("linux-tools", {configs = {bpftool = true}})
    add_packages("linux-tools")
else
    before_build(function (target)
        os.addenv("PATH", path.join(os.scriptdir(), "..", "..", "tools"))
    end)
end

-- we use the vendored libbpf sources for libbpf-bootstrap.
-- for some projects you may want to use the system-installed libbpf, so you can run `xmake f --system-libbpf=y`
if has_config("system-libbpf") then
    add_requires("libbpf", {system = true})
else
    target("libbpf")
        set_kind("static")
        set_basename("bpf")
        add_files("../../libbpf/src/*.c")
        add_includedirs("../../libbpf/include")
        add_includedirs("../../libbpf/include/uapi", {public = true})
        add_includedirs("$(buildir)", {interface = true})
        add_configfiles("../../libbpf/src/(*.h)", {prefixdir = "bpf"})
        add_packages("elfutils", "zlib")
        if is_plat("android") then
            add_defines("__user=", "__force=", "__poll_t=uint32_t")
        end
end

target("minimal")
    set_kind("binary")
    add_files("minimal.c", "minimal.bpf.c")
    add_packages("linux-headers")
    if not has_config("system-libbpf") then
        add_deps("libbpf")
    end

附加信息和错误日志

[ 88%]: cache compiling.release minimal.c
/usr/bin/clang -c -Qunused-arguments -m64 -fvisibility=hidden -O3 -I../../vmlinux -Ibuild/.gens/minimal/linux/x86_64/release/rules/bpf -I../../libbpf/include/uapi -Ibuild -isystem /usr/src/linux-headers-5.19.0-45-generic/include -DNDEBUG -o build/.objs/minimal/linux/x86_64/release/minimal.c.o minimal.c
error: @programdir/modules/private/async/runjobs.lua:256: @programdir/modules/private/action/build/object.lua:91: @programdir/modules/core/tools/gcc.lua:805: In file included from minimal.c:6:
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.19.0-45-generic/include/linux/types.h:6:
In file included from /usr/src/linux-headers-5.19.0-45-generic/include/uapi/linux/types.h:14:
In file included from /usr/include/linux/posix_types.h:5:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/stddef.h:11:2: error: expected identifier
false = 0,
^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stdbool.h:17:15: note: expanded from macro 'false'
#define false 0
^
In file included from minimal.c:6:
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.19.0-45-generic/include/linux/types.h:6:
In file included from /usr/src/linux-headers-5.19.0-45-generic/include/uapi/linux/types.h:14:
In file included from /usr/include/linux/posix_types.h:5:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/stddef.h:12:2: error: expected identifier
true = 1
^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stdbool.h:16:14: note: expanded from macro 'true'
#define true 1
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:15:26: error: typedef redefinition with different types ('__kernel_fd_set' vs 'struct fd_set')
typedef __kernel_fd_set fd_set;
^
/usr/include/x86_64-linux-gnu/sys/select.h:70:5: note: previous definition is here
} fd_set;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:16:25: error: typedef redefinition with different types ('__kernel_dev_t' (aka 'unsigned int') vs '__dev_t' (aka 'unsigned long'))
typedef __kernel_dev_t dev_t;
^
/usr/include/x86_64-linux-gnu/sys/types.h:59:17: note: previous definition is here
typedef __dev_t dev_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:20:15: error: typedef redefinition with different types ('u32' (aka 'unsigned int') vs '__nlink_t' (aka 'unsigned long'))
typedef u32 nlink_t;
^
/usr/include/x86_64-linux-gnu/sys/types.h:74:19: note: previous definition is here
typedef __nlink_t nlink_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:26:26: error: typedef redefinition with different types ('__kernel_timer_t' (aka 'int') vs '__timer_t' (aka 'void '))
typedef __kernel_timer_t timer_t;
^
/usr/include/x86_64-linux-gnu/bits/types/timer_t.h:7:19: note: previous definition is here
typedef __timer_t timer_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:30:17: error: cannot combine with previous 'bool' declaration specifier
typedef _Bool bool;
^
/usr/lib/llvm-14/lib/clang/14.0.0/include/stdbool.h:15:14: note: expanded from macro 'bool'
#define bool _Bool
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:46:26: error: typedef redefinition with different types ('__kernel_loff_t' (aka 'long long') vs '__loff_t' (aka 'long'))
typedef __kernel_loff_t loff_t;
^
/usr/include/x86_64-linux-gnu/sys/types.h:42:18: note: previous definition is here
typedef __loff_t loff_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:107:15: error: typedef redefinition with different types ('u64' (aka 'unsigned long long') vs '__uint64_t' (aka 'unsigned long'))
typedef u64 uint64_t;
^
/usr/include/x86_64-linux-gnu/bits/stdint-uintn.h:27:20: note: previous definition is here
typedef __uint64_t uint64_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:108:15: error: typedef redefinition with different types ('u64' (aka 'unsigned long long') vs '__uint64_t' (aka 'unsigned long'))
typedef u64 u_int64_t;
^
/usr/include/x86_64-linux-gnu/sys/types.h:161:20: note: previous definition is here
typedef __uint64_t u_int64_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:109:15: error: typedef redefinition with different types ('s64' (aka 'long long') vs '__int64_t' (aka 'long'))
typedef s64 int64_t;
^
/usr/include/x86_64-linux-gnu/bits/stdint-intn.h:27:19: note: previous definition is here
typedef __int64_t int64_t;
^
In file included from minimal.c:6:
In file included from build/bpf/libbpf.h:18:
In file included from ../../libbpf/include/uapi/linux/bpf.h:11:
/usr/src/linux-headers-5.19.0-45-generic/include/linux/types.h:126:13: error: typedef redefinition with different types ('u64' (aka 'unsigned long long') vs '__blkcnt_t' (aka 'long'))
typedef u64 blkcnt_t;
^
/usr/include/x86_64-linux-gnu/sys/types.h:192:20: note: previous definition is here
typedef __blkcnt_t blkcnt_t; /
Type to count number of disk blocks. */
^
12 errors generated.
stack traceback:
[C]: in function 'error'
[@programdir/core/base/os.lua:921]:
[@programdir/modules/core/tools/gcc.lua:805]: in function 'catch'
[@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
[@programdir/modules/core/tools/gcc.lua:746]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:280]:
[@programdir/core/tool/compiler.lua:278]: in function 'compile'
[@programdir/modules/private/action/build/object.lua:91]: in function 'script'
[@programdir/modules/private/action/build/object.lua:122]: in function 'build_object'
[@programdir/modules/private/action/build/object.lua:147]: in function 'jobfunc'
[@programdir/modules/private/async/runjobs.lua:232]:
[C]: in function 'xpcall'
[@programdir/core/base/utils.lua:280]: in function 'trycall'
[@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
[@programdir/modules/private/async/runjobs.lua:218]: in function 'cotask'
[@programdir/core/base/scheduler.lua:404]:

stack traceback:
[C]: in function 'error'
@programdir/core/base/os.lua:921: in function 'base/os.raiselevel'
(...tail calls...)
@programdir/modules/private/async/runjobs.lua:256: in field 'catch'
@programdir/core/sandbox/modules/try.lua:123: in global 'try'
@programdir/modules/private/async/runjobs.lua:218: in upvalue 'cotask'
@programdir/core/base/scheduler.lua:404: in function <@programdir/core/base/scheduler.lua:397>

@lyg4795 lyg4795 added the bug label Sep 16, 2023
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: Failed to compile bpf-bootstrap

@waruqi
Copy link
Member

waruqi commented Sep 25, 2023

我这里可以,应该是优先用了你系统安装的 linux-headers ,但是你的 linux-headers 版本跟 bpf 代码不匹配导致。。

可以改下 xmake.lua ,add_requires("linux-headers", {system = false}) 强制走 xmake-repo 仓库的 linux-header 版本试试

  => install linux-headers 5.16.9 .. ok
configure
{
    kind = static
    arch = x86_64
    host = linux
    clean = true
    buildir = build
    ndk_stdcxx = true
    plat = linux
    ccache = true
    mode = release
}
ruki@0670fbc641d6:/mnt/xmake/tests/projects/linux/bpf/minimal$ xmake -rv
checking for the c compiler (cc) ... clang
checking for flags (-O3) ... ok
checking for flags (-DNDEBUG) ... ok
[ 20%]: compiling.bpf src/minimal.bpf.c
/usr/lib/llvm-15/bin/clang -c -Qunused-arguments -m64 -fvisibility=hidden -O3 -Ibuild/.gens/minimal/linux/x86_64/release/rules/bpf -isystem /home/ruki/.xmake/packages/l/linux-headers/5.16.9/b91d1c6942fb4a8dbe3966154df72863/include -isystem /home/ruki/.xmake/packages/l/libbpf/v0.3/1580e2873bd94b0aad0763599ebba227/include -isystem /home/ruki/.xmake/packages/l/libbpf/v0.3/1580e2873bd94b0aad0763599ebba227/include/uapi -isystem /home/ruki/.xmake/packages/l/libelf/0.8.13/6e832e45281b46079dad3aa1ffc4fb39/include -isystem /home/ruki/.xmake/packages/l/libelf/0.8.13/6e832e45281b46079dad3aa1ffc4fb39/include/libelf -isystem /home/ruki/.xmake/packages/z/zlib/v1.3/a22e9c20d1164438a547d3a64f770c7f/include -DNDEBUG -target bpf -g -O2 -D__TARGET_ARCH_x86 -o build/.gens/minimal/linux/x86_64/release/rules/bpf/minimal.bpf.o src/minimal.bpf.c
[ 40%]: cache compiling.release src/minimal.c
/usr/lib/llvm-15/bin/clang -c -Qunused-arguments -m64 -fvisibility=hidden -O3 -Ibuild/.gens/minimal/linux/x86_64/release/rules/bpf -isystem /home/ruki/.xmake/packages/l/linux-headers/5.16.9/b91d1c6942fb4a8dbe3966154df72863/include -isystem /home/ruki/.xmake/packages/l/libbpf/v0.3/1580e2873bd94b0aad0763599ebba227/include -isystem /home/ruki/.xmake/packages/l/libbpf/v0.3/1580e2873bd94b0aad0763599ebba227/include/uapi -isystem /home/ruki/.xmake/packages/l/libelf/0.8.13/6e832e45281b46079dad3aa1ffc4fb39/include -isystem /home/ruki/.xmake/packages/l/libelf/0.8.13/6e832e45281b46079dad3aa1ffc4fb39/include/libelf -isystem /home/ruki/.xmake/packages/z/zlib/v1.3/a22e9c20d1164438a547d3a64f770c7f/include -DNDEBUG -o build/.objs/minimal/linux/x86_64/release/src/minimal.c.o src/minimal.c
checking for flags (-MMD -MF) ... ok
checking for the linker (ld) ... clang++
[ 60%]: linking.release minimal
/usr/lib/llvm-15/bin/clang++ -o build/linux/x86_64/release/minimal build/.objs/minimal/linux/x86_64/release/src/minimal.c.o -m64 -L/home/ruki/.xmake/packages/l/libbpf/v0.3/1580e2873bd94b0aad0763599ebba227/lib -L/home/ruki/.xmake/packages/l/libelf/0.8.13/6e832e45281b46079dad3aa1ffc4fb39/lib -L/home/ruki/.xmake/packages/z/zlib/v1.3/a22e9c20d1164438a547d3a64f770c7f/lib -s -lbpf -lelf -lz
[100%]: build ok, spent 1.331s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants