Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
33 changes: 27 additions & 6 deletions build_system/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,33 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
// FIXME: should not use shell command!
run_command(&[&"cp", &"-r", &dir_to_copy, &sysroot_path], None).map(|_| ())
};
walk_dir(
library_dir.join(format!("target/{}/{}/deps", config.target_triple, channel)),
&mut copier.clone(),
&mut copier,
false,
)?;
let target_dir = library_dir.join(format!("target/{}/{}", config.target_triple, channel));
let deps_dir = target_dir.join("deps");
if deps_dir.is_dir() {
// Keep copying in the old directory just in case.
walk_dir(&deps_dir, &mut copier.clone(), &mut copier, false)?;
} else {
let build_dir = target_dir.join("build");
walk_dir(
&build_dir,
&mut |package_dir: &Path| {
walk_dir(
package_dir,
&mut |unit_dir: &Path| {
let out_dir = unit_dir.join("out");
if out_dir.is_dir() {
walk_dir(&out_dir, &mut copier.clone(), &mut copier.clone(), false)?;
}
Ok(())
},
&mut |_| Ok(()),
false,
)
},
&mut |_| Ok(()),
false,
)?;
}

// Copy the source files to the sysroot (Rust for Linux needs this).
let sysroot_src_path = start_dir.join("sysroot/lib/rustlib/src/rust");
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2026-07-24"
channel = "nightly-2026-08-04"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
159 changes: 103 additions & 56 deletions src/asm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// cSpell:ignoreRegExp [afkspqvwy]reg

use std::borrow::Cow;
use std::fmt::Write;

use gccjit::{LValue, RValue, ToRValue, Type};
use rustc_abi::Size;
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_codegen_ssa::mir::operand::OperandValue;
use rustc_codegen_ssa::mir::place::PlaceRef;
Expand All @@ -11,14 +13,16 @@ use rustc_codegen_ssa::traits::{
GlobalAsmOperandRef, InlineAsmOperandRef,
};
use rustc_middle::bug;
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
use rustc_middle::ty::Instance;
use rustc_middle::ty::layout::LayoutOf;
use rustc_span::{DUMMY_SP, Span};
use rustc_target::asm::*;

use crate::builder::Builder;
use crate::callee::get_fn;
use crate::context::CodegenCx;
use crate::errors::{NulBytesInAsm, UnwindingInlineAsm};
use crate::diagnostics::{NulBytesInAsm, UnwindingInlineAsm};
use crate::type_of::LayoutGccExt;

// Rust asm! and GCC Extended Asm semantics differ substantially.
Expand Down Expand Up @@ -143,6 +147,9 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
// Clobbers collected from `out("explicit register") _` and `inout("explicit_reg") var => _`
let mut clobbers = vec![];

// Symbols name that needs to be inserted to asm const ptr template string.
let mut const_syms = vec![];

// We're trying to preallocate space for the template
let mut constants_len = 0;

Expand Down Expand Up @@ -305,17 +312,12 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
}
}

InlineAsmOperandRef::Const { ref string } => {
constants_len += string.len() + att_dialect as usize;
InlineAsmOperandRef::Const { .. } => {
// We don't know the size at this point, just some estimate.
constants_len += 20;
}

InlineAsmOperandRef::SymFn { instance } => {
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O)
// or byte count suffixes (x86 Windows).
constants_len += self.tcx.symbol_name(instance).name.len();
}
InlineAsmOperandRef::SymStatic { def_id } => {
InlineAsmOperandRef::SymThreadLocalStatic { def_id } => {
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O).
constants_len +=
Expand Down Expand Up @@ -411,24 +413,22 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
// processed in the previous pass
}

InlineAsmOperandRef::SymFn { instance } => {
inputs.push(AsmInOperand {
constraint: "X".into(),
rust_idx,
val: get_fn(self.cx, instance).get_address(None),
});
}

InlineAsmOperandRef::SymStatic { def_id } => {
inputs.push(AsmInOperand {
constraint: "X".into(),
rust_idx,
val: self.cx.get_static(def_id).get_address(None),
});
}
InlineAsmOperandRef::Const { value, ty: _ } => match value {
Scalar::Int(_) => (),
Scalar::Ptr(ptr, _) => {
let (prov, _) = ptr.prov_and_relative_offset();
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
let (val, sym) = self.cx.alloc_to_backend(global_alloc, true).unwrap();
const_syms.push(sym.unwrap());
inputs.push(AsmInOperand { constraint: "X".into(), rust_idx, val });
}
},

