Skip to content

Commit cebdda3

Browse files
author
Triton Library
committed
Merge branch 'dev-v1.0' of github.com:JonathanSalwan/Triton into dev-v1.0
2 parents b41f0e0 + d66a9d9 commit cebdda3

File tree

7 files changed

+96
-17
lines changed

7 files changed

+96
-17
lines changed

.github/workflows/codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
2424
- name: Install dependencies
2525
run: |
26-
sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev
26+
sudo apt-get install python3-setuptools lcov libboost-dev libgmp-dev libmpfr-dev
2727
2828
- name: Install LLVM and Clang
2929
uses: KyleMayes/install-llvm-action@v2

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
2727
- name: Install dependencies
2828
run: |
29-
sudo apt-get install python3-setuptools libboost-dev libgmp-dev
29+
sudo apt-get install python3-setuptools libboost-dev libgmp-dev libmpfr-dev
3030
3131
- name: Install LLVM and Clang
3232
uses: KyleMayes/install-llvm-action@v2

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ RUN DEBIAN_FRONTEND="noninteractive" \
2424
pkg-config \
2525
python3-pip \
2626
python3-venv \
27-
tar && \
27+
tar \
28+
libmpfr-dev && \
2829
apt clean
2930

3031
ENV VIRTUAL_ENV=/Triton-venv

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ You can use cmake to generate the .sln file of libTriton.
183183
-DCAPSTONE_LIBRARIES="C:/Users/jonathan/Works/Tools/capstone-5.0.1-win64/capstone.lib" ..
184184
```
185185

186+
You can use setup.py to generate the debug version of triton.pyd on Windows.
187+
188+
```console
189+
> git clone https://github.com/JonathanSalwan/Triton.git
190+
> cd Triton
191+
> $env:COMPILER_DIR="C:/deps/llvm/llvm2116r/bin"
192+
> $env:CMAKE_PREFIX_PATH="C:/deps/llvm/llvm-project-21.1.6.src/install/lib/cmake/llvm;C:/code/cxx-common-cmake/build/install"
193+
> python_d -m build --wheel
194+
> python_d -m pip install (Get-ChildItem .\dist\triton_library*)
195+
196+
```
197+
186198
However, if you prefer to directly download the precompiled library, check out our AppVeyor's [artefacts](https://ci.appveyor.com/project/JonathanSalwan/triton/history).
187199
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)
188200
packages for Visual Studio 2012.

setup.py

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,23 @@
2020
VERSION_MAJOR = 1
2121
VERSION_MINOR = 0
2222
VERSION_PATCH = 0
23+
ON = "ON"
24+
OFF = "OFF"
25+
26+
clang = "clang"
27+
clang_cl = "clang_cl"
28+
vs2022 = "vs2022"
29+
Release = "Release"
30+
Debug = "Debug"
2331

2432
RELEASE_CANDIDATE = 4
33+
Z3_INTERFACE = ON
34+
LLVM_INTERFACE = OFF
35+
BITWUZLA_INTERFACE = OFF
36+
BOOST_INTERFACE = OFF
37+
38+
BUILDTOOLS = vs2022 # clang or clang_cl or vs2022
39+
CMAKE_BUILD_TYPE = Release # Release or Debug
2540

2641
VERSION = f'{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}' + \
2742
f'rc{RELEASE_CANDIDATE}' if RELEASE_CANDIDATE else ''
@@ -59,7 +74,7 @@ def build_extension(self, ext):
5974
cmake_args = [
6075
# General arguments.
6176
'-DPYTHON_EXECUTABLE=' + sys.executable,
62-
'-DCMAKE_BUILD_TYPE=Release',
77+
'-DCMAKE_BUILD_TYPE='+ CMAKE_BUILD_TYPE,
6378
]
6479

6580
# Interfaces can be defined using environment variables.
@@ -70,7 +85,7 @@ def build_extension(self, ext):
7085
# BITWUZLA_INTERFACE=Off
7186
# BOOST_INTERFACE=Off
7287
#
73-
for arg, value in [('Z3_INTERFACE', 'On'), ('LLVM_INTERFACE', 'Off'), ('BITWUZLA_INTERFACE', 'Off'), ('BOOST_INTERFACE', 'Off')]:
88+
for arg, value in [('Z3_INTERFACE', Z3_INTERFACE), ('LLVM_INTERFACE', LLVM_INTERFACE), ('BITWUZLA_INTERFACE', BITWUZLA_INTERFACE), ('BOOST_INTERFACE', BOOST_INTERFACE)]:
7489
if os.getenv(arg):
7590
cmake_args += [f'-D{arg}=' + os.getenv(arg)]
7691
else:
@@ -89,11 +104,27 @@ def build_extension(self, ext):
89104
build_args += ['--', '-j4']
90105

91106
elif platform.system() == "Windows":
92-
cmake_args += [
93-
'-G Visual Studio 17 2022',
94-
]
95-
build_args += ['--', '/m:4']
96-
107+
if BUILDTOOLS == vs2022:
108+
cmake_args += [
109+
"-G Visual Studio 17 2022",
110+
]
111+
build_args += ["--", "/m:4"]
112+
else:
113+
assert os.getenv('COMPILER_DIR'), "COMPILER_DIR(clang or clang_cl) env not found"
114+
if BUILDTOOLS == clang:
115+
cmake_args += [
116+
"-DCMAKE_C_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang.exe",
117+
"-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang++.exe",
118+
"-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe",
119+
"-G Ninja",
120+
]
121+
if BUILDTOOLS == clang_cl:
122+
cmake_args += [
123+
"-DCMAKE_C_COMPILER= " + os.getenv('COMPILER_DIR') + "/clang-cl.exe",
124+
"-DCMAKE_CXX_COMPILER=" + os.getenv('COMPILER_DIR') + "/clang-cl.exe",
125+
"-DCMAKE_RC_COMPILER=" + os.getenv('COMPILER_DIR') + "/llvm-rc.exe",
126+
"-G Ninja",
127+
]
97128
else:
98129
raise Exception(f'Platform not supported: {platform.system()}')
99130

@@ -123,7 +154,6 @@ def build_extension(self, ext):
123154

124155
if os.getenv('BITWUZLA_INCLUDE_DIRS'):
125156
cmake_args += ['-DBITWUZLA_INCLUDE_DIRS=' + os.getenv('BITWUZLA_INCLUDE_DIRS')]
126-
127157
# Custom Capstone paths.
128158
if os.getenv('CAPSTONE_LIBRARIES'):
129159
cmake_args += ['-DCAPSTONE_LIBRARIES=' + os.getenv('CAPSTONE_LIBRARIES')]
@@ -155,11 +185,11 @@ def build_extension(self, ext):
155185
os.makedirs(self.build_lib)
156186

157187
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
158-
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python-triton'] + build_args, cwd=self.build_temp)
188+
subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python-triton'] + build_args, cwd=self.build_temp)
159189

160190
# The autocomplete file has to be built separately.
161191
if (is_cmake_true(python_autocomplete_value)):
162-
subprocess.check_call(['cmake', '--build', '.', '--config', 'Release', '--target', 'python_autocomplete'], cwd=self.build_temp)
192+
subprocess.check_call(['cmake', '--build', '.', '--config', CMAKE_BUILD_TYPE, '--target', 'python_autocomplete'], cwd=self.build_temp)
163193

164194
def copy_extension_to_source(self, ext):
165195
fullname = self.get_ext_fullname(ext.name)
@@ -172,7 +202,10 @@ def copy_extension_to_source(self, ext):
172202
src_filename = os.path.join(self.build_temp + '/src/libtriton', 'libtriton.dylib')
173203
dst_filename = os.path.join(self.build_lib, os.path.basename(filename))
174204
elif platform.system() == "Windows":
175-
src_filename = os.path.join(self.build_temp + '\\src\\libtriton\\Release', 'triton.pyd')
205+
if BUILDTOOLS == vs2022:
206+
src_filename = os.path.join(self.build_temp + '/src/libtriton/' + CMAKE_BUILD_TYPE, 'triton.pyd')
207+
else:
208+
src_filename = os.path.join(self.build_temp + '/src/libtriton', 'triton.pyd')
176209
dst_filename = os.path.join(self.build_lib, os.path.basename(filename))
177210
else:
178211
raise Exception(f'Platform not supported: {platform.system()}')

src/libtriton/ast/astContext.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ namespace triton {
353353
return this->bv(expr2->getBitvectorMask(), expr2->getBitvectorSize());
354354

355355
/* Optimization: A | A = A */
356-
if (expr1->equalTo(expr2))
356+
/* Only apply when both operands are concrete. Two different symbolic expressions
357+
* may evaluate to the same value but represent distinct computations. */
358+
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
357359
return expr1;
358360
}
359361

@@ -603,7 +605,9 @@ namespace triton {
603605
return this->bvneg(expr2);
604606

605607
/* Optimization: A - A = 0 */
606-
if (expr1->equalTo(expr2))
608+
/* Only apply when both operands are concrete to preserve symbolic information.
609+
* Different symbolic expressions may evaluate equal but must remain distinct. */
610+
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
607611
return this->bv(0, expr1->getBitvectorSize());
608612
}
609613

@@ -732,7 +736,10 @@ namespace triton {
732736
return expr2;
733737

734738
/* Optimization: A ^ A = 0 */
735-
if (expr1->equalTo(expr2))
739+
/* Only apply when both operands are concrete to avoid losing symbolic information.
740+
* Two different symbolic expressions may have the same concrete value temporarily,
741+
* but they represent different symbolic computations that must be preserved. */
742+
if (!expr1->isSymbolized() && !expr2->isSymbolized() && expr1->equalTo(expr2))
736743
return this->bv(0, expr1->getBitvectorSize());
737744
}
738745

src/scripts/docker/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ RUN yum install -y \
1717
libzstd-devel \
1818
ncurses-devel
1919

20+
ENV VIRTUAL_ENV=/Triton-venv
21+
RUN python3.10 -m venv $VIRTUAL_ENV
22+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
23+
24+
RUN . $VIRTUAL_ENV/bin/activate && \
25+
pip install --upgrade pip
26+
2027
RUN python3.10 -m pip install meson
2128

2229
ENV DEPENDENCIES_DIR=/tmp/triton-dependencies
@@ -25,6 +32,25 @@ ENV SOURCE_DIR=/src
2532
# Create directory for dependencies.
2633
RUN mkdir -p $DEPENDENCIES_DIR
2734

35+
# Download, build and install GMP.
36+
RUN echo "[+] Download, build and install GMP" && \
37+
cd $DEPENDENCIES_DIR && \
38+
curl -LO https://ftp.gnu.org/gnu/gmp/gmp-6.3.0.tar.xz && \
39+
tar xf gmp-6.3.0.tar.xz && \
40+
cd gmp-6.3.0 && \
41+
./configure --disable-assembly --enable-cxx && \
42+
make -j$(nproc) && \
43+
make install
44+
45+
46+
RUN echo "[+] Download, build and install mpfr" && \
47+
cd $DEPENDENCIES_DIR && \
48+
curl -LO https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.1.tar.xz && \
49+
tar xf mpfr-4.2.1.tar.xz && \
50+
cd mpfr-4.2.1 && \
51+
./configure && \
52+
make -j$(nproc) && make install
53+
2854
# Download, build and install Bitwuzla.
2955
RUN echo "[+] Download, build and install Bitwuzla" && \
3056
cd $DEPENDENCIES_DIR && \

0 commit comments

Comments
 (0)