Merge branch 'dev-v1.0' of github.com:JonathanSalwan/Triton into dev-v1.0

This commit is contained in:
Triton Library 2026-03-08 19:08:21 +01:00
commit cebdda3a5c
7 changed files with 96 additions and 17 deletions

View file

@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev
sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev libmpfr-dev
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2

View file

@ -26,7 +26,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get install python3-setuptools libboost-dev libgmp-dev
sudo apt-get install python3-setuptools libboost-dev libgmp-dev libmpfr-dev
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2

View file

@ -24,7 +24,8 @@ RUN DEBIAN_FRONTEND="noninteractive" \
pkg-config \
python3-pip \
python3-venv \
tar && \
tar \
libmpfr-dev && \
apt clean
ENV VIRTUAL_ENV=/Triton-venv

View file

@ -183,6 +183,18 @@ You can use cmake to generate the .sln file of libTriton.
-DCAPSTONE_LIBRARIES="C:/Users/jonathan/Works/Tools/capstone-5.0.1-win64/capstone.lib" ..
```
You can use setup.py to generate the debug version of triton.pyd on Windows.
```console
> git clone https://github.com/JonathanSalwan/Triton.git
> cd Triton
> $env:COMPILER_DIR="C:/deps/llvm/llvm2116r/bin"
> $env:CMAKE_PREFIX_PATH="C:/deps/llvm/llvm-project-21.1.6.src/install/lib/cmake/llvm;C:/code/cxx-common-cmake/build/install"
> python_d -m build --wheel
> python_d -m pip install (Get-ChildItem .\dist\triton_library*)
```
However, if you prefer to directly download the precompiled library, check out our AppVeyor's [artefacts](https://ci.appveyor.com/project/JonathanSalwan/triton/history).
Note that if you use AppVeyor's artefacts, you probably have to install the [Visual C++ Redistributable](https://www.microsoft.com/en-US/download/details.aspx?id=30679)
packages for Visual Studio 2012.

View file

@ -20,8 +20,23 @@ from setuptools.command.build_ext import build_ext
VERSION_MAJOR = 1
VERSION_MINOR = 0
VERSION_PATCH = 0
ON = "ON"
OFF = "OFF"
clang = "clang"
clang_cl = "clang_cl"
vs2022 = "vs2022"
Release = "Release"
Debug = "Debug"
RELEASE_CANDIDATE = 4
Z3_INTERFACE = ON
LLVM_INTERFACE = OFF
BITWUZLA_INTERFACE = OFF
BOOST_INTERFACE = OFF
BUILDTOOLS = vs2022 # clang or clang_cl or vs2022
CMAKE_BUILD_TYPE = Release # Release or Debug
VERSION = f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}' + \
f'rc{RELEASE_CANDIDATE}' if RELEASE_CANDIDATE else ''
@ -59,7 +74,7 @@ class CMakeBuild(build_ext):
cmake_args = [
# General arguments.
'-DPYTHON_EXECUTABLE=' + sys.executable,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_BUILD_TYPE='+ CMAKE_BUILD_TYPE,
]
# Interfaces can be defined using environment variables.
@ -70,7 +85,7 @@ class CMakeBuild(build_ext):
# BITWUZLA_INTERFACE=Off
# BOOST_INTERFACE=Off
#
for arg, value in [('Z3_INTERFACE', 'On'), ('LLVM_INTERFACE', 'Off'), ('BITWUZLA_INTERFACE', 'Off'), ('BOOST_INTERFACE', 'Off')]:
for arg, value in [('Z3_INTERFACE', Z3_INTERFACE), ('LLVM_INTERFACE', LLVM_INTERFACE), ('BITWUZLA_INTERFACE', BITWUZLA_INTERFACE), ('BOOST_INTERFACE', BOOST_INTERFACE)]:
if os.getenv(arg):
cmake_args += [f'-D{arg}=' + os.getenv(arg)]
else:
@ -89,11 +104,27 @@ class CMakeBuild(build_ext):
build_args += ['--', '-j4']
elif platform.system() == "Windows":
cmake_args += [
'-G Visual Studio 17 2022',
]
build_args += ['--', '/m:4']
if BUILDTOOLS == vs2022:
cmake_args += [
"-G Visual Studio 17 2022",
]
build_args += ["--", "/m:4"]
else:
assert os.getenv('COMPILER_DIR'), "COMPILER_DIR(clang or clang_cl) env not found"
if BUILDTOOLS == clang:
cmake_args += [
"-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang.exe",
"-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang++.exe",
"-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe",
"-G Ninja",
]
if BUILDTOOLS == clang_cl:
cmake_args += [
"-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "/clang-cl.exe",
"-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang-cl.exe",
"-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe",
"-G Ninja",
]
else:
raise Exception(f'Platform not supported: {platform.system()}')
@ -123,7 +154,6 @@ class CMakeBuild(build_ext):
if os.getenv('BITWUZLA_INCLUDE_DIRS'):
cmake_args += ['-DBITWUZLA_INCLUDE_DIRS=' + os.getenv('BITWUZLA_INCLUDE_DIRS')]
# Custom Capstone paths.
if os.getenv('CAPSTONE_LIBRARIES'):
cmake_args += ['-DCAPSTONE_LIBRARIES=' + os.getenv('CAPSTONE_LIBRARIES')]
@ -155,11 +185,11 @@ class CMakeBuild(build_ext):
os.makedirs(self.build_lib)
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python-triton'] + build_args, cwd=self.build_temp)
subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python-triton'] + build_args, cwd=self.build_temp)
# The autocomplete file has to be built separately.
if (is_cmake_true(python_autocomplete_value)):
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python_autocomplete'], cwd=self.build_temp)
subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python_autocomplete'], cwd=self.build_temp)
def copy_extension_to_source(self, ext):
fullname = self.get_ext_fullname(ext.name)
@ -172,7 +202,10 @@ class CMakeBuild(build_ext):
src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib')
dst_filename = os.path.join(self.build_lib, os.path.basename(filename))
elif platform.system() == "Windows":
src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\Release', 'triton.pyd')
if BUILDTOOLS == vs2022:
src_filename = os.path.join(self.build_temp + '/src/libtriton/' + CMAKE_BUILD_TYPE, 'triton.pyd')
else:
src_filename = os.path.join(self.build_temp + '/src/libtriton', 'triton.pyd')
dst_filename = os.path.join(self.build_lib, os.path.basename(filename))
else:
raise Exception(f'Platform not supported: {platform.system()}')

View file

@ -353,7 +353,9 @@ namespace triton {
return this->bv(expr2->getBitvectorMask(), expr2->getBitvectorSize());
/* Optimization: A | A = A */
if (expr1->equalTo(expr2))
/* Only apply when both operands are concrete. Two different symbolic expressions
* may evaluate to the same value but represent distinct computations. */
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
return expr1;
}
@ -603,7 +605,9 @@ namespace triton {
return this->bvneg(expr2);
/* Optimization: A - A = 0 */
if (expr1->equalTo(expr2))
/* Only apply when both operands are concrete to preserve symbolic information.
* Different symbolic expressions may evaluate equal but must remain distinct. */
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
return this->bv(0, expr1->getBitvectorSize());
}
@ -732,7 +736,10 @@ namespace triton {
return expr2;
/* Optimization: A ^ A = 0 */
if (expr1->equalTo(expr2))
/* Only apply when both operands are concrete to avoid losing symbolic information.
* Two different symbolic expressions may have the same concrete value temporarily,
* but they represent different symbolic computations that must be preserved. */
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
return this->bv(0, expr1->getBitvectorSize());
}

View file

@ -17,6 +17,13 @@ RUN yum install -y \
libzstd-devel \
ncurses-devel
ENV VIRTUAL_ENV=/Triton-venv
RUN python3.10 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN . $VIRTUAL_ENV/bin/activate && \
pip install --upgrade pip
RUN python3.10 -m pip install meson
ENV DEPENDENCIES_DIR=/tmp/triton-dependencies
@ -25,6 +32,25 @@ ENV SOURCE_DIR=/src
# Create directory for dependencies.
RUN mkdir -p $DEPENDENCIES_DIR
# Download, build and install GMP.
RUN echo "[+] Download, build and install GMP" && \
cd $DEPENDENCIES_DIR && \
curl -LO https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz && \
tar xf gmp-6.3.0.tar.xz && \
cd gmp-6.3.0 && \
./configure --disable-assembly --enable-cxx && \
make -j$(nproc) && \
make install
RUN echo "[+] Download, build and install mpfr" && \
cd $DEPENDENCIES_DIR && \
curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz && \
tar xf mpfr-4.2.1.tar.xz && \
cd mpfr-4.2.1 && \
./configure && \
make -j$(nproc) && make install
# Download, build and install Bitwuzla.
RUN echo "[+] Download, build and install Bitwuzla" && \
cd $DEPENDENCIES_DIR && \