2023-02-08 08:18:53

by Thorsten Leemhuis

[permalink] [raw]
Subject: compile error due to relocation problems in tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)

Hi! My daily linux-next builds for Fedora 36, 37 and 38 failed due to a
compile error today. I lack time to investigate this properly currently
(sorry!), but wanted to report it at least briefly nevertheless.

See below for the error log. I noticed there where changes from Jiri
("tools/resolve_btfids: Compile resolve_btfids as host program") and Ian
("tools/resolve_btfids: Tidy HOST_OVERRIDES") merged yesterday that
touch the code in question, which made me wonder if they cause this. But
maybe my spec file (it's based on the one from Fedora rawhide's kernel)
is doing something it shouldn't do.

Here are the build errors:

On x86_64:

> + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=x86_64 'KCFLAGS= ' WITH_GCOV=0 -j2 bzImage
> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
> /usr/bin/ld: failed to set dynamic section sizes: bad value
> collect2: error: ld returned 1 exit status
> make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
> make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
> make: *** [Makefile:1438: tools/bpf/resolve_btfids] Error 2
> make: *** Waiting for unfinished jobs....

On arm64:

> + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=arm64 'KCFLAGS= ' WITH_GCOV=0 -j4 Image.gz
> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)(.text+0x21c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `stderr@@GLIBC_2.17'
> /usr/bin/ld: final link failed: bad value
> collect2: error: ld returned 1 exit status
> make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
> make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
> make: *** [Makefile:1439: tools/bpf/resolve_btfids] Error 2
> make: *** Waiting for unfinished jobs....

For complete logs click on the "builder-live.log" links on
https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5502791/


Yesterdays logs can be found here:
https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5495974/

Ciao, Thorsten


2023-02-08 09:27:50

by Jiri Olsa

[permalink] [raw]
Subject: Re: compile error due to relocation problems in tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)

On Wed, Feb 08, 2023 at 09:18:31AM +0100, Thorsten Leemhuis wrote:
> Hi! My daily linux-next builds for Fedora 36, 37 and 38 failed due to a
> compile error today. I lack time to investigate this properly currently
> (sorry!), but wanted to report it at least briefly nevertheless.
>
> See below for the error log. I noticed there where changes from Jiri
> ("tools/resolve_btfids: Compile resolve_btfids as host program") and Ian
> ("tools/resolve_btfids: Tidy HOST_OVERRIDES") merged yesterday that
> touch the code in question, which made me wonder if they cause this. But
> maybe my spec file (it's based on the one from Fedora rawhide's kernel)
> is doing something it shouldn't do.
>
> Here are the build errors:
>
> On x86_64:
>
> > + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=x86_64 'KCFLAGS= ' WITH_GCOV=0 -j2 bzImage
> > /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
> > /usr/bin/ld: failed to set dynamic section sizes: bad value
> > collect2: error: ld returned 1 exit status
> > make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
> > make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
> > make: *** [Makefile:1438: tools/bpf/resolve_btfids] Error 2
> > make: *** Waiting for unfinished jobs....
>
> On arm64:
>
> > + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=arm64 'KCFLAGS= ' WITH_GCOV=0 -j4 Image.gz
> > /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
> > /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)(.text+0x21c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `stderr@@GLIBC_2.17'
> > /usr/bin/ld: final link failed: bad value
> > collect2: error: ld returned 1 exit status
> > make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
> > make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
> > make: *** [Makefile:1439: tools/bpf/resolve_btfids] Error 2
> > make: *** Waiting for unfinished jobs....
>
> For complete logs click on the "builder-live.log" links on
> https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5502791/
>
>
> Yesterdays logs can be found here:
> https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5495974/
>
> Ciao, Thorsten

ciao ;-)

I managed to reproduce and patch below fixes the issue for me,
could you please test?

I have in stack several other fixes for this, would be great
if you could test them, I'll cc you

jirka


---
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index 2abdd85b4a08..ac548a7baa73 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -19,7 +19,7 @@ endif

# Overrides for the prepare step libraries.
HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
- CROSS_COMPILE=""
+ CROSS_COMPILE="" EXTRA_CFLAGS="$(HOSTCFLAGS)"

