Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm 17 fixes #688

Merged
merged 37 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
36166b5
llvm 17 fix
2over12 Sep 26, 2023
f56369a
more instances
2over12 Sep 26, 2023
1aa7ed4
more fixes
2over12 Sep 26, 2023
300fb6a
add inline
2over12 Sep 26, 2023
9e8e5d1
bump ci
2over12 Sep 29, 2023
aedcf3a
bump cxx common
2over12 Sep 29, 2023
8530806
add 17 case
2over12 Sep 29, 2023
4d43f04
bump xcode version
2over12 Oct 2, 2023
f8a2de9
macos 13
2over12 Oct 2, 2023
3813b1c
xcode 15
2over12 Oct 2, 2023
94cca13
bump docker to llvm 17
2over12 Oct 2, 2023
d2dde5f
change actual matrix value
2over12 Oct 2, 2023
2410156
opaque pointers are the default now
2over12 Oct 3, 2023
fe5f008
actually remove the option
2over12 Oct 3, 2023
6bdab47
debug size
2over12 Oct 3, 2023
c5fcd56
install tree
2over12 Oct 3, 2023
782a4f9
fix install
2over12 Oct 3, 2023
c4a1fcd
fix install?
2over12 Oct 3, 2023
5e1e62e
get tree after
2over12 Oct 3, 2023
f2f7de4
build dir?
2over12 Oct 3, 2023
ae0a7ab
tree above
2over12 Oct 3, 2023
d640cfe
accumulate
2over12 Oct 3, 2023
4f44a92
bug?
2over12 Oct 3, 2023
befdfcb
try to remove intermediate packaging
2over12 Oct 3, 2023
9844784
fix opt
2over12 Oct 3, 2023
4fb57a0
only inline
2over12 Oct 3, 2023
5871c2d
give up on function inlining
2over12 Oct 3, 2023
ab87efd
llvm 17
2over12 Oct 3, 2023
f4c1271
remove debug tasks
2over12 Oct 4, 2023
6c727a5
Update scripts/build.sh
2over12 Oct 11, 2023
e7d058a
Revert "Update scripts/build.sh"
2over12 Oct 11, 2023
ddbaf13
debug
2over12 Oct 11, 2023
ed1ed25
try clear out old build
2over12 Oct 12, 2023
cf44f4e
retest
2over12 Oct 12, 2023
126219b
try to save more space
2over12 Oct 12, 2023
247ae62
up
2over12 Oct 12, 2023
59b4532
Clear space and don't use cxx-common docker image (#689)
ekilmer Oct 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name: VCPKG Continuous Integration
on:
# Run this workflow once every 6 hours against the master branch
schedule:
- cron: "0 */6 * * *"
- cron: "0 */6 * * *"

push:
branches:
- 'master'
- "master"

tags:
- "*"
Expand All @@ -22,13 +22,11 @@ jobs:
fail-fast: false
matrix:
image:
- { name: 'ubuntu', tag: '22.04' }
llvm: ['15', '16']
- { name: "ubuntu", tag: "22.04" }
llvm: ["17"]
compiler:
- { CC: 'clang', CXX: 'clang++' }
- { CC: 'gcc', CXX: 'g++' }
exclude:
- { llvm: '15', compiler: { CC: 'gcc', CXX: 'g++' } }
- { CC: "clang", CXX: "clang++" }
- { CC: "gcc", CXX: "g++" }

env:
CC: ${{ matrix.compiler.CC }}
Expand All @@ -55,6 +53,7 @@ jobs:
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
./scripts/build.sh --llvm-version ${{ matrix.llvm }}
rm -r remill-build/_CPack_Packages
- name: Build with build-presets script
shell: bash
run: |
Expand Down Expand Up @@ -110,10 +109,10 @@ jobs:
strategy:
fail-fast: false
matrix:
os: ['macos-12']
llvm: ['15', '16']
os: ["macos-13"]
llvm: ["17"]

runs-on: macos-12
runs-on: macos-13

