From aa49fcc4fba15594f5db947e9bf285fe5f145466 Mon Sep 17 00:00:00 2001 From: Eric Kilmer Date: Sat, 13 Feb 2021 11:22:32 -0500 Subject: [PATCH] Support LLVM 11 (#729) * Add guards based on LLVM version for 11 compatibility * Use remill LLVM 11 compat headers * CI support for LLVM 11 --- .github/workflows/ci.yml | 2 +- .github/workflows/vcpkg_ci.yml | 6 ++++-- mcsema/BC/Function.cpp | 13 +++++++++---- mcsema/BC/Optimize.cpp | 7 ++++++- scripts/docker-lifter-entrypoint.sh | 3 +++ tools/mcsema_lift/Lift.cpp | 4 ++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a06b629d0..50b917ca9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ jobs: needs: [VersionFile] strategy: matrix: - llvm: ["900", "1000"] + llvm: ["900", "1000", "1100"] ubuntu: ["20.04", "18.04"] steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/vcpkg_ci.yml b/.github/workflows/vcpkg_ci.yml index 07642551b..e6a1ff9be 100644 --- a/.github/workflows/vcpkg_ci.yml +++ b/.github/workflows/vcpkg_ci.yml @@ -18,7 +18,8 @@ jobs: - { name: 'ubuntu', tag: '20.04' } llvm: [ '9', - '10' + '10', + '11' ] runs-on: ubuntu-20.04 @@ -76,7 +77,8 @@ jobs: ] llvm: [ '9', - '10' + '10', + '11' ] runs-on: ${{ matrix.os }} diff --git a/mcsema/BC/Function.cpp b/mcsema/BC/Function.cpp index 5e7062171..eb9bbd453 100644 --- a/mcsema/BC/Function.cpp +++ b/mcsema/BC/Function.cpp @@ -25,7 +25,6 @@ #pragma clang diagnostic ignored "-Wswitch-enum" #include #include -#include #include #include #include @@ -47,6 +46,8 @@ #include #include #include +#include +#include #include #include #include @@ -211,7 +212,11 @@ static llvm::Function *GetValueTracer(void) { if (reg->type == gWordType && reg != pc_reg) { ss << reg->name << format; args.push_back( +#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) new llvm::LoadInst(reg->AddressOf(state_ptr, block), "", block)); +#else + new llvm::LoadInst(reg->type, reg->AddressOf(state_ptr, block), "", block)); +#endif } } ss << '\n'; @@ -1671,9 +1676,9 @@ static llvm::Function *LiftFunction(const NativeModule *cfg_module, return lifted_func; } -using Calls_t = std::vector; +using Calls_t = std::vector; -static bool ShouldInline(const llvm::CallSite &cs) { +static bool ShouldInline(const remill::compat::llvm::CallSite &cs) { if (!cs) { return false; } @@ -1686,7 +1691,7 @@ static Calls_t InlinableCalls(llvm::Function &func) { Calls_t out; for (auto &bb : func) { for (auto &inst : bb) { - auto cs = llvm::CallSite(&inst); + auto cs = remill::compat::llvm::CallSite(&inst); if (ShouldInline(cs)) { out.push_back(std::move(cs)); } diff --git a/mcsema/BC/Optimize.cpp b/mcsema/BC/Optimize.cpp index 05a0fc7dc..0c648b0d1 100644 --- a/mcsema/BC/Optimize.cpp +++ b/mcsema/BC/Optimize.cpp @@ -1539,7 +1539,12 @@ static void GlobalizeStateStructures(void) { llvm::PointerType::get(itp->getType(), 0)); ptr = TryGetRegAlias(ptr, offset); itp->replaceAllUsesWith( - new llvm::LoadInst(ptr, load->getName(), load)); +#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) + new llvm::LoadInst(ptr, load->getName(), load) +#else + new llvm::LoadInst(ptr->getType(), ptr, load->getName(), load) +#endif + ); to_remove.push_back(itp); } } diff --git a/scripts/docker-lifter-entrypoint.sh b/scripts/docker-lifter-entrypoint.sh index 9af50dfe2..a0a503616 100755 --- a/scripts/docker-lifter-entrypoint.sh +++ b/scripts/docker-lifter-entrypoint.sh @@ -56,6 +56,9 @@ case ${LLVM_VERSION} in llvm100*) V=10.0 ;; + llvm110*) + V=11.0 + ;; *) echo "Unknown LLVM version: ${LLVM_VERSION}" exit 1 diff --git a/tools/mcsema_lift/Lift.cpp b/tools/mcsema_lift/Lift.cpp index 9c728c912..4cc73ec94 100644 --- a/tools/mcsema_lift/Lift.cpp +++ b/tools/mcsema_lift/Lift.cpp @@ -305,7 +305,11 @@ struct ABILibsLoader { for (auto &alias : abi_lib->aliases()) { if (auto fn = llvm::dyn_cast(alias.getAliasee())) { +#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) CloneFunction(*fn, alias.getName()); +#else + CloneFunction(*fn, alias.getName().str()); +#endif } }