Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly link necessary LLVM libraries to target jit. #23

Open
SaltyChiang opened this issue Mar 1, 2024 · 0 comments
Open

Explicitly link necessary LLVM libraries to target jit. #23

SaltyChiang opened this issue Mar 1, 2024 · 0 comments

Comments

@SaltyChiang
Copy link

QDP-JIT links all available LLVM libraries to target jit by using LLVM_AVAILABLE_LIBS.

target_link_libraries( jit PUBLIC ${LLVM_AVAILABLE_LIBS} )

In some Linux distros like Debian, LLVM_AVAILABLE_LIBS contains both static and shared libraries in LLVM shipped with apt install llvm-dev, and acquires more packages to be installed, even though they are not actually needed. The log below shows the result of llvm-dev shipped with Debian 12, which is actually llvm-14.

message( STATUS "${LLVM_AVAILABLE_LIBS}" )
LLVMDemangle;LLVMSupport;LLVMTableGen;LLVMTableGenGlobalISel;LLVMCore;LLVMFuzzMutate;LLVMFileCheck;LLVMInterfaceStub;LLVMIRReader;LLVMCodeGen;LLVMSelectionDAG;LLVMAsmPrinter;LLVMMIRParser;LLVMGlobalISel;LLVMBinaryFormat;LLVMBitReader;LLVMBitWriter;LLVMBitstreamReader;LLVMDWARFLinker;LLVMExtensions;LLVMFrontendOpenACC;LLVMFrontendOpenMP;LLVMTransformUtils;LLVMInstrumentation;LLVMAggressiveInstCombine;LLVMInstCombine;LLVMScalarOpts;LLVMipo;LLVMVectorize;LLVMObjCARCOpts;LLVMCoroutines;LLVMCFGuard;LLVMLinker;LLVMAnalysis;LLVMLTO;LLVMMC;LLVMMCParser;LLVMMCDisassembler;LLVMMCA;LLVMObject;LLVMObjectYAML;LLVMOption;LLVMRemarks;LLVMDebuginfod;LLVMDebugInfoDWARF;LLVMDebugInfoGSYM;LLVMDebugInfoMSF;LLVMDebugInfoCodeView;LLVMDebugInfoPDB;LLVMSymbolize;LLVMDWP;LLVMExecutionEngine;LLVMInterpreter;LLVMJITLink;LLVMMCJIT;LLVMOrcJIT;LLVMOrcShared;LLVMOrcTargetProcess;LLVMRuntimeDyld;LLVMPerfJITEvents;LLVMTarget;LLVMAArch64CodeGen;LLVMAArch64AsmParser;LLVMAArch64Disassembler;LLVMAArch64Desc;LLVMAArch64Info;LLVMAArch64Utils;LLVMAMDGPUCodeGen;LLVMAMDGPUAsmParser;LLVMAMDGPUDisassembler;LLVMAMDGPUTargetMCA;LLVMAMDGPUDesc;LLVMAMDGPUInfo;LLVMAMDGPUUtils;LLVMARMCodeGen;LLVMARMAsmParser;LLVMARMDisassembler;LLVMARMDesc;LLVMARMInfo;LLVMARMUtils;LLVMAVRCodeGen;LLVMAVRAsmParser;LLVMAVRDisassembler;LLVMAVRDesc;LLVMAVRInfo;LLVMBPFCodeGen;LLVMBPFAsmParser;LLVMBPFDisassembler;LLVMBPFDesc;LLVMBPFInfo;LLVMHexagonCodeGen;LLVMHexagonAsmParser;LLVMHexagonDisassembler;LLVMHexagonDesc;LLVMHexagonInfo;LLVMLanaiCodeGen;LLVMLanaiAsmParser;LLVMLanaiDisassembler;LLVMLanaiDesc;LLVMLanaiInfo;LLVMMipsCodeGen;LLVMMipsAsmParser;LLVMMipsDisassembler;LLVMMipsDesc;LLVMMipsInfo;LLVMMSP430CodeGen;LLVMMSP430Desc;LLVMMSP430Info;LLVMMSP430AsmParser;LLVMMSP430Disassembler;LLVMNVPTXCodeGen;LLVMNVPTXDesc;LLVMNVPTXInfo;LLVMPowerPCCodeGen;LLVMPowerPCAsmParser;LLVMPowerPCDisassembler;LLVMPowerPCDesc;LLVMPowerPCInfo;LLVMRISCVCodeGen;LLVMRISCVAsmParser;LLVMRISCVDisassembler;LLVMRISCVDesc;LLVMRISCVInfo;LLVMSparcCodeGen;LLVMSparcAsmParser;LLVMSparcDisassembler;LLVMSparcDesc;LLVMSparcInfo;LLVMSystemZCodeGen;LLVMSystemZAsmParser;LLVMSystemZDisassembler;LLVMSystemZDesc;LLVMSystemZInfo;LLVMVECodeGen;LLVMVEAsmParser;LLVMVEDisassembler;LLVMVEInfo;LLVMVEDesc;LLVMWebAssemblyCodeGen;LLVMWebAssemblyAsmParser;LLVMWebAssemblyDisassembler;LLVMWebAssemblyDesc;LLVMWebAssemblyInfo;LLVMWebAssemblyUtils;LLVMX86CodeGen;LLVMX86AsmParser;LLVMX86Disassembler;LLVMX86TargetMCA;LLVMX86Desc;LLVMX86Info;LLVMXCoreCodeGen;LLVMXCoreDisassembler;LLVMXCoreDesc;LLVMXCoreInfo;LLVMM68kCodeGen;LLVMM68kInfo;LLVMM68kDesc;LLVMM68kAsmParser;LLVMM68kDisassembler;LLVMAsmParser;LLVMLineEditor;LLVMProfileData;LLVMCoverage;LLVMPasses;LLVMTextAPI;LLVMDlltoolDriver;LLVMLibDriver;LLVMXRay;LLVMWindowsManifest;LTO;MLIRSupportIndentedOstream;LLVMCFIVerify;LLVMDiff;LLVMExegesisX86;LLVMExegesisAArch64;LLVMExegesisPowerPC;LLVMExegesisMips;LLVMExegesis;LLVM;Remarks;Polly

