All of lore.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 v2] bpftool: fix linkage with statically built libllvm
Date: Thu, 22 Dec 2022 09:06:24 -0800	[thread overview]
Message-ID: <Y6SOkLtwRfF1WTcK@google.com> (raw)
In-Reply-To: <20221222102627.1643709-1-aspsk@isovalent.com>

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


  reply	other threads:[~2022-12-22 17:06 UTC|newest]

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

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=Y6SOkLtwRfF1WTcK@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 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.