RM ?= rm
HOSTCC ?= gcc

2023-02-08 12:19:53

by Thorsten Leemhuis

[permalink] [raw]
Subject: Re: compile error due to relocation problems in tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)

On 08.02.23 10:24, Jiri Olsa wrote:
> On Wed, Feb 08, 2023 at 09:18:31AM +0100, Thorsten Leemhuis wrote:
>> Hi! My daily linux-next builds for Fedora 36, 37 and 38 failed due to a
>> compile error today. I lack time to investigate this properly currently
>> (sorry!), but wanted to report it at least briefly nevertheless.
>>
>> See below for the error log. I noticed there where changes from Jiri
>> ("tools/resolve_btfids: Compile resolve_btfids as host program") and Ian
>> ("tools/resolve_btfids: Tidy HOST_OVERRIDES") merged yesterday that
>> touch the code in question, which made me wonder if they cause this. But
>> maybe my spec file (it's based on the one from Fedora rawhide's kernel)
>> is doing something it shouldn't do.
>>
>> Here are the build errors:
>>
>> On x86_64:
>>
>>> + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=x86_64 'KCFLAGS= ' WITH_GCOV=0 -j2 bzImage
>>> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE
>>> /usr/bin/ld: failed to set dynamic section sizes: bad value
>>> collect2: error: ld returned 1 exit status
>>> make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.x86_64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
>>> make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
>>> make: *** [Makefile:1438: tools/bpf/resolve_btfids] Error 2
>>> make: *** Waiting for unfinished jobs....
>>
>> On arm64:
>>
>>> + /usr/bin/make -s 'HOSTCFLAGS=-O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mbranch-protection=standard -fasynchronous-unwind-tables -fstack-clash-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer' 'HOSTLDFLAGS=-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -specs=/usr/lib/rpm/redhat/redhat-package-notes' ARCH=arm64 'KCFLAGS= ' WITH_GCOV=0 -j4 Image.gz
>>> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `stderr@@GLIBC_2.17' which may bind externally can not be used when making a shared object; recompile with -fPIC
>>> /usr/bin/ld: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//libbpf/libbpf.a(libbpf-in.o)(.text+0x21c): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `stderr@@GLIBC_2.17'
>>> /usr/bin/ld: final link failed: bad value
>>> collect2: error: ld returned 1 exit status
>>> make[2]: *** [Makefile:87: /builddir/build/BUILD/kernel-next-20230208/linux-6.2.0-0.0.next.20230208.350.vanilla.fc38.aarch64/tools/bpf/resolve_btfids//resolve_btfids] Error 1
>>> make[1]: *** [Makefile:76: bpf/resolve_btfids] Error 2
>>> make: *** [Makefile:1439: tools/bpf/resolve_btfids] Error 2
>>> make: *** Waiting for unfinished jobs....
>>
>> For complete logs click on the "builder-live.log" links on
>> https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5502791/
>>
>>
>> Yesterdays logs can be found here:
>> https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/next/build/5495974/
>>
>> Ciao, Thorsten
>
> ciao ;-)
>
> I managed to reproduce and patch below fixes the issue for me,
> could you please test?

Yeah, that fixes is. Feel free to add a:

Tested-by: Thorsten Leemhuis <[email protected]>

> I have in stack several other fixes for this, would be great
> if you could test them, I'll cc you

Yeah, no problem.

Ciao, Thorsten

> ---
> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
> index 2abdd85b4a08..ac548a7baa73 100644
> --- a/tools/bpf/resolve_btfids/Makefile
> +++ b/tools/bpf/resolve_btfids/Makefile
> @@ -19,7 +19,7 @@ endif
>
> # Overrides for the prepare step libraries.
> HOST_OVERRIDES := AR="$(HOSTAR)" CC="$(HOSTCC)" LD="$(HOSTLD)" ARCH="$(HOSTARCH)" \
> - CROSS_COMPILE=""
> + CROSS_COMPILE="" EXTRA_CFLAGS="$(HOSTCFLAGS)"
>
> RM ?= rm
> HOSTCC ?= gcc
>