diff mbox series

[bpf-next] libbpf: fix build issue with llvm-readelf

Message ID 20220204211302.302066-1-yhs@fb.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] libbpf: fix build issue with llvm-readelf | expand

Checks

Context Check Description
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 8 maintainers not CCed: kpsingh@kernel.org john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com nathan@kernel.org llvm@lists.linux.dev netdev@vger.kernel.org ndesaulniers@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch fail ERROR: Avoid using diff content in the commit message - patch(1) might not work
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yonghong Song Feb. 4, 2022, 9:13 p.m. UTC
There are cases where clang compiler is packaged in a way
readelf is a symbolic link to llvm-readelf. In such cases,
llvm-readelf will be used instead of default binutils readelf,
and the following error will appear during libbpf build:

  Warning: Num of global symbols in
   /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/sharedobjs/libbpf-in.o (367)
   does NOT match with num of versioned symbols in
   /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.so libbpf.map (383).
   Please make sure all LIBBPF_API symbols are versioned in libbpf.map.
  --- /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_global_syms.tmp ...
  +++ /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_versioned_syms.tmp ...
  @@ -324,6 +324,22 @@
   btf__str_by_offset
   btf__type_by_id
   btf__type_cnt
  +LIBBPF_0.0.1
  +LIBBPF_0.0.2
  +LIBBPF_0.0.3
  +LIBBPF_0.0.4
  +LIBBPF_0.0.5
  +LIBBPF_0.0.6
  +LIBBPF_0.0.7
  +LIBBPF_0.0.8
  +LIBBPF_0.0.9
  +LIBBPF_0.1.0
  +LIBBPF_0.2.0
  +LIBBPF_0.3.0
  +LIBBPF_0.4.0
  +LIBBPF_0.5.0
  +LIBBPF_0.6.0
  +LIBBPF_0.7.0
   libbpf_attach_type_by_name
   libbpf_find_kernel_btf
   libbpf_find_vmlinux_btf_id
  make[2]: *** [Makefile:184: check_abi] Error 1
  make[1]: *** [Makefile:140: all] Error 2

The above failure is due to different printouts for some ABS
versioned symbols. For example, with the same libbpf.so,
  $ /bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
     134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.5.0
     202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.6.0
     ...
  $ /opt/llvm/bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
     134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.5.0@@LIBBPF_0.5.0
     202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.6.0@@LIBBPF_0.6.0
     ...
The binutils readelf doesn't print out the symbol LIBBPF_* version and llvm-readelf does.
Such a difference caused libbpf build failure with llvm-readelf.

To fix the issue, let us do proper filtering for LIBBPF_*@@LIBBPF_* symbols.
The proposed fix works for both binutils readelf and llvm-readelf.

