Skip to contentSkip to conversation

resolve_btfids breaks kernel cross-compilation

DISCUSSION Seth Forshee 3 participants 8 messages Sep 16, 2020 – Sep 18, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

Thanks,
Seth

#1 lore raw
Quoted 21 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:
Quoted 8 lines

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

could you please share the command line and setup?

thanks,
jirka

#2 lore raw
Quoted 26 lines · Jiri Olsa
Quoted 25 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

Quoted 6 lines
Quoted 4 lines

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

could you please share the command line and setup?

I just reproduced.. checking on fix

jirka

#3 lore raw
Quoted 27 lines · Jiri Olsa
Quoted 26 lines · Jiri Olsa
Quoted 25 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

could you please share the command line and setup?

I just reproduced.. checking on fix

I still need to check on few things, but patch below should help

we might have a problem for cross builds with different endianity than the host because libbpf does not support reading BTF data with different endianity, and we get:

BTFIDS vmlinux
libbpf: non-native ELF endianness is not supported

jirka

---

tools/bpf/resolve_btfids/Makefile +2 -0
index a88cd4426398..d3c818b8d8d3 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 include ../../scripts/Makefile.include
+include ../../scripts/Makefile.arch
 
 ifeq ($(srctree),)
 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
@@ -29,6 +30,7 @@ endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
+ARCH     = $(HOSTARCH)
 
 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
 
#4 lore raw
Quoted 62 lines · Jiri Olsa
Quoted 27 lines · Jiri Olsa
Quoted 26 lines · Jiri Olsa
Quoted 25 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

could you please share the command line and setup?

I just reproduced.. checking on fix

I still need to check on few things, but patch below should help

we might have a problem for cross builds with different endianity than the host because libbpf does not support reading BTF data with different endianity, and we get:

BTFIDS vmlinux
libbpf: non-native ELF endianness is not supported

jirka

---

tools/bpf/resolve_btfids/Makefile +1 -0
index a88cd4426398..d3c818b8d8d3 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 include ../../scripts/Makefile.include
+include ../../scripts/Makefile.arch
 
 ifeq ($(srctree),)
 srctree := $(patsubst %/,%,$(dir $(CURDIR)))

tools/bpf/resolve_btfids/Makefile endif · line 36

Quoted 7 lines
tools/bpf/resolve_btfids/Makefile +1 -0
@@ -29,6 +30,7 @@ endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
+ARCH     = $(HOSTARCH)
 
 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
 

and I realized we can have CONFIG_DEBUG_INFO_BTF without CONFIG_BPF, so we need also fix below for such cases

jirka

---

scripts/link-vmlinux.sh +4 -1
index e6e2d9e5ff48..8a990933a690 100755
@@ -343,7 +343,10 @@ vmlinux_link vmlinux "${kallsymso}" ${btf_vmlinux_bin_o}
 # fill in BTF IDs
 if [ -n "${CONFIG_DEBUG_INFO_BTF}" ]; then
 info BTFIDS vmlinux
-${RESOLVE_BTFIDS} vmlinux
+if [ -z "${CONFIG_BPF}" ]; then
+  no_fail=--no-fail
+fi
+${RESOLVE_BTFIDS} $no_fail vmlinux
 fi
 
 if [ -n "${CONFIG_BUILDTIME_TABLE_SORT}" ]; then
#5 lore raw
In reply to Jiri Olsa
Quoted 33 lines · Jiri Olsa
Quoted 32 lines · Jiri Olsa
Quoted 31 lines · Jiri Olsa
Quoted 29 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

could you please share the command line and setup?

I just reproduced.. checking on fix

I still need to check on few things, but patch below should help

It does help with the word size problem, thanks.

Quoted 6 lines

we might have a problem for cross builds with different endianity than the host because libbpf does not support reading BTF data with different endianity, and we get:

BTFIDS vmlinux
libbpf: non-native ELF endianness is not supported

Yes, I see this now when cross building for s390.

Thanks,
Seth

Quoted 25 lines

jirka

---

tools/bpf/resolve_btfids/Makefile +2 -0
index a88cd4426398..d3c818b8d8d3 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 include ../../scripts/Makefile.include
+include ../../scripts/Makefile.arch
 
 ifeq ($(srctree),)
 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
@@ -29,6 +30,7 @@ endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
+ARCH     = $(HOSTARCH)
 
 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
 
