Skip to content

Commit 36a516d

Browse files
authored
Merge pull request #740 from rust-lang/sync_from_rust_2025_07_21
Sync from rust 2025/07/21
2 parents 2e94f54 + 566c9ae commit 36a516d

22 files changed

+278
-90
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ dependencies = [
143143
"libc",
144144
]
145145

146+
[[package]]
147+
name = "object"
148+
version = "0.37.1"
149+
source = "registry+https://github.com/rust-lang/crates.io-index"
150+
checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a"
151+
dependencies = [
152+
"memchr",
153+
]
154+
146155
[[package]]
147156
name = "once_cell"
148157
version = "1.20.2"
@@ -179,6 +188,7 @@ dependencies = [
179188
"boml",
180189
"gccjit",
181190
"lang_tester",
191+
"object",
182192
"tempfile",
183193
]
184194

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

2424
[dependencies]
25+
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
26+
tempfile = "3.20"
2527
gccjit = "2.7"
2628
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
2729

@@ -31,7 +33,6 @@ gccjit = "2.7"
3133
[dev-dependencies]
3234
boml = "0.3.1"
3335
lang_tester = "0.8.0"
34-
tempfile = "3.20"
3536

3637
[profile.dev]
3738
# By compiling dependencies with optimizations, performing tests gets much faster.

build_system/src/abi_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn run() -> Result<(), String> {
3131
Some("clones/abi-cafe".as_ref()),
3232
true,
3333
)
34-
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
34+
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;
3535
// Configure abi-cafe to use the exact same rustc version we use - this is crucial.
3636
// Otherwise, the concept of ABI compatibility becomes meanignless.
3737
std::fs::copy("rust-toolchain", "clones/abi-cafe/rust-toolchain")

build_system/src/fuzz.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ pub fn run() -> Result<(), String> {
4343
"--start" => {
4444
start =
4545
str::parse(&args.next().ok_or_else(|| "Fuzz start not provided!".to_string())?)
46-
.map_err(|err| (format!("Fuzz start not a number {err:?}!")))?;
46+
.map_err(|err| format!("Fuzz start not a number {err:?}!"))?;
4747
}
4848
"--count" => {
4949
count =
5050
str::parse(&args.next().ok_or_else(|| "Fuzz count not provided!".to_string())?)
51-
.map_err(|err| (format!("Fuzz count not a number {err:?}!")))?;
51+
.map_err(|err| format!("Fuzz count not a number {err:?}!"))?;
5252
}
5353
"-j" | "--jobs" => {
5454
threads = str::parse(
5555
&args.next().ok_or_else(|| "Fuzz thread count not provided!".to_string())?,
5656
)
57-
.map_err(|err| (format!("Fuzz thread count not a number {err:?}!")))?;
57+
.map_err(|err| format!("Fuzz thread count not a number {err:?}!"))?;
5858
}
5959
_ => return Err(format!("Unknown option {arg}")),
6060
}
@@ -66,7 +66,7 @@ pub fn run() -> Result<(), String> {
6666
Some("clones/rustlantis".as_ref()),
6767
true,
6868
)
69-
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
69+
.map_err(|err| format!("Git clone failed with message: {err:?}!"))?;
7070

7171
// Ensure that we are on the newest rustlantis commit.
7272
let cmd: &[&dyn AsRef<OsStr>] = &[&"git", &"pull", &"origin"];

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-07-04"
2+
channel = "nightly-2025-07-21"
33
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/allocator.rs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
21
#[cfg(feature = "master")]
3-
use gccjit::{FnAttribute, VarAttribute};
2+
use gccjit::FnAttribute;
3+
use gccjit::{Context, FunctionType, RValue, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
55
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
66
alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -71,15 +71,13 @@ pub(crate) unsafe fn codegen(
7171
None,
7272
);
7373

74-
let name = mangle_internal_symbol(tcx, OomStrategy::SYMBOL);
75-
let global = context.new_global(None, GlobalKind::Exported, i8, name);
76-
#[cfg(feature = "master")]
77-
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
78-
tcx.sess.default_visibility(),
79-
)));
80-
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
81-
let value = context.new_rvalue_from_int(i8, value as i32);
82-
global.global_set_initializer_rvalue(value);
74+
create_const_value_function(
75+
tcx,
76+
context,
77+
&mangle_internal_symbol(tcx, OomStrategy::SYMBOL),
78+
i8,
79+
context.new_rvalue_from_int(i8, tcx.sess.opts.unstable_opts.oom.should_panic() as i32),
80+
);
8381

