Skip to content

Commit

Permalink
Merge branch 'JonathanSalwan:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
selimsandal authored Oct 23, 2024
2 parents 718168c + b022f31 commit 6c7ae40
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .build_number
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1595
1597
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install python-setuptools lcov libboost-dev libgmp-dev
sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install python-setuptools libboost-dev libgmp-dev
sudo apt-get install python3-setuptools libboost-dev libgmp-dev
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1
Expand Down
12 changes: 11 additions & 1 deletion .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
include:
- python-version: 3.8
pycp: cp38-cp38
Expand All @@ -76,6 +76,12 @@ jobs:
- python-version: 3.11
pycp: cp311-cp311
pylib: python311.lib
- python-version: 3.12
pycp: cp312-cp312
pylib: python312.lib
- python-version: 3.13
pycp: cp313-cp313
pylib: python313.lib
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -155,6 +161,10 @@ jobs:
pycp: cp39-cp39
- python-version: 3.10
pycp: cp310-cp310
# - python-version: 3.11
# pycp: cp311-cp311
# - python-version: 3.12
# pycp: cp312-cp312
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND GCOV)
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test-python
COMMAND ctest --output-on-failure
COMMAND lcov --no-checksum --directory $<TARGET_FILE_DIR:triton> --capture --output-file coverage.info
COMMAND lcov --remove coverage.info '/usr*' --remove coverage.info 'pintools*' --remove coverage.info 'examples*' -o coverage.info
COMMAND lcov --ignore-errors unused --remove coverage.info '/usr*' --remove coverage.info 'pintools*' --remove coverage.info 'examples*' -o coverage.info
COMMAND genhtml coverage.info -o coverage
COMMAND ${CMAKE_COMMAND} -E echo "-- Report generated in ${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html"
)
Expand Down Expand Up @@ -187,13 +187,13 @@ if(LLVM_INTERFACE)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
if(LLVM_LINK_LLVM_DYLIB)
set(LLVM_LIBRARIES LLVM)
else()
set(LLVM_LIBRARIES ${LLVM_AVAILABLE_LIBS})
endif()
endif()
include_directories(${LLVM_INCLUDE_DIRS})
set(TRITON_LLVM_INTERFACE ON)
endif()

Expand Down
2 changes: 1 addition & 1 deletion CMakeModules/FindBITWUZLA.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()

if(NOT BITWUZLA_INCLUDE_DIRS AND NOT BITWUZLA_LIBRARIES)
find_path(BITWUZLA_INCLUDE_DIR
NAMES bitwuzla/bitwuzla.h
NAMES bitwuzla/bitwuzla.h bitwuzla/cpp/bitwuzla.h
PATHS ${BITWUZLA_PKGCONF_INCLUDE_DIRS}
)

Expand Down
6 changes: 6 additions & 0 deletions src/libtriton/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(LIBTRITON_SOURCE_FILES
stubs/x8664-ms-libc.cpp
stubs/x8664-systemv-libc.cpp
utils/coreUtils.cpp
utils/softfloat.cpp
)