Reported-by: Delyan Kratunov <delyank@fb.com>
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/lib/bpf/Makefile | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko Feb. 4, 2022, 9:31 p.m. UTC | #1
On Fri, Feb 4, 2022 at 1:13 PM Yonghong Song <yhs@fb.com> wrote:
>
> There are cases where clang compiler is packaged in a way
> readelf is a symbolic link to llvm-readelf. In such cases,
> llvm-readelf will be used instead of default binutils readelf,
> and the following error will appear during libbpf build:
>
>   Warning: Num of global symbols in
>    /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/sharedobjs/libbpf-in.o (367)
>    does NOT match with num of versioned symbols in
>    /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.so libbpf.map (383).
>    Please make sure all LIBBPF_API symbols are versioned in libbpf.map.
>   --- /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_global_syms.tmp ...
>   +++ /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_versioned_syms.tmp ...
>   @@ -324,6 +324,22 @@
>    btf__str_by_offset
>    btf__type_by_id
>    btf__type_cnt
>   +LIBBPF_0.0.1
>   +LIBBPF_0.0.2
>   +LIBBPF_0.0.3
>   +LIBBPF_0.0.4
>   +LIBBPF_0.0.5
>   +LIBBPF_0.0.6
>   +LIBBPF_0.0.7
>   +LIBBPF_0.0.8
>   +LIBBPF_0.0.9
>   +LIBBPF_0.1.0
>   +LIBBPF_0.2.0
>   +LIBBPF_0.3.0
>   +LIBBPF_0.4.0
>   +LIBBPF_0.5.0
>   +LIBBPF_0.6.0
>   +LIBBPF_0.7.0
>    libbpf_attach_type_by_name
>    libbpf_find_kernel_btf
>    libbpf_find_vmlinux_btf_id
>   make[2]: *** [Makefile:184: check_abi] Error 1
>   make[1]: *** [Makefile:140: all] Error 2
>
> The above failure is due to different printouts for some ABS
> versioned symbols. For example, with the same libbpf.so,
>   $ /bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
>      134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.5.0
>      202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.6.0
>      ...
>   $ /opt/llvm/bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
>      134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.5.0@@LIBBPF_0.5.0
>      202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.6.0@@LIBBPF_0.6.0
>      ...
> The binutils readelf doesn't print out the symbol LIBBPF_* version and llvm-readelf does.
> Such a difference caused libbpf build failure with llvm-readelf.
>
> To fix the issue, let us do proper filtering for LIBBPF_*@@LIBBPF_* symbols.
> The proposed fix works for both binutils readelf and llvm-readelf.
>
> Reported-by: Delyan Kratunov <delyank@fb.com>
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
>  tools/lib/bpf/Makefile | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
> index f947b61b2107..d1577c26c16b 100644
> --- a/tools/lib/bpf/Makefile
> +++ b/tools/lib/bpf/Makefile
> @@ -132,7 +132,8 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
>  VERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so | \
>                               sed 's/\[.*\]//' | \
>                               awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \

have you tried just doing !/UND|ABS/ here?