steps:
- uses: actions/checkout@v2
Expand All @@ -137,7 +136,7 @@ jobs:
shell: bash
run: |
brew install ninja
export CMAKE_TOOLCHAIN_FILE=$(pwd)/../lifting-bits-downloads/vcpkg_${{ matrix.os}}_llvm-${{ matrix.llvm }}_xcode-14.2_amd64/scripts/buildsystems/vcpkg.cmake
export CMAKE_TOOLCHAIN_FILE=$(pwd)/../lifting-bits-downloads/vcpkg_${{ matrix.os}}_llvm-${{ matrix.llvm }}_xcode-15.0_amd64/scripts/buildsystems/vcpkg.cmake
export INSTALL_DIR=$(pwd)/remill-preset-install
./scripts/build-preset.sh release
- name: Run tests
Expand Down Expand Up @@ -167,12 +166,9 @@ jobs:
name: ${{ matrix.os }}_llvm${{ matrix.llvm }}_tgz_package
path: ${{ steps.package_names.outputs.TGZ_PACKAGE_PATH }}




release_packages:
# Do not run the release procedure if any of the builds has failed
needs: [ build_linux, build_mac ]
needs: [build_linux, build_mac]
runs-on: ubuntu-22.04
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')

Expand Down Expand Up @@ -238,20 +234,19 @@ jobs:
asset_name: remill_macos-12_packages.zip
asset_content_type: application/gzip


Docker_Linux:
runs-on: ubuntu-latest
strategy:
matrix:
llvm: ["15", "16"]
llvm: ["17"]
ubuntu: ["22.04"]
steps:
- uses: actions/checkout@v2
- name: Build LLVM ${{ matrix.llvm }} on ${{ matrix.ubuntu }}
run: |
docker build . -t ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest -f Dockerfile --build-arg UBUNTU_VERSION=${{ matrix.ubuntu }} --build-arg ARCH=amd64 --build-arg LLVM_VERSION=${{ matrix.llvm }}
- name: Test Docker image
run: |
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch64 --ir_out /dev/stdout --address 0x400544 --bytes FD7BBFA90000009000601891FD030091B7FFFF97E0031F2AFD7BC1A8C0035FD6
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch32 -ir_out /dev/stderr --bytes 0cd04de208008de504108de500208de508309de504009de500109de5903122e0c20fa0e110109fe5001091e5002081e5040081e50cd08de21eff2fe14000000000000000
- uses: actions/checkout@v2
- name: Build LLVM ${{ matrix.llvm }} on ${{ matrix.ubuntu }}
run: |
docker build . -t ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest -f Dockerfile --build-arg UBUNTU_VERSION=${{ matrix.ubuntu }} --build-arg ARCH=amd64 --build-arg LLVM_VERSION=${{ matrix.llvm }}
- name: Test Docker image
run: |
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch64 --ir_out /dev/stdout --address 0x400544 --bytes FD7BBFA90000009000601891FD030091B7FFFF97E0031F2AFD7BC1A8C0035FD6
docker run --rm ghcr.io/lifting-bits/remill/remill-llvm${{ matrix.llvm }}-ubuntu${{ matrix.ubuntu }}-amd64:latest --arch aarch32 -ir_out /dev/stderr --bytes 0cd04de208008de504108de500208de508309de504009de500109de5903122e0c20fa0e110109fe5001091e5002081e5040081e50cd08de21eff2fe14000000000000000
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ message(STATUS "LLVM Libraries: ${llvm_libs}")
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")

include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})

