Skip to content

Commit e0fa780

Browse files
authored
Allow all LLVM versions >= 15 and support dynamic linking (#55)
* Use newest llvm-sys build.rs and support dyn linking * Bump LLVM to version 18 Use LLVM version 18 in all build scripts, since it is fully compatible with the existing LLVM 15 code. * Allow llvm version >= 15 * Bump CI checkout to use v4 * Set supported versions to 15-18
1 parent f0ee670 commit e0fa780

File tree

10 files changed

+503
-178
lines changed

10 files changed

+503
-178
lines changed

.github/workflows/cpp.yml

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,119 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11-
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
1211

1312
jobs:
14-
linux:
13+
linux-llvm-15:
1514
runs-on: ubuntu-latest
15+
env:
16+
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
1617
steps:
17-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1819
- name: Packages
19-
run: sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev libboost-program-options-dev cppcheck clang-tidy clang-format
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install zlib1g-dev libzstd-dev cppcheck clang-tidy clang-format llvm-15 llvm-15-dev
2023
- name: Code quality - fmt
21-
run: ./tool/format.sh check
24+
run: ./tool/format.sh check
2225
- name: Code quality - cppcheck
2326
run: ./tool/static-analysis-cppcheck.sh
2427
- name: Code quality - clang-tidy
2528
run: ./tool/static-analysis-tidy.sh
2629
- name: Build
27-
run: mkdir build/ && cd build && cmake .. && make
30+
run: |
31+
mkdir build
32+
cd build
33+
cmake ..
34+
make
2835
- name: Test
36+
working-directory: build/
2937
run: make test
38+
- name: cli
39+
working-directory: build/
40+
run: |
41+
./nyxstone "mov rax, rbx"
42+
./nyxstone "jmp label" --labels "label=0x1000"
43+
44+
mac-llvm-15:
45+
runs-on: macos-latest
46+
steps:
47+
- uses: actions/checkout@v4
48+
- name: Packages
49+
run: brew install llvm@15
50+
- name: Build
51+
run: |
52+
mkdir build
53+
cd build
54+
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" cmake ..
55+
make
56+
- name: Test
3057
working-directory: build/
58+
run: make test
3159
- name: cli
60+
working-directory: build/
3261
run: |
33-
./nyxstone "mov rax, rbx" &&
62+
./nyxstone "mov rax, rbx"
3463
./nyxstone "jmp label" --labels "label=0x1000"
3564
65+
mac-llvm-16:
66+
runs-on: macos-latest
67+
steps:
68+
- uses: actions/checkout@v4
69+
- name: Packages
70+
run: brew install llvm@16
71+
- name: Build
72+
run: |
73+
mkdir build
74+
cd build
75+
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" cmake ..
76+
make
77+
- name: Test
78+
working-directory: build/
79+
run: make test
80+
- name: cli
3681
working-directory: build/
82+
run: |
83+
./nyxstone "mov rax, rbx"
84+
./nyxstone "jmp label" --labels "label=0x1000"
85+
86+
mac-llvm-17:
87+
runs-on: macos-latest
88+
steps:
89+
- uses: actions/checkout@v4
90+
- name: Packages
91+
run: brew install llvm@17
92+
- name: Build
93+
run: |
94+
mkdir build
95+
cd build
96+
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" cmake ..
97+
make
98+
- name: Test
99+
working-directory: build/
100+
run: make test
101+
- name: cli
102+
working-directory: build/
103+
run: |
104+
./nyxstone "mov rax, rbx"
105+
./nyxstone "jmp label" --labels "label=0x1000"
106+
107+
mac-llvm-18:
108+
runs-on: macos-latest
109+
steps:
110+
- uses: actions/checkout@v4
111+
- name: Packages
112+
run: brew install llvm@18
113+
- name: Build
114+
run: |
115+
mkdir build
116+
cd build
117+
NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@18)" cmake ..
118+
make
119+
- name: Test
120+
working-directory: build/
121+
run: make test
122+
- name: cli
123+
working-directory: build/
124+
run: |
125+
./nyxstone "mov rax, rbx"
126+
./nyxstone "jmp label" --labels "label=0x1000"

.github/workflows/python.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ on:
66
pull_request:
77
branches: [ "main" ]
88

9-
env:
10-
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
11-
129
jobs:
1310
build:
1411
runs-on: ubuntu-latest
1512
env:
1613
working-dir: ./bindings/python
14+
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
1715

1816
steps:
19-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v4
2018
- name: Packages
21-
run: sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install zlib1g-dev libzstd-dev llvm-15 llvm-15-dev
2222
- name: Build
2323
run: pip install .
2424
working-directory: ${{ env.working-dir }}

.github/workflows/rust.yml

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,24 @@ on:
88

99
env:
1010
CARGO_TERM_COLOR: always
11-
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
1211