> -                             grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
> +                             grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' | \
> +                             cut -d@ -f1 | sort -u | wc -l)
>
>  CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
>
> @@ -195,7 +196,8 @@ check_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
>                 readelf --dyn-syms --wide $(OUTPUT)libbpf.so |           \
>                     sed 's/\[.*\]//' |                                   \
>                     awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
> -                   grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
> +                   grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' |     \
> +                   cut -d@ -f1 |                                        \
>                     sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
>                 diff -u $(OUTPUT)libbpf_global_syms.tmp                  \
>                      $(OUTPUT)libbpf_versioned_syms.tmp;                 \
> --
> 2.30.2
>
Yonghong Song Feb. 4, 2022, 9:36 p.m. UTC | #2
On 2/4/22 1:31 PM, Andrii Nakryiko wrote:
> On Fri, Feb 4, 2022 at 1:13 PM Yonghong Song <yhs@fb.com> wrote:
>>
>> There are cases where clang compiler is packaged in a way
>> readelf is a symbolic link to llvm-readelf. In such cases,
>> llvm-readelf will be used instead of default binutils readelf,
>> and the following error will appear during libbpf build:
>>
>>    Warning: Num of global symbols in
>>     /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/sharedobjs/libbpf-in.o (367)
>>     does NOT match with num of versioned symbols in
>>     /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf.so libbpf.map (383).
>>     Please make sure all LIBBPF_API symbols are versioned in libbpf.map.
>>    --- /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_global_syms.tmp ...
>>    +++ /home/yhs/work/bpf-next/tools/testing/selftests/bpf/tools/build/libbpf/libbpf_versioned_syms.tmp ...
>>    @@ -324,6 +324,22 @@
>>     btf__str_by_offset
>>     btf__type_by_id
>>     btf__type_cnt
>>    +LIBBPF_0.0.1
>>    +LIBBPF_0.0.2
>>    +LIBBPF_0.0.3
>>    +LIBBPF_0.0.4
>>    +LIBBPF_0.0.5
>>    +LIBBPF_0.0.6
>>    +LIBBPF_0.0.7
>>    +LIBBPF_0.0.8
>>    +LIBBPF_0.0.9
>>    +LIBBPF_0.1.0
>>    +LIBBPF_0.2.0
>>    +LIBBPF_0.3.0
>>    +LIBBPF_0.4.0
>>    +LIBBPF_0.5.0
>>    +LIBBPF_0.6.0
>>    +LIBBPF_0.7.0
>>     libbpf_attach_type_by_name
>>     libbpf_find_kernel_btf
>>     libbpf_find_vmlinux_btf_id
>>    make[2]: *** [Makefile:184: check_abi] Error 1
>>    make[1]: *** [Makefile:140: all] Error 2
>>
>> The above failure is due to different printouts for some ABS
>> versioned symbols. For example, with the same libbpf.so,
>>    $ /bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
>>       134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.5.0
>>       202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LIBBPF_0.6.0
>>       ...
>>    $ /opt/llvm/bin/readelf --dyn-syms --wide tools/lib/bpf/libbpf.so | grep "LIBBPF" | grep ABS
>>       134: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.5.0@@LIBBPF_0.5.0
>>       202: 0000000000000000     0 OBJECT  GLOBAL DEFAULT   ABS LIBBPF_0.6.0@@LIBBPF_0.6.0
>>       ...
>> The binutils readelf doesn't print out the symbol LIBBPF_* version and llvm-readelf does.
>> Such a difference caused libbpf build failure with llvm-readelf.
>>
>> To fix the issue, let us do proper filtering for LIBBPF_*@@LIBBPF_* symbols.
>> The proposed fix works for both binutils readelf and llvm-readelf.
>>
>> Reported-by: Delyan Kratunov <delyank@fb.com>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   tools/lib/bpf/Makefile | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
>> index f947b61b2107..d1577c26c16b 100644
>> --- a/tools/lib/bpf/Makefile
>> +++ b/tools/lib/bpf/Makefile
>> @@ -132,7 +132,8 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
>>   VERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so | \
>>                                sed 's/\[.*\]//' | \
>>                                awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
> 
> have you tried just doing !/UND|ABS/ here?

It works and even simpler.
Thanks for suggestion. Will send v2.

> 
>> -                             grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
>> +                             grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' | \
>> +                             cut -d@ -f1 | sort -u | wc -l)
>>
>>   CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
>>
>> @@ -195,7 +196,8 @@ check_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
>>                  readelf --dyn-syms --wide $(OUTPUT)libbpf.so |           \
>>                      sed 's/\[.*\]//' |                                   \
>>                      awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
>> -                   grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |             \
>> +                   grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' |     \
>> +                   cut -d@ -f1 |                                        \
>>                      sort -u > $(OUTPUT)libbpf_versioned_syms.tmp;        \
>>                  diff -u $(OUTPUT)libbpf_global_syms.tmp                  \
>>                       $(OUTPUT)libbpf_versioned_syms.tmp;                 \
>> --
>> 2.30.2
>>
diff mbox series

Patch

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index f947b61b2107..d1577c26c16b 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -132,7 +132,8 @@  GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
 VERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so | \
 			      sed 's/\[.*\]//' | \
 			      awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}' | \
-			      grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
+			      grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' | \
+			      cut -d@ -f1 | sort -u | wc -l)
 
 CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
 
@@ -195,7 +196,8 @@  check_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
 		readelf --dyn-syms --wide $(OUTPUT)libbpf.so |		 \
 		    sed 's/\[.*\]//' |					 \
 		    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
-		    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |		 \
+		    grep -Eo '[^ ]+@LIBBPF_' | grep -Ev '^LIBBPF_' |	 \
+		    cut -d@ -f1 |					 \
 		    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp; 	 \
 		diff -u $(OUTPUT)libbpf_global_syms.tmp			 \
 		     $(OUTPUT)libbpf_versioned_syms.tmp;		 \