Skip to content

Commit 15f6155

Browse files
committed
Merge branch 'master' into sync_from_rust_2025_05_09
2 parents fcb4ef5 + cfe88fa commit 15f6155

21 files changed

+234
-71
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cargo.lock linguist-generated=false

CONTRIBUTING.md

Lines changed: 101 additions & 0 deletions
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.

Cargo.lock

Lines changed: 4 additions & 4 deletions
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
]

Cargo.toml

Lines changed: 2 additions & 2 deletions
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.

Readme.md

Lines changed: 30 additions & 14 deletions
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/`.

build_system/Cargo.toml

Lines changed: 1 addition & 1 deletion
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"

build_system/src/main.rs

Lines changed: 3 additions & 1 deletion
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() {

build_system/src/utils.rs

Lines changed: 1 addition & 1 deletion
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

libgccjit.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0ea98a1365b81f7488073512c850e8ee951a4afd
1+
8b194529188f9d3a98cc211caa805a5355bfa8f0

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2025-04-25"
2+
channel = "nightly-2025-04-26"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/abi.rs

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use rustc_middle::ty::Ty;
99
use rustc_middle::ty::layout::LayoutOf;
1010
#[cfg(feature = "master")]
1111
use rustc_session::config;
12-
#[cfg(feature = "master")]
13-
use rustc_target::callconv::Conv;
1412
use rustc_target::callconv::{ArgAttributes, CastTarget, FnAbi, PassMode};
13+
#[cfg(feature = "master")]
14+
use rustc_target::callconv::{Conv, RiscvInterruptKind};
1515

1616
use crate::builder::Builder;
1717
use crate::context::CodegenCx;
@@ -240,38 +240,57 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
240240

241241
#[cfg(feature = "master")]
242242
pub fn conv_to_fn_attribute<'gcc>(conv: Conv, arch: &str) -> Option<FnAttribute<'gcc>> {
243-
// TODO: handle the calling conventions returning None.
244243
let attribute = match conv {
245-
Conv::C
246-
| Conv::Rust
247-
| Conv::CCmseNonSecureCall
248-
| Conv::CCmseNonSecureEntry
249-
| Conv::RiscvInterrupt { .. } => return None,
250-
Conv::Cold => return None,
244+
Conv::C | Conv::Rust => return None,
245+
Conv::CCmseNonSecureCall => {
246+
if arch == "arm" {
247+
FnAttribute::ArmCmseNonsecureCall
248+
} else {
249+
return None;
250+
}
251+
}
252+
Conv::CCmseNonSecureEntry => {
253+
if arch == "arm" {
254+
FnAttribute::ArmCmseNonsecureEntry
255+
} else {
256+
return None;
257+
}
258+
}
259+
Conv::Cold => FnAttribute::Cold,
260+
// NOTE: the preserve attributes are not yet implemented in GCC:
261+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110899
251262
Conv::PreserveMost => return None,
252263
Conv::PreserveAll => return None,
253264
Conv::GpuKernel => {
254-
// TODO(antoyo): remove clippy allow attribute when this is implemented.
255-
#[allow(clippy::if_same_then_else)]
256265
if arch == "amdgpu" {
257-
return None;
266+
FnAttribute::GcnAmdGpuHsaKernel
258267
} else if arch == "nvptx64" {
259-
return None;
268+
FnAttribute::NvptxKernel
260269
} else {
261270
panic!("Architecture {} does not support GpuKernel calling convention", arch);
262271
}
263272
}
264-
Conv::AvrInterrupt => return None,
265-
Conv::AvrNonBlockingInterrupt => return None,
266-
Conv::ArmAapcs => return None,
267-
Conv::Msp430Intr => return None,
268-
Conv::X86Fastcall => return None,
269-
Conv::X86Intr => return None,
270-
Conv::X86Stdcall => return None,
271-
Conv::X86ThisCall => return None,
273+
// TODO(antoyo): check if those AVR attributes are mapped correctly.
274+
Conv::AvrInterrupt => FnAttribute::AvrSignal,
275+
Conv::AvrNonBlockingInterrupt => FnAttribute::AvrInterrupt,
276+
Conv::ArmAapcs => FnAttribute::ArmPcs("aapcs"),
277+
Conv::Msp430Intr => FnAttribute::Msp430Interrupt,
278+
Conv::RiscvInterrupt { kind } => {
279+
let kind = match kind {
280+
RiscvInterruptKind::Machine => "machine",
281+
RiscvInterruptKind::Supervisor => "supervisor",
282+
};
283+
FnAttribute::RiscvInterrupt(kind)
284+
}
285+
Conv::X86Fastcall => FnAttribute::X86FastCall,
286+
Conv::X86Intr => FnAttribute::X86Interrupt,
287+
Conv::X86Stdcall => FnAttribute::X86Stdcall,
288+
Conv::X86ThisCall => FnAttribute::X86ThisCall,
289+
// NOTE: the vectorcall calling convention is not yet implemented in GCC:
290+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89485
272291
Conv::X86VectorCall => return None,
273-
Conv::X86_64SysV => FnAttribute::SysvAbi,
274-
Conv::X86_64Win64 => FnAttribute::MsAbi,
292+
Conv::X86_64SysV => FnAttribute::X86SysvAbi,
293+
Conv::X86_64Win64 => FnAttribute::X86MsAbi,
275294
};
276295
Some(attribute)
277296
}

src/archive.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::path::Path;
2+
3+
use rustc_codegen_ssa::back::archive::{
4+
ArArchiveBuilder, ArchiveBuilder, ArchiveBuilderBuilder, DEFAULT_OBJECT_READER,
5+
};
6+
use rustc_session::Session;
7+
8+
pub(crate) struct ArArchiveBuilderBuilder;
9+
10+
impl ArchiveBuilderBuilder for ArArchiveBuilderBuilder {
11+
fn new_archive_builder<'a>(&self, sess: &'a Session) -> Box<dyn ArchiveBuilder + 'a> {
12+
Box::new(ArArchiveBuilder::new(sess, &DEFAULT_OBJECT_READER))
13+
}
14+
15+
fn create_dll_import_lib(
16+
&self,
17+
_sess: &Session,
18+
_lib_name: &str,
19+
_import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,
20+
_output_path: &Path,
21+
) {
22+
unimplemented!("creating dll imports is not yet supported");
23+
}
24+
}

src/attributes.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,8 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
8888
let target_features = function_features
8989
.iter()
9090
.filter_map(|feature| {
91-
// FIXME(antoyo): for some reasons, disabling SSE results in the following error when
92-
// compiling Rust for Linux:
93-
// SSE register return with SSE disabled
94-
// TODO(antoyo): support soft-float and retpoline-external-thunk.
95-
if feature.contains("soft-float")
96-
|| feature.contains("retpoline-external-thunk")
97-
|| *feature == "-sse"
98-
{
91+
// TODO(antoyo): support soft-float.
92+
if feature.contains("soft-float") {
9993
return None;
10094
}
10195

src/back/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ fn thin_lto(
593593
Ok((opt_jobs, copy_jobs))
594594
}
595595

596-
pub unsafe fn optimize_thin_module(
596+
pub fn optimize_thin_module(
597597
thin_module: ThinModule<GccCodegenBackend>,
598598
_cgcx: &CodegenContext<GccCodegenBackend>,
599599
) -> Result<ModuleCodegen<GccContext>, FatalError> {

src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::base::add_pic_option;
1414
use crate::errors::CopyBitcode;
1515
use crate::{GccCodegenBackend, GccContext};
1616

17-
pub(crate) unsafe fn codegen(
17+
pub(crate) fn codegen(
1818
cgcx: &CodegenContext<GccCodegenBackend>,
1919
dcx: DiagCtxtHandle<'_>,
2020
module: ModuleCodegen<GccContext>,

0 commit comments

Comments
 (0)