Skip to content

Subtree update GCC backend 2025 05 14 #141002

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

Merged
merged 56 commits into from
May 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
8582bc4
Pass MonoItemData to MonoItem::define
bjorn3 Dec 12, 2024
25df5d0
Pass &mut self to codegen_global_asm
bjorn3 Dec 12, 2024
61d1c13
Merge commit '4f83a4258deb99f3288a7122c0d5a78200931c61' into subtree-…
antoyo Apr 25, 2025
84c5fd7
Enable `[no-mentions]` and `[issue-links]` in `rustbot`
Urgau Apr 25, 2025
f894c1b
Merge pull request #653 from Urgau/triagebot-issue-links-no-mentions
antoyo Apr 25, 2025
612d7f5
Merge branch 'master' into sync_from_rust_2025_04_26
antoyo Apr 26, 2025
3893560
Update to nightly-2025-04-26
antoyo Apr 26, 2025
72b6614
Merge pull request #654 from rust-lang/sync_from_rust_2025_04_26
antoyo Apr 26, 2025
d62fe1e
Implement the internal feature `cfg_target_has_reliable_f16_f128`
tgross35 Apr 24, 2025
ce5a198
add contibuting.md
g4titanx Jan 3, 2025
a5b947b
modify docs
g4titanx Feb 7, 2025
f150171
Some improvements
antoyo Apr 29, 2025
d11bfe9
Use the correct name of the project
antoyo Apr 29, 2025
62814f0
Improve the doc
antoyo Apr 29, 2025
2e9ec93
Fix links in CONTRIBUTING.md
antoyo Apr 29, 2025
43747ce
Fix links in CONTRIBUTING.md
antoyo Apr 29, 2025
6d8fffe
Merge pull request #586 from g4titanx/contributing
antoyo Apr 29, 2025
8b15bfb
Clean up docs
GuillaumeGomez Apr 30, 2025
2884979
Merge pull request #656 from GuillaumeGomez/cleanup
antoyo Apr 30, 2025
283e2cf
Rollup merge of #134232 - bjorn3:naked_asm_improvements, r=wesleywiser
matthiaskrgr Apr 30, 2025
6fad1ba
Support more calling convention attributes
antoyo Apr 30, 2025
337998a
Merge pull request #657 from rust-lang/feature/more-calling-conv-attr…
antoyo Apr 30, 2025
1047a7c
Added a .gitattributes file for showing cargo.lock diffs (#659)
albus-droid May 1, 2025
7008f35
Initial support for dynamically linked crates
Bryanskiy Sep 30, 2024
fcb4ef5
Rename Instance::new to Instance::new_raw and add a note that it is raw
compiler-errors Apr 28, 2025
e608520
Stop ignoring the feature -sse
antoyo May 6, 2025
633ecc8
Merge pull request #660 from rust-lang/fix/disabling-sse
antoyo May 6, 2025
3278cb5
Migrate to 2024 edition
GuillaumeGomez May 7, 2025
8e9a840
Migrate build system to 2024 edition
GuillaumeGomez May 7, 2025
dcfd5c3
Remove unneeded `let_chains` feature
GuillaumeGomez May 7, 2025
7f2f0d2
Update tests to 2024 edition
GuillaumeGomez May 7, 2025
0bdf072
Mark back::lto::optimize_thin_module` and `back::write::codegen` func…
GuillaumeGomez May 7, 2025
390fc73
Fix new clippy lints
GuillaumeGomez May 7, 2025
cfe88fa
Merge pull request #663 from GuillaumeGomez/edition-2024
antoyo May 9, 2025
1ac2283
Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations
Urgau May 8, 2025
7e5fa89
remove 'unordered' atomic intrinsics
RalfJung May 5, 2025
33966cc
Add a workaround for 128 bit switches
FractalFir May 9, 2025
3cffea7
Merge pull request #668 from FractalFir/int128_fix
antoyo May 10, 2025
db5831c
Rollup merge of #140660 - RalfJung:more-order, r=WaffleLapkin
matthiaskrgr May 10, 2025
25dd45f
Correctly handle branches when updating repository
GuillaumeGomez May 10, 2025
43b9588
Regenerate intrinsics
GuillaumeGomez May 10, 2025
f111416
Fixed a recursive inling bug, added a test for it
FractalFir May 9, 2025
c7740d2
Rollup merge of #140792 - Urgau:minimum-maximum-intrinsics, r=scottmc…
fmease May 11, 2025
d8e2d24
Merge pull request #666 from FractalFir/master
antoyo May 11, 2025
2d794d4
Merge pull request #671 from GuillaumeGomez/regen-intrinsics-2
antoyo May 11, 2025
47beac1
Merge branch 'master' into sync_from_rust_2025_05_12
antoyo May 12, 2025
c12d12b
Fix for renamed/removed UI tests
antoyo May 9, 2025
bef68d0
Update to nightly-2025-05-12
antoyo May 12, 2025
5701150
Fix for libgccjit 12
antoyo May 12, 2025
878a173
Fix for the fminimum intrinsics
antoyo May 12, 2025
44af0a8
Stop ignoring test_mm512_stream_ps stdarch test
antoyo May 14, 2025
f38d6d0
Fix for xsave test on Intel SDE
antoyo May 14, 2025
6ba33f5
Merge pull request #673 from rust-lang/sync_from_rust_2025_05_12
antoyo May 14, 2025
1c4ab86
Merge commit '6ba33f5e1189a5ae58fb96ce3546e76b13d090f5' into subtree-…
GuillaumeGomez May 14, 2025
7a47a6a
Update gcc version used in rustc_codegen_version
GuillaumeGomez May 14, 2025
d5c5a82
Update `src/gcc` submodule to `04ce66d8c918de9273bd7101638ad8724edf5e21`
GuillaumeGomez May 14, 2025
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
1 change: 1 addition & 0 deletions compiler/rustc_codegen_gcc/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cargo.lock linguist-generated=false
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ jobs:
if: ${{ matrix.cargo_runner }}
run: |
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
# TODO: remove --skip test_mm512_stream_ps when stdarch is updated in rustc.
# TODO: remove --skip test_tile_ when it's implemented.
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_
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_
# Summary job for the merge queue.
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
Expand Down
101 changes: 101 additions & 0 deletions compiler/rustc_codegen_gcc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Contributing to rustc_codegen_gcc

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.

## Getting Started

### Setting Up Your Development Environment

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:

- Required dependencies and system packages
- Repository setup and configuration
- Build process
- Basic test verification

Once you've completed the setup process outlined in the README, you can proceed with the contributor-specific information below.

## Communication Channels

- Matrix: Join our [Matrix channel](https://matrix.to/#/#rustc_codegen_gcc:matrix.org)
- IRC: Join us on [IRC](https://web.libera.chat/#rustc_codegen_gcc)
- [GitHub Issues](https://github.com/rust-lang/rustc_codegen_gcc/issues): For bug reports and feature discussions

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.

## Understanding Core Concepts

### Common Development Tasks

#### Running Specific Tests

To run specific tests, use appropriate flags such as:

- `./y.sh test --test-libcore`
- `./y.sh test --std-tests`
- `cargo test -- <name of test>`

Additionally, you can run the tests of `libgccjit`:

```bash
# libgccjit tests
cd gcc-build/gcc
make check-jit
# For a specific test:
make check-jit RUNTESTFLAGS="-v -v -v jit.exp=jit.dg/test-asm.cc"
```

#### Debugging Tools

The project provides several environment variables for debugging:

- `CG_GCCJIT_DUMP_GIMPLE`: Dumps the GIMPLE IR
- `CG_RUSTFLAGS`: Additional Rust flags
- `CG_GCCJIT_DUMP_MODULE`: Dumps a specific module
- `CG_GCCJIT_DUMP_TO_FILE`: Creates C-like representation

Full list of debugging options can be found in the [README](Readme.md#env-vars).

## Making Contributions

### Finding Issues to Work On

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")
2. Check the [progress report](https://blog.antoyo.xyz/rustc_codegen_gcc-progress-report-34#state_of_rustc_codegen_gcc) for larger initiatives
3. Consider improving documentation or investigating [failing tests](https://github.com/rust-lang/rustc_codegen_gcc/tree/master/tests) (except `failing-ui-tests12.txt`)

### Pull Request Process

1. Fork the repository and create a new branch
2. Make your changes with clear commit messages
3. Add tests for new functionality
4. Update documentation as needed
5. Submit a PR with a description of your changes

### Code Style Guidelines

- Follow Rust standard coding conventions
- Ensure your code passes `rustfmt` and `clippy`
- Add comments explaining complex logic, especially in GCC interface code

## Additional Resources

- [Rustc Dev Guide](https://rustc-dev-guide.rust-lang.org/)
- [GCC Internals Documentation](https://gcc.gnu.org/onlinedocs/gccint/)
- Project-specific documentation in the `doc/` directory:
- [Common errors](doc/errors.md)
- [Debugging](doc/debugging.md)
- [Debugging libgccjit](doc/debugging-libgccjit.md)
- [Git subtree sync](doc/subtree.md)
- [List of useful commands](doc/tips.md)
- [Send a patch to GCC](doc/sending-gcc-patch.md)

## Getting Help

If you're stuck or unsure about anything:
1. Check the existing documentation in the `doc/` directory
2. Ask in the IRC or Matrix channels
3. Open a GitHub issue for technical problems
4. Comment on the issue you're working on if you need guidance

Remember that all contributions, including documentation improvements, bug reports, and feature requests, are valuable to the project.
8 changes: 4 additions & 4 deletions compiler/rustc_codegen_gcc/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ dependencies = [

[[package]]
name = "gccjit"
version = "2.5.0"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2895ddec764de7ac76fe6c056050c4801a80109c066f177a00a9cc8dee02b29b"
checksum = "ae99a89184220d967dd300139f2d2ae7d52c1a69d632b24aacc57c54625254ce"
dependencies = [
"gccjit_sys",
]

[[package]]
name = "gccjit_sys"
version = "0.6.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac133db68db8a6a8b2c51ef4b18d8ea16682d5814c4641272fe37bbbc223d5f3"
checksum = "24edb7bfe2b7b27c6d09ed23eebfcab0b359c8fe978433f902943e6f127a0f1b"
dependencies = [
"libc",
]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_gcc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rustc_codegen_gcc"
version = "0.1.0"
authors = ["Antoni Boucher <[email protected]>"]
edition = "2018"
edition = "2024"
license = "MIT OR Apache-2.0"

[lib]
Expand All @@ -22,7 +22,7 @@ master = ["gccjit/master"]
default = ["master"]

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

# Local copy.
Expand Down
44 changes: 30 additions & 14 deletions compiler/rustc_codegen_gcc/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,38 @@ This is a GCC codegen for rustc, which means it can be loaded by the existing ru
The primary goal of this project is to be able to compile Rust code on platforms unsupported by LLVM.
A secondary goal is to check if using the gcc backend will provide any run-time speed improvement for the programs compiled using rustc.

### Dependencies

**rustup:** Follow the instructions on the official [website](https://www.rust-lang.org/tools/install)

**DejaGnu:** Consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)


## Getting Started

## Building

**This requires a patched libgccjit in order to work.
Note: **This requires a patched libgccjit in order to work.
You need to use my [fork of gcc](https://github.com/rust-lang/gcc) which already includes these patches.**
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.

```bash
$ cp config.example.toml config.toml
```
### Dependencies

- rustup: follow instructions on the [official website](https://rustup.rs)
- consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)
- additional packages: `flex`, `libmpfr-dev`, `libgmp-dev`, `libmpc3`, `libmpc-dev`

### Quick start

1. Clone and configure the repository:
```bash
git clone https://github.com/rust-lang/rustc_codegen_gcc
cd rustc_codegen_gcc
cp config.example.toml config.toml
```

2. Build and test:
```bash
./y.sh prepare # downloads and patches sysroot
./y.sh build --sysroot --release

# Verify setup with a simple test
./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml

# Run full test suite (expect ~100 failing UI tests)
./y.sh test --release
```

If don't need to test GCC patches you wrote in our GCC fork, then the default configuration should
be all you need. You can update the `rustc_codegen_gcc` without worrying about GCC.
Expand Down Expand Up @@ -143,7 +159,7 @@ You can do the same manually (although we don't recommend it):
$ 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
```

## Env vars
## Environment variables

* _**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/`.
* _**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/`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/build_system/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "y"
version = "0.1.0"
edition = "2021"
edition = "2024"

[dependencies]
boml = "0.3.1"
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_gcc/build_system/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ pub enum Command {

fn main() {
if env::var("RUST_BACKTRACE").is_err() {
env::set_var("RUST_BACKTRACE", "1");
unsafe {
env::set_var("RUST_BACKTRACE", "1");
}
}

let command = match env::args().nth(1).as_deref() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/build_system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, ExitStatus, Output};

#[cfg(unix)]
extern "C" {
unsafe extern "C" {
fn raise(signal: c_int) -> c_int;
}

Expand Down
54 changes: 38 additions & 16 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#![feature(
no_core, lang_items, intrinsics, unboxed_closures, extern_types,
decl_macro, rustc_attrs, transparent_unions, auto_traits, freeze_impls,
no_core,
lang_items,
intrinsics,
unboxed_closures,
extern_types,
decl_macro,
rustc_attrs,
transparent_unions,
auto_traits,
freeze_impls,
thread_local
)]
#![no_core]
Expand Down Expand Up @@ -35,13 +43,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
pub trait DispatchFromDyn<T> {}

// &T -> &U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
// &mut T -> &mut U
impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
// *const T -> *const U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}

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

#[lang = "receiver"]
trait Receiver {
}
trait Receiver {}

#[lang = "copy"]
pub trait Copy {}
Expand All @@ -67,10 +74,13 @@ impl Copy for u16 {}
impl Copy for u32 {}
impl Copy for u64 {}
impl Copy for usize {}
impl Copy for u128 {}
impl Copy for i8 {}
impl Copy for i16 {}
impl Copy for i32 {}
impl Copy for i64 {}
impl Copy for isize {}
impl Copy for i128 {}
impl Copy for f32 {}
impl Copy for f64 {}
impl Copy for char {}
Expand Down Expand Up @@ -336,7 +346,6 @@ impl PartialEq for u32 {
}
}