InlineAsmOperandRef::Const { .. } => {
// processed in the previous pass
InlineAsmOperandRef::SymThreadLocalStatic { def_id } => {
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (MachO).
constants_len +=
self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name.len();
}

InlineAsmOperandRef::Label { .. } => {
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
template_str.push_str(escaped_char);
}
}
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span: _ } => {
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier, span } => {
let mut push_to_template = |modifier, gcc_idx| {
use std::fmt::Write;

Expand Down Expand Up @@ -504,26 +504,44 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
push_to_template(modifier, gcc_index);
}

InlineAsmOperandRef::SymFn { instance } => {
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O)
// or byte count suffixes (x86 Windows).
let name = self.tcx.symbol_name(instance).name;
template_str.push_str(name);
InlineAsmOperandRef::Const { value, ty } => {
match value {
Scalar::Int(int) => {
// Const operands get injected directly into the template
let string = rustc_codegen_ssa::common::asm_const_to_str(
self.tcx,
span,
int,
self.layout_of(ty),
);
template_str.push_str(&string);
}

Scalar::Ptr(ptr, _) => {
let (_, offset) = ptr.prov_and_relative_offset();
let sym = const_syms.remove(0);
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O)
// or byte count suffixes (x86 Windows).
template_str.push_str(sym.name);

if offset != Size::ZERO {
let offset =
self.sign_extend_to_target_isize(offset.bytes());
write!(template_str, "{offset:+}").unwrap();
}
}
}
}

InlineAsmOperandRef::SymStatic { def_id } => {
InlineAsmOperandRef::SymThreadLocalStatic { def_id } => {
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O).
let instance = Instance::mono(self.tcx, def_id);
let name = self.tcx.symbol_name(instance).name;
template_str.push_str(name);
}

InlineAsmOperandRef::Const { ref string } => {
template_str.push_str(string);
}

InlineAsmOperandRef::Label { label } => {
let label_gcc_index =
labels.iter().position(|&l| l == label).expect("wrong rust index");
Expand Down Expand Up @@ -948,26 +966,55 @@ impl<'gcc, 'tcx> AsmCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
.unwrap_or(string.len());
}
}
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span: _ } => {
InlineAsmTemplatePiece::Placeholder { operand_idx, modifier: _, span } => {
match operands[operand_idx] {
GlobalAsmOperandRef::Const { ref string } => {
// Const operands get injected directly into the
// template. Note that we don't need to escape %
// here unlike normal inline assembly.
template_str.push_str(string);
}
GlobalAsmOperandRef::Const { value, ty } => {
match value {
Scalar::Int(int) => {
// Const operands get injected directly into the
// template. Note that we don't need to escape %
// here unlike normal inline assembly.
let string = rustc_codegen_ssa::common::asm_const_to_str(
self.tcx,
span,
int,
self.layout_of(ty),
);
template_str.push_str(&string);
}

GlobalAsmOperandRef::SymFn { instance } => {
let function = get_fn(self, instance);
self.add_used_function(function);
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O)
// or byte count suffixes (x86 Windows).
let name = self.tcx.symbol_name(instance).name;
template_str.push_str(name);
Scalar::Ptr(ptr, _) => {
let (prov, offset) = ptr.prov_and_relative_offset();
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
let symbol_name = match global_alloc {
GlobalAlloc::Function { instance } => {
let function = get_fn(self, instance);
self.add_used_function(function);
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O)
// or byte count suffixes (x86 Windows).
self.tcx.symbol_name(instance)
}
_ => {
let (_, syms) =
self.alloc_to_backend(global_alloc, true).unwrap();
// FIXME(antoyo): set the global variable as used.
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O).
syms.unwrap()
}
};
template_str.push_str(symbol_name.name);

if offset != Size::ZERO {
let offset =
self.sign_extend_to_target_isize(offset.bytes());
write!(template_str, "{offset:+}").unwrap();
}
}
}
}

GlobalAsmOperandRef::SymStatic { def_id } => {
GlobalAsmOperandRef::SymThreadLocalStatic { def_id } => {
// FIXME(antoyo): set the global variable as used.
// FIXME(@Amanieu): Additional mangling is needed on
// some targets to add a leading underscore (Mach-O).
Expand Down
2 changes: 1 addition & 1 deletion src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use rustc_session::Session;
use tempfile::{TempDir, tempdir};

use crate::back::write::{codegen, save_temp_bitcode};
use crate::errors::LtoBitcodeFromRlib;
use crate::diagnostics::LtoBitcodeFromRlib;
use crate::gcc_util::new_context;
use crate::{GccCodegenBackend, GccContext, LtoMode, SyncContext, to_gcc_opt_level};

Expand Down
2 changes: 1 addition & 1 deletion src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_log::tracing::debug;
use rustc_session::config::OutputType;
use rustc_target::spec::SplitDebuginfo;

use crate::errors::CopyBitcode;
use crate::diagnostics::CopyBitcode;
use crate::gcc_util::add_pic_option;
use crate::{GccContext, LtoMode};

Expand Down
Loading
Loading