[PATCH] perf llvm: fix check feature libclang faled to cope with latest llvm

From: Yang Jihong
Date: Sat Apr 16 2022 - 02:38:53 EST


For llvm13, perf build check libclang failed even if llmv libraries have been
installed in the system. The output file is as follows:

# cat ./build/feature/test-clang.make.output
/usr/local/lib/libLLVMSupport.a(Path.cpp.o): In function `llvm::sys::fs::expandTildeExpr(llvm::SmallVectorImpl<char>&)':
Path.cpp:(.text._ZN4llvm3sys2fsL15expandTildeExprERNS_15SmallVectorImplIcEE+0x13b): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/lib/libLLVMSupport.a(Path.cpp.o): In function `llvm::sys::path::home_directory(llvm::SmallVectorImpl<char>&) [clone .localalias.6]':
Path.cpp:(.text._ZN4llvm3sys4path14home_directoryERNS_15SmallVectorImplIcEE+0x88): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/lib/libclangDriver.a(Darwin.cpp.o): In function `clang::driver::toolchains::Darwin::addProfileRTLibs(llvm::opt::ArgList const&, llvm::SmallVector<char const*, 16u>&) const':
Darwin.cpp:(.text._ZNK5clang6driver10toolchains6Darwin16addProfileRTLibsERKN4llvm3opt7ArgListERNS3_11SmallVectorIPKcLj16EEE+0x217): undefined reference to `llvm::getInstrProfSectionName[abi:cxx11](llvm::InstrProfSectKind, llvm::Triple::ObjectFormatType, bool)'
collect2: error: ld returned 1 exit status

Because relevant link library is missing. For llvm13, getInstrProfSectionName
interface is in libLLVMInstrumentation, which is part of BPF component library.

The solution has been verified in the llvm13 environment, as following:

# make OUTPUT= CC=gcc CXX=g++ CFLAGS= CXXFLAGS= \
LDFLAGS="-static -Wl,-z,noexecstack" \
-C /home/aa/linux/tools/build/feature test-clang.bin V=1
make: Entering directory '/home/aa/linux/tools/build/feature'
g++ -MD -Wall -Werror -o test-clang.bin test-clang.cpp -static -Wl,-z,noexecstack > test-clang.make.output 2>&1 -std=gnu++14 \
-I/usr/local/include \
-L/usr/local/lib \
-Wl,--start-group -lclangBasic -lclangDriver \
-lclangFrontend -lclangEdit -lclangLex \
-lclangAST -Wl,--end-group \
-lLLVMBPFDisassembler -lLLVMMCDisassembler -lLLVMBPFAsmParser -lLLVMBPFCodeGen -lLLVMSelectionDAG -lLLVMipo -lLLVMInstrumentation -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMFrontendOpenMP -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMAsmPrinter -lLLVMDebugInfoMSF -lLLVMDebugInfoDWARF -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMAggressiveInstCombine -lLLVMTransformUtils -lLLVMBitWriter -lLLVMAnalysis -lLLVMProfileData -lLLVMObject -lLLVMTextAPI -lLLVMMCParser -lLLVMMC -lLLVMDebugInfoCodeView -lLLVMBitReader -lLLVMOption -lLLVMCore -lLLVMRemarks -lLLVMBitstreamReader -lLLVMBinaryFormat -lLLVMSupport -lLLVMDemangle \
-lrt -ldl -lpthread -lm -lz -ltinfo -lxml2 \
> test-clang.make.output 2>&1
make: Leaving directory '/home/aa/linux/tools/build/feature'

Signed-off-by: Yang Jihong <yangjihong1@xxxxxxxxxx>
---
tools/build/feature/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index de66e1cc0734..af667972cb88 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -322,7 +322,7 @@ $(OUTPUT)test-clang.bin:
-Wl,--start-group -lclangBasic -lclangDriver \
-lclangFrontend -lclangEdit -lclangLex \
-lclangAST -Wl,--end-group \
- $(shell $(LLVM_CONFIG) --libs Core option) \
+ $(shell $(LLVM_CONFIG) --libs Core option BPF) \
$(shell $(LLVM_CONFIG) --system-libs) \
> $(@:.bin=.make.output) 2>&1

--
2.30.GIT