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

RISCV basic support #1318

Merged
merged 15 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 11 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
10 changes: 5 additions & 5 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
name: Get vcpkg
with:
repository: 'microsoft/vcpkg'
ref: '2022.04.12'
ref: '2024.05.24'
path: '${{ github.workspace }}/_vcpkg'
fetch-depth: 0

Expand All @@ -64,7 +64,7 @@ jobs:
- name: Configure (Windows)
if: ${{ matrix.platform == 'windows' }}
run: |
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}\vcpkg\triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DCOMPILE_RISCV:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}\vcpkg\triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
env:
# capstone 4.0.2 does not produce a CMake Config, hence the need to point directly to include directories and libraries
CAPSTONE_INCLUDE_DIRS: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/include
Expand All @@ -76,7 +76,7 @@ jobs:
if: ${{ matrix.platform != 'windows' }}
run: |
python -m pip install importlib-resources
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}/vcpkg/triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
cmake --preset=${{ matrix.cmake-preset }} -DBUILD_SHARED_LIBS:BOOL=ON -DCOMPILE_RISCV:BOOL=ON -DVCPKG_OVERLAY_TRIPLETS:PATH=${{ github.workspace }}/vcpkg/triplets -DVCPKG_TARGET_TRIPLET:STRING=${{ matrix.vcpkg-triplet }}
env:
# capstone 4.0.2 does not produce a CMake Config, hence the need to point directly to include directories and libraries
CAPSTONE_INCLUDE_DIRS: ${{ github.workspace }}/build/${{ matrix.cmake-preset }}/vcpkg_installed/${{ matrix.vcpkg-triplet }}/include
Expand All @@ -86,7 +86,7 @@ jobs:

- name: Build
run: |
cmake --build --preset build-${{ matrix.cmake-preset }} --config Release
cmake --build --preset build-${{ matrix.cmake-preset }} --config Release -DCOMPILE_RISCV:BOOL=ON

- name: Test
# Test disabled on Windows `pip install lief` fails as there is no ready to use .whl and compilation fails
Expand All @@ -98,7 +98,7 @@ jobs:

- name: Install
run: |
cmake --build --preset build-${{ matrix.cmake-preset }} --config Release --target install
cmake --build --preset build-${{ matrix.cmake-preset }} --config Release --target install -DCOMPILE_RISCV:BOOL=ON

- name: Upload
uses: actions/upload-artifact@v3
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ endif()
message(STATUS "Compiling with Capstone")
find_package(CAPSTONE 5 REQUIRED)
message(STATUS "CAPSTONE version: ${CAPSTONE_VERSION}")
if(NOT ${CS_VERSION_MAJOR} MATCHES 4)
Copy link
Owner

Choose a reason for hiding this comment

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

What if it's capstone 3? Maybe we should use GREATER_EQUAL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Triton's dependency list says that libcapstone >= 4.0.x is required.
Actually it was once GREATER_EQUAL, but vcpkg builder doesn't like it because CS_VERSION_MAJOR is treated as an empty variable

Copy link
Owner

Choose a reason for hiding this comment

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

Good point. Well, ok to lets keep if(NOT ${CS_VERSION_MAJOR} MATCHES 4) if it's better for CIs.

Copy link
Owner

Choose a reason for hiding this comment

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

Other solutions:

  1. we could upgrade the cmake used by vcpkg. GREATER_EQUAL is used from cmake 3.7.2.
  2. On cmake 3.0.2 we have the GREATER variable.

Copy link
Owner

@JonathanSalwan JonathanSalwan Jul 22, 2024

Choose a reason for hiding this comment

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

Looks like cmake 3.30 is used by vcpkg. So, using GREATER should be ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GREATER_EQUAL is ok too with manually specified first argument

set(COMPILE_RISCV ON)
endif()
if(${COMPILE_RISCV})
add_definitions(-DCOMPILE_RISCV)
endif()
if(TARGET capstone::capstone)
link_libraries(capstone::capstone)
elseif(DEFINED CAPSTONE_INCLUDE_DIRS)
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ COPY . /Triton
# cmake >= 3.20
RUN apt update && apt upgrade -y && apt install -y build-essential clang curl git libboost-all-dev libgmp-dev libpython3-dev libpython3-stdlib llvm-12 llvm-12-dev python3-pip tar ninja-build pkg-config && apt-get clean && pip install --upgrade pip && pip3 install Cython lief cmake meson

# libcapstone >= 4.0.x
# libcapstone >= 5.0.x
RUN cd /tmp && \
curl -o cap.tgz -L https://github.com/aquynh/capstone/archive/5.0.1.tar.gz && \
tar xvf cap.tgz && cd capstone-5.0.1/ && ./make.sh && make install && rm -rf /tmp/cap* \
tar xvf cap.tgz && cd capstone-5.0.1/ && CAPSTONE_ARCHS="arm aarch64 riscv x86" ./make.sh && \
make install && rm -rf /tmp/cap* \
&& ln -s /usr/lib/libcapstone.so.5 /usr/lib/x86_64-linux-gnu/libcapstone.so

# libbitwuzla >= 0.4.0
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

#include <stdio.h>
#include <stdlib.h>

char *serial = "\x31\x3e\x3d\x26\x31";

int check(char *ptr)
{
int i;
int hash = 0xABCD;

for (i = 0; ptr[i]; i++)
hash += ptr[i] ^ serial[i % 5];

return hash;
}

int main(int ac, char **av)
{
int ret;

if (ac != 2)
return -1;

ret = check(av[1]);
if (ret == 0xad6d)
printf("Win\n");
else
printf("fail\n");

return 0;
}

Loading
Loading