Skip to content

Commit 5000522

Browse files
Leo-YanKernel Patches Daemon
authored andcommitted
selftests/bpf: Avoid static LLVM linking for cross builds
The BPF selftests prefer static LLVM linking, which works for native builds but can break cross builds. Its --link-static output may include host-only libraries that are unavailable for the cross compilation, causing link failures. Avoid static LLVM linking for cross builds and use shared LLVM libraries instead. Native builds keep the existing behavior. Signed-off-by: Leo Yan <leo.yan@arm.com>
1 parent 4711abc commit 5000522

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tools/testing/selftests/bpf/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,15 @@ ifeq ($(feature-llvm),1)
194194
LLVM_CONFIG_LIB_COMPONENTS := mcdisassembler all-targets
195195
# both llvm-config and lib.mk add -D_GNU_SOURCE, which ends up as conflict
196196
LLVM_CFLAGS += $(filter-out -D_GNU_SOURCE,$(shell $(LLVM_CONFIG) --cflags))
197-
# Prefer linking statically if it's available, otherwise fallback to shared
198-
ifeq ($(shell $(LLVM_CONFIG) --link-static --libs >/dev/null 2>&1 && echo static),static)
197+
# Cross compilation must use dynamic linking to avoid unresolved library
198+
# dependencies. For native build, prefer linking statically if it's
199+
# available, otherwise fallback to shared.
200+
ifneq ($(ARCH), $(HOSTARCH))
201+
LLVM_LINK_STATIC :=
202+
else
203+
LLVM_LINK_STATIC := $(shell $(LLVM_CONFIG) --link-static --libs >/dev/null 2>&1 && echo y)
204+
endif
205+
ifeq ($(LLVM_LINK_STATIC),y)
199206
LLVM_LDLIBS += $(shell $(LLVM_CONFIG) --link-static --libs $(LLVM_CONFIG_LIB_COMPONENTS))
200207
LLVM_LDLIBS += $(filter-out -lxml2,$(shell $(LLVM_CONFIG) --link-static --system-libs $(LLVM_CONFIG_LIB_COMPONENTS)))
201208
LLVM_LDLIBS += -lstdc++

0 commit comments

Comments
 (0)