mchalupa / dg

[LLVM Static Slicer] Various program analyses, construction of dependence graphs and program slicing of LLVM bitcode.
MIT License
484 stars 135 forks source link

Build failed #449

Open for-just-we opened 1 year ago

for-just-we commented 1 year ago

Environment is:

CMake message is:

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Build type not set. Setting default.
-- Build type: RelWithDebInfo
-- Found LLVM 11.0.0
-- Using LLVMConfig.cmake in: xxx/llvm-11.0.0/lib/cmake/llvm
-- LLVM binaries: xxx/llvm-11.0.0/bin
-- Linker detection: GNU ld
-- LLVM include dir: xxx/llvm-11.0.0/include
-- LLVM libraries dir: xxx/llvm-11.0.0/lib
-- LLVM definitions: -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-- Looking for headers in: xxx/llvm-11.0.0/include
-- Looking for libraries in: xxx/llvm-11.0.0/lib
-- LLVM linking: dynamic
-- SVF dir: xxx/SVF-2.3
-- SVF libraries dir: xxx/SVF-2.3/lib
-- SVF include dir: xxx/SVF-2.3/include
-- SVF libs: Svf;Cudd
-- Using compiler: /usr/bin/c++
-- Performing Test HAS_FUZZER
-- Performing Test HAS_FUZZER - Failed
-- Will NOT build fuzzing tests (requires Clang 6 or newer)
-- Using compilation flags: -O2 -g -DNDEBUG
-- Additional compilation flags:  -std=c++14 -fno-rtti -Wall -Wextra -fno-exceptions
-- CMAKE_INSTALL_LIBDIR: "lib"
-- CMAKE_INSTALL_INCLUDEDIR: "include"
-- Found Git: /usr/bin/git (found version "2.17.1") 
-- clang: xxx/llvm-11.0.0/bin/clang
-- llvm-link: xxx/llvm-11.0.0/bin/llvm-link
-- lli: xxx/llvm-11.0.0/bin/lli
-- opt: xxx/llvm-11.0.0/bin/opt
-- Performing test sanitizers_work with xxx/llvm-11.0.0/bin/clang
-- Performing test sanitizers_work with xxx/llvm-11.0.0/bin/clang - Success
-- Configuring done
-- Generating done
-- Build files have been written to: xxx/dg/build

build process is:

[  1%] Building CXX object lib/CMakeFiles/dganalysis.dir/BBlockBase.cpp.o
[  2%] Building CXX object lib/CMakeFiles/dgvra.dir/ValueRelations/Relations.cpp.o
[  2%] Building CXX object lib/CMakeFiles/dganalysis.dir/Debug.cpp.o
[  3%] Building CXX object tools/CMakeFiles/llvm-to-source.dir/llvm-to-source.cpp.o
[  3%] Building CXX object lib/CMakeFiles/dgcda.dir/ControlDependence/NTSCD.cpp.o
[  4%] Building CXX object lib/CMakeFiles/dganalysis.dir/Offset.cpp.o
[  6%] Linking CXX shared library libdgcda.so
[  6%] Built target dgcda
[  7%] Linking CXX shared library libdganalysis.so
[  7%] Built target dganalysis
[  7%] Building CXX object lib/CMakeFiles/dgdda.dir/MemorySSA/MemorySSA.cpp.o
[  9%] Building CXX object lib/CMakeFiles/dgdda.dir/MemorySSA/ModRef.cpp.o
[  8%] Building CXX object lib/CMakeFiles/dgdda.dir/MemorySSA/Definitions.cpp.o
[ 10%] Building CXX object lib/CMakeFiles/dgdda.dir/ReadWriteGraph/ReadWriteGraph.cpp.o
[ 10%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/PointerAnalysis.cpp.o
[ 12%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/Pointer.cpp.o
[ 12%] Linking CXX shared library libdgvra.so
[ 12%] Built target dgvra
[ 13%] Building CXX object lib/CMakeFiles/dgllvmvra.dir/llvm/ValueRelations/GraphBuilder.cpp.o
[ 14%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/PointerGraph.cpp.o
[ 14%] Building CXX object lib/CMakeFiles/dgllvmvra.dir/llvm/ValueRelations/GraphElements.cpp.o
[ 15%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/PointerGraphOptimizations.cpp.o
[ 17%] Building CXX object lib/CMakeFiles/dgllvmvra.dir/llvm/ValueRelations/RelationsAnalyzer.cpp.o
[ 17%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/PointerGraphValidator.cpp.o
[ 18%] Linking CXX executable llvm-to-source
/usr/bin/ld: 找不到 -lLLVM
collect2: error: ld returned 1 exit status
tools/CMakeFiles/llvm-to-source.dir/build.make:96: recipe for target 'tools/llvm-to-source' failed
make[2]: *** [tools/llvm-to-source] Error 1
CMakeFiles/Makefile2:1925: recipe for target 'tools/CMakeFiles/llvm-to-source.dir/all' failed
make[1]: *** [tools/CMakeFiles/llvm-to-source.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 19%] Building CXX object lib/CMakeFiles/dgpta.dir/PointerAnalysis/PointsToSet.cpp.o
[ 20%] Building CXX object lib/CMakeFiles/dgllvmvra.dir/llvm/ValueRelations/StructureAnalyzer.cpp.o
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp: In member function ‘bool dg::pta::PointerGraphValidator::checkOperands()’:
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘ALLOC’ not handled in switch [-Wswitch]
         switch (nd->getType()) {
                ^
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘CALL’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘CALL_FUNCPTR’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘CALL_RETURN’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘ENTRY’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘RETURN’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘FORK’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘JOIN’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘INVALIDATE_LOCALS’ not handled in switch [-Wswitch]
xxx/dg/lib/PointerAnalysis/PointerGraphValidator.cpp:125:16: warning: enumeration value ‘INVALIDATED’ not handled in switch [-Wswitch]
[ 20%] Building CXX object lib/CMakeFiles/dgllvmvra.dir/llvm/ValueRelations/ValueRelations.cpp.o
[ 21%] Linking CXX shared library libdgpta.so
[ 21%] Built target dgpta
[ 21%] Linking CXX shared library libdgdda.so
[ 21%] Built target dgdda
[ 23%] Linking CXX shared library libdgllvmvra.so
/usr/bin/ld: 找不到 -lLLVM
collect2: error: ld returned 1 exit status
lib/CMakeFiles/dgllvmvra.dir/build.make:162: recipe for target 'lib/libdgllvmvra.so' failed
make[2]: *** [lib/libdgllvmvra.so] Error 1
CMakeFiles/Makefile2:1406: recipe for target 'lib/CMakeFiles/dgllvmvra.dir/all' failed
make[1]: *** [lib/CMakeFiles/dgllvmvra.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2

It seems that dg could not link to LLVM, the default linking mode is dynamic link, and variable ${llvm} is set to LLVM. Is there any problems in here? How could I fix this?

mchalupa commented 1 year ago

Did you build LLVM as shared library? If not, either do that or you may try turning of dynamic linking.

for-just-we commented 1 year ago

Did you build LLVM as shared library? If not, either do that or you may try turning of dynamic linking.

It seems I did not add LLVM_BUILD_LLVM_DYLIB when build LLVM, is dynamic linking the default building mode of dg ? And if I want to build dg static link to LLVM, what should I do? Simply change LLVM_LINK_DYLIB to OFF?

mchalupa commented 1 year ago

is dynamic linking the default building mode of dg ? And if I want to build dg static link to LLVM, what should I do? Simply change LLVM_LINK_DYLIB to OFF?

The answer is "yes" for both questions ;)

for-just-we commented 1 year ago

questions

Thank you very much, I can build it successfully on my Ubuntu virtual machine. But there is a new problem, when I try to build it in the same way on MacOS + m2 (arm64 arch). There is always error : Undefined symbols for architecture arm64: llvm::Constant::get xxxx.

It seems dg could not successfully link to LLVM when statically build. Should I modify CMakelist.txt?

mchalupa commented 1 year ago

Should I modify CMakelist.txt?

I vaguely remember that there was some kind of this problem when statically linking on MacOS. If you know how to fix that, feel free to goo ahead and do it. You can also send a PR.

for-just-we commented 1 year ago

Should I modify CMakelist.txt?

I vaguely remember that there was some kind of this problem when statically linking on MacOS. If you know how to fix that, feel free to goo ahead and do it. You can also send a PR.

Ok, I will try, so could I first assume there would be no problem dynamically linking to LLVM on MacOS?