8482
create_wrapper_function(
8583
tcx,
@@ -91,6 +89,34 @@ pub(crate) unsafe fn codegen(
9189
);
9290
}
9391

92+
fn create_const_value_function(
93+
tcx: TyCtxt<'_>,
94+
context: &Context<'_>,
95+
name: &str,
96+
output: Type<'_>,
97+
value: RValue<'_>,
98+
) {
99+
let func = context.new_function(None, FunctionType::Exported, output, &[], name, false);
100+
101+
#[cfg(feature = "master")]
102+
{
103+
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
104+
tcx.sess.default_visibility(),
105+
)));
106+
107+
// FIXME(antoyo): cg_llvm sets AlwaysInline, but AlwaysInline is different in GCC and using
108+
// it here will causes linking errors when using LTO.
109+
func.add_attribute(FnAttribute::Inline);
110+
}
111+
112+
if tcx.sess.must_emit_unwind_tables() {
113+
// TODO(antoyo): emit unwind tables.
114+
}
115+
116+
let block = func.new_block("entry");
117+
block.end_with_return(None, value);
118+
}
119+
94120
fn create_wrapper_function(
95121
tcx: TyCtxt<'_>,
96122
context: &Context<'_>,

src/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
8787
#[cfg_attr(not(feature = "master"), allow(unused_variables))] func: Function<'gcc>,
8888
instance: ty::Instance<'tcx>,
8989
) {
90-
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
90+
let codegen_fn_attrs = cx.tcx.codegen_instance_attrs(instance.def);
9191

9292
#[cfg(feature = "master")]
9393
{

src/back/lto.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::sync::Arc;
2424

2525
use gccjit::{Context, OutputKind};
2626
use object::read::archive::ArchiveFile;
27-
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
27+
use rustc_codegen_ssa::back::lto::{SerializedModule, ThinModule, ThinShared};
2828
use rustc_codegen_ssa::back::symbol_export;
2929
use rustc_codegen_ssa::back::write::{CodegenContext, FatLtoInput};
3030
use rustc_codegen_ssa::traits::*;
@@ -176,7 +176,7 @@ pub(crate) fn run_fat(
176176
cgcx: &CodegenContext<GccCodegenBackend>,
177177
modules: Vec<FatLtoInput<GccCodegenBackend>>,
178178
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
179-
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
179+
) -> Result<ModuleCodegen<GccContext>, FatalError> {
180180
let dcx = cgcx.create_dcx();
181181
let dcx = dcx.handle();
182182
let lto_data = prepare_lto(cgcx, dcx)?;
@@ -201,7 +201,7 @@ fn fat_lto(
201201
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
202202
tmp_path: TempDir,
203203
//symbols_below_threshold: &[String],
204-
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
204+
) -> Result<ModuleCodegen<GccContext>, FatalError> {
205205
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
206206
info!("going for a fat lto");
207207

@@ -334,7 +334,7 @@ fn fat_lto(
334334
// of now.
335335
module.module_llvm.temp_dir = Some(tmp_path);
336336

337-
Ok(LtoModuleCodegen::Fat(module))
337+
Ok(module)
338338
}
339339

340340
pub struct ModuleBuffer(PathBuf);
@@ -358,7 +358,7 @@ pub(crate) fn run_thin(
358358
cgcx: &CodegenContext<GccCodegenBackend>,
359359
modules: Vec<(String, ThinBuffer)>,
360360
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
361-
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
361+
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
362362
let dcx = cgcx.create_dcx();
363363
let dcx = dcx.handle();
364364
let lto_data = prepare_lto(cgcx, dcx)?;
@@ -427,7 +427,7 @@ fn thin_lto(
427427
tmp_path: TempDir,
428428
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
429429
//_symbols_below_threshold: &[String],
430-
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
430+
) -> Result<(Vec<ThinModule<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
431431
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
432432
info!("going for that thin, thin LTO");
433433

@@ -573,8 +573,7 @@ fn thin_lto(
573573
}*/
574574

575575
info!(" - {}: re-compiled", module_name);
576-
opt_jobs
577-
.push(LtoModuleCodegen::Thin(ThinModule { shared: shared.clone(), idx: module_index }));
576+
opt_jobs.push(ThinModule { shared: shared.clone(), idx: module_index });
578577
}
579578

580579
// Save the current ThinLTO import information for the next compilation

src/back/write.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ use crate::{GccCodegenBackend, GccContext};
1616

1717
pub(crate) fn codegen(
1818
cgcx: &CodegenContext<GccCodegenBackend>,
19-
dcx: DiagCtxtHandle<'_>,
2019
module: ModuleCodegen<GccContext>,
2120
config: &ModuleConfig,
2221
) -> Result<CompiledModule, FatalError> {
22+
let dcx = cgcx.create_dcx();
23+
let dcx = dcx.handle();
24+
2325
let _timer = cgcx.prof.generic_activity_with_arg("GCC_module_codegen", &*module.name);
2426
{
2527
let context = &module.module_llvm.context;

src/builder.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
539539

540540
fn ret(&mut self, mut value: RValue<'gcc>) {
541541
let expected_return_type = self.current_func().get_return_type();
542-
if !expected_return_type.is_compatible_with(value.get_type()) {
543-
// NOTE: due to opaque pointers now being used, we need to cast here.
544-
value = self.context.new_cast(self.___location, value, expected_return_type);
542+
let value_type = value.get_type();
543+
if !expected_return_type.is_compatible_with(value_type) {
544+
// NOTE: due to opaque pointers now being used, we need to (bit)cast here.
545+
if self.is_native_int_type(value_type) && self.is_native_int_type(expected_return_type)
546+
{
547+
value = self.context.new_cast(self.___location, value, expected_return_type);
548+
} else {
549+
value = self.context.new_bitcast(self.___location, value, expected_return_type);
550+
}
545551
}
546552
self.llbb().end_with_return(self.___location, value);
547553
}
@@ -926,10 +932,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
926932
.get_address(self.___location)
927933
}
928934

929-
fn dynamic_alloca(&mut self, _len: RValue<'gcc>, _align: Align) -> RValue<'gcc> {
930-
unimplemented!();
931-
}
932-
933935
fn load(&mut self, pointee_ty: Type<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
934936
let block = self.llbb();
935937
let function = block.get_function();
@@ -1282,11 +1284,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12821284

12831285
fn intcast(
12841286
&mut self,
1285-
value: RValue<'gcc>,
1287+
mut value: RValue<'gcc>,
12861288
dest_typ: Type<'gcc>,
1287-
_is_signed: bool,
1289+
is_signed: bool,
12881290
) -> RValue<'gcc> {
1289-
// NOTE: is_signed is for value, not dest_typ.
1291+
let value_type = value.get_type();
1292+
if is_signed && !value_type.is_signed(self.cx) {
1293+
let signed_type = value_type.to_signed(self.cx);
1294+
value = self.gcc_int_cast(value, signed_type);
1295+
} else if !is_signed && value_type.is_signed(self.cx) {
1296+
let unsigned_type = value_type.to_unsigned(self.cx);
1297+
value = self.gcc_int_cast(value, unsigned_type);
1298+
}
1299+
12901300
self.gcc_int_cast(value, dest_typ)
12911301
}
12921302

0 commit comments

Comments
 (0)