Skip to content

Commit a69bc17

Browse files
committed
Auto merge of #141002 - GuillaumeGomez:subtree-update_cg_gcc_2025-05-14, r=GuillaumeGomez
Subtree update GCC backend 2025 05 14 cc `@antoyo`
2 parents c8bda74 + d5c5a82 commit a69bc17

30 files changed

+911
-249
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cargo.lock linguist-generated=false

compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ jobs:
101101
if: ${{ matrix.cargo_runner }}
102102
run: |
103103
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
104-
# TODO: remove --skip test_mm512_stream_ps when stdarch is updated in rustc.
105104
# TODO: remove --skip test_tile_ when it's implemented.
106-
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features --cfg stdarch_intel_sde" ./y.sh cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml -- --skip rtm --skip tbm --skip sse4a --skip test_mm512_stream_ps --skip test_tile_
105+
STDARCH_TEST_SKIP_FUNCTION="xsave,xsaveopt,xsave64,xsaveopt64" STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ./y.sh cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml -- --skip rtm --skip tbm --skip sse4a --skip test_tile_
107106
108107
# Summary job for the merge queue.
109108
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Contributing to rustc_codegen_gcc
2+
3+
Welcome to the `rustc_codegen_gcc` project! This guide will help you get started as a contributor. The project aims to provide a GCC codegen backend for rustc, allowing Rust compilation on platforms unsupported by LLVM and potentially improving runtime performance through GCC's optimizations.
4+
5+
## Getting Started
6+
7+
### Setting Up Your Development Environment
8+
9+
For detailed setup instructions including dependencies, build steps, and initial testing, please refer to our [README](Readme.md). The README contains the most up-to-date information on:
10+
11+
- Required dependencies and system packages
12+
- Repository setup and configuration
13+
- Build process
14+
- Basic test verification
15+
16+
Once you've completed the setup process outlined in the README, you can proceed with the contributor-specific information below.
17+
18+
## Communication Channels
19+
20+
- Matrix: Join our [Matrix channel](https://matrix.to/#/#rustc_codegen_gcc:matrix.org)
21+
- IRC: Join us on [IRC](https://web.libera.chat/#rustc_codegen_gcc)
22+
- [GitHub Issues](https://github.com/rust-lang/rustc_codegen_gcc/issues): For bug reports and feature discussions
23+
24+
We encourage new contributors to join our communication channels and introduce themselves. Feel free to ask questions about where to start or discuss potential contributions.
25+
26+
## Understanding Core Concepts
27+
28+
### Common Development Tasks
29+
30+
#### Running Specific Tests
31+
32+
To run specific tests, use appropriate flags such as:
33+
34+
- `./y.sh test --test-libcore`
35+
- `./y.sh test --std-tests`
36+
- `cargo test -- <name of test>`
37+
38+
Additionally, you can run the tests of `libgccjit`:
39+
40+
```bash
41+
# libgccjit tests
42+
cd gcc-build/gcc
43+
make check-jit
44+
# For a specific test:
45+
make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-asm.cc"
46+
```
47+
48+
#### Debugging Tools
49+
50+
The project provides several environment variables for debugging:
51+
52+
- `CG_GCCJIT_DUMP_GIMPLE`: Dumps the GIMPLE IR
53+
- `CG_RUSTFLAGS`: Additional Rust flags
54+
- `CG_GCCJIT_DUMP_MODULE`: Dumps a specific module
55+
- `CG_GCCJIT_DUMP_TO_FILE`: Creates C-like representation
56+
57+
Full list of debugging options can be found in the [README](Readme.md#env-vars).
58+
59+
## Making Contributions
60+
61+
### Finding Issues to Work On
62+
63+
1. Look for issues labeled with [`good first issue`](https://github.com/rust-lang/rustc_codegen_gcc/issues?q=is%3Aissue%20state%3Aopen%20label%3A"good%20first%20issue") or [`help wanted`](https://github.com/rust-lang/rustc_codegen_gcc/issues?q=is%3Aissue%20state%3Aopen%20label%3A"help%20wanted")
64+
2. Check the [progress report](https://blog.antoyo.xyz/rustc_codegen_gcc-progress-report-34#state_of_rustc_codegen_gcc) for larger initiatives
65+
3. Consider improving documentation or investigating [failing tests](https://github.com/rust-lang/rustc_codegen_gcc/tree/master/tests) (except `failing-ui-tests12.txt`)
66+
67+
### Pull Request Process
68+
69+
1. Fork the repository and create a new branch
70+
2. Make your changes with clear commit messages
71+
3. Add tests for new functionality
72+
4. Update documentation as needed
73+
5. Submit a PR with a description of your changes
74+
75+
### Code Style Guidelines
76+
77+
- Follow Rust standard coding conventions
78+
- Ensure your code passes `rustfmt` and `clippy`
79+
- Add comments explaining complex logic, especially in GCC interface code
80+
81+
## Additional Resources
82+
83+
- [Rustc Dev Guide](https://rustc-dev-guide.rust-lang.org/)
84+
- [GCC Internals Documentation](https://gcc.gnu.org/onlinedocs/gccint/)
85+
- Project-specific documentation in the `doc/` directory:
86+
- [Common errors](doc/errors.md)
87+
- [Debugging](doc/debugging.md)
88+
- [Debugging libgccjit](doc/debugging-libgccjit.md)
89+
- [Git subtree sync](doc/subtree.md)
90+
- [List of useful commands](doc/tips.md)
91+
- [Send a patch to GCC](doc/sending-gcc-patch.md)
92+
93+
## Getting Help
94+
95+
If you're stuck or unsure about anything:
96+
1. Check the existing documentation in the `doc/` directory
97+
2. Ask in the IRC or Matrix channels
98+
3. Open a GitHub issue for technical problems
99+
4. Comment on the issue you're working on if you need guidance
100+
101+
Remember that all contributions, including documentation improvements, bug reports, and feature requests, are valuable to the project.

compiler/rustc_codegen_gcc/Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ dependencies = [
5656

5757
[[package]]
5858
name = "gccjit"
59-
version = "2.5.0"
59+
version = "2.7.0"
6060
source = "registry+https://github.com/rust-lang/crates.io-index"
61-
checksum = "2895ddec764de7ac76fe6c056050c4801a80109c066f177a00a9cc8dee02b29b"
61+
checksum = "ae99a89184220d967dd300139f2d2ae7d52c1a69d632b24aacc57c54625254ce"
6262
dependencies = [
6363
"gccjit_sys",
6464
]
6565

6666
[[package]]
6767
name = "gccjit_sys"
68-
version = "0.6.0"
68+
version = "0.8.0"
6969
source = "registry+https://github.com/rust-lang/crates.io-index"
70-
checksum = "ac133db68db8a6a8b2c51ef4b18d8ea16682d5814c4641272fe37bbbc223d5f3"
70+
checksum = "24edb7bfe2b7b27c6d09ed23eebfcab0b359c8fe978433f902943e6f127a0f1b"
7171
dependencies = [
7272
"libc",
7373
]

compiler/rustc_codegen_gcc/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rustc_codegen_gcc"
33
version = "0.1.0"
44
authors = ["Antoni Boucher <[email protected]>"]
5-
edition = "2018"
5+
edition = "2024"
66
license = "MIT OR Apache-2.0"
77

88
[lib]
@@ -22,7 +22,7 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

2424
[dependencies]
25-
gccjit = "2.5"
25+
gccjit = "2.7"
2626
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
2727

2828
# Local copy.

compiler/rustc_codegen_gcc/Readme.md

+30-14
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,38 @@ This is a GCC codegen for rustc, which means it can be loaded by the existing ru
1212
The primary goal of this project is to be able to compile Rust code on platforms unsupported by LLVM.
1313
A secondary goal is to check if using the gcc backend will provide any run-time speed improvement for the programs compiled using rustc.
1414

15-
### Dependencies
16-
17-
**rustup:** Follow the instructions on the official [website](https://www.rust-lang.org/tools/install)
18-
19-
**DejaGnu:** Consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)
20-
21-
15+
## Getting Started
2216

23-
## Building
24-
25-
**This requires a patched libgccjit in order to work.
17+
Note: **This requires a patched libgccjit in order to work.
2618
You need to use my [fork of gcc](https://github.com/rust-lang/gcc) which already includes these patches.**
19+
The default configuration (see below in the [Quick start](#quick-start) section) will download a `libgccjit` built in the CI that already contains these patches, so you don't need to build this fork yourself if you use the default configuration.
2720

28-
```bash
29-
$ cp config.example.toml config.toml
30-
```
21+
### Dependencies
22+
23+
- rustup: follow instructions on the [official website](https://rustup.rs)
24+
- consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)
25+
- additional packages: `flex`, `libmpfr-dev`, `libgmp-dev`, `libmpc3`, `libmpc-dev`
26+
27+
### Quick start
28+
29+
1. Clone and configure the repository:
30+
```bash
31+
git clone https://github.com/rust-lang/rustc_codegen_gcc
32+
cd rustc_codegen_gcc
33+
cp config.example.toml config.toml
34+
```
35+
36+
2. Build and test:
37+
```bash
38+
./y.sh prepare # downloads and patches sysroot
39+
./y.sh build --sysroot --release
40+
41+
# Verify setup with a simple test
42+
./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml
43+
44+
# Run full test suite (expect ~100 failing UI tests)
45+
./y.sh test --release
46+
```
3147

3248
If don't need to test GCC patches you wrote in our GCC fork, then the default configuration should
3349
be all you need. You can update the `rustc_codegen_gcc` without worrying about GCC.
@@ -143,7 +159,7 @@ You can do the same manually (although we don't recommend it):
143159
$ LIBRARY_PATH="[gcc-path value]" LD_LIBRARY_PATH="[gcc-path value]" rustc +$(cat $CG_GCCJIT_DIR/rust-toolchain | grep 'channel' | cut -d '=' -f 2 | sed 's/"//g' | sed 's/ //g') -Cpanic=abort -Zcodegen-backend=$CG_GCCJIT_DIR/target/release/librustc_codegen_gcc.so --sysroot $CG_GCCJIT_DIR/build_sysroot/sysroot my_crate.rs
144160
```
145161

146-
## Env vars
162+
## Environment variables
147163

148164
* _**CG_GCCJIT_DUMP_ALL_MODULES**_: Enables dumping of all compilation modules. When set to "1", a dump is created for each module during compilation and stored in `/tmp/reproducers/`.
149165
* _**CG_GCCJIT_DUMP_MODULE**_: Enables dumping of a specific module. When set with the module name, e.g., `CG_GCCJIT_DUMP_MODULE=module_name`, a dump of that specific module is created in `/tmp/reproducers/`.

compiler/rustc_codegen_gcc/build_system/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "y"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55

66
[dependencies]
77
boml = "0.3.1"

compiler/rustc_codegen_gcc/build_system/src/main.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ pub enum Command {
6060

6161
fn main() {
6262
if env::var("RUST_BACKTRACE").is_err() {
63-
env::set_var("RUST_BACKTRACE", "1");
63+
unsafe {
64+
env::set_var("RUST_BACKTRACE", "1");
65+
}
6466
}
6567

6668
let command = match env::args().nth(1).as_deref() {

compiler/rustc_codegen_gcc/build_system/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
1010
use std::process::{Command, ExitStatus, Output};
1111

1212
#[cfg(unix)]
13-
extern "C" {
13+
unsafe extern "C" {
1414
fn raise(signal: c_int) -> c_int;
1515
}
1616

compiler/rustc_codegen_gcc/example/mini_core.rs

+38-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#![feature(
2-
no_core, lang_items, intrinsics, unboxed_closures, extern_types,
3-
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
2+
no_core,
3+
lang_items,
4+
intrinsics,
5+
unboxed_closures,
6+
extern_types,
7+
decl_macro,
8+
rustc_attrs,
9+
transparent_unions,
10+
auto_traits,
11+
freeze_impls,
412
thread_local
513
)]
614
#![no_core]
@@ -35,13 +43,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
3543
pub trait DispatchFromDyn<T> {}
3644

3745
// &T -> &U
38-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
46+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
3947
// &mut T -> &mut U
40-
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
48+
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
4149
// *const T -> *const U
42-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
50+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
4351
// *mut T -> *mut U
44-
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
52+
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
4553
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
4654

4755
#[lang = "legacy_receiver"]
@@ -52,8 +60,7 @@ impl<T: ?Sized> LegacyReceiver for &mut T {}
5260
impl<T: ?Sized, A: Allocator> LegacyReceiver for Box<T, A> {}
5361

5462
#[lang = "receiver"]
55-
trait Receiver {
56-
}
63+
trait Receiver {}
5764

5865
#[lang = "copy"]
5966
pub trait Copy {}
@@ -67,10 +74,13 @@ impl Copy for u16 {}
6774
impl Copy for u32 {}
6875
impl Copy for u64 {}
6976
impl Copy for usize {}
77+
impl Copy for u128 {}
7078
impl Copy for i8 {}
7179
impl Copy for i16 {}
7280
impl Copy for i32 {}
81+
impl Copy for i64 {}
7382
impl Copy for isize {}
83+
impl Copy for i128 {}
7484
impl Copy for f32 {}
7585
impl Copy for f64 {}
7686
impl Copy for char {}
@@ -336,7 +346,6 @@ impl PartialEq for u32 {
336346
}
337347
}
338348

339-
340349
impl PartialEq for u64 {
341350
fn eq(&self, other: &u64) -> bool {
342351
(*self) == (*other)
@@ -523,7 +532,11 @@ fn panic_in_cleanup() -> ! {
523532
#[track_caller]
524533
fn panic_bounds_check(index: usize, len: usize) -> ! {
525534
unsafe {
526-
libc::printf("index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8, len, index);
535+
libc::printf(
536+
"index out of bounds: the len is %d but the index is %d\n\0" as *const str as *const i8,
537+
len,
538+
index,
539+
);
527540
intrinsics::abort();
528541
}
529542
}
@@ -551,8 +564,7 @@ pub trait Deref {
551564
fn deref(&self) -> &Self::Target;
552565
}
553566

554-
pub trait Allocator {
555-
}
567+
pub trait Allocator {}
556568

557569
impl Allocator for () {}
558570

@@ -634,6 +646,8 @@ pub union MaybeUninit<T> {
634646
}
635647

636648
pub mod intrinsics {
649+
#[rustc_intrinsic]
650+
pub const fn black_box<T>(_dummy: T) -> T;
637651
#[rustc_intrinsic]
638652
pub fn abort() -> !;
639653
#[rustc_intrinsic]
@@ -711,19 +725,27 @@ pub struct VaList<'a>(&'a mut VaListImpl);
711725

712726
#[rustc_builtin_macro]
713727
#[rustc_macro_transparency = "semitransparent"]
714-
pub macro stringify($($t:tt)*) { /* compiler built-in */ }
728+
pub macro stringify($($t:tt)*) {
729+
/* compiler built-in */
730+
}
715731

716732
#[rustc_builtin_macro]
717733
#[rustc_macro_transparency = "semitransparent"]
718-
pub macro file() { /* compiler built-in */ }
734+
pub macro file() {
735+
/* compiler built-in */
736+
}
719737

720738
#[rustc_builtin_macro]
721739
#[rustc_macro_transparency = "semitransparent"]
722-
pub macro line() { /* compiler built-in */ }
740+
pub macro line() {
741+
/* compiler built-in */
742+
}
723743

724744
#[rustc_builtin_macro]
725745
#[rustc_macro_transparency = "semitransparent"]
726-
pub macro cfg() { /* compiler built-in */ }
746+
pub macro cfg() {
747+
/* compiler built-in */
748+
}
727749

728750
pub static A_STATIC: u8 = 42;
729751

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0ea98a1365b81f7488073512c850e8ee951a4afd
1+
04ce66d8c918de9273bd7101638ad8724edf5e21
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2025-04-25"
2+
channel = "nightly-2025-05-12"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

0 commit comments

Comments
 (0)