ROCm / ROCm-CompilerSupport

The compiler support repository provides various Lightning Compiler related services.
45 stars 31 forks source link

Link additional required LLVM libraries #19

Closed candrews closed 4 years ago

candrews commented 5 years ago

Without these additional required dependencies, linking fails with errors such as: undefined reference tollvm::errs()'`

candrews commented 5 years ago

This patch was originally authored by @davidrohr (https://github.com/justxi/rocm/pull/48) who has been working with @justxi and I to package ROC for Gentoo. I'm hoping they'll jump in here too.

Without these changes, I'm getting this error output:

[65/85] : && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -fPIC -O2 -march=native -pipe -fuse-linker-plugin -flto -ftree-vectorize -ftree-slp-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize  -Wl,-O1 -Wl,--as-needed -flto -Wl,--hash-style=gnu -shared -Wl,-soname,libamd_comgr.so -o libamd_comgr.so CMakeFiles/amd_comgr.dir/src/MsgPackReader.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-compiler.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-device-libs.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-disassembly.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-elfdump.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-metadata.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-msgpack.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-objdump.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-symbol.cpp.o CMakeFiles/amd_comgr.dir/src/comgr.cpp.o -L/usr/lib/llvm/roc/lib -Wl,-rpath,/usr/lib/llvm/roc/lib: -pthread -Wl,--version-script=/var/tmp/portage/dev-libs/rocm-comgr-2.6.0/work/ROCm-CompilerSupport-roc-2.6.0/lib/comgr/src/exportmap -Wl,--no-undefined /usr/lib64/libyaml-cpp.so.0.6.2 /usr/lib/llvm/roc/lib/libclangFrontendTool.so.9svn /usr/lib/llvm/roc/lib/libclangFrontend.so.9svn /usr/lib/llvm/roc/lib/libclangBasic.so.9svn /usr/lib/llvm/roc/lib/libclangDriver.so.9svn /usr/lib/llvm/roc/lib/libclangSerialization.so.9svn -llldELF -llldCommon /usr/lib/llvm/roc/lib/libLLVMAMDGPUCodeGen.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUAsmParser.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUDesc.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUDisassembler.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUInfo.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUUtils.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86CodeGen.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86AsmParser.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Desc.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Disassembler.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Info.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Utils.so.9svn /usr/lib/llvm/roc/lib/libLLVMDebugInfoDWARF.so.9svn /usr/lib/llvm/roc/lib/libLLVMSymbolize.so.9svn && :
FAILED: libamd_comgr.so 
: && /usr/lib/ccache/bin/x86_64-pc-linux-gnu-g++ -fPIC -O2 -march=native -pipe -fuse-linker-plugin -flto -ftree-vectorize -ftree-slp-vectorize -falign-functions=32 -fgraphite-identity -floop-nest-optimize  -Wl,-O1 -Wl,--as-needed -flto -Wl,--hash-style=gnu -shared -Wl,-soname,libamd_comgr.so -o libamd_comgr.so CMakeFiles/amd_comgr.dir/src/MsgPackReader.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-compiler.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-device-libs.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-disassembly.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-elfdump.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-metadata.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-msgpack.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-objdump.cpp.o CMakeFiles/amd_comgr.dir/src/comgr-symbol.cpp.o CMakeFiles/amd_comgr.dir/src/comgr.cpp.o -L/usr/lib/llvm/roc/lib -Wl,-rpath,/usr/lib/llvm/roc/lib: -pthread -Wl,--version-script=/var/tmp/portage/dev-libs/rocm-comgr-2.6.0/work/ROCm-CompilerSupport-roc-2.6.0/lib/comgr/src/exportmap -Wl,--no-undefined /usr/lib64/libyaml-cpp.so.0.6.2 /usr/lib/llvm/roc/lib/libclangFrontendTool.so.9svn /usr/lib/llvm/roc/lib/libclangFrontend.so.9svn /usr/lib/llvm/roc/lib/libclangBasic.so.9svn /usr/lib/llvm/roc/lib/libclangDriver.so.9svn /usr/lib/llvm/roc/lib/libclangSerialization.so.9svn -llldELF -llldCommon /usr/lib/llvm/roc/lib/libLLVMAMDGPUCodeGen.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUAsmParser.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUDesc.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUDisassembler.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUInfo.so.9svn /usr/lib/llvm/roc/lib/libLLVMAMDGPUUtils.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86CodeGen.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86AsmParser.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Desc.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Disassembler.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Info.so.9svn /usr/lib/llvm/roc/lib/libLLVMX86Utils.so.9svn /usr/lib/llvm/roc/lib/libLLVMDebugInfoDWARF.so.9svn /usr/lib/llvm/roc/lib/libLLVMSymbolize.so.9svn && :
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/dev-libs/rocm-comgr-2.6.0/temp/libamd_comgr.so.DFl0No.ltrans0.ltrans.o: in function `COMGR::msgpack::Reader::setError(llvm::Twine const&) [clone .constprop.0]':
<artificial>:(.text+0x2b1): undefined reference to `llvm::errs()'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: <artificial>:(.text+0x2bf): undefined reference to `llvm::Twine::print(llvm::raw_ostream&) const'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: <artificial>:(.text+0x2f1): undefined reference to `llvm::raw_ostream::write(unsigned char)'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/dev-libs/rocm-comgr-2.6.0/temp/libamd_comgr.so.DFl0No.ltrans0.ltrans.o: in function `llvm::SmallVectorTemplateBase<llvm::SmallString<128u>, false>::grow(unsigned long) [clone .constprop.0]':
<artificial>:(.text+0x89a): undefined reference to `llvm::report_bad_alloc_error(char const*, bool)'
/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/dev-libs/rocm-comgr-2.6.0/temp/libamd_comgr.so.DFl0No.ltrans0.ltrans.o: in function `std::enable_if<!std::is_array<llvm::StringError>::value, std::unique_ptr<llvm::StringError, std::default_delete<llvm::StringError> > >::type llvm::make_unique<llvm::StringError, llvm::StringRef&, llvm::object::object_error>(llvm::StringRef&, llvm::object::object_error&&) [clone .isra.0] [clone .constprop.0]':
<artificial>:(.text+0x8ec): undefined reference to `llvm::object::object_category()'

I have ROC llvm,lld,clang installed in /usr/lib/llvm/roc/

davidrohr commented 5 years ago

These I basically the errors I had as well. I actually didn't check in detail, and just added them as explicit dependency. If they should be added as transitive dependency, then this could also indicate that something is wrong with our llvm-roc package.

justxi commented 5 years ago

Hi, I tested the install script (ebuild) from @davidrohr and with the patch it worked. I am also interessted in understanding and solving this, because in the past there were other ROCM packages which needed additional dependencies to compile them succesfully.

scott-linder commented 5 years ago

That ld command-line should include libLLVMSupport, and does not, so something is certainly wrong. Can you find the copy of LLVMExports.cmake you are using? It might shed some light on how the dependencies are being defined. For example, I do see libLLVMAMDGPUCodeGen in the command-line you posted, and in my copy of LLVMExports.cmake I see a dependency from LLVMAMDGPUCodeGen to LLVMSupport:

set_target_properties(LLVMAMDGPUCodeGen PROPERTIES
  INTERFACE_LINK_LIBRARIES "LLVMAMDGPUDesc;LLVMAMDGPUInfo;LLVMAMDGPUUtils;LLVMAnalysis;LLVMAsmPrinter;LLVMBinaryFormat;LLVMCodeGen;LLVMCore;LLVMDemangle;LLVMGlobalISel;LLVMLinker;LLVMMC;LLVMMIRParser;LLVMScalarOpts;LLVMSelectionDAG;LLVMSupport;LLVMTarget;LLVMTransformUtils;LLVMVectorize;LLVMipo"
)

Not too long ago Comgr did explicitly mention these, but they were removed as they were considered redundant. I'm not sure what the correct approach is, but I think understanding why you are getting different behavior would help.

candrews commented 5 years ago

Here's my /usr/lib/llvm/roc/lib/cmake/llvm/LLVMExports.cmake

scott-linder commented 5 years ago

Thank you! Having a look definitely sheds some light on the strange behavior. I'm not sure what the difference is between your build of LLVM and mine, but the set_target_properties for the IMPORTED targets is completely absent from your copy. All I see is the add_library, which explains why none of the transitive dependencies are being propagated to the Comgr build.

My initial reaction is that this is an issue with the LLVM build, not with Comgr. I can't imagine why LLVM would intentionally omit INTERFACE_LINK_LIBRARIES on these IMPORTED targets?

candrews commented 5 years ago

@scott-linder I've updated this PR with the changes necessary to build comgr 2.8.0.

Do you have any further thoughts on this topic?

Thank you once again!

scott-linder commented 4 years ago

I'm still just not sure what build/install of LLVM reproduces this issue. If we land this PR, but our internal build does not rely on it (i.e. because our build of LLVM actually describes transitive dependencies correctly) then we are likely to keep breaking you going forward.

My preferred fix would be getting whatever LLVM build you are using to describe the transitive dependencies correctly. Do you have more information on how you are building/installing LLVM?

candrews commented 4 years ago

Do you have more information on how you are building/installing LLVM?

The build is pretty straightforward, here's the ebuild: https://github.com/gentoo/gentoo/blob/e800eb711b7372087af804f91c5cb14b8e7d35bf/sys-devel/llvm-roc/llvm-roc-2.9.0.ebuild

Hopefully that's understandable; if not, I'm happy to answer any questions.