From 66ef46be8a0ddb27d1bee7aa6f5fcd652a3a53cb Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Wed, 29 Jun 2022 00:21:54 +1000 Subject: [PATCH] Remove compatibility for LLVM < 14 (#606) * Remove compatibility with LLVM < 14 * Remove redundant VectorType compat file * Remove redundant Attributes compat file * Remove redundant BitcodeReaderWriter compat file * Remove redundant Verifier compat file * Remove redundant Cloning compat file * Remove redundant DebugInfo compat file * Remove redundant GlobalValue compat file * Remove redundant FileSystem compat file * Remove redundant JITSymbol compat file * Remove redundant TargetLibraryInfo compat file * Remove redundant ScalarTransforms compat file * Actually remove the file this time * Remove redundant ToolOutputFile compat file * Remove redundant DataLayout compat file * Move Error helpers out of Compat directory * Remove redundant CallSite compat file * Remove redundant RuntimeDyld compat file * Remove redundant CTypes compat file * Modify build script to exclude LLVM 13 * Update references to LLVM in README --- README.md | 10 +- include/remill/Arch/Arch.h | 2 - include/remill/BC/Annotate.h | 145 ------------ include/remill/BC/Compat/Attributes.h | 32 --- .../remill/BC/Compat/BitcodeReaderWriter.h | 26 -- include/remill/BC/Compat/CTypes.h | 30 --- include/remill/BC/Compat/CallSite.h | 104 -------- include/remill/BC/Compat/CallingConvention.h | 30 --- include/remill/BC/Compat/Cloning.h | 40 ---- include/remill/BC/Compat/DataLayout.h | 26 -- include/remill/BC/Compat/DebugInfo.h | 27 --- include/remill/BC/Compat/FileSystem.h | 30 --- include/remill/BC/Compat/GlobalValue.h | 32 --- include/remill/BC/Compat/IRReader.h | 37 --- include/remill/BC/Compat/JITSymbol.h | 28 --- include/remill/BC/Compat/RuntimeDyld.h | 21 -- include/remill/BC/Compat/ScalarTransforms.h | 25 -- include/remill/BC/Compat/TargetLibraryInfo.h | 32 --- include/remill/BC/Compat/ToolOutputFile.h | 27 --- include/remill/BC/Compat/VectorType.h | 38 --- include/remill/BC/Compat/Verifier.h | 25 -- include/remill/BC/{Compat => }/Error.h | 42 +--- include/remill/BC/Util.h | 1 - include/remill/BC/Version.h | 224 ++---------------- lib/Arch/Arch.cpp | 30 +-- lib/BC/Annotate.cpp | 3 - lib/BC/InstructionLifter.cpp | 2 +- lib/BC/InstructionLifter.h | 1 - lib/BC/Optimizer.cpp | 21 +- lib/BC/Util.cpp | 66 +----- scripts/build.sh | 6 +- 31 files changed, 47 insertions(+), 1116 deletions(-) delete mode 100644 include/remill/BC/Compat/Attributes.h delete mode 100644 include/remill/BC/Compat/BitcodeReaderWriter.h delete mode 100644 include/remill/BC/Compat/CTypes.h delete mode 100644 include/remill/BC/Compat/CallSite.h delete mode 100644 include/remill/BC/Compat/CallingConvention.h delete mode 100644 include/remill/BC/Compat/Cloning.h delete mode 100644 include/remill/BC/Compat/DataLayout.h delete mode 100644 include/remill/BC/Compat/DebugInfo.h delete mode 100644 include/remill/BC/Compat/FileSystem.h delete mode 100644 include/remill/BC/Compat/GlobalValue.h delete mode 100644 include/remill/BC/Compat/IRReader.h delete mode 100644 include/remill/BC/Compat/JITSymbol.h delete mode 100644 include/remill/BC/Compat/RuntimeDyld.h delete mode 100644 include/remill/BC/Compat/ScalarTransforms.h delete mode 100644 include/remill/BC/Compat/TargetLibraryInfo.h delete mode 100644 include/remill/BC/Compat/ToolOutputFile.h delete mode 100644 include/remill/BC/Compat/VectorType.h delete mode 100644 include/remill/BC/Compat/Verifier.h rename include/remill/BC/{Compat => }/Error.h (75%) diff --git a/README.md b/README.md index 9e860ec8..1aa66dca 100644 --- a/README.md +++ b/README.md @@ -40,8 +40,8 @@ Most of Remill's dependencies can be provided by the [cxx-common](https://github | [Google Flags](https://github.com/google/glog) | Latest | | [Google Log](https://github.com/google/glog) | Latest | | [Google Test](https://github.com/google/googletest) | Latest | -| [LLVM](http://llvm.org/) | 12 | -| [Clang](http://clang.llvm.org/) | 12 | +| [LLVM](http://llvm.org/) | 14 | +| [Clang](http://clang.llvm.org/) | 14 | | [Intel XED](https://software.intel.com/en-us/articles/xed-x86-encoder-decoder-software-library) | Latest | | [Python](https://www.python.org/) | 2.7 | | Unzip | Latest | @@ -55,7 +55,7 @@ Remill now comes with a Dockerfile for easier testing. This Dockerfile reference The Dockerfile allows for quick builds of multiple supported LLVM, architecture, and Linux configurations. -Quickstart (builds Remill against LLVM 12 on Ubuntu 20.04 for AMD64): +Quickstart (builds Remill against LLVM 14 on Ubuntu 20.04 for AMD64): Clone Remill: ```shell @@ -71,7 +71,7 @@ docker build . -t remill \ -f Dockerfile \ --build-arg UBUNTU_VERSION=20.04 \ --build-arg ARCH=amd64 \ - --build-arg LLVM_VERSION=12 + --build-arg LLVM_VERSION=14 ``` Ensure remill works: @@ -79,7 +79,7 @@ Ensure remill works: # Decode some AMD64 instructions to LLVM docker run --rm -it remill \ --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000 - + # Decode some AArch64 instructions to LLVM docker run --rm -it remill \ --arch aarch64 --address 0x400544 --ir_out /dev/stdout \ diff --git a/include/remill/Arch/Arch.h b/include/remill/Arch/Arch.h index 1920545e..9216b673 100644 --- a/include/remill/Arch/Arch.h +++ b/include/remill/Arch/Arch.h @@ -23,8 +23,6 @@ #pragma clang diagnostic ignored "-Wold-style-cast" #pragma clang diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wswitch-enum" -#include -#include #include #include diff --git a/include/remill/BC/Annotate.h b/include/remill/BC/Annotate.h index 9bccd5b4..100aad7e 100644 --- a/include/remill/BC/Annotate.h +++ b/include/remill/BC/Annotate.h @@ -72,13 +72,6 @@ DECLARE_FUNC_ORIGIN_TYPE(Semantics, Helper); // is supposed to be part of multiple pairs const std::string TieKind = "remill.function.tie"; -// Versions before LLVM-4.0 do not have metadata for functions. There is (probably) no reasonable way -// to simulate them, therefore older version do not provide this functionality. However, since these -// annotations are not crucial to lift itself, definition of functions are provided (so that project) -// compiles. They issue error and return negative answers and nullptrs. - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(4, 0) - template static bool Contains(llvm::MDString *node) { return node && node->getString().contains(OriginType::metadata_value); @@ -253,142 +246,4 @@ GetTieMapping(llvm::Module &module, const std::string &kind = TieKind) { std::vector{kind}); } -#else - -# define NOT_AVAILABLE(Err) \ - LOG(Err) \ - << "LLVM version is less than 4.0, functions metadata are not avalaible" - -template -static bool Contains(llvm::MDString *node) { - NOT_AVAILABLE(ERROR); - return false; -} - -template -static llvm::MDNode *GetNode(llvm::Function *func) { - NOT_AVAILABLE(ERROR); - return nullptr; -} - -template -static bool Remove(llvm::Function *func) { - NOT_AVAILABLE(ERROR); - return false; -} - -// Give function OriginType -template -static void Annotate(llvm::Function *func) { - NOT_AVAILABLE(ERROR); -} - -template -static bool HasOriginType(llvm::Function *func) { - NOT_AVAILABLE(ERROR); - return false; -} - -template -static bool HasOriginType(llvm::Function *func) { - NOT_AVAILABLE(ERROR); - return false; -} - -template -static void GetFunctionsByOrigin(llvm::Module &module, Container &result) { - NOT_AVAILABLE(ERROR); -} - -template -static Container GetFunctionsByOrigin(llvm::Module &module) { - NOT_AVAILABLE(ERROR); - return {}; -} - -template -static void ChangeOriginType(llvm::Function *func) { - NOT_AVAILABLE(ERROR); -} - -template -static bool ChangeOriginType(llvm::Function *func) { - NOT_AVAILABLE(ERROR); - return false; -} - -static inline llvm::MDNode *GetTieNode(llvm::Function *func, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return nullptr; -} - -static inline bool IsTied(llvm::Function *func, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return false; -} - -static inline llvm::MDNode *TieFunction(llvm::Function *first, - llvm::Function *second, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return nullptr; -} - -static inline std::pair -TieFunctions(llvm::Function *first, llvm::Function *second, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return {}; -} - -static inline llvm::Function *GetTied(llvm::Function *func, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return nullptr; -} - -template -static void -GetTieMapping(llvm::Module &module, BinaryPredicate pred, - std::unordered_map &result, - const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); -} - -template -static std::unordered_map -GetTieMapping(llvm::Module &module, BinaryPredicate pred, - const Container &kinds) { - NOT_AVAILABLE(ERROR); - return {}; -} - -template > -static std::unordered_map -GetTieMapping(llvm::Module &module, const Container &kinds) { - NOT_AVAILABLE(ERROR); - return {}; -} - -template -static std::unordered_map -GetTieMapping(llvm::Module &module, const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return {}; -} - -static inline std::unordered_map -GetTieMapping(llvm::Module &module, const std::string &kind = TieKind) { - NOT_AVAILABLE(ERROR); - return {}; -} - -# undef NOT_AVAILABLE - -#endif - - } // namespace remill diff --git a/include/remill/BC/Compat/Attributes.h b/include/remill/BC/Compat/Attributes.h deleted file mode 100644 index b4cf8892..00000000 --- a/include/remill/BC/Compat/Attributes.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include "remill/BC/Version.h" - -namespace llvm { -namespace AttributeLoc { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(5, 0) -constexpr auto ReturnIndex = llvm::AttributeSet::ReturnIndex; -constexpr auto FunctionIndex = llvm::AttributeSet::FunctionIndex; -#else -constexpr auto ReturnIndex = llvm::AttributeList::ReturnIndex; -constexpr auto FunctionIndex = llvm::AttributeList::FunctionIndex; -#endif -} // namespace AttributeLoc -} // namespace llvm diff --git a/include/remill/BC/Compat/BitcodeReaderWriter.h b/include/remill/BC/Compat/BitcodeReaderWriter.h deleted file mode 100644 index 87b483b4..00000000 --- a/include/remill/BC/Compat/BitcodeReaderWriter.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(4, 0) -# include -# include -#else -# include -#endif diff --git a/include/remill/BC/Compat/CTypes.h b/include/remill/BC/Compat/CTypes.h deleted file mode 100644 index d497ad38..00000000 --- a/include/remill/BC/Compat/CTypes.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if __has_include() -# include - -namespace llvm { - -// TODO(pag): This is a rather ugly hack; had some issues with anvill not -// compiling on macOS due to these C types. -struct LLVMOpaqueNamedMDNode; -using LLVMNamedMDNodeRef = struct LLVMOpaqueNamedMDNode *; -} // namespace llvm - -#endif diff --git a/include/remill/BC/Compat/CallSite.h b/include/remill/BC/Compat/CallSite.h deleted file mode 100644 index 12bca93a..00000000 --- a/include/remill/BC/Compat/CallSite.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2021 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include "remill/BC/Version.h" - - -/* In llvm-11 llvm::CallSite got partially replace by llvm::AbstractCallSite - * for read-only operations and llvm::CallBase was made public (was considered - * implementation before) - * This header tries to provide at least some compatibility for what is - * currently used. - */ - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) - -# include -namespace remill::compat::llvm { - -struct CallSite : private ::llvm::CallSite { - using parent = ::llvm::CallSite; - - /* List of "allowed" methods (thanks to private inheritance) - * that prevent user from accidentally using functionality that - * would break other llvm version. - * If you want to add method here, make sure other versions have it - * as well. - */ - using parent::isCall; - using parent::parent; - using parent::operator bool; - using parent::getCalledFunction; - using parent::getCalledValue; - using parent::getInstruction; - using parent::setCalledFunction; -}; - -} // namespace remill::compat::llvm - -#else - -# include -# include -# include -namespace remill::compat::llvm { - -struct CallSite { - ::llvm::CallBase *cb; - - CallSite(::llvm::Instruction *inst) - : cb(::llvm::dyn_cast_or_null<::llvm::CallBase>(inst)) {} - - CallSite(::llvm::User *user) - : CallSite(::llvm::dyn_cast_or_null<::llvm::Instruction>(user)) {} - - bool isCall() const { - return cb && ::llvm::isa<::llvm::CallInst>(*cb); - } - - ::llvm::Value *getCalledValue() { - if (!static_cast(*this)) { - return nullptr; - } - return cb->getCalledOperand(); - } - - ::llvm::Function *getCalledFunction() const { - if (!*this) { - return nullptr; - } - return cb->getCalledFunction(); - } - - void setCalledFunction(::llvm::Function *fn) { - return cb->setCalledFunction(fn); - } - - operator bool() const { - return cb; - } - - ::llvm::CallBase *getInstruction() { - return cb; - } -}; - -} // namespace remill::compat::llvm - -#endif diff --git a/include/remill/BC/Compat/CallingConvention.h b/include/remill/BC/Compat/CallingConvention.h deleted file mode 100644 index 4a131068..00000000 --- a/include/remill/BC/Compat/CallingConvention.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include "remill/BC/Version.h" - -namespace llvm { -namespace CallingConv { - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(5, 0) -constexpr auto Win64 = X86_64_Win64; -#endif - -} // namespace CallingConv -} // namespace llvm diff --git a/include/remill/BC/Compat/Cloning.h b/include/remill/BC/Compat/Cloning.h deleted file mode 100644 index 4f83b903..00000000 --- a/include/remill/BC/Compat/Cloning.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2021 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "remill/BC/Version.h" - -/* This compatibility relates to the changes made in CallSite.h. - */ - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(11, 0) - -#include -#include -#include - -namespace llvm { - - inline static InlineResult InlineFunction(CallBase *CB, InlineFunctionInfo &IFI, - AAResults *CalleeAAR = nullptr, - bool InsertLifetime = true, - Function *ForwardVarArgsTo = nullptr) { - return InlineFunction(*CB, IFI, CalleeAAR, InsertLifetime, ForwardVarArgsTo); - } - -} // namespace llvm - -#endif diff --git a/include/remill/BC/Compat/DataLayout.h b/include/remill/BC/Compat/DataLayout.h deleted file mode 100644 index ee5c1294..00000000 --- a/include/remill/BC/Compat/DataLayout.h +++ /dev/null @@ -1,26 +0,0 @@ -#include - -namespace remill { - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(10, 0) -inline static uint64_t TypeSizeToBits(uint64_t bits) { - return bits; -} -inline static uint64_t BitsToTypeSize(uint64_t size) { - return size; -} -#else -inline static uint64_t TypeSizeToBits(llvm::TypeSize type_type) { - return type_type.getFixedSize(); -} -inline static llvm::TypeSize BitsToTypeSize(uint64_t size) { - return llvm::TypeSize::Fixed(size); -} -#endif - -inline static uint64_t SizeOfTypeInBits(const llvm::DataLayout &data_layout, - llvm::Type *type) { - return TypeSizeToBits(data_layout.getTypeSizeInBits(type)); -} - -} // namespace remill diff --git a/include/remill/BC/Compat/DebugInfo.h b/include/remill/BC/Compat/DebugInfo.h deleted file mode 100644 index 1bba5ed3..00000000 --- a/include/remill/BC/Compat/DebugInfo.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 7) -# include -#else -# include -#endif - -#include diff --git a/include/remill/BC/Compat/FileSystem.h b/include/remill/BC/Compat/FileSystem.h deleted file mode 100644 index dba2fc47..00000000 --- a/include/remill/BC/Compat/FileSystem.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(5, 0) -# include -#endif - -namespace llvm { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(5, 0) -using file_magic = llvm::sys::fs::file_magic; -#endif -} // namespace llvm diff --git a/include/remill/BC/Compat/GlobalValue.h b/include/remill/BC/Compat/GlobalValue.h deleted file mode 100644 index 7c4f4b5c..00000000 --- a/include/remill/BC/Compat/GlobalValue.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once -#include - -#include "remill/BC/Version.h" - -namespace remill { - -inline static llvm::Type *GetValueType(llvm::GlobalValue *global) { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 7) - return global->getType()->getElementType(); -#else - return global->getValueType(); -#endif -} - -} // namespace remill diff --git a/include/remill/BC/Compat/IRReader.h b/include/remill/BC/Compat/IRReader.h deleted file mode 100644 index 369ee2a8..00000000 --- a/include/remill/BC/Compat/IRReader.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 6) - -namespace llvm { -class Module; - -template -inline static std::unique_ptr parseIRFile(Args &... args) { - return std::unique_ptr(ParseIRFile(args...)); -} - -} // namespace llvm - -#endif diff --git a/include/remill/BC/Compat/JITSymbol.h b/include/remill/BC/Compat/JITSymbol.h deleted file mode 100644 index a5fd7faf..00000000 --- a/include/remill/BC/Compat/JITSymbol.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(4, 0) -# include -namespace llvm { -using JITSymbol = llvm::RuntimeDyld::SymbolInfo; -using JITSymbolResolver = llvm::RuntimeDyld::SymbolResolver; -} // namespace llvm -#else -# include -#endif diff --git a/include/remill/BC/Compat/RuntimeDyld.h b/include/remill/BC/Compat/RuntimeDyld.h deleted file mode 100644 index f9594ebc..00000000 --- a/include/remill/BC/Compat/RuntimeDyld.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include - -#include "remill/BC/Version.h" diff --git a/include/remill/BC/Compat/ScalarTransforms.h b/include/remill/BC/Compat/ScalarTransforms.h deleted file mode 100644 index 9c0677ad..00000000 --- a/include/remill/BC/Compat/ScalarTransforms.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2019 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(7, 0) -# include -#endif diff --git a/include/remill/BC/Compat/TargetLibraryInfo.h b/include/remill/BC/Compat/TargetLibraryInfo.h deleted file mode 100644 index 6cf7d267..00000000 --- a/include/remill/BC/Compat/TargetLibraryInfo.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 7) -# include -#else -# include - -namespace llvm { - -using TargetLibraryInfoImpl = TargetLibraryInfo; - -} // namespace llvm - -#endif diff --git a/include/remill/BC/Compat/ToolOutputFile.h b/include/remill/BC/Compat/ToolOutputFile.h deleted file mode 100644 index 374ab607..00000000 --- a/include/remill/BC/Compat/ToolOutputFile.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2018 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(6, 0) -namespace llvm { -using ToolOutputFile = tool_output_file; -} // namespace llvm -#endif diff --git a/include/remill/BC/Compat/VectorType.h b/include/remill/BC/Compat/VectorType.h deleted file mode 100644 index fe842244..00000000 --- a/include/remill/BC/Compat/VectorType.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include "remill/BC/Version.h" - -// Hack in a 'FixedVectorType' for LLVM < 11 -namespace llvm { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) -using FixedVectorType = VectorType; -#endif - - -inline static constexpr auto GetFixedVectorTypeId(void) { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) - return Type::VectorTyID; -#else - return Type::FixedVectorTyID; -#endif -} - -} // namespace llvm diff --git a/include/remill/BC/Compat/Verifier.h b/include/remill/BC/Compat/Verifier.h deleted file mode 100644 index 64e1a600..00000000 --- a/include/remill/BC/Compat/Verifier.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (c) 2017 Trail of Bits, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "remill/BC/Version.h" - -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 5) -# include -#else -# include -#endif diff --git a/include/remill/BC/Compat/Error.h b/include/remill/BC/Error.h similarity index 75% rename from include/remill/BC/Compat/Error.h rename to include/remill/BC/Error.h index 3842fe61..f8dea4c1 100644 --- a/include/remill/BC/Compat/Error.h +++ b/include/remill/BC/Error.h @@ -18,15 +18,12 @@ #include #include #include +#include #include #include "remill/BC/Version.h" -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) -# include -#endif - namespace remill { template @@ -34,12 +31,10 @@ inline static bool IsError(llvm::ErrorOr &val) { return !val; } -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) template inline static bool IsError(llvm::Expected &val) { return !val; } -#endif template inline static bool IsError(T *ptr) { @@ -69,14 +64,11 @@ inline static std::string GetErrorString(llvm::Error &val) { return err; } -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) - template inline static std::string GetErrorString(llvm::Expected &val) { auto err = val.takeError(); return GetErrorString(err); } -#endif inline static std::error_code GetErrorCode(const char *) { return std::make_error_code(std::errc::invalid_argument); @@ -122,12 +114,10 @@ inline static T *GetPointer(llvm::ErrorOr &val) { return val.operator->(); } -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) template inline static T *GetPointer(llvm::Expected &val) { return val.operator->(); } -#endif template inline static T *GetPointer(T *val) { @@ -144,12 +134,10 @@ inline static T &GetReference(llvm::ErrorOr &val) { return val.operator*(); } -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) template inline static T &GetReference(llvm::Expected &val) { return val.operator*(); } -#endif template inline static T &GetReference(T *val) { @@ -162,31 +150,3 @@ inline static T &GetReference(T &val) { } } // namespace remill -namespace llvm { - -#if LLVM_VERSION_NUMBER <= LLVM_VERSION(6, 0) -inline static Error createStringError(std::error_code EC, char const *Msg) { - return make_error(Msg, EC); -} - -/// Create formatted StringError object. -template -inline static Error createStringError(std::error_code EC, char const *Fmt, - const Ts &... Vals) { - std::string Buffer; - raw_string_ostream Stream(Buffer); - Stream << format(Fmt, Vals...); - return make_error(Stream.str(), EC); -} -#endif - -#if LLVM_VERSION_NUMBER <= LLVM_VERSION(8, 0) - -template -inline static Error createStringError(std::errc EC, char const *Fmt, - const Ts &... Vals) { - return createStringError(std::make_error_code(EC), Fmt, Vals...); -} -#endif - -} // namespace llvm diff --git a/include/remill/BC/Util.h b/include/remill/BC/Util.h index 8d386cca..f9ae2f4d 100644 --- a/include/remill/BC/Util.h +++ b/include/remill/BC/Util.h @@ -23,7 +23,6 @@ #pragma clang diagnostic ignored "-Wold-style-cast" #pragma clang diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wswitch-enum" -#include #include #include #include diff --git a/include/remill/BC/Version.h b/include/remill/BC/Version.h index ceb7cc59..e25982c6 100644 --- a/include/remill/BC/Version.h +++ b/include/remill/BC/Version.h @@ -29,216 +29,24 @@ #define LLVM_VERSION_NUMBER LLVM_VERSION(LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR) -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 5) -# error "Minimum supported LLVM version is 3.5" -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(5, 0) -# define IF_LLVM_LT_500(...) __VA_ARGS__ -# define IF_LLVM_LT_500_(...) __VA_ARGS__, -# define _IF_LLVM_LT_500(...) , __VA_ARGS__ -# define IF_LLVM_GTE_500(...) -# define IF_LLVM_GTE_500_(...) -# define _IF_LLVM_GTE_500(...) -#else -# define IF_LLVM_LT_500(...) -# define IF_LLVM_LT_500_(...) -# define _IF_LLVM_LT_500(...) -# define IF_LLVM_GTE_500(...) __VA_ARGS__ -# define IF_LLVM_GTE_500_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_500(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(4, 0) -# define IF_LLVM_LT_400(...) __VA_ARGS__ -# define IF_LLVM_LT_400_(...) __VA_ARGS__, -# define _IF_LLVM_LT_400(...) , __VA_ARGS__ -# define IF_LLVM_GTE_400(...) -# define IF_LLVM_GTE_400_(...) -# define _IF_LLVM_GTE_400(...) -#else -# define IF_LLVM_LT_400(...) -# define IF_LLVM_LT_400_(...) -# define _IF_LLVM_LT_400(...) -# define IF_LLVM_GTE_400(...) __VA_ARGS__ -# define IF_LLVM_GTE_400_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_400(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 9) -# define IF_LLVM_LT_390(...) __VA_ARGS__ -# define IF_LLVM_LT_390_(...) __VA_ARGS__, -# define _IF_LLVM_LT_390(...) , __VA_ARGS__ -# define IF_LLVM_GTE_390(...) -# define IF_LLVM_GTE_390_(...) -# define _IF_LLVM_GTE_390(...) -#else -# define IF_LLVM_LT_390(...) -# define IF_LLVM_LT_390_(...) -# define _IF_LLVM_LT_390(...) -# define IF_LLVM_GTE_390(...) __VA_ARGS__ -# define IF_LLVM_GTE_390_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_390(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 8) -# define IF_LLVM_LT_380(...) __VA_ARGS__ -# define IF_LLVM_LT_380_(...) __VA_ARGS__, -# define _IF_LLVM_LT_380(...) , __VA_ARGS__ -# define IF_LLVM_GTE_380(...) -# define IF_LLVM_GTE_380_(...) -# define _IF_LLVM_GTE_380(...) -#else -# define IF_LLVM_LT_380(...) -# define IF_LLVM_LT_380_(...) -# define _IF_LLVM_LT_380(...) -# define IF_LLVM_GTE_380(...) __VA_ARGS__ -# define IF_LLVM_GTE_380_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_380(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 7) -# define IF_LLVM_LT_370(...) __VA_ARGS__ -# define IF_LLVM_LT_370_(...) __VA_ARGS__, -# define _IF_LLVM_LT_370(...) , __VA_ARGS__ -# define IF_LLVM_GTE_370(...) -# define IF_LLVM_GTE_370_(...) -# define _IF_LLVM_GTE_370(...) -#else -# define IF_LLVM_LT_370(...) -# define IF_LLVM_LT_370_(...) -# define _IF_LLVM_LT_370(...) -# define IF_LLVM_GTE_370(...) __VA_ARGS__ -# define IF_LLVM_GTE_370_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_370(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 6) -# define IF_LLVM_LT_360(...) __VA_ARGS__ -# define IF_LLVM_LT_360_(...) __VA_ARGS__, -# define _IF_LLVM_LT_360(...) , __VA_ARGS__ -# define IF_LLVM_GTE_360(...) -# define IF_LLVM_GTE_360_(...) -# define _IF_LLVM_GTE_360(...) -#else -# define IF_LLVM_LT_360(...) -# define IF_LLVM_LT_360_(...) -# define _IF_LLVM_LT_360(...) -# define IF_LLVM_GTE_360(...) __VA_ARGS__ -# define IF_LLVM_GTE_360_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_360(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(8, 0) -# define IF_LLVM_LT_800(...) __VA_ARGS__ -# define IF_LLVM_LT_800_(...) __VA_ARGS__, -# define _IF_LLVM_LT_800(...) , __VA_ARGS__ -# define IF_LLVM_GTE_800(...) -# define IF_LLVM_GTE_800_(...) -# define _IF_LLVM_GTE_800(...) -#else -# define IF_LLVM_LT_800(...) -# define IF_LLVM_LT_800_(...) -# define _IF_LLVM_LT_800(...) -# define IF_LLVM_GTE_800(...) __VA_ARGS__ -# define IF_LLVM_GTE_800_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_800(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(9, 0) -# define IF_LLVM_LT_900(...) __VA_ARGS__ -# define IF_LLVM_LT_900_(...) __VA_ARGS__, -# define _IF_LLVM_LT_900(...) , __VA_ARGS__ -# define IF_LLVM_GTE_900(...) -# define IF_LLVM_GTE_900_(...) -# define _IF_LLVM_GTE_900(...) -#else -# define IF_LLVM_LT_900(...) -# define IF_LLVM_LT_900_(...) -# define _IF_LLVM_LT_900(...) -# define IF_LLVM_GTE_900(...) __VA_ARGS__ -# define IF_LLVM_GTE_900_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_900(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(10, 0) -# define IF_LLVM_LT_1000(...) __VA_ARGS__ -# define IF_LLVM_LT_1000_(...) __VA_ARGS__, -# define _IF_LLVM_LT_1000(...) , __VA_ARGS__ -# define IF_LLVM_GTE_1000(...) -# define IF_LLVM_GTE_1000_(...) -# define _IF_LLVM_GTE_1000(...) -#else -# define IF_LLVM_LT_1000(...) -# define IF_LLVM_LT_1000_(...) -# define _IF_LLVM_LT_1000(...) -# define IF_LLVM_GTE_1000(...) __VA_ARGS__ -# define IF_LLVM_GTE_1000_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_1000(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) -# define IF_LLVM_LT_1100(...) __VA_ARGS__ -# define IF_LLVM_LT_1100_(...) __VA_ARGS__, -# define _IF_LLVM_LT_1100(...) , __VA_ARGS__ -# define IF_LLVM_GTE_1100(...) -# define IF_LLVM_GTE_1100_(...) -# define _IF_LLVM_GTE_1100(...) -#else -# define IF_LLVM_LT_1100(...) -# define IF_LLVM_LT_1100_(...) -# define _IF_LLVM_LT_1100(...) -# define IF_LLVM_GTE_1100(...) __VA_ARGS__ -# define IF_LLVM_GTE_1100_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_1100(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(12, 0) -# define IF_LLVM_LT_1200(...) __VA_ARGS__ -# define IF_LLVM_LT_1200_(...) __VA_ARGS__, -# define _IF_LLVM_LT_1200(...) , __VA_ARGS__ -# define IF_LLVM_GTE_1200(...) -# define IF_LLVM_GTE_1200_(...) -# define _IF_LLVM_GTE_1200(...) -#else -# define IF_LLVM_LT_1200(...) -# define IF_LLVM_LT_1200_(...) -# define _IF_LLVM_LT_1200(...) -# define IF_LLVM_GTE_1200(...) __VA_ARGS__ -# define IF_LLVM_GTE_1200_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_1200(...) , __VA_ARGS__ -#endif - -#if LLVM_VERSION_NUMBER < LLVM_VERSION(13, 0) -# define IF_LLVM_LT_1300(...) __VA_ARGS__ -# define IF_LLVM_LT_1300_(...) __VA_ARGS__, -# define _IF_LLVM_LT_1300(...) , __VA_ARGS__ -# define IF_LLVM_GTE_1300(...) -# define IF_LLVM_GTE_1300_(...) -# define _IF_LLVM_GTE_1300(...) -#else -# define IF_LLVM_LT_1300(...) -# define IF_LLVM_LT_1300_(...) -# define _IF_LLVM_LT_1300(...) -# define IF_LLVM_GTE_1300(...) __VA_ARGS__ -# define IF_LLVM_GTE_1300_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_1300(...) , __VA_ARGS__ -#endif - #if LLVM_VERSION_NUMBER < LLVM_VERSION(14, 0) -# define IF_LLVM_LT_1400(...) __VA_ARGS__ -# define IF_LLVM_LT_1400_(...) __VA_ARGS__, -# define _IF_LLVM_LT_1400(...) , __VA_ARGS__ -# define IF_LLVM_GTE_1400(...) -# define IF_LLVM_GTE_1400_(...) -# define _IF_LLVM_GTE_1400(...) +# error "Minimum supported LLVM version is 14.0" +#endif + +#if LLVM_VERSION_NUMBER < LLVM_VERSION(15, 0) +# define IF_LLVM_LT_1500(...) __VA_ARGS__ +# define IF_LLVM_LT_1500_(...) __VA_ARGS__, +# define _IF_LLVM_LT_1500(...) , __VA_ARGS__ +# define IF_LLVM_GTE_1500(...) +# define IF_LLVM_GTE_1500_(...) +# define _IF_LLVM_GTE_1500(...) #else -# define IF_LLVM_LT_1400(...) -# define IF_LLVM_LT_1400_(...) -# define _IF_LLVM_LT_1400(...) -# define IF_LLVM_GTE_1400(...) __VA_ARGS__ -# define IF_LLVM_GTE_1400_(...) __VA_ARGS__, -# define _IF_LLVM_GTE_1400(...) , __VA_ARGS__ +# define IF_LLVM_LT_1500(...) +# define IF_LLVM_LT_1500_(...) +# define _IF_LLVM_LT_1500(...) +# define IF_LLVM_GTE_1500(...) __VA_ARGS__ +# define IF_LLVM_GTE_1500_(...) __VA_ARGS__, +# define _IF_LLVM_GTE_1500(...) , __VA_ARGS__ #endif #define IF_LLVM_LT(major, minor, ...) IF_LLVM_LT_##major##minor##0(__VA_ARGS__) diff --git a/lib/Arch/Arch.cpp b/lib/Arch/Arch.cpp index d39bf08f..32e294eb 100644 --- a/lib/Arch/Arch.cpp +++ b/lib/Arch/Arch.cpp @@ -36,9 +36,6 @@ #include "remill/Arch/Name.h" #include "remill/BC/ABI.h" -#include "remill/BC/Compat/Attributes.h" -#include "remill/BC/Compat/DebugInfo.h" -#include "remill/BC/Compat/GlobalValue.h" #include "remill/BC/Util.h" #include "remill/BC/Version.h" #include "remill/OS/OS.h" @@ -401,10 +398,7 @@ static bool BlockHasSpecialVars(llvm::Function *basic_block) { // Add attributes to llvm::Argument in a way portable across LLVMs static void AddNoAliasToArgument(llvm::Argument *arg) { - IF_LLVM_LT_390(arg->addAttr(llvm::AttributeSet::get( - arg->getContext(), arg->getArgNo() + 1, llvm::Attribute::NoAlias));); - - IF_LLVM_GTE_390(arg->addAttr(llvm::Attribute::NoAlias);); + arg->addAttr(llvm::Attribute::NoAlias); } } // namespace @@ -612,12 +606,8 @@ llvm::Value *Register::AddressOf(llvm::Value *state_ptr, // Add the metadata to `inst`. if (auto inst = llvm::dyn_cast(ret); inst) { -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 6) auto reg_name_md = llvm::ValueAsMetadata::get(constant_name); auto reg_name_node = llvm::MDNode::get(context, reg_name_md); -#else - auto reg_name_node = llvm::MDNode::get(context, reg->constant_name); -#endif inst->setMetadata(arch->reg_md_id, reg_name_node); inst->setName(name); } @@ -643,23 +633,13 @@ void Arch::PrepareModuleDataLayout(llvm::Module *mod) const { llvm::AttributeSet target_attribs; - target_attribs = target_attribs.addAttribute( - context, - IF_LLVM_LT_500_(llvm::AttributeSet::FunctionIndex) "target-features"); - target_attribs = target_attribs.addAttribute( - context, IF_LLVM_LT_500_(llvm::AttributeSet::FunctionIndex) "target-cpu"); + target_attribs = target_attribs.addAttribute(context, "target-features"); + target_attribs = target_attribs.addAttribute(context, "target-cpu"); for (llvm::Function &func : *mod) { auto attribs = func.getAttributes(); - IF_LLVM_LT_1400( - attribs = attribs.removeAttributes( - context, llvm::AttributeLoc::FunctionIndex, target_attribs) - ); - - IF_LLVM_GTE_1400( - attribs = attribs.removeFnAttributes(context, llvm::AttributeMask(target_attribs)) - ); - + attribs = attribs.removeFnAttributes(context, + llvm::AttributeMask(target_attribs)); func.setAttributes(attribs); } } diff --git a/lib/BC/Annotate.cpp b/lib/BC/Annotate.cpp index 71dfa5db..373d4a37 100644 --- a/lib/BC/Annotate.cpp +++ b/lib/BC/Annotate.cpp @@ -54,8 +54,6 @@ const std::string McSemaHelper::metadata_value = const std::string Semantics::metadata_value = Helper::metadata_value + ".semantics"; -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(4, 0) - llvm::MDNode *TieFunction(llvm::Function *first, llvm::Function *second, const std::string &kind) { auto &C = first->getContext(); @@ -92,5 +90,4 @@ llvm::Function *GetTied(llvm::Function *func, const std::string &kind) { return llvm::dyn_cast(casted->getValue()); } -#endif } // namespace remill diff --git a/lib/BC/InstructionLifter.cpp b/lib/BC/InstructionLifter.cpp index 1f5bfed0..5461f945 100644 --- a/lib/BC/InstructionLifter.cpp +++ b/lib/BC/InstructionLifter.cpp @@ -381,7 +381,7 @@ llvm::Value *InstructionLifter::LiftShiftRegisterOperand( const llvm::DataLayout data_layout(module); auto reg = LoadRegValue(block, state_ptr, arch_reg.name); auto reg_type = reg->getType(); - auto reg_size = SizeOfTypeInBits(data_layout, reg_type); + auto reg_size = data_layout.getTypeSizeInBits(reg_type).getFixedSize(); auto word_size = impl->arch->address_size; auto op_type = llvm::Type::getIntNTy(context, op.size); diff --git a/lib/BC/InstructionLifter.h b/lib/BC/InstructionLifter.h index 9c890a6b..70a9a87c 100644 --- a/lib/BC/InstructionLifter.h +++ b/lib/BC/InstructionLifter.h @@ -47,7 +47,6 @@ #include "remill/Arch/Instruction.h" #include "remill/Arch/Name.h" #include "remill/BC/ABI.h" -#include "remill/BC/Compat/DataLayout.h" #include "remill/BC/IntrinsicTable.h" #include "remill/BC/Util.h" #include "remill/OS/OS.h" diff --git a/lib/BC/Optimizer.cpp b/lib/BC/Optimizer.cpp index aa4cf91d..0ed8966f 100644 --- a/lib/BC/Optimizer.cpp +++ b/lib/BC/Optimizer.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -37,8 +38,6 @@ #include #include "remill/Arch/Arch.h" -#include "remill/BC/Compat/ScalarTransforms.h" -#include "remill/BC/Compat/TargetLibraryInfo.h" #include "remill/BC/Util.h" namespace remill { @@ -64,15 +63,12 @@ void OptimizeModule(const remill::Arch *arch, llvm::Module *module, builder.Inliner = llvm::createFunctionInliningPass(250); builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`. builder.DisableUnrollLoops = false; // Unroll loops! - IF_LLVM_LT_900(builder.DisableUnitAtATime = false;) builder.RerollLoops = false; builder.SLPVectorize = guide.slp_vectorize; builder.LoopVectorize = guide.loop_vectorize; - IF_LLVM_GTE_360(builder.VerifyInput = guide.verify_input;) - IF_LLVM_GTE_360(builder.VerifyOutput = guide.verify_output;) - - // TODO(pag): Not sure when this became available. - IF_LLVM_GTE_800(builder.MergeFunctions = false;) + builder.VerifyInput = guide.verify_input; + builder.VerifyOutput = guide.verify_output; + builder.MergeFunctions = false; builder.populateFunctionPassManager(func_manager); builder.populateModulePassManager(module_manager); @@ -105,15 +101,12 @@ void OptimizeBareModule(llvm::Module *module, OptimizationGuide guide) { builder.Inliner = llvm::createFunctionInliningPass(250); builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`. builder.DisableUnrollLoops = false; // Unroll loops! - IF_LLVM_LT_900(builder.DisableUnitAtATime = false;) builder.RerollLoops = false; builder.SLPVectorize = guide.slp_vectorize; builder.LoopVectorize = guide.loop_vectorize; - IF_LLVM_GTE_360(builder.VerifyInput = guide.verify_input;) - IF_LLVM_GTE_360(builder.VerifyOutput = guide.verify_output;) - - // TODO(pag): Not sure when this became available. - IF_LLVM_GTE_800(builder.MergeFunctions = false;) + builder.VerifyInput = guide.verify_input; + builder.VerifyOutput = guide.verify_output; + builder.MergeFunctions = false; builder.populateFunctionPassManager(func_manager); builder.populateModulePassManager(module_manager); diff --git a/lib/BC/Util.cpp b/lib/BC/Util.cpp index c4245553..7af782ef 100644 --- a/lib/BC/Util.cpp +++ b/lib/BC/Util.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -40,22 +41,17 @@ #include #include #include +#include +#include #include #include #include +#include #include "remill/Arch/Arch.h" #include "remill/Arch/Name.h" #include "remill/BC/ABI.h" #include "remill/BC/Annotate.h" -#include "remill/BC/Compat/BitcodeReaderWriter.h" -#include "remill/BC/Compat/CallSite.h" -#include "remill/BC/Compat/DebugInfo.h" -#include "remill/BC/Compat/GlobalValue.h" -#include "remill/BC/Compat/IRReader.h" -#include "remill/BC/Compat/ToolOutputFile.h" -#include "remill/BC/Compat/VectorType.h" -#include "remill/BC/Compat/Verifier.h" #include "remill/BC/IntrinsicTable.h" #include "remill/BC/Util.h" #include "remill/BC/Version.h" @@ -151,9 +147,6 @@ llvm::CallInst *AddCall(llvm::BasicBlock *source_block, const IntrinsicTable &intrinsics) { llvm::IRBuilder<> ir(source_block); auto args = LiftedFunctionArgs(source_block, intrinsics); -#if LLVM_VERSION_NUMBER < LLVM_VERSION(11, 0) - return ir.CreateCall(dest_func, args); -#else if (auto func = llvm::dyn_cast(dest_func); func) { return ir.CreateCall(func, args); @@ -167,7 +160,6 @@ llvm::CallInst *AddCall(llvm::BasicBlock *source_block, llvm::FunctionCallee callee(func_type, dest_func); return ir.CreateCall(callee, args); } -#endif } // Create a tail-call from one lifted function to another. @@ -473,26 +465,11 @@ bool StoreModuleToFile(llvm::Module *module, std::string_view file_name, return false; } -#if LLVM_VERSION_NUMBER > LLVM_VERSION(3, 5) std::error_code ec; -# if LLVM_VERSION_NUMBER < LLVM_VERSION(7, 0) - llvm::ToolOutputFile bc(tmp_name.c_str(), ec, llvm::sys::fs::F_RW); -# else llvm::ToolOutputFile bc(tmp_name.c_str(), ec, llvm::sys::fs::OF_None); -# endif CHECK(!ec) << "Unable to open output bitcode file for writing: " << tmp_name; -#else - llvm::tool_output_file bc(tmp_name.c_str(), error, llvm::sys::fs::F_RW); - CHECK(error.empty() && !bc.os().has_error()) - << "Unable to open output bitcode file for writing: " << tmp_name << ": " - << error; -#endif -#if LLVM_VERSION_NUMBER < LLVM_VERSION(7, 0) - llvm::WriteBitcodeToFile(module, bc.os()); -#else llvm::WriteBitcodeToFile(*module, bc.os()); -#endif bc.keep(); if (!bc.os().has_error()) { std::string file_name_(file_name.data(), file_name.size()); @@ -511,21 +488,10 @@ bool StoreModuleToFile(llvm::Module *module, std::string_view file_name, bool StoreModuleIRToFile(llvm::Module *module, std::string_view file_name_, bool allow_failure) { std::string file_name(file_name_.data(), file_name_.size()); -#if LLVM_VERSION_NUMBER <= LLVM_VERSION(3, 5) - std::string error; - llvm::raw_fd_ostream dest(file_name.c_str(), error, llvm::sys::fs::F_Text); - auto good = error.empty(); -#elif LLVM_VERSION_NUMBER < LLVM_VERSION(13, 0) - std::error_code ec; - llvm::raw_fd_ostream dest(file_name.c_str(), ec, llvm::sys::fs::F_Text); - auto good = !ec; - auto error = ec.message(); -#else std::error_code ec; llvm::raw_fd_ostream dest(file_name.c_str(), ec, llvm::sys::fs::OF_Text); auto good = !ec; auto error = ec.message(); -#endif if (!good) { LOG_IF(FATAL, allow_failure) << "Could not save LLVM IR to " << file_name << ": " << error; @@ -733,9 +699,9 @@ std::vector CallersOf(llvm::Function *func) { std::vector callers; for (auto user : func->users()) { - if (auto cs = compat::llvm::CallSite(user); cs.isCall()) { - if (cs.getCalledFunction() == func) { - callers.push_back(llvm::cast(user)); + if (auto cs = llvm::dyn_cast(user)) { + if (cs->getCalledFunction() == func) { + callers.push_back(cs); } } } @@ -744,11 +710,7 @@ std::vector CallersOf(llvm::Function *func) { // Returns the name of a module. std::string ModuleName(llvm::Module *module) { -#if LLVM_VERSION_NUMBER < LLVM_VERSION(3, 6) - return module->getModuleIdentifier(); -#else return module->getName().str(); -#endif } std::string ModuleName(const std::unique_ptr &module) { @@ -941,7 +903,7 @@ RecontextualizeType(llvm::Type *type, llvm::LLVMContext &context, break; } - case llvm::GetFixedVectorTypeId(): { + case llvm::Type::FixedVectorTyID: { auto arr_type = llvm::dyn_cast(type); auto elem_type = arr_type->getElementType(); cached = llvm::FixedVectorType::get( @@ -1672,18 +1634,14 @@ void CloneFunctionInto(llvm::Function *source_func, llvm::Function *dest_func, // Make sure that when we're cloning functions that we don't // throw away register names and such. -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 9) dest_func->getContext().setDiscardValueNames(false); -#endif dest_func->setAttributes(source_func->getAttributes()); dest_func->setLinkage(source_func->getLinkage()); dest_func->setVisibility(source_func->getVisibility()); dest_func->setCallingConv(source_func->getCallingConv()); -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(3, 6) dest_func->setIsMaterializable(source_func->isMaterializable()); -#endif // Clone the basic blocks and their instructions. std::unordered_map block_map; @@ -1912,7 +1870,7 @@ void MoveFunctionIntoModule(llvm::Function *func, llvm::Module *dest_module) { existing_decl_in_dest_module = nullptr; } - IF_LLVM_GTE_370(ClearMetaData(func);) + ClearMetaData(func); // Fill up the locals so that they map to themselves. for (auto &arg : func->args()) { @@ -2081,7 +2039,7 @@ llvm::Value *LoadFromMemory(const IntrinsicTable &intrinsics, } // Build up the vector in the nearly the same was as we do with arrays. - case llvm::GetFixedVectorTypeId(): { + case llvm::Type::FixedVectorTyID: { auto vec_type = llvm::dyn_cast(type); const auto num_elems = vec_type->getNumElements(); const auto elem_type = vec_type->getElementType(); @@ -2262,7 +2220,7 @@ llvm::Value *StoreToMemory(const IntrinsicTable &intrinsics, } // Build up the vector store in the nearly the same was as we do with arrays. - case llvm::GetFixedVectorTypeId(): { + case llvm::Type::FixedVectorTyID: { auto vec_type = llvm::dyn_cast(type); const auto num_elems = vec_type->getNumElements(); const auto elem_type = vec_type->getElementType(); @@ -2371,14 +2329,12 @@ BuildIndexes(const llvm::DataLayout &dl, llvm::Type *type, size_t offset, // happens LOG(FATAL) << "Called BuildIndexes on unsupported type: " << remill::LLVMThingToString(type); -#if LLVM_VERSION_NUMBER >= LLVM_VERSION(11, 0) } else if (auto svt_type = llvm::dyn_cast(type); svt_type) { // same as above, but for scalable vectors LOG(FATAL) << "Called BuildIndexes on unsupported type: " << remill::LLVMThingToString(type); -#endif } return {offset, type}; diff --git a/scripts/build.sh b/scripts/build.sh index a8b3bbe7..d440585b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -272,10 +272,6 @@ function Package function GetLLVMVersion { case ${1} in - 13) - LLVM_VERSION=llvm-13 - return 0 - ;; 14) LLVM_VERSION=llvm-14 return 0 @@ -295,7 +291,7 @@ function Help echo "" echo "Options:" echo " --prefix Change the default (${INSTALL_DIR}) installation prefix." - echo " --llvm-version Change the default (13) LLVM version." + echo " --llvm-version Change the default (14) LLVM version." echo " --build-dir Change the default (${BUILD_DIR}) build directory." echo " --debug Build with Debug symbols." echo " --extra-cmake-args Extra CMake arguments to build with."