impl PartialEq for u64 {
fn eq(&self, other: &u64) -> bool {
(*self) == (*other)
Expand Down Expand Up @@ -523,7 +532,11 @@ fn panic_in_cleanup() -> ! {
#[track_caller]
fn panic_bounds_check(index: usize, len: usize) -> ! {
unsafe {
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);
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,
);
intrinsics::abort();
}
}
Expand Down Expand Up @@ -551,8 +564,7 @@ pub trait Deref {
fn deref(&self) -> &Self::Target;
}

pub trait Allocator {
}
pub trait Allocator {}

impl Allocator for () {}

Expand Down Expand Up @@ -634,6 +646,8 @@ pub union MaybeUninit<T> {
}

pub mod intrinsics {
#[rustc_intrinsic]
pub const fn black_box<T>(_dummy: T) -> T;
#[rustc_intrinsic]
pub fn abort() -> !;
#[rustc_intrinsic]
Expand Down Expand Up @@ -711,19 +725,27 @@ pub struct VaList<'a>(&'a mut VaListImpl);

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro stringify($($t:tt)*) { /* compiler built-in */ }
pub macro stringify($($t:tt)*) {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro file() { /* compiler built-in */ }
pub macro file() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro line() { /* compiler built-in */ }
pub macro line() {
/* compiler built-in */
}

#[rustc_builtin_macro]
#[rustc_macro_transparency = "semitransparent"]
pub macro cfg() { /* compiler built-in */ }
pub macro cfg() {
/* compiler built-in */
}

pub static A_STATIC: u8 = 42;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/libgccjit.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0ea98a1365b81f7488073512c850e8ee951a4afd
04ce66d8c918de9273bd7101638ad8724edf5e21
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2025-04-25"
channel = "nightly-2025-05-12"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
Loading
Loading