# Define all header files
Expand Down Expand Up @@ -106,6 +107,7 @@ set(LIBTRITON_HEADER_FILES
includes/triton/comparableFunctor.hpp
includes/triton/context.hpp
includes/triton/coreUtils.hpp
includes/triton/softfloat.hpp
includes/triton/cpuInterface.hpp
includes/triton/cpuSize.hpp
includes/triton/dllexport.hpp
Expand Down Expand Up @@ -157,6 +159,10 @@ set(LIBTRITON_HEADER_FILES
includes/triton/z3ToTriton.hpp
)

set_source_files_properties(utils/softfloat.cpp PROPERTIES COMPILE_DEFINITIONS
${CMAKE_CXX_BYTE_ORDER}
)

# Define all resource files
set(LIBTRITON_RESOURCE_FILES
includes/triton/version.hpp.in
Expand Down
17 changes: 16 additions & 1 deletion src/libtriton/arch/arm/aarch64/aarch64Cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,23 @@ namespace triton {
break;
}

case triton::extlibs::capstone::ARM64_OP_FP: {
if (size == 0) {
throw triton::exceptions::Disassembly("Aarch64Cpu::disassembly(): Cannot correctly decode FP operand");
}

Immediate imm{op->fp, size, this->getEndianness()};

/* Set Shift type and value */
imm.setShiftType(this->capstoneShiftToTritonShift(op->shift.type));
imm.setShiftValue(op->shift.value);

inst.operands.push_back(triton::arch::OperandWrapper(imm));
break;
}

default:
/* NOTE: FP, CIMM, and missing one are not supported yet. */
/* NOTE: CIMM, and missing one are not supported yet. */
throw triton::exceptions::Disassembly("AArch64Cpu::disassembly(): Invalid operand.");
} // switch
} // for operand
Expand Down
6 changes: 3 additions & 3 deletions src/libtriton/arch/arm/aarch64/aarch64Semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3298,7 +3298,7 @@ namespace triton {
auto op = this->symbolicEngine->getOperandAst(inst, src);

/* Create the semantics of the LOAD */
auto node1 = this->astCtxt->sx(dst.getBitSize() - 8, op);
auto node1 = this->astCtxt->sx(dst.getBitSize() - 8, this->astCtxt->extract(7, 0, op));

/* Create symbolic expression */
auto expr1 = this->symbolicEngine->createSymbolicExpression(inst, node1, dst, "LDRSB operation - LOAD access");
Expand Down Expand Up @@ -3353,7 +3353,7 @@ namespace triton {
auto op = this->symbolicEngine->getOperandAst(inst, src);

/* Create the semantics of the LOAD */
auto node1 = this->astCtxt->sx(dst.getBitSize() - 16, op);
auto node1 = this->astCtxt->sx(dst.getBitSize() - 16, this->astCtxt->extract(15, 0, op));

/* Create symbolic expression */
auto expr1 = this->symbolicEngine->createSymbolicExpression(inst, node1, dst, "LDRSH operation - LOAD access");
Expand Down Expand Up @@ -3413,7 +3413,7 @@ namespace triton {
auto op = this->symbolicEngine->getOperandAst(inst, src);

/* Create the semantics of the LOAD */
auto node1 = this->astCtxt->sx(dst.getBitSize() - 32, op);
auto node1 = this->astCtxt->sx(dst.getBitSize() - 32, this->astCtxt->extract(31, 0, op));

/* Create symbolic expression */
auto expr1 = this->symbolicEngine->createSymbolicExpression(inst, node1, dst, "LDRSW operation - LOAD access");
Expand Down
1 change: 1 addition & 0 deletions src/libtriton/arch/arm/aarch64/aarch64Specifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ namespace triton {
break;

case triton::extlibs::capstone::ARM64_INS_BIC:
case triton::extlibs::capstone::ARM64_INS_BICS:
tritonId = triton::arch::arm::aarch64::ID_INS_BIC;
break;

Expand Down
43 changes: 42 additions & 1 deletion src/libtriton/arch/immediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
** This program is under the terms of the Apache License 2.0.
*/

#include <triton/immediate.hpp>
#include <triton/cpuSize.hpp>
#include <triton/exceptions.hpp>
#include <triton/immediate.hpp>
#include <triton/softfloat.hpp>
#include <triton/coreUtils.hpp>

#ifdef LITTLE_ENDIAN // provided by CMake
constexpr auto sys_endianness = triton::arch::LE_ENDIANNESS;
#else
constexpr auto sys_endianness = triton::arch::BE_ENDIANNESS;
#endif


namespace triton {
Expand All @@ -24,6 +31,40 @@ namespace triton {
}


Immediate::Immediate(double value, triton::uint32 size /* bytes */, triton::arch::endianness_e platform_endianness) {
triton::uint64 imm_value;
auto need_swap = sys_endianness != platform_endianness;

if (size == sizeof(double)) {
static_assert(sizeof(double) == sizeof(triton::uint64), "Unexpected double type size");
std::memcpy(&imm_value, &value, sizeof(double));
if (need_swap) {
imm_value = utils::byteswap(imm_value);
}
}

else if (size == sizeof(float)) { // single-precision
float fvalue = static_cast<float>(value);
triton::uint32 repr;
static_assert(sizeof(float) == sizeof(uint32_t), "Unexpected float type size");
std::memcpy(&repr, &fvalue, sizeof(float));
imm_value = need_swap ? static_cast<triton::uint64>(utils::byteswap(repr)) : static_cast<triton::uint64>(repr);
}

else if (size == 2) { // half-precision
float fvalue = static_cast<float>(value);
triton::uint16 repr = triton::sf::f32_to_f16(fvalue);
imm_value = need_swap ? static_cast<triton::uint64>(utils::byteswap(repr)) : static_cast<triton::uint64>(repr);
}

else {
throw triton::exceptions::Immediate("Immediate::Immediate(double): Invalid encoding size.");
}

this->setValue(imm_value, size);
}


Immediate::Immediate(const Immediate& other)
: BitsVector(other),
ArmOperandProperties(other) {
Expand Down
11 changes: 11 additions & 0 deletions src/libtriton/includes/triton/coreUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sstream>
#include <string>
#include <algorithm>
#include <type_traits>

#include <triton/config.hpp>
Expand Down Expand Up @@ -81,6 +82,16 @@ namespace triton {
template <> TRITON_EXPORT triton::uint80 cast(const triton::uint512& value);
template <> TRITON_EXPORT triton::uint512 cast(const triton::uint80& value);

template <typename T>
std::enable_if_t<std::is_unsigned_v<T>, T> byteswap(T value) {
std::array<std::byte, sizeof(value)> repr;
std::memcpy(&repr, &value, sizeof(value));
std::reverse(repr.begin(), repr.end());
T result;
std::memcpy(&result, &repr, sizeof(result));
return result;
}

/*! @} End of utils namespace */
};
/*! @} End of triton namespace */
Expand Down
3 changes: 3 additions & 0 deletions src/libtriton/includes/triton/immediate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ namespace triton {
//! Constructor.
TRITON_EXPORT Immediate(triton::uint64 value, triton::uint32 size /* bytes*/);

//! Constructor.
TRITON_EXPORT Immediate(double value, triton::uint32 size /* bytes */, triton::arch::endianness_e platform_endianness);

//! Constructor by copy.
TRITON_EXPORT Immediate(const Immediate& other);

Expand Down
35 changes: 35 additions & 0 deletions src/libtriton/includes/triton/softfloat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! \file
/*
** Copyright (C) - Triton
**
** This program is under the terms of the Apache License 2.0.
*/

#ifndef TRITON_SOFTFLOAT_HPP
#define TRITON_SOFTFLOAT_HPP

#include <cstdint>

//! The Triton namespace
namespace triton {
/*!
* \addtogroup triton
* @{
*/
//! The Softfloat namespace
namespace sf {
/*!
* \ingroup triton
* \addtogroup softfloat
* @{
*/

//! Cast 32-bit floating point value to 16-bit according to IEEE-754
auto f32_to_f16(float value) -> uint16_t;

/*! @} End of softfloat namespace */
};
/*! @} End of triton namespace */
};

#endif /* TRITON_SOFTFLOAT_HPP */
49 changes: 49 additions & 0 deletions src/libtriton/utils/softfloat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! \file
/*
** Copyright (C) - Triton
**
** This program is under the terms of the Apache License 2.0.
*/

#include <triton/softfloat.hpp>

#include <cstring>

namespace triton {
namespace sf {

uint16_t f32_to_f16(float value) {
uint32_t f;

static_assert(sizeof(float) == sizeof(uint32_t), "Unexpected float type size");
std::memcpy(&f, &value, sizeof(uint32_t));

uint16_t sign = ((f >> 16) & 0x8000);
int16_t exponent = ((f >> 23) & 0xff) - 127 + 15;
uint16_t mantissa = ((f >> 13) & 0x3ff);

if (exponent <= 0) {
if (exponent < -10) {
return sign;
}
mantissa = (mantissa | 0x400) >> (1 - exponent);
return sign | mantissa;
}

else if (exponent == 0xff - (127 - 15)) {
if (mantissa) {
return sign | 0x7fff;
} else {
return sign | 0x7c00;
}
}

else if (exponent > 30) {
return sign | 0x7c00;
}

return sign | (exponent << 10) | mantissa;
}

}; /* sf namespace */
}; /* triton namespace */
4 changes: 2 additions & 2 deletions src/scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG BASE_IMG
ARG BASE_IMG=quay.io/pypa/manylinux_2_28_x86_64

FROM $BASE_IMG

Expand Down Expand Up @@ -41,7 +41,7 @@ RUN echo "[+] Download, build and install Bitwuzla" && \
git clone https://github.com/bitwuzla/bitwuzla.git && \
cd bitwuzla && \
git checkout -b 0.4.0 0.4.0 && \
export PY310_PATH=$(dirname $(realpath -L $(which python3.10))) && \
export PY310_PATH=$(python3.10 -c 'import sys, os; print(os.path.dirname(sys.executable))') && \
CC=clang CXX=clang++ PATH=$PATH:$PY310_PATH python3.10 ./configure.py --shared --prefix $(pwd)/install && \
cd build && \
PATH=$PATH:$PY310_PATH ninja -j $(nproc) install
Expand Down
18 changes: 18 additions & 0 deletions src/scripts/docker/build-wheel-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ export PYTHON_LIBRARY=$($PYTHON_BINARY -c "from sysconfig import get_paths; prin

$PYTHON_BINARY -m build --wheel --outdir $WHEEL_DIR/linux_x86_64

# Build Triton Python wheel package for Python 3.12.
echo "[+] Build Triton wheel package for Python 3.12"
cd $SOURCE_DIR
export PYTHON_BINARY=/opt/_internal/cpython-3.12.*/bin/python
export PYTHON_INCLUDE_DIRS=$($PYTHON_BINARY -c "from sysconfig import get_paths; print(get_paths()['include'])")
export PYTHON_LIBRARY=$($PYTHON_BINARY -c "from sysconfig import get_paths; print(get_paths()['include'])")

$PYTHON_BINARY -m build --wheel --outdir $WHEEL_DIR/linux_x86_64

# Build Triton Python wheel package for Python 3.13.
echo "[+] Build Triton wheel package for Python 3.13"
cd $SOURCE_DIR
export PYTHON_BINARY=/opt/_internal/cpython-3.13.0/bin/python
export PYTHON_INCLUDE_DIRS=$($PYTHON_BINARY -c "from sysconfig import get_paths; print(get_paths()['include'])")
export PYTHON_LIBRARY=$($PYTHON_BINARY -c "from sysconfig import get_paths; print(get_paths()['include'])")

$PYTHON_BINARY -m build --wheel --outdir $WHEEL_DIR/linux_x86_64

# Repair wheels.
echo "[+] Repair wheel packages"
cd $SOURCE_DIR
Expand Down
Loading

0 comments on commit 6c7ae40

Please sign in to comment.