8000 Update to llvm 17.0.6 by nsurbay · Pull Request #253 · QBDI/QBDI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update to llvm 17.0.6 #253

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

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build-x86:
runs-on: macos-latest
runs-on: macos-13
env:
QBDI_ARCH: 'X86_64'
QBDI_PLATFORM: 'osx'
Expand Down Expand Up @@ -65,14 +65,15 @@ jobs:
path: build/QBDI-*.pkg

build-aarch64:
runs-on: [self-hosted, macOS, ARM64]
runs-on: macos-14
env:
QBDI_ARCH: 'AARCH64'
QBDI_PLATFORM: 'osx'
MACOSX_DEPLOYMENT_TARGET: '10.14'
steps:
- name: Install system dependencies
run: |
brew install cmake ninja ccache
python3 -m pip install --upgrade pip setuptools wheel
- name: checkout
uses: actions/checkout@v3
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/python_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build-pyqbdi-x64:
runs-on: macos-latest
runs-on: macos-13
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
Expand Down Expand Up @@ -62,10 +62,10 @@ jobs:
path: dist/*

build-pyqbdi-aarch64:
runs-on: [self-hosted, macOS, ARM64]
runs-on: macos-14
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.10', '3.11', '3.12']
fail-fast: false
env:
QBDI_ARCH: 'AARCH64'
Expand All @@ -74,9 +74,14 @@ jobs:
_PYTHON_HOST_PLATFORM: "macosx-11.0-arm64"
ARCHFLAGS: "-arch arm64"
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
run: |
python${{ matrix.python-version }} -m pip install --upgrade pip setuptools wheel build
brew install cmake ninja ccache
python3 -m pip install --upgrade pip setuptools wheel build
- name: checkout
uses: actions/checkout@v3
- name: Cache ccache
Expand All @@ -101,8 +106,8 @@ jobs:
key: QBDI-third-party-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cmake') }}
- name: Build PyQBDI ${{ matrix.python-version }}
run: |
python${{ matrix.python-version }} --version
python${{ matrix.python-version }} -m build -w
python3 --version
python3 -m build -w
- name: Export package
uses: actions/upload-artifact@v3
with:
Expand Down
32 changes: 5 additions & 27 deletions cmake/llvm/QBDI_llvm.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set(__add_qbdi_llvm ON)
include(FetchContent)

# configure FetchContent
set(QBDI_LLVM_MAJOR_VERSION 15)
set(QBDI_LLVM_VERSION 15.0.7)
set(QBDI_LLVM_MAJOR_VERSION 17)
set(QBDI_LLVM_VERSION 17.0.6)

# download and include llvm cmake module
option(QBDI_INCLUDE_LLVM_CMAKE_MODUKE "Include llvm cmake module" ON)
Expand All @@ -16,48 +16,26 @@ if(QBDI_INCLUDE_LLVM_CMAKE_MODUKE)
llvm_cmake
URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${QBDI_LLVM_VERSION}/cmake-${QBDI_LLVM_VERSION}.src.tar.xz"
URL_HASH
"SHA256=8986f29b634fdaa9862eedda78513969fe9788301c9f2d938f4c10a3e7a3e7ea"
"SHA256=807f069c54dc20cb47b21c1f6acafdd9c649f3ae015609040d6182cab01140f4"
SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/cmake"
DOWNLOAD_DIR "${QBDI_THIRD_PARTY_DIRECTORY}/llvm-cmake-download")

if(NOT llvm_cmake_POPULATED)
FetchContent_Populate(llvm_cmake)
endif()
list(APPEND CMAKE_MODULE_PATH "${llvm_cmake_SOURCE_DIR}/Modules")
endif()

FetchContent_Declare(
llvm
URL "https://github.com/llvm/llvm-project/releases/download/llvmorg-${QBDI_LLVM_VERSION}/llvm-${QBDI_LLVM_VERSION}.src.tar.xz"
URL_HASH
"SHA256=4ad8b2cc8003c86d0078d15d987d84e3a739f24aae9033865c027abae93ee7a4"
"SHA256=b638167da139126ca11917b6880207cc6e8f9d1cbb1a48d87d017f697ef78188"
DOWNLOAD_DIR "${QBDI_THIRD_PARTY_DIRECTORY}/llvm-download")

FetchContent_GetProperties(llvm)
if(NOT llvm_POPULATED)
FetchContent_Populate(llvm)

# hack of llvm compilation : when crosscompile,
# the nested cmake need to access to module.
if(QBDI_INCLUDE_LLVM_CMAKE_MODUKE)
# copy the module files in cmake/modules
file(
COPY "${llvm_cmake_SOURCE_DIR}/Modules/"
DESTINATION "${llvm_SOURCE_DIR}/cmake/modules/"
FILES_MATCHING
PATTERN "*.cmake")
endif()

# hack of llvm compilation : when crosscompile,
# the nested compilation ignore
# LLVM_INCLUDE_BENCHMARKS, and force the inclusion of
# ${llvm_cmake_SOURCE_DIR}/../third-party/benchmark
# Just creates an empty file there and emtpies
# ${llvm_cmake_SOURCE_DIR}/benchmarks/CMakeLists.txt
file(MAKE_DIRECTORY "${llvm_SOURCE_DIR}/../third-party/benchmark")
file(REMOVE "${llvm_SOURCE_DIR}/benchmarks/CMakeLists.txt")
file(TOUCH "${llvm_SOURCE_DIR}/../third-party/benchmark/CMakeLists.txt"
"${llvm_SOURCE_DIR}/benchmarks/CMakeLists.txt")

set(CMAKE_CXX_STANDARD
17
CACHE STRING "USE CPP 17")
Expand Down
4 changes: 2 additions & 2 deletions docker/ci_linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG DOCKER_IMG="debian:10"
ARG DOCKER_IMG="debian:12"

FROM $DOCKER_IMG

Expand All @@ -24,7 +24,7 @@ RUN apt-get update && \
ccache \
g++ \
g++-multilib \
libstdc++-10-dev \
libstdc++-11-dev \
make \
ninja-build \
pkg-config \
Expand Down
4 changes: 2 additions & 2 deletions docker/ci_linux/img_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ BASEDIR=$(pwd -P)
GITDIR=$(git rev-parse --show-toplevel)

if [[ "${QBDI_ARCH}" = "X86_64" ]]; then
DOCKER_IMG="amd64/debian:11"
DOCKER_IMG="amd64/debian:12"
elif [[ "${QBDI_ARCH}" = "X86" ]]; then
DOCKER_IMG="i386/debian:11"
DOCKER_IMG="i386/debian:12"
else
echo "Unknown QBDI_ARCH : ${QBDI_ARCH}"
exit 1
Expand Down
6 changes: 2 additions & 4 deletions docker/ci_linux_arm/images/Dockerfile.dockcross
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ FROM $DOCKER_IMG

ENV CLICOLOR_FORCE=1

# need qemu >= 6.0 to run QBDI test
RUN echo "deb http://deb.debian.org/debian bullseye-backports main" >> /etc/apt/sources.list && \
apt-get update && \
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get install -y --no-install-recommends \
bash \
ca-certificates \
ccache \
git \
python3 \
qemu-user-static \
wget \
zip && \
apt -t bullseye-backports install qemu-user-static && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

38 changes: 15 additions & 23 deletions src/Engine/LLVMCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/MC/MCAsmBackend.h"
#include "llvm/MC/MCAsmInfo.h"
Expand All @@ -38,18 +37,18 @@
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/MCValue.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"

#include "QBDI/Config.h"
#include "Engine/LLVMCPU.h"
#include "Patch/Types.h"
#include "Utility/LogSys.h"
#include "Utility/System.h"
#include "Utility/memory_ostream.h"

#include "spdlog/fmt/bin_to_hex.h"

Expand Down Expand Up @@ -185,38 +184,33 @@ bool LLVMCPU::getInstruction(llvm::MCInst &instr, uint64_t &size,
}

void LLVMCPU::writeInstruction(const llvm::MCInst inst,
memory_ostream &stream) const {
llvm::SmallVectorImpl<char> &CB,
rword address) const {
// MCCodeEmitter needs a fixups array
llvm::SmallVector<llvm::MCFixup, 4> fixups;

uint64_t pos = stream.current_pos();
uint64_t pos = CB.size();
QBDI_DEBUG_BLOCK({
rword address = reinterpret_cast<rword>(stream.get_ptr()) + pos;
std::string disass = showInst(inst, address);
QBDI_DEBUG("Assembling {} at 0x{:x}", disass.c_str(), address);
QBDI_DEBUG("Assembling {} for 0x{:x}", disass.c_str(), address);
});
assembler->getEmitter().encodeInstruction(inst, stream, fixups, *MSTI);
uint64_t size = stream.current_pos() - pos;
assembler->getEmitter().encodeInstruction(inst, CB, fixups, *MSTI);
auto buffRef = llvm::MutableArrayRef<char>(CB).drop_front(pos);

if (fixups.size() > 0) {
llvm::MCValue target = llvm::MCValue();
llvm::MCFixup fixup = fixups.pop_back_val();
int64_t value;
if (fixup.getValue()->evaluateAsAbsolute(value)) {
assembler->getBackend().applyFixup(
*assembler, fixup, target,
llvm::MutableArrayRef<char>((char *)stream.get_ptr() + pos, size),
(uint64_t)value, true, MSTI.get());
assembler->getBackend().applyFixup(*assembler, fixup, target, buffRef,
(uint64_t)value, true, MSTI.get());
} else {
QBDI_WARN("Could not evalutate fixup, might crash!");
}
}

QBDI_DEBUG("Assembly result at 0x{:x} is: {:n}",
reinterpret_cast<rword>(stream.get_ptr()) + pos,
spdlog::to_hex(reinterpret_cast<uint8_t *>(stream.get_ptr()) + pos,
reinterpret_cast<uint8_t *>(stream.get_ptr()) +
stream.current_pos()));
QBDI_DEBUG("Assembly result for 0x{:x} is: {:n}", address,
spdlog::to_hex(buffRef));
}

std::string LLVMCPU::showInst(const llvm::MCInst &inst, rword address) const {
Expand Down Expand Up @@ -262,13 +256,11 @@ void LLVMCPU::setOptions(Options opts) {
}

int LLVMCPU::getMCInstSize(const llvm::MCInst &inst) const {
uint8_t buff[32];
llvm::sys::MemoryBlock os{&buff, sizeof(buff)};
memory_ostream stream{os};
llvm::SmallVector<char, 16> stream;

writeInstruction(inst, stream);

return stream.current_pos();
return stream.size();
}

} // namespace QBDI
5 changes: 3 additions & 2 deletions src/Engine/LLVMCPU.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vector>

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"

#include "QBDI/Options.h"
#include "QBDI/State.h"
Expand All @@ -46,7 +47,6 @@ class raw_pwrite_stream;
} // namespace llvm

namespace QBDI {
class memory_ostream;
struct RegLLVM;

class LLVMCPU {
Expand Down Expand Up @@ -85,7 +85,8 @@ class LLVMCPU {
LLVMCPU(const LLVMCPU &) = delete;
LLVMCPU &operator=(const LLVMCPU &) = delete;

void writeInstruction(llvm::MCInst inst, memory_ostream &stream) const;
void writeInstruction(llvm::MCInst inst, llvm::SmallVectorImpl<char> &CB,
rword address = 0) const;

bool getInstruction(llvm::MCInst &inst, uint64_t &size,
llvm::ArrayRef<uint8_t> bytes, uint64_t address) const;
Expand Down
7 changes: 4 additions & 3 deletions src/ExecBlock/AARCH64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
set(SOURCES "${CMAKE_CURRENT_LIST_DIR}/ExecBlock_AARCH64.cpp")

if(QBDI_PLATFORM_LINUX OR QBDI_PLATFORM_ANDROID)
list(APPEND SOURCES "${CMAKE_CURRENT_LIST_DIR}/linux-android-AARCH64.s")
list(APPEND SOURCES "${CMAKE_CURRENT_LIST_DIR}/linux-android_AARCH64.s")

elseif(QBDI_PLATFORM_OSX)
list(APPEND SOURCES "${CMAKE_CURRENT_LIST_DIR}/osx-AARCH64.s")
list(APPEND SOURCES "${CMAKE_CURRENT_LIST_DIR}/osx_AARCH64.s")

#elseif(QBDI_PLATFORM_IOS)
# list(APPEND SOURCES ${CMAKE_CURRENT_LIST_DIR}/ios-AARCH64.s)
# list(APPEND SOURCES ${CMAKE_CURRENT_LIST_DIR}/ios_AARCH64.s)

else()
message(FATAL_ERROR "No stub for ${QBDI_PLATFORM} (${QBDI_ARCH})")
Expand Down
6 changes: 3 additions & 3 deletions src/ExecBlock/AARCH64/ExecBlock_AARCH64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern void qbdi_runCodeBlock(void *codeBlock,

namespace QBDI {

static const uint32_t MINIMAL_BLOCK_SIZE = 0x10;
static const uint32_t MINIMAL_BLOCK_SIZE = 0xc;

void ExecBlock::selectSeq(uint16_t seqID) {
QBDI_REQUIRE(seqID < seqRegistry.size());
Expand Down Expand Up @@ -106,15 +106,15 @@ bool ExecBlock::writePatch(std::vector<Patch>::const_iterator seqCurrent,
if (not applyRelocatedInst(
changeScratchRegister(llvmcpu, backupSR.writeScratchRegister,
srInfo.writeScratchRegister),
&tagRegistry, llvmcpu, MINIMAL_BLOCK_SIZE + epilogueSize)) {
&tagRegistry, llvmcpu, MINIMAL_BLOCK_SIZE)) {
QBDI_DEBUG("Not enough space left: rollback");
srInfo = backupSR;
return false;
}
}

if (not applyRelocatedInst(p.insts, &tagRegistry, llvmcpu,
MINIMAL_BLOCK_SIZE + epilogueSize)) {
MINIMAL_BLOCK_SIZE)) {
QBDI_DEBUG("Not enough space left: rollback");
srInfo = backupSR;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ __qbdi_runCodeBlock:

# mark stack as no-exec
.section .note.GNU-stack,"",@progbits

Loading
0