public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Anton Protopopov <aspsk@isovalent.com>
Cc: bpf@vger.kernel.org, Quentin Monnet <quentin@isovalent.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: Re: [PATCH bpf-next] bpftool: fix linkage with statically built libllvm
Date: Wed, 21 Dec 2022 11:33:57 -0800	[thread overview]
Message-ID: <Y6NfpU8zo6t3dEhC@google.com> (raw)
In-Reply-To: <20221221103007.1311799-1-aspsk@isovalent.com>

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


  reply	other threads:[~2022-12-21 19:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 10:30 [PATCH bpf-next] bpftool: fix linkage with statically built libllvm Anton Protopopov
2022-12-21 19:33 ` sdf [this message]
2022-12-22 10:20   ` Anton Protopopov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y6NfpU8zo6t3dEhC@google.com \
    --to=sdf@google.com \
    --cc=aspsk@isovalent.com \
    --cc=bpf@vger.kernel.org \
    --cc=jean-philippe@linaro.org \
    --cc=quentin@isovalent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox