Skip to content

Commit b33119f

Browse files
committed
Auto merge of #149642 - GuillaumeGomez:subtree-update_cg_gcc_2025-12-04, r=GuillaumeGomez
cg_gcc subtree update cc `@antoyo` r? ghost
2 parents 29e035e + 94f1bfe commit b33119f

File tree

10 files changed

+322
-276
lines changed

10 files changed

+322
-276
lines changed

compiler/rustc_codegen_gcc/CONTRIBUTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,43 @@ We encourage new contributors to join our communication channels and introduce t
2525

2626
## Understanding Core Concepts
2727

28+
### Sysroot & compilation flags
29+
30+
#### What *is* the sysroot?
31+
The **sysroot** is the directory that stores the compiled standard
32+
library (`core`, `alloc`, `std`, `test`, …) and compiler built-ins.
33+
Rustup ships these libraries **pre-compiled with LLVM**.
34+
35+
**rustc_codegen_gcc** replaces LLVM with the GCC backend.
36+
37+
The freshly compiled sysroot ends up in
38+
`build/build_sysroot/...`.
39+
40+
A rebuild of sysroot is needed when
41+
42+
* the backend changes in a way that affects code generation, or
43+
* the user switches toolchains / updates submodules.
44+
45+
Both backend and sysroot can be built using different [profiles](https://doc.rust-lang.org/cargo/reference/profiles.html#default-profiles).
46+
That is exactly what the `--sysroot`, `--release-sysroot` and `--release` flag supported by the build system script `y.sh` take care of.
47+
48+
49+
#### Typical flag combinations
50+
51+
| Command | Backend Profile | Sysroot Profile | Usage Scenario |
52+
|--------------------------------------------|-------------------------------|----------------------------------|------------------------------------------------------------|
53+
| `./y.sh build` |  dev* |  n/a |  Build backend in dev mode with optimized dependencies without rebuilding sysroot |
54+
| `./y.sh build --release` |  release (optimized) |  n/a |  Build backend in release mode with optimized dependencies without rebuilding sysroot |
55+
| `./y.sh build --release --sysroot` |  release (optimized) |  dev |  Build backend in release mode with optimized dependencies and sysroot in dev mode (unoptimized) |
56+
| `./y.sh build --sysroot` |  dev* |  dev |  Build backend in dev mode with optimized dependencies and sysroot in dev mode (unoptimized) |
57+
| `./y.sh build --release-sysroot --sysroot`|  dev* |  release (optimized) |  Build backend in dev mode and sysroot in release mode, both with optimized dependencies |
58+
59+
\* In `dev` mode, dependencies are compiled with optimizations, while the code of the backend itself is not.
60+
61+
62+
Note: `--release-sysroot` must be used together with `--sysroot`.
63+
64+
2865
### Common Development Tasks
2966

3067
#### Running Specific Tests

compiler/rustc_codegen_gcc/Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ dependencies = [
6565

6666
[[package]]
6767
name = "gccjit_sys"
68-
version = "1.1.1"
68+
version = "1.1.2"
6969
source = "registry+https://github.com/rust-lang/crates.io-index"
70-
checksum = "263da4f60b7bb5d6a5b21efda961741051ebdbf0e380a09118b03cce66a8c77e"
70+
checksum = "4f81d901767ddba371a619fa9bba657066a4d3c5607ee69bbb557c1c5ba9bf85"
7171
dependencies = [
7272
"libc",
7373
]

compiler/rustc_codegen_gcc/build_system/src/build.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ impl BuildArg {
4646
println!(
4747
r#"
4848
`build` command help:
49-
50-
--sysroot : Build with sysroot"#
49+
--sysroot : When used on its own, build backend in dev mode with optimized dependencies
50+
and sysroot in dev mode (unoptimized)
51+
When used together with --release, build backend in release mode with optimized dependencies
52+
When used together with --release-sysroot,
53+
build the sysroot in release mode with optimized dependencies instead of in dev mode
54+
--release-sysroot : When combined with --sysroot, additionally
55+
build the sysroot in release mode with optimized dependencies.
56+
It has no effect if `--sysroot` is not specified.
57+
It should not be used on its own.
58+
--sysroot-panic-abort : Build the sysroot without unwinding support"#
5159
);
5260
ConfigInfo::show_usage();
5361
println!(" --help : Show this help");

compiler/rustc_codegen_gcc/build_system/src/config.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,14 +459,11 @@ impl ConfigInfo {
459459

460460
pub fn show_usage() {
461461
println!(
462-
"\
463-
--features [arg] : Add a new feature [arg]
462+
" --features [arg] : Add a new feature [arg]
464463
--target-triple [arg] : Set the target triple to [arg]
465464
--target [arg] : Set the target to [arg]
465+
--release : Build backend in release mode with optimized dependencies
466466
--out-dir : Location where the files will be generated
467-
--release : Build in release mode
468-
--release-sysroot : Build sysroot in release mode
469-
--sysroot-panic-abort : Build the sysroot without unwinding support
470467
--config-file : Location of the config file to be used
471468
--gcc-path : Location of the GCC root folder
472469
--cg_gcc-path : Location of the rustc_codegen_gcc root folder (used

compiler/rustc_codegen_gcc/build_system/src/test.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ fn show_usage() {
6464
r#"
6565
`test` command help:
6666
67-
--release : Build codegen in release mode
68-
--sysroot-panic-abort : Build the sysroot without unwinding support.
6967
--features [arg] : Add a new feature [arg]
7068
--use-system-gcc : Use system installed libgccjit
7169
--build-only : Only build rustc_codegen_gcc then exits
@@ -92,7 +90,6 @@ struct TestArg {
9290
test_args: Vec<String>,
9391
nb_parts: Option<usize>,
9492
current_part: Option<usize>,
95-
sysroot_panic_abort: bool,
9693
config_info: ConfigInfo,
9794
sysroot_features: Vec<String>,
9895
keep_lto_tests: bool,
@@ -128,9 +125,6 @@ impl TestArg {
128125
test_arg.current_part =
129126
Some(get_number_after_arg(&mut args, "--current-part")?);
130127
}
131-
"--sysroot-panic-abort" => {
132-
test_arg.sysroot_panic_abort = true;
133-
}
134128
"--keep-lto-tests" => {
135129
test_arg.keep_lto_tests = true;
136130
}

compiler/rustc_codegen_gcc/src/int.rs

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -287,51 +287,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
287287
// TODO(antoyo): remove duplication with intrinsic?
288288
let name = if self.is_native_int_type(lhs.get_type()) {
289289
match oop {
290-
OverflowOp::Add => match new_kind {
291-
Int(I8) => "__builtin_add_overflow",
292-
Int(I16) => "__builtin_add_overflow",
293-
Int(I32) => "__builtin_sadd_overflow",
294-
Int(I64) => "__builtin_saddll_overflow",
295-
Int(I128) => "__builtin_add_overflow",
296-
297-
Uint(U8) => "__builtin_add_overflow",
298-
Uint(U16) => "__builtin_add_overflow",
299-
Uint(U32) => "__builtin_uadd_overflow",
300-
Uint(U64) => "__builtin_uaddll_overflow",
301-
Uint(U128) => "__builtin_add_overflow",
302-
303-
_ => unreachable!(),
304-
},
305-
OverflowOp::Sub => match new_kind {
306-
Int(I8) => "__builtin_sub_overflow",
307-
Int(I16) => "__builtin_sub_overflow",
308-
Int(I32) => "__builtin_ssub_overflow",
309-
Int(I64) => "__builtin_ssubll_overflow",
310-
Int(I128) => "__builtin_sub_overflow",
311-
312-
Uint(U8) => "__builtin_sub_overflow",
313-
Uint(U16) => "__builtin_sub_overflow",
314-
Uint(U32) => "__builtin_usub_overflow",
315-
Uint(U64) => "__builtin_usubll_overflow",
316-
Uint(U128) => "__builtin_sub_overflow",
317-
318-
_ => unreachable!(),
319-
},
320-
OverflowOp::Mul => match new_kind {
321-
Int(I8) => "__builtin_mul_overflow",
322-
Int(I16) => "__builtin_mul_overflow",
323-
Int(I32) => "__builtin_smul_overflow",
324-
Int(I64) => "__builtin_smulll_overflow",
325-
Int(I128) => "__builtin_mul_overflow",
326-
327-
Uint(U8) => "__builtin_mul_overflow",
328-
Uint(U16) => "__builtin_mul_overflow",
329-
Uint(U32) => "__builtin_umul_overflow",
330-
Uint(U64) => "__builtin_umulll_overflow",
331-
Uint(U128) => "__builtin_mul_overflow",
332-
333-
_ => unreachable!(),
334-
},
290+
OverflowOp::Add => "__builtin_add_overflow",
291+
OverflowOp::Sub => "__builtin_sub_overflow",
292+
OverflowOp::Mul => "__builtin_mul_overflow",
335293
}
336294
} else {
337295
let (func_name, width) = match oop {

0 commit comments

Comments
 (0)