Here LLVMDebuginfod acquires CURL::libcurl, which means I have to install libcurl-openssl-dev and then add find_package(CURL REQUIRED) before find_package(LLVM "14.0" REQUIRED CONFIG).

Most of libraries above are static, but something like LLVM, Polly are actually shared libraries. Linking all of them to jit causes

$ ./t_basic 
: CommandLine Error: Option 'amdgpu-dump-hsa-metadata' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
[1]    2157571 IOT instruction  ./t_basic

$ ldd ./t_basic 
        linux-vdso.so.1 (0x00007ffc867fa000)
        libLLVM-14.so.1 => /usr/lib/llvm-14/lib/libLLVM-14.so.1 (0x00007f6414a00000)
        libcuda.so.1 => /usr/lib/x86_64-linux-gnu/nvidia/current/libcuda.so.1 (0x00007f6412c00000)
        libmpi.so.40 => /lib/x86_64-linux-gnu/libmpi.so.40 (0x00007f641f97f000)
        libxml2.so.2 => /lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f6412a54000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f6412800000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f6414921000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f641f95d000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f641261f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f641facf000)
        libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f641f951000)
        libedit.so.2 => /lib/x86_64-linux-gnu/libedit.so.2 (0x00007f641f917000)
        libz3.so.4 => /lib/x86_64-linux-gnu/libz3.so.4 (0x00007f6410e00000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f641b3e1000)
        libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f641b3ae000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f641f910000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f641b3a9000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f641b3a4000)
        libopen-rte.so.40 => /lib/x86_64-linux-gnu/libopen-rte.so.40 (0x00007f6412563000)
        libopen-pal.so.40 => /lib/x86_64-linux-gnu/libopen-pal.so.40 (0x00007f64124ac000)
        libhwloc.so.15 => /lib/x86_64-linux-gnu/libhwloc.so.15 (0x00007f641244f000)
        libicuuc.so.72 => /lib/x86_64-linux-gnu/libicuuc.so.72 (0x00007f6410c02000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f641b373000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f641b35b000)
        libevent_core-2.1.so.7 => /lib/x86_64-linux-gnu/libevent_core-2.1.so.7 (0x00007f64148eb000)
        libevent_pthreads-2.1.so.7 => /lib/x86_64-linux-gnu/libevent_pthreads-2.1.so.7 (0x00007f64148e6000)
        libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007f6412a26000)
        libicudata.so.72 => /lib/x86_64-linux-gnu/libicudata.so.72 (0x00007f640ee00000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f6412442000)

And ldd shows the executable requires LLVM-14.so, which is unnecessary.

I think we can filter out useless libraries from the list, and ensure that the final executables are fully statically or fully dynamically linked to LLVM.

FYI, I use

list(FILTER LLVM_AVAILABLE_LIBS INCLUDE REGEX "LLVM(MCJIT|.+(CodeGen|AsmParser))" )
target_link_libraries( jit PUBLIC ${LLVM_AVAILABLE_LIBS} ) 

to exclude unnecessary libraries, and the executable is statically linked against LLVM now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant