lifting-bits / mcsema

Framework for lifting x86, amd64, aarch64, sparc32, and sparc64 program binaries to LLVM bitcode
https://www.trailofbits.com/expertise/mcsema
GNU Affero General Public License v3.0
2.64k stars 343 forks source link

Building mcsema with clang12 error #768

Closed vladimirtelepov closed 2 years ago

vladimirtelepov commented 2 years ago

OS: Ubuntu20.04 CC=Clang-12 CXX=Clang++-12

this commands works fine:

git clone --depth 1 --single-branch --branch master https://github.com/lifting-bits/remill.git
git clone --depth 1 --single-branch --branch master https://github.com/lifting-bits/mcsema.git
git clone --branch master https://github.com/lifting-bits/anvill.git
( cd anvill && git checkout -b release_bc3183b bc3183b )
export CC="$(which clang)"
export CXX="$(which clang++)"
./remill/scripts/build.sh --llvm-version 12 --download-dir ./
pushd remill-build
sudo cmake --build . --target install
popd
mkdir anvill-build
pushd anvill-build
cmake -DVCPKG_ROOT=$(pwd)/../vcpkg_ubuntu-20.04_llvm-12_amd64 ../anvill

but

sudo cmake --build . --target install

fails with error message

[  3%] Checking the git repository for changes...
[  3%] Built target check_git_anvill
[  7%] Building CXX object libraries/version/CMakeFiles/anvill_version.dir/Version.cpp.o
[ 10%] Linking CXX static library libanvill_version.a
[ 10%] Built target anvill_version
[ 14%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/AArch64_C.cpp.o
[ 17%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/SPARC32_C.cpp.o
[ 21%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/SPARC64_C.cpp.o
[ 25%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/X86_C.cpp.o
[ 28%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/X86_FastCall.cpp.o
[ 32%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/X86_StdCall.cpp.o
[ 35%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/X86_ThisCall.cpp.o
[ 39%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/X86_64_SysV.cpp.o
[ 42%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/AllocationState.cpp.o
[ 46%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Arch/Arch.cpp.o
[ 50%] Building CXX object anvill/CMakeFiles/anvill.dir/src/TypeParser.cpp.o
[ 53%] Building CXX object anvill/CMakeFiles/anvill.dir/src/TypePrinter.cpp.o
[ 57%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Program.cpp.o
[ 60%] Building CXX object anvill/CMakeFiles/anvill.dir/src/RecoverMemRefs.cpp.o
[ 64%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Decl.cpp.o
[ 67%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Lift.cpp.o
[ 71%] Building CXX object anvill/CMakeFiles/anvill.dir/src/MCToIRLifter.cpp.o
[ 75%] Building CXX object anvill/CMakeFiles/anvill.dir/src/Optimize.cpp.o
/home/vladimir/programming/mcsema/anvill/anvill/src/Optimize.cpp:913:17: error: no member named 'createConstantPropagationPass' in namespace 'llvm'
  fpm.add(llvm::createConstantPropagationPass());
          ~~~~~~^
1 error generated.
make[2]: *** [anvill/CMakeFiles/anvill.dir/build.make:314: anvill/CMakeFiles/anvill.dir/src/Optimize.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:405: anvill/CMakeFiles/anvill.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
michaelbrownuc commented 2 years ago

You can patch the source by replacing createConstantPropagationPass with createInstSimplifyPass

This is an LLVM API change, I thought it was in 13, not 12 though.

vladimirtelepov commented 2 years ago

You can patch the source by replacing createConstantPropagationPass with createInstSimplifyPass

This is an LLVM API change, I thought it was in 13, not 12 though.

got this error

Optimize.cpp:913:17: error: no member named 'createInstSimplifyPass' in namespace 'llvm'
  fpm.add(llvm::createInstSimplifyPass());
          ~~~~~~^
1 error generated.
make[2]: *** [anvill/CMakeFiles/anvill.dir/build.make:314: anvill/CMakeFiles/anvill.dir/src/Optimize.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:405: anvill/CMakeFiles/anvill.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
vladimirtelepov commented 2 years ago

@michaelbrownuc any updates on issue? I tried build latest version(82c310697f1019bafee72265c490ac4aa959e2aa) but error still occur. File compiles after removing optimization. But other error occurs. image After removing quotes and next try other error occur. image image

michaelbrownuc commented 2 years ago

IIRC there are a few API changes to make, including the one in the second screenshot. In that case removing the -1 parameter should solve that compiler error.

vladimirtelepov commented 2 years ago

@michaelbrownuc now have this error image

vladimirtelepov commented 2 years ago

@invlpg seg_type is used and returned later in function GetSegmentType so just removing code doesnt work.

xathrya commented 2 years ago

simply removed that optimization and it compiles.

// fpm.add(llvm::createInstSimplifyPass());

Also "getTypeByName" is not in "llvm::Module" it seems? https://reviews.llvm.org/D78793

had to remove this code to get it compiling on llvm 12.

https://github.com/lifting-bits/mcsema/blob/87239ee2879b7ce7f8274a8b868d09bf0867acd3/mcsema/BC/Segment.cpp#L106

  auto seg_type = gModule->getTypeByName(type_name);
  if (seg_type) {
    return seg_type;
  }

getTypeByName is moved to other place. Try this, it work for me

auto seg_type = llvm::StructType::getTypeByName(gModule->getContext(), type_name);
vladimirtelepov commented 2 years ago

Thanks, it works.