Skip to content

Commit 23a495d

Browse files
committed
feat: add llvm 20 support
1 parent db7e714 commit 23a495d

File tree

23 files changed

+68
-8
lines changed

23 files changed

+68
-8
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-linux-x86_64.tar.gz", "libLLVM-17.so"]
2626
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-linux-x86_64.tar.gz", "libLLVM.so.18.1"]
2727
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-linux-x86_64.tar.gz", "libLLVM.so.19.1"]
28+
- ["20", "20-1", "v20.1.1-rust-1.87/llvm-lld-20.1.1-rust-1.87-linux-x86_64.tar.gz", "libLLVM.so.20.1"]
2829
steps:
2930
- name: Checkout Repo
3031
uses: actions/checkout@v2
@@ -150,6 +151,7 @@ jobs:
150151
- ["17", "17-0", "1.75", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-linux-x86_64.tar.gz", "libLLVM-17.so"]
151152
- ["18", "18-1", "1.78", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-linux-x86_64.tar.gz", "libLLVM.so.18.1"]
152153
- ["19", "19-1", "1.84", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-linux-x86_64.tar.gz", "libLLVM.so.19.1"]
154+
- ["20", "20-1", "1.87", "v20.1.1-rust-1.87/llvm-lld-20.1.1-rust-1.87-linux-x86_64.tar.gz", "libLLVM.so.20.1"]
153155
steps:
154156
- name: Checkout Repo
155157
uses: actions/checkout@v2

.github/workflows/macos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-macos-x86_64.tar.gz", "macos-13"]
2626
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-macos-arm64.tar.gz", "macos-latest"]
2727
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-macos-arm64.tar.gz", "macos-latest"]
28+
- ["20", "20-1", "v20.1.1-rust-1.87/llvm-lld-20.1.1-rust-1.87-macos-arm64.tar.gz", "macos-latest"]
2829
steps:
2930
- name: Checkout Repo
3031
uses: actions/checkout@v2

.github/workflows/windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
- ["17", "17-0", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-windows-x86_64.7z"]
2626
- ["18", "18-1", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-windows-x86_64.7z"]
2727
- ["19", "19-1", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-windows-x86_64.7z"]
28+
- ["20", "20-1", "v20.1.1-rust-1.87/llvm-lld-20.1.1-rust-1.87-windows-x86_64.7z"]
2829
steps:
2930
- name: Checkout Repo
3031
uses: actions/checkout@v2
@@ -149,6 +150,7 @@ jobs:
149150
- ["17", "17-0", "1.75", "v17.0.6-rust-1.75/llvm-lld-17.0.6-rust-1.75-windows-x86_64.7z"]
150151
- ["18", "18-1", "1.78", "v18.1.2-rust-1.78/llvm-lld-18.1.2-rust-1.78-windows-x86_64.7z"]
151152
- ["19", "19-1", "1.84", "v19.1.5-rust-1.84/llvm-lld-19.1.5-rust-1.84-windows-x86_64.7z"]
153+
- ["20", "20-1", "1.87", "v20.1.1-rust-1.87/llvm-lld-20.1.1-rust-1.87-windows-x86_64.7z"]
152154
steps:
153155
- name: Checkout Repo
154156
uses: actions/checkout@v2

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ When importing this crate in your `Cargo.toml`, you will need to specify the LLV
2727

2828
```toml
2929
[dependencies]
30-
llvm-plugin = { git = "https://github.com/jamesmth/llvm-plugin-rs", features = ["llvm19-1"] }
30+
llvm-plugin = { git = "https://github.com/jamesmth/llvm-plugin-rs", features = ["llvm20-1"] }
3131
```
3232

33-
Supported versions: LLVM 11-19 mapping to a cargo feature flag `llvmX-Y` where `X` and `Y` are the LLVM major and minor versions.
33+
Supported versions: LLVM 11-20 mapping to a cargo feature flag `llvmX-Y` where `X` and `Y` are the LLVM major and minor versions.
3434

3535
## Getting Started
3636

examples/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ achieved with simple LLVM passes.
99
<summary><em>Execute the example</em></summary>
1010

1111
```shell
12-
$ cargo b --example hello-world --features llvm19-1
12+
$ cargo b --example hello-world --features llvm20-1
1313
$ opt --load-pass-plugin=target/debug/examples/libhello_world.so --passes=hello-world in.ll -S -o out.ll
1414
```
1515

@@ -21,7 +21,7 @@ achieved with simple LLVM passes.
2121
<summary><em>Execute the example</em></summary>
2222

2323
```shell
24-
$ cargo b --example opcode-counter --features llvm19-1
24+
$ cargo b --example opcode-counter --features llvm20-1
2525
$ opt --load-pass-plugin=target/debug/examples/libopcode_counter.so --passes=opcode-counter-printer in.ll -S -o out.ll
2626
```
2727

@@ -33,7 +33,7 @@ achieved with simple LLVM passes.
3333
<summary><em>Execute the example</em></summary>
3434

3535
```shell
36-
$ cargo b --example inject-printf --features llvm19-1
36+
$ cargo b --example inject-printf --features llvm20-1
3737
$ opt --load-pass-plugin=target/debug/examples/libinject_printf.so --passes=inject-func-call in.ll -S -o out.ll
3838
```
3939

@@ -45,7 +45,7 @@ achieved with simple LLVM passes.
4545
<summary><em>Execute the example</em></summary>
4646

4747
```shell
48-
$ cargo b --example static-call-counter --features llvm19-1
48+
$ cargo b --example static-call-counter --features llvm20-1
4949
$ opt --load-pass-plugin=target/debug/examples/libstatic_call_counter.so --passes=static-cc-printer in.ll -S -o out.ll
5050
```
5151

@@ -57,7 +57,7 @@ achieved with simple LLVM passes.
5757
<summary><em>Execute the example</em></summary>
5858

5959
```shell
60-
$ cargo b --example string-obf --features llvm19-1
60+
$ cargo b --example string-obf --features llvm20-1
6161
$ opt --load-pass-plugin=target/debug/examples/libstring_obf.so --passes=string-obfuscator-pass in.ll -S -o out.ll
6262
```
6363

examples/inject_printf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use llvm_plugin::{
1414
feature = "llvm17-0",
1515
feature = "llvm18-1",
1616
feature = "llvm19-1",
17+
feature = "llvm20-1",
1718
)))]
1819
macro_rules! ptr_type {
1920
($cx:ident, $ty:ident) => {
@@ -26,6 +27,7 @@ macro_rules! ptr_type {
2627
feature = "llvm17-0",
2728
feature = "llvm18-1",
2829
feature = "llvm19-1",
30+
feature = "llvm20-1",
2931
))]
3032
macro_rules! ptr_type {
3133
($cx:ident, $ty:ident) => {

examples/strings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use llvm_plugin::{
1616
feature = "llvm17-0",
1717
feature = "llvm18-1",
1818
feature = "llvm19-1",
19+
feature = "llvm20-1",
1920
)))]
2021
macro_rules! ptr_type {
2122
($cx:ident, $ty:ident) => {
@@ -28,6 +29,7 @@ macro_rules! ptr_type {
2829
feature = "llvm17-0",
2930
feature = "llvm18-1",
3031
feature = "llvm19-1",
32+
feature = "llvm20-1",
3133
))]
3234
macro_rules! ptr_type {
3335
($cx:ident, $ty:ident) => {
@@ -192,6 +194,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
192194
feature = "llvm17-0",
193195
feature = "llvm18-1",
194196
feature = "llvm19-1",
197+
feature = "llvm20-1",
195198
)))]
196199
let var10 = unsafe {
197200
builder.build_gep(
@@ -207,6 +210,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
207210
feature = "llvm17-0",
208211
feature = "llvm18-1",
209212
feature = "llvm19-1",
213+
feature = "llvm20-1",
210214
))]
211215
let var10 = unsafe {
212216
builder.build_gep(
@@ -223,6 +227,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
223227
feature = "llvm17-0",
224228
feature = "llvm18-1",
225229
feature = "llvm19-1",
230+
feature = "llvm20-1",
226231
)))]
227232
let var11 = builder
228233
.build_load(phi1.as_basic_value().into_pointer_value(), "")
@@ -233,6 +238,7 @@ fn create_decode_fn<'a>(module: &mut Module<'a>) -> FunctionValue<'a> {
233238
feature = "llvm17-0",
234239
feature = "llvm18-1",
235240
feature = "llvm19-1",
241+
feature = "llvm20-1",
236242
))]
237243
let var11 = builder
238244
.build_load(cx.i8_type(), phi1.as_basic_value().into_pointer_value(), "")
@@ -292,6 +298,7 @@ fn create_decode_stub<'a>(
292298
feature = "llvm17-0",
293299
feature = "llvm18-1",
294300
feature = "llvm19-1",
301+
feature = "llvm20-1",
295302
)))]
296303
let s = builder
297304
.build_struct_gep(gs.as_pointer_value(), id, "")
@@ -302,6 +309,7 @@ fn create_decode_stub<'a>(
302309
feature = "llvm17-0",
303310
feature = "llvm18-1",
304311
feature = "llvm19-1",
312+
feature = "llvm20-1",
305313
))]
306314
let s = {
307315
let i8_ty_ptr = ptr_type!(cx, i8_type);

llvm-plugin/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ llvm16-0 = ["inkwell/llvm16-0-no-llvm-linking"]
3333
llvm17-0 = ["inkwell/llvm17-0-no-llvm-linking"]
3434
llvm18-1 = ["inkwell/llvm18-1-no-llvm-linking"]
3535
llvm19-1 = ["inkwell/llvm19-1-no-llvm-linking"]
36+
llvm20-1 = ["inkwell/llvm20-1-no-llvm-linking"]
3637

3738
target-x86 = ["inkwell/target-x86"]
3839
target-arm = ["inkwell/target-arm"]

llvm-plugin/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ mod llvm_sys {
216216
(18, 1)
217217
} else if cfg!(feature = "llvm19-1") {
218218
(19, 1)
219+
} else if cfg!(feature = "llvm20-1") {
220+
(20, 1)
219221
} else {
220222
panic!("Missing llvm* feature")
221223
}

llvm-plugin/cpp/ffi.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ auto passBuilderAddOptimizerLastEPCallback(
118118

119119
Builder.registerOptimizerLastEPCallback(
120120
[Data = std::move(Data), Callback](llvm::ModulePassManager &PassManager,
121+
#if (LLVM_VERSION_MAJOR >= 20)
122+
LlvmOptLevel Opt,
123+
llvm::ThinOrFullLTOPhase) {
124+
#else
121125
LlvmOptLevel Opt) {
126+
#endif
122127
const auto OptFFI = getFFIOptimizationLevel(Opt);
123128
Callback(Data.get(), PassManager, OptFFI);
124129
});
@@ -134,7 +139,12 @@ auto passBuilderAddOptimizerEarlyEPCallback(
134139

135140
Builder.registerOptimizerEarlyEPCallback(
136141
[Data = std::move(Data), Callback](llvm::ModulePassManager &PassManager,
142+
#if (LLVM_VERSION_MAJOR >= 20)
143+
LlvmOptLevel Opt,
144+
llvm::ThinOrFullLTOPhase) {
145+
#else
137146
LlvmOptLevel Opt) {
147+
#endif
138148
const auto OptFFI = getFFIOptimizationLevel(Opt);
139149
Callback(Data.get(), PassManager, OptFFI);
140150
});
@@ -151,7 +161,12 @@ auto passBuilderAddPipelineEarlySimplificationEPCallback(
151161

152162
Builder.registerPipelineEarlySimplificationEPCallback(
153163
[Data = std::move(Data), Callback](llvm::ModulePassManager &PassManager,
164+
#if (LLVM_VERSION_MAJOR >= 20)
165+
LlvmOptLevel Opt,
166+
llvm::ThinOrFullLTOPhase) {
167+
#else
154168
LlvmOptLevel Opt) {
169+
#endif
155170
const auto OptFFI = getFFIOptimizationLevel(Opt);
156171
Callback(Data.get(), PassManager, OptFFI);
157172
});

0 commit comments

Comments
 (0)