eshard/obfuscator-llvm

Failed to build in msys2 mingw-clang toolchain

tingtho opened this issue · 2 comments

enviroment, use the https://github.com/eshard/obfuscator-llvm/tree/fix-build-llvm-15-16 version

clang --version
clang version 15.0.5
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:/msys2/clang64/bin

Failed in last link stager.

[8/8] Linking CXX shared library libLLVMObfuscator.dll
FAILED: libLLVMObfuscator.dll libLLVMObfuscator.dll.a
cmd.exe /C "cd . && D:\msys2\clang64\bin\c++.exe -Wall -Wextra -Wno-unused-parameter   -shared -o libLLVMObfuscator.dll -Wl,--out-implib,libLLVMObfuscator.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/LLVMObfuscator.dir/Plugin.cpp.obj CMakeFiles/LLVMObfuscator.dir/utils/Utils.cpp.obj CMakeFiles/LLVMObfuscator.dir/utils/CryptoUtils.cpp.obj CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj CMakeFiles/LLVMObfuscator.dir/flattening/Flattening.cpp.obj CMakeFiles/LLVMObfuscator.dir/split/SplitBasicBlocks.cpp.obj CMakeFiles/LLVMObfuscator.dir/substitution/Substitution.cpp.obj  D:/msys2/clang64/lib/libLLVMCore.a  D:/msys2/clang64/lib/libLLVMSupport.a  D:/msys2/clang64/lib/libLLVMBinaryFormat.a  D:/msys2/clang64/lib/libLLVMRemarks.a  D:/msys2/clang64/lib/libLLVMBitstreamReader.a  D:/msys2/clang64/lib/libLLVMSupport.a  -lpsapi  -lshell32  -lole32  -luuid  -ladvapi32  D:/msys2/clang64/lib/libz.dll.a  D:/msys2/clang64/lib/libzstd.dll.a  D:/msys2/clang64/lib/libLLVMDemangle.a  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
ld.lld: error: undefined symbol: llvm::DemoteRegToStack(llvm::Instruction&, bool, llvm::Instruction*)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/utils/Utils.cpp.obj:(llvm::fixStack(llvm::Function*))

ld.lld: error: undefined symbol: llvm::DemotePHIToStack(llvm::PHINode*, llvm::Instruction*)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/utils/Utils.cpp.obj:(llvm::fixStack(llvm::Function*))

ld.lld: error: undefined symbol: llvm::Function::viewCFG() const
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::BogusControlFlow::bogus(llvm::Function&))
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::BogusControlFlow::bogus(llvm::Function&))
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::BogusControlFlow::doF(llvm::Module&))

ld.lld: error: undefined symbol: llvm::CloneBasicBlock(llvm::BasicBlock const*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::Twine const&, llvm::Function*, llvm::ClonedCodeInfo*, llvm::DebugInfoFinder*)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::BogusControlFlow::createAlteredBasicBlock(llvm::BasicBlock*, llvm::Twine const&, llvm::Function*))

ld.lld: error: undefined symbol: llvm::ValueMapper::ValueMapper(llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::RemapFlags, llvm::ValueMapTypeRemapper*, llvm::ValueMaterializer*)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::MapValue(llvm::Value const*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::RemapFlags, llvm::ValueMapTypeRemapper*, llvm::ValueMaterializer*))

ld.lld: error: undefined symbol: llvm::ValueMapper::mapValue(llvm::Value const&)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::MapValue(llvm::Value const*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::RemapFlags, llvm::ValueMapTypeRemapper*, llvm::ValueMaterializer*))

ld.lld: error: undefined symbol: llvm::ValueMapper::~ValueMapper()
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::MapValue(llvm::Value const*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::RemapFlags, llvm::ValueMapTypeRemapper*, llvm::ValueMaterializer*))
>>> referenced by CMakeFiles/LLVMObfuscator.dir/bogus/BogusControlFlow.cpp.obj:(llvm::MapValue(llvm::Value const*, llvm::ValueMap<llvm::Value const*, llvm::WeakTrackingVH, llvm::ValueMapConfig<llvm::Value const*, llvm::sys::SmartMutex<false>>>&, llvm::RemapFlags, llvm::ValueMapTypeRemapper*, llvm::ValueMaterializer*))

ld.lld: error: undefined symbol: llvm::LowerSwitchPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
>>> referenced by CMakeFiles/LLVMObfuscator.dir/flattening/Flattening.cpp.obj:(llvm::FlatteningObfuscatorPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&))
c++: error: linker command failed with exit code 1 (use -v to see invocation)

I guess you would need to add

LLVMTransformUtils for DemoteRegToStack

Can you try to add LLVMTransformUtils to target_link_libraries() in CMakeLists.txt ?,
It might pull the others symbols as well.

I guess you would need to add

LLVMTransformUtils for DemoteRegToStack

Can you try to add LLVMTransformUtils to target_link_libraries() in CMakeLists.txt ?, It might pull the others symbols as well.

:D
Already solved Thanks for your reply. Adding the following static library link will allow it to compile successfully under mysys2's mingw-clang
target_link_libraries(LLVMObfuscator LLVMCore LLVMSupport LLVMAnalysis LLVMTransformUtils)