1312
jobs:
14-
linux:
13+
linux-llvm-15:
1514
runs-on: ubuntu-latest
1615
env:
1716
working-dir: ./bindings/rust
17+
NYXSTONE_LLVM_PREFIX: "/usr/lib/llvm-15/"
18+
NYXSTONE_LINK_FFI: "1"
1819
steps:
19-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2021
- name: Packages
21-
run: sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install llvm-15 llvm-15-dev zlib1g-dev libzstd-dev
2225
- name: Code quality
23-
run: cargo fmt --all -- --check && cargo clippy -- -D warnings
26+
run: |
27+
cargo fmt --all -- --check
28+
cargo clippy -- -D warnings
2429
working-directory: ${{ env.working-dir }}
2530
- name: Build
2631
run: cargo build
@@ -29,16 +34,63 @@ jobs:
2934
run: cargo test
3035
working-directory: ${{ env.working-dir }}
3136

32-
mac:
37+
mac-llvm-15:
3338
runs-on: macos-latest
3439
env:
3540
working-dir: ./bindings/rust
3641
steps:
37-
- uses: actions/checkout@v3
42+
- uses: actions/checkout@v4
43+
- name: Packages
44+
run: brew install llvm@15
45+
- name: Build
46+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" NYXSTONE_LINK_FFI=1 cargo build
47+
working-directory: ${{ env.working-dir }}
48+
- name: Run tests
49+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@15)" NYXSTONE_LINK_FFI=1 cargo test
50+
working-directory: ${{ env.working-dir }}
51+
52+
mac-llvm-16:
53+
runs-on: macos-latest
54+
env:
55+
working-dir: ./bindings/rust
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: Packages
59+
run: brew install llvm@16
60+
- name: Build
61+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" NYXSTONE_LINK_FFI=1 cargo build
62+
working-directory: ${{ env.working-dir }}
63+
- name: Run tests
64+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@16)" NYXSTONE_LINK_FFI=1 cargo test
65+
working-directory: ${{ env.working-dir }}
66+
67+
mac-llvm-17:
68+
runs-on: macos-latest
69+
env:
70+
working-dir: ./bindings/rust
71+
steps:
72+
- uses: actions/checkout@v4
73+
- name: Packages
74+
run: brew install llvm@17
75+
- name: Build
76+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" NYXSTONE_LINK_FFI=1 cargo build
77+
working-directory: ${{ env.working-dir }}
78+
- name: Run tests
79+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@17)" NYXSTONE_LINK_FFI=1 cargo test
80+
working-directory: ${{ env.working-dir }}
81+
82+
mac-llvm-18:
83+
runs-on: macos-latest
84+
env:
85+
working-dir: ./bindings/rust
86+
steps:
87+
- uses: actions/checkout@v4
88+
- name: Packages
89+
run: brew install llvm@18
3890
- name: Build
39-
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX=$(brew --prefix llvm@15) cargo build
91+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@18)" NYXSTONE_LINK_FFI=1 cargo build
4092
working-directory: ${{ env.working-dir }}
4193
- name: Run tests
42-
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX=$(brew --prefix llvm@15) cargo test
94+
run: RUSTFLAGS="-L$(brew --prefix zstd)/lib" RUSTDOCFLAGS="-L$(brew --prefix zstd)/lib" NYXSTONE_LLVM_PREFIX="$(brew --prefix llvm@18)" NYXSTONE_LINK_FFI=1 cargo test
4395
working-directory: ${{ env.working-dir }}
4496

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ option(NYXSTONE_SANITIZERS "Enable sanitizers" OFF)
1919

2020
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2121

22-
if(DEFINED $ENV{NYXSTONE_LLVM_PREFIX})
22+
if(DEFINED ENV{NYXSTONE_LLVM_PREFIX})
2323
# Ignore LLVM_ROOT variables
2424
set(CMAKE_FIND_USE_PACKAGE_ROOT_PATH OFF)
2525
set(CMAKE_PREFIX_PATH $ENV{NYXSTONE_LLVM_PREFIX})
2626
endif()
2727

