diff mbox series

[bpf-next] bpftool: fix linkage with statically built libllvm

Message ID 20221221103007.1311799-1-aspsk@isovalent.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpftool: fix linkage with statically built libllvm | expand

Checks

Context Check Description
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 15 maintainers not CCed: trix@redhat.com ast@kernel.org kpsingh@kernel.org haoluo@google.com song@kernel.org daniel@iogearbox.net yhs@fb.com llvm@lists.linux.dev andrii@kernel.org martin.lau@linux.dev sdf@google.com ndesaulniers@google.com john.fastabend@gmail.com nathan@kernel.org jolsa@kernel.org
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/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-7 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-8 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-2 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for test_maps on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 success Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 success Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 success Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-16 fail Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on s390x with gcc

Commit Message

Anton Protopopov Dec. 21, 2022, 10:30 a.m. UTC
Since the eb9d1acf634b commit ("bpftool: Add LLVM as default library for
disassembling JIT-ed programs") we might link the bpftool program with the
libllvm library.  This works fine when a dynamically built libllvm available,
but fails if we want to link bpftool with a statically built llvm:

    /usr/bin/ld: /usr/local/lib/libLLVMSupport.a(CrashRecoveryContext.cpp.o): in function `llvm::CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup()':
    CrashRecoveryContext.cpp:(.text._ZN4llvm27CrashRecoveryContextCleanupD0Ev+0x17): undefined reference to `operator delete(void*, unsigned long)'
    /usr/bin/ld: /usr/local/lib/libLLVMSupport.a(CrashRecoveryContext.cpp.o): in function `llvm::CrashRecoveryContext::~CrashRecoveryContext()':
    CrashRecoveryContext.cpp:(.text._ZN4llvm20CrashRecoveryContextD2Ev+0xc8): undefined reference to `operator delete(void*, unsigned long)'
    ...

To fix this we need to explicitly link bpftool with required libraries, namely,
libstdc++ and those provided by `llvm-config --system-libs`.  This patch
doesn't change the build with a dynamically built libllvm, as the `llvm-config
--system-libs` list is empty in this case, and the bpftool is linked with the
libstdc++ in any case as this is a dynamic dependency of libLLVM.so.

eb9d1acf634b commit ("bpftool: Add LLVM as default library for disassembling JIT-ed programs")
Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
---
 tools/bpf/bpftool/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stanislav Fomichev Dec. 21, 2022, 7:33 p.m. UTC | #1
On 12/21, Anton Protopopov wrote:
> Since the eb9d1acf634b commit ("bpftool: Add LLVM as default library for
> disassembling JIT-ed programs") we might link the bpftool program with the
> libllvm library.  This works fine when a dynamically built libllvm  
> available,
> but fails if we want to link bpftool with a statically built llvm:

>      /usr/bin/ld:  
> /usr/local/lib/libLLVMSupport.a(CrashRecoveryContext.cpp.o): in function  
> `llvm::CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup()':
>       
> CrashRecoveryContext.cpp:(.text._ZN4llvm27CrashRecoveryContextCleanupD0Ev+0x17):  
> undefined reference to `operator delete(void*, unsigned long)'
>      /usr/bin/ld:  
> /usr/local/lib/libLLVMSupport.a(CrashRecoveryContext.cpp.o): in function  
> `llvm::CrashRecoveryContext::~CrashRecoveryContext()':
>       
> CrashRecoveryContext.cpp:(.text._ZN4llvm20CrashRecoveryContextD2Ev+0xc8):  
> undefined reference to `operator delete(void*, unsigned long)'
>      ...

> To fix this we need to explicitly link bpftool with required libraries,  
> namely,
> libstdc++ and those provided by `llvm-config --system-libs`.  This patch
> doesn't change the build with a dynamically built libllvm, as the  
> `llvm-config
> --system-libs` list is empty in this case, and the bpftool is linked with  
> the
> libstdc++ in any case as this is a dynamic dependency of libLLVM.so.

> eb9d1acf634b commit ("bpftool: Add LLVM as default library for  
> disassembling JIT-ed programs")
> Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
> ---
>   tools/bpf/bpftool/Makefile | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index 787b857d3fb5..e4c15095eac7 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -144,7 +144,7 @@ ifeq ($(feature-llvm),1)
>     CFLAGS  += -DHAVE_LLVM_SUPPORT
>     LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
>     CFLAGS  += $(shell $(LLVM_CONFIG) --cflags --libs  
> $(LLVM_CONFIG_LIB_COMPONENTS))
> -  LIBS    += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> +  LIBS    += $(shell $(LLVM_CONFIG) --libs --system-libs  
> $(LLVM_CONFIG_LIB_COMPONENTS)) -lstdc++


Why not do separate lines? We can then maybe do a bit safer approach?

LIBS += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
ifeq ($(USE_STATIC_COMPONENTS), static)
LIBS += $(shell $(LLVM_CONFIG) --system-libs))
LIBS += -lstdc++
endif

Can we use `llvm-config --shared-mode` to get USE_STATIC_COMPONENTS?

>     LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
>   else
>     # Fall back on libbfd
> --
> 2.34.1
Anton Protopopov Dec. 22, 2022, 10:20 a.m. UTC | #2
On 22/12/21 11:33, sdf@google.com wrote:
> On 12/21, Anton Protopopov wrote:
> >   [...]
> 
> > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > index 787b857d3fb5..e4c15095eac7 100644
> > --- a/tools/bpf/bpftool/Makefile
> > +++ b/tools/bpf/bpftool/Makefile
> > @@ -144,7 +144,7 @@ ifeq ($(feature-llvm),1)
> >     CFLAGS  += -DHAVE_LLVM_SUPPORT
> >     LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
> >     CFLAGS  += $(shell $(LLVM_CONFIG) --cflags --libs
> > $(LLVM_CONFIG_LIB_COMPONENTS))
> > -  LIBS    += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> > +  LIBS    += $(shell $(LLVM_CONFIG) --libs --system-libs
> > $(LLVM_CONFIG_LIB_COMPONENTS)) -lstdc++
> 
> 
> Why not do separate lines? We can then maybe do a bit safer approach?
> 
> LIBS += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
> ifeq ($(USE_STATIC_COMPONENTS), static)
> LIBS += $(shell $(LLVM_CONFIG) --system-libs))
> LIBS += -lstdc++
> endif
> 
> Can we use `llvm-config --shared-mode` to get USE_STATIC_COMPONENTS?

Thanks, I didn't know about the --shared-mode thing. I will send the v2.

> 
> >     LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
> >   else
> >     # Fall back on libbfd
> > --
> > 2.34.1
>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 787b857d3fb5..e4c15095eac7 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -144,7 +144,7 @@  ifeq ($(feature-llvm),1)
   CFLAGS  += -DHAVE_LLVM_SUPPORT
   LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
   CFLAGS  += $(shell $(LLVM_CONFIG) --cflags --libs $(LLVM_CONFIG_LIB_COMPONENTS))
-  LIBS    += $(shell $(LLVM_CONFIG) --libs $(LLVM_CONFIG_LIB_COMPONENTS))
+  LIBS    += $(shell $(LLVM_CONFIG) --libs --system-libs $(LLVM_CONFIG_LIB_COMPONENTS)) -lstdc++
   LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
 else
   # Fall back on libbfd