string(REPLACE "." ";" LLVM_VERSION_LIST ${LLVM_PACKAGE_VERSION})
list(GET LLVM_VERSION_LIST 0 LLVM_MAJOR_VERSION)
list(GET LLVM_VERSION_LIST 1 LLVM_MINOR_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Choose your LLVM version
ARG LLVM_VERSION=16
ARG LLVM_VERSION=17
ARG ARCH=amd64
ARG UBUNTU_VERSION=22.04
ARG DISTRO_BASE=ubuntu${UBUNTU_VERSION}
Expand Down
1 change: 1 addition & 0 deletions bin/differential_tester_x86/LiftAndCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <glog/logging.h>
#include <gtest/gtest.h>
#include <llvm/ADT/StringExtras.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/ExecutionEngine/Interpreter.h>
Expand Down
2 changes: 1 addition & 1 deletion include/remill/Arch/Arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#pragma clang diagnostic ignored "-Wswitch-enum"

#include <llvm/ADT/SmallVector.h>
#include <llvm/ADT/Triple.h>
#include <llvm/TargetParser/Triple.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/IRBuilder.h>
#include <remill/BC/InstructionLifter.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/AArch64/Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include <gflags/gflags.h>
#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/TargetParser/Triple.h>

#include <algorithm>
#include <cctype>
Expand Down
1 change: 1 addition & 0 deletions lib/Arch/Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <glog/logging.h>
#include <llvm/ADT/APInt.h>
#include <llvm/ADT/SmallVector.h>
#include <llvm/IR/AttributeMask.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/Name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "remill/Arch/Name.h"

#include <llvm/ADT/Triple.h>
#include <llvm/TargetParser/Triple.h>

namespace remill {

Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/Sleigh/AArch32Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "AArch32Arch.h"

#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/TargetParser/Triple.h>
#include <remill/Arch/AArch32/ArchContext.h>

#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/Sleigh/ARMBase.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/TargetParser/Triple.h>
#include <remill/Arch/AArch32/AArch32Base.h>
#include <remill/Arch/Name.h>
#include <remill/BC/ABI.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/Sleigh/X86Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/TargetParser/Triple.h>
#include <remill/Arch/Context.h>
#include <remill/Arch/Name.h>
#include <remill/Arch/X86/X86Base.h>
Expand Down
2 changes: 1 addition & 1 deletion lib/Arch/X86/Arch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/

#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/IR/Attributes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Module.h>
#include <llvm/TargetParser/Triple.h>
#include <remill/Arch/ArchBase.h> // For `Arch` and `ArchImpl`.
#include <remill/Arch/X86/X86Base.h>

Expand Down
101 changes: 33 additions & 68 deletions lib/BC/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include "remill/BC/Optimizer.h"

#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/Analysis/CGSCCPassManager.h>
#include <llvm/Analysis/InlineCost.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DataLayout.h>
Expand All @@ -29,9 +30,15 @@
#include <llvm/IR/MDBuilder.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/Type.h>
#include <llvm/Pass.h>
#include <llvm/Passes/OptimizationLevel.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/TargetParser/Triple.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/IPO/Inliner.h>
#include <llvm/Transforms/IPO/ModuleInliner.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Utils/Cloning.h>
#include <llvm/Transforms/Utils/Local.h>
Expand All @@ -46,81 +53,39 @@ namespace remill {
void OptimizeModule(const remill::Arch *arch, llvm::Module *module,
std::function<llvm::Function *(void)> generator,
OptimizationGuide guide) {

llvm::legacy::FunctionPassManager func_manager(module);
llvm::legacy::PassManager module_manager;

auto TLI =
new llvm::TargetLibraryInfoImpl(llvm::Triple(module->getTargetTriple()));

TLI->disableAllFunctions(); // `-fno-builtin`.

llvm::PassManagerBuilder builder;
// TODO(alex): Some of the optimization passes that the builder adds still rely on typed pointers
// so we cannot use them. We should switch to using the new pass manager and choose which passes
// we want.
builder.OptLevel = 0;
builder.SizeLevel = 0;
builder.Inliner = llvm::createFunctionInliningPass(250);
builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`.
builder.DisableUnrollLoops = false; // Unroll loops!
#if LLVM_VERSION_NUMBER < LLVM_VERSION(16, 0)
builder.RerollLoops = false;
#endif
builder.SLPVectorize = guide.slp_vectorize;
builder.LoopVectorize = guide.loop_vectorize;
builder.VerifyInput = guide.verify_input;
builder.VerifyOutput = guide.verify_output;
builder.MergeFunctions = false;

builder.populateFunctionPassManager(func_manager);
builder.populateModulePassManager(module_manager);
func_manager.doInitialization();
llvm::Function *func = nullptr;
while (nullptr != (func = generator())) {
func_manager.run(*func);
}
func_manager.doFinalization();
module_manager.run(*module);
OptimizeBareModule(module, guide);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we want to do about this i dont see an easy way to do single function inlining anymore i guess we could probably manually call llvm::InlineFunction etc but that seems excessive for something only called in the trace lifter idk

}

// Optimize a normal module. This might not contain special Remill-specific
// intrinsics functions like `__remill_jump`, etc.
void OptimizeBareModule(llvm::Module *module, OptimizationGuide guide) {
llvm::legacy::FunctionPassManager func_manager(module);
llvm::legacy::PassManager module_manager;

auto TLI =
new llvm::TargetLibraryInfoImpl(llvm::Triple(module->getTargetTriple()));
llvm::ModuleAnalysisManager mam;
llvm::FunctionAnalysisManager fam;
llvm::LoopAnalysisManager lam;
llvm::CGSCCAnalysisManager cam;


llvm::PipelineTuningOptions opts;
opts.InlinerThreshold = 250;
llvm::PassBuilder pb(nullptr, opts);

pb.registerModuleAnalyses(mam);
pb.registerFunctionAnalyses(fam);
pb.registerLoopAnalyses(lam);
pb.registerCGSCCAnalyses(cam);
pb.crossRegisterProxies(lam, fam, cam, mam);

llvm::ModulePassManager mpm;
mpm.addPass(llvm::ModuleInlinerPass(llvm::getInlineParams(250)));

TLI->disableAllFunctions(); // `-fno-builtin`.
mpm.run(*module, mam);

llvm::PassManagerBuilder builder;
// TODO(alex): Some of the optimization passes that the builder adds still rely on typed pointers
// so we cannot use them. We should switch to using the new pass manager and choose which passes
// we want.
builder.OptLevel = 0;
builder.SizeLevel = 0;
builder.Inliner = llvm::createFunctionInliningPass(250);
builder.LibraryInfo = TLI; // Deleted by `llvm::~PassManagerBuilder`.
builder.DisableUnrollLoops = false; // Unroll loops!
#if LLVM_VERSION_NUMBER < LLVM_VERSION(16, 0)
builder.RerollLoops = false;
#endif
builder.SLPVectorize = guide.slp_vectorize;
builder.LoopVectorize = guide.loop_vectorize;
builder.VerifyInput = guide.verify_input;
builder.VerifyOutput = guide.verify_output;
builder.MergeFunctions = false;

builder.populateFunctionPassManager(func_manager);
builder.populateModulePassManager(module_manager);
func_manager.doInitialization();
for (auto &func : *module) {
func_manager.run(func);
}
func_manager.doFinalization();
module_manager.run(*module);
mam.clear();
fam.clear();
lam.clear();
cam.clear();
}

} // namespace remill
11 changes: 0 additions & 11 deletions lib/BC/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1205,17 +1205,6 @@ MoveConstantIntoModule(llvm::Constant *c, llvm::Module *dest_module,
moved_c = ret;
return ret;
}
case llvm::Instruction::Select: {
2over12 marked this conversation as resolved.
Show resolved Hide resolved
auto ret = llvm::ConstantExpr::getSelect(
MoveConstantIntoModule(ce->getOperand(0), dest_module, value_map,
type_map),
MoveConstantIntoModule(ce->getOperand(1), dest_module, value_map,
type_map),
MoveConstantIntoModule(ce->getOperand(2), dest_module, value_map,
type_map));
moved_c = ret;
return ret;
}
case llvm::Instruction::Shl: {
const auto b = llvm::dyn_cast<llvm::ShlOperator>(ce);
auto ret = llvm::ConstantExpr::getShl(
Expand Down
2 changes: 1 addition & 1 deletion lib/OS/OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include <gflags/gflags.h>
#include <glog/logging.h>
#include <llvm/ADT/Triple.h>
#include <llvm/TargetParser/Triple.h>

namespace remill {

Expand Down
Loading
Loading