#6 lore raw
Quoted 42 lines · Seth Forshee
Quoted 33 lines · Jiri Olsa
Quoted 32 lines · Jiri Olsa
Quoted 31 lines · Jiri Olsa
Quoted 29 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

could you please share the command line and setup?

I just reproduced.. checking on fix

I still need to check on few things, but patch below should help

It does help with the word size problem, thanks.

Quoted 8 lines
Quoted 6 lines

we might have a problem for cross builds with different endianity than the host because libbpf does not support reading BTF data with different endianity, and we get:

BTFIDS vmlinux
libbpf: non-native ELF endianness is not supported

Yes, I see this now when cross building for s390.

Andrii,
I read you might be already working on this?
https://lore.kernel.org/bpf/CAEf4Bza9tZ-Jj0dj9Ne0fmxa95t=9XxxJR+Ce=6hDmw_d8uVFA@mail.gmail.com/

thanks,
jirka

Quoted 30 lines

Thanks,
Seth

Quoted 25 lines

jirka

---

tools/bpf/resolve_btfids/Makefile +2 -0
index a88cd4426398..d3c818b8d8d3 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 include ../../scripts/Makefile.include
+include ../../scripts/Makefile.arch
 
 ifeq ($(srctree),)
 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
@@ -29,6 +30,7 @@ endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
+ARCH     = $(HOSTARCH)
 
 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
 
#7 lore raw
Quoted 48 lines · Jiri Olsa
Quoted 46 lines · Seth Forshee
Quoted 33 lines · Jiri Olsa
Quoted 32 lines · Jiri Olsa
Quoted 31 lines · Jiri Olsa
Quoted 29 lines · Seth Forshee

The requirement to build resolve_btfids whenever CONFIG_DEBUG_INFO_BTF is enabled breaks some cross builds. For example, when building a 64-bit powerpc kernel on amd64 I get:

Auto-detecting system features:
... libelf: [ [32mon[m ]
... zlib: [ [32mon[m ]
... bpf: [ [31mOFF[m ]

BPF API too old
make[6]: *** [Makefile:295: bpfdep] Error 1

The contents of tools/bpf/resolve_btfids/feature/test-bpf.make.output:

In file included from /home/sforshee/src/u-k/unstable/tools/arch/powerpc/include/uapi/asm/bitsperlong.h:11,

                  from /usr/include/asm-generic/int-ll64.h:12,
                  from /usr/include/asm-generic/types.h:7,
                  from /usr/include/x86_64-linux-gnu/asm/types.h:1,
                  from /home/sforshee/src/u-k/unstable/tools/include/linux/types.h:10,
                  from /home/sforshee/src/u-k/unstable/tools/include/uapi/linux/bpf.h:11,
                  from test-bpf.c:3:

/home/sforshee/src/u-k/unstable/tools/include/asm-generic/bitsperlong.h:14:2: error: #error Inconsistent word size. Check asm/bitsperlong.h
14 | #error Inconsistent word size. Check asm/bitsperlong.h
| ^~~~~

This is because tools/arch/powerpc/include/uapi/asm/bitsperlong.h sets __BITS_PER_LONG based on the predefinied compiler macro __powerpc64__, which is not defined by the host compiler. What can we do to get cross builds working again?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

could you please share the command line and setup?

I just reproduced.. checking on fix

I still need to check on few things, but patch below should help

It does help with the word size problem, thanks.

Quoted 4 lines

we might have a problem for cross builds with different endianity than the host because libbpf does not support reading BTF data with different endianity, and we get:

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

BTFIDS vmlinux
libbpf: non-native ELF endianness is not supported

Yes, I see this now when cross building for s390.

Andrii,
I read you might be already working on this?
https://lore.kernel.org/bpf/CAEf4Bza9tZ-Jj0dj9Ne0fmxa95t=9XxxJR+Ce=6hDmw_d8uVFA@mail.gmail.com/

Yes, it's one of the limitations I'm solving, stay tuned.

Quoted 34 lines

thanks,
jirka

Quoted 30 lines

Thanks,
Seth

Quoted 25 lines

jirka

---

tools/bpf/resolve_btfids/Makefile +2 -0
index a88cd4426398..d3c818b8d8d3 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 include ../../scripts/Makefile.include
+include ../../scripts/Makefile.arch
 
 ifeq ($(srctree),)
 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
@@ -29,6 +30,7 @@ endif
 AR       = $(HOSTAR)
 CC       = $(HOSTCC)
 LD       = $(HOSTLD)
+ARCH     = $(HOSTARCH)
 
 OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/