28-
find_package(LLVM-Wrapper 15 REQUIRED COMPONENTS
28+
find_package(LLVM-Wrapper COMPONENTS
2929
core
3030
mc
3131
AllTargetsCodeGens

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Nyxstone is a powerful assembly and disassembly library based on LLVM. It doesn
2626

2727
## Core Features
2828

29-
* Assembles and disassembles code for all architectures supported by LLVM 15, including x86, ARM, MIPS, RISC-V and others.
29+
* Assembles and disassembles code for all architectures supported by the linked LLVM, including x86, ARM, MIPS, RISC-V and others.
3030

3131
* C++ library based on LLVM with Rust and Python bindings.
3232

@@ -51,38 +51,47 @@ This section provides instructions on how to get started with Nyxstone, covering
5151

5252
### Prerequisites
5353

54-
Before building Nyxstone, ensure clang and LLVM 15 are present as statically linked libraries. Nyxstone looks for `llvm-config` in your system's `$PATH` or the specified environment variable `$NYXSTONE_LLVM_PREFIX/bin`.
54+
Before building Nyxstone, ensure clang and LLVM are present on your system. Nyxstone supports LLVM major versions 15-18.
55+
When building it looks for `llvm-config` in your system's `$PATH` or the specified environment variable `$NYXSTONE_LLVM_PREFIX/bin`.
5556

56-
Installation Options for LLVM 15:
57+
Installation Options for LLVM versions 15-18:
5758

58-
* Debian/Ubuntu
59+
* Ubuntu
5960
```bash
60-
sudo apt install llvm-15 llvm-15-dev
61-
export NYXSTONE_LLVM_PREFIX=/usr/lib/llvm-15/
61+
sudo apt install llvm-${version} llvm-${version}-dev
62+
```
63+
64+
* Debian
65+
LLVM version 15 and 16 are available through debian repositories. Installation is the same as for Ubuntu.
66+
For versions 17 or 18 refer to [https://apt.llvm.org/](https://apt.llvm.org/) for installation instructions.
67+
68+
* Arch
69+
```bash
70+
sudo pacman -S llvm llvm-libs
6271
```
6372

6473
* Homebrew (macOS, Linux and others):
6574
```bash
66-
brew install llvm@15
67-
export NYXSTONE_LLVM_PREFIX=/opt/homebrew/opt/llvm@15
75+
brew install llvm@18
76+
export NYXSTONE_LLVM_PREFIX=/opt/homebrew/opt/llvm@18
6877
```
6978

7079
* From LLVM Source:
7180

72-
_Note_: On Windows you need to run these commands from a Visual Studio 2022 x64 command prompt. Additionally replace `~lib/my-llvm-15` with a different path.
81+
_Note_: On Windows you need to run these commands from a Visual Studio 2022 x64 command prompt. Additionally replace `~lib/my-llvm-18` with a different path.
7382

7483
```bash
7584
# checkout llvm
76-
git clone -b release/15.x --single-branch https://github.com/llvm/llvm-project.git
85+
git clone -b release/18.x --single-branch https://github.com/llvm/llvm-project.git
7786
cd llvm-project
7887

7988
# build LLVM with custom installation directory
8089
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_PARALLEL_LINK_JOBS=1
8190
cmake --build build
82-
cmake --install build --prefix ~/lib/my-llvm-15
91+
cmake --install build --prefix ~/lib/my-llvm-18
8392

8493
# export path
85-
export NYXSTONE_LLVM_PREFIX=~/lib/my-llvm-15
94+
export NYXSTONE_LLVM_PREFIX=~/lib/my-llvm-18
8695
```
8796

8897
Also make sure to install any system dependent libraries needed by your LLVM version for static linking. They can be viewed with the command `llvm-config --system-libs`; the list can be empty. On Ubuntu/Debian, you will need the packages `zlib1g-dev` and `zlibstd-dev`.
@@ -169,7 +178,7 @@ $ ./nyxstone -p "0x1000" -l ".label=0x1238" "jmp .label"
169178

170179
### C++ Library
171180

172-
To use Nyxstone as a C++ library, your C++ code has to be linked against Nyxstone and LLVM 15.
181+
To use Nyxstone as a C++ library, your C++ code has to be linked against Nyxstone and LLVM.
173182

174183
The following cmake example assumes Nyxstone in a subdirectory `nyxstone` in your project:
175184

@@ -321,3 +330,6 @@ The current contributors are:
321330
* Marc Fyrbiak (emproof)
322331
* Tim Blazytko (emproof)
323332

333+
## Acknowledgements
334+
335+
To ensure that we link LLVM correctly with proper versioning in Rust, we adapted the build.rs from [llvm-sys](https://gitlab.com/taricorp/llvm-sys.rs/).

bindings/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## Installation
77

8-
You need to have LLVM 15 (with static library support) installed to build the nyxstone bindings. The `setup.py` searches for LLVM in the `PATH` or in the directory set in the environment variable `NYXSTONE_LLVM_PREFIX`. Specifically, it searches for the binary `$NYXSTONE_LLVM_PREFIX/bin/llvm-config` and uses it to set the required libraries and cpp flags.
8+
You need to have LLVM (with major version in the range 15-18) installed to build the nyxstone bindings. The `setup.py` searches for LLVM in the `PATH` or in the directory set in the environment variable `NYXSTONE_LLVM_PREFIX`. Specifically, it searches for the binary `$NYXSTONE_LLVM_PREFIX/bin/llvm-config` and uses it to set the required libraries and cpp flags.
99

1010
Running
1111

0 commit comments

Comments
 (0)