* [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm
@ 2022-12-22 10:26 Anton Protopopov
2022-12-22 17:06 ` sdf
2022-12-22 19:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Anton Protopopov @ 2022-12-22 10:26 UTC (permalink / raw)
To: bpf, Stanislav Fomichev, Quentin Monnet, Jean-Philippe Brucker
Cc: Anton Protopopov
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 shared libllvm library is 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)'
...
So in the case of static libllvm we need to explicitly link bpftool with
required libraries, namely, libstdc++ and those provided by the `llvm-config
--system-libs` command. We can distinguish between the shared and static cases
by using the `llvm-config --shared-mode` command.
eb9d1acf634b commit ("bpftool: Add LLVM as default library for disassembling JIT-ed programs")
Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
---
v2:
Use llvm-config to distinguish between shared and static modes (Stanislav)
tools/bpf/bpftool/Makefile | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index 313fd1b09189..ab20ecc5acce 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -145,6 +145,10 @@ ifeq ($(feature-llvm),1)
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))
+ ifeq ($(shell $(LLVM_CONFIG) --shared-mode),static)
+ LIBS += $(shell $(LLVM_CONFIG) --system-libs $(LLVM_CONFIG_LIB_COMPONENTS))
+ LIBS += -lstdc++
+ endif
LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
else
# Fall back on libbfd
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm
2022-12-22 10:26 [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm Anton Protopopov
@ 2022-12-22 17:06 ` sdf
2022-12-22 19:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: sdf @ 2022-12-22 17:06 UTC (permalink / raw)
To: Anton Protopopov; +Cc: bpf, Quentin Monnet, Jean-Philippe Brucker
On 12/22, 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 shared libllvm library is
> 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)'
> ...
> So in the case of static libllvm we need to explicitly link bpftool with
> required libraries, namely, libstdc++ and those provided by the
> `llvm-config
> --system-libs` command. We can distinguish between the shared and static
> cases
> by using the `llvm-config --shared-mode` command.
> eb9d1acf634b commit ("bpftool: Add LLVM as default library for
> disassembling JIT-ed programs")
> Signed-off-by: Anton Protopopov <aspsk@isovalent.com>
Acked-by: Stanislav Fomichev <sdf@google.com>
Thank you!
> ---
> v2:
> Use llvm-config to distinguish between shared and static modes
> (Stanislav)
> tools/bpf/bpftool/Makefile | 4 ++++
> 1 file changed, 4 insertions(+)
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index 313fd1b09189..ab20ecc5acce 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -145,6 +145,10 @@ ifeq ($(feature-llvm),1)
> 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))
> + ifeq ($(shell $(LLVM_CONFIG) --shared-mode),static)
> + LIBS += $(shell $(LLVM_CONFIG) --system-libs
> $(LLVM_CONFIG_LIB_COMPONENTS))
> + LIBS += -lstdc++
> + endif
> LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags)
> else
> # Fall back on libbfd
> --
> 2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm
2022-12-22 10:26 [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm Anton Protopopov
2022-12-22 17:06 ` sdf
@ 2022-12-22 19:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-12-22 19:20 UTC (permalink / raw)
To: Anton Protopopov; +Cc: bpf, sdf, quentin, jean-philippe
Hello:
This patch was applied to bpf/bpf.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Thu, 22 Dec 2022 10:26:27 +0000 you 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 shared libllvm library is 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)'
> ...
>
> [...]
Here is the summary with links:
- [bpf-next,v2] bpftool: fix linkage with statically built libllvm
https://git.kernel.org/bpf/bpf/c/55171f2930be
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-22 19:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22 10:26 [PATCH bpf-next v2] bpftool: fix linkage with statically built libllvm Anton Protopopov
2022-12-22 17:06 ` sdf
2022-12-22 19:20 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.