Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e826ee4

Browse files
committed
Auto merge of rust-lang#125463 - GuillaumeGomez:rollup-287wx4y, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - rust-lang#125263 (rust-lld: fallback to rustc's sysroot if there's no path to the linker in the target sysroot) - rust-lang#125345 (rustc_codegen_llvm: add support for writing summary bitcode) - rust-lang#125362 (Actually use TAIT instead of emulating it) - rust-lang#125412 (Don't suggest adding the unexpected cfgs to the build-script it-self) - rust-lang#125445 (Migrate `run-make/rustdoc-with-short-out-dir-option` to `rmake.rs`) - rust-lang#125452 (Cleanup check-cfg handling in core and std) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8679004 + a8a71d0 commit e826ee4

File tree

32 files changed

+335
-187
lines changed

32 files changed

+335
-187
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn produce_final_output_artifacts(
200200
// to get rid of it.
201201
for output_type in crate_output.outputs.keys() {
202202
match *output_type {
203-
OutputType::Bitcode => {
203+
OutputType::Bitcode | OutputType::ThinLinkBitcode => {
204204
// Cranelift doesn't have bitcode
205205
// user_wants_bitcode = true;
206206
// // Copy to .bc, but always keep the .0.bc. There is a later

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ impl ThinBufferMethods for ThinBuffer {
335335
fn data(&self) -> &[u8] {
336336
unimplemented!();
337337
}
338+
339+
fn thin_link_data(&self) -> &[u8] {
340+
unimplemented!();
341+
}
338342
}
339343

340344
pub struct GccContext {
@@ -414,7 +418,7 @@ impl WriteBackendMethods for GccCodegenBackend {
414418
back::write::codegen(cgcx, dcx, module, config)
415419
}
416420

417-
fn prepare_thin(_module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
421+
fn prepare_thin(_module: ModuleCodegen<Self::Module>, _emit_summary: bool) -> (String, Self::ThinBuffer) {
418422
unimplemented!();
419423
}
420424

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,12 @@ pub(crate) fn run_thin(
230230
thin_lto(cgcx, &dcx, modules, upstream_modules, cached_modules, &symbols_below_threshold)
231231
}
232232

233-
pub(crate) fn prepare_thin(module: ModuleCodegen<ModuleLlvm>) -> (String, ThinBuffer) {
233+
pub(crate) fn prepare_thin(
234+
module: ModuleCodegen<ModuleLlvm>,
235+
emit_summary: bool,
236+
) -> (String, ThinBuffer) {
234237
let name = module.name;
235-
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true);
238+
let buffer = ThinBuffer::new(module.module_llvm.llmod(), true, emit_summary);
236239
(name, buffer)
237240
}
238241

@@ -672,9 +675,9 @@ unsafe impl Send for ThinBuffer {}
672675
unsafe impl Sync for ThinBuffer {}
673676

674677
impl ThinBuffer {
675-
pub fn new(m: &llvm::Module, is_thin: bool) -> ThinBuffer {
678+
pub fn new(m: &llvm::Module, is_thin: bool, emit_summary: bool) -> ThinBuffer {
676679
unsafe {
677-
let buffer = llvm::LLVMRustThinLTOBufferCreate(m, is_thin);
680+
let buffer = llvm::LLVMRustThinLTOBufferCreate(m, is_thin, emit_summary);
678681
ThinBuffer(buffer)
679682
}
680683
}
@@ -688,6 +691,14 @@ impl ThinBufferMethods for ThinBuffer {
688691
slice::from_raw_parts(ptr, len)
689692
}
690693
}
694+
695+
fn thin_link_data(&self) -> &[u8] {
696+
unsafe {
697+
let ptr = llvm::LLVMRustThinLTOBufferThinLinkDataPtr(self.0) as *const _;
698+
let len = llvm::LLVMRustThinLTOBufferThinLinkDataLen(self.0);
699+
slice::from_raw_parts(ptr, len)
700+
}
701+
}
691702
}
692703

693704
impl Drop for ThinBuffer {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,15 @@ pub(crate) unsafe fn codegen(
709709
// asm from LLVM and use `gcc` to create the object file.
710710

711711
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
712+
let bc_summary_out =
713+
cgcx.output_filenames.temp_path(OutputType::ThinLinkBitcode, module_name);
712714
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
713715

714716
if config.bitcode_needed() {
715717
let _timer = cgcx
716718
.prof
717719
.generic_activity_with_arg("LLVM_module_codegen_make_bitcode", &*module.name);
718-
let thin = ThinBuffer::new(llmod, config.emit_thin_lto);
720+
let thin = ThinBuffer::new(llmod, config.emit_thin_lto, config.emit_thin_lto_summary);
719721
let data = thin.data();
720722

721723
if let Some(bitcode_filename) = bc_out.file_name() {
@@ -726,6 +728,25 @@ pub(crate) unsafe fn codegen(
726728
);
727729
}
728730

731+
if config.emit_thin_lto_summary
732+
&& let Some(thin_link_bitcode_filename) = bc_summary_out.file_name()
733+
{
734+
let summary_data = thin.thin_link_data();
735+
cgcx.prof.artifact_size(
736+
"llvm_bitcode_summary",
737+
thin_link_bitcode_filename.to_string_lossy(),
738+
summary_data.len() as u64,
739+
);
740+
741+
let _timer = cgcx.prof.generic_activity_with_arg(
742+
"LLVM_module_codegen_emit_bitcode_summary",
743+
&*module.name,
744+
);
745+
if let Err(err) = fs::write(&bc_summary_out, summary_data) {
746+
dcx.emit_err(WriteBytecode { path: &bc_summary_out, err });
747+
}
748+
}
749+
729750
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
730751
let _timer = cgcx
731752
.prof

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ impl WriteBackendMethods for LlvmCodegenBackend {
237237
) -> Result<CompiledModule, FatalError> {
238238
back::write::codegen(cgcx, dcx, module, config)
239239
}
240-
fn prepare_thin(module: ModuleCodegen<Self::Module>) -> (String, Self::ThinBuffer) {
241-
back::lto::prepare_thin(module)
240+
fn prepare_thin(
241+
module: ModuleCodegen<Self::Module>,
242+
emit_summary: bool,
243+
) -> (String, Self::ThinBuffer) {
244+
back::lto::prepare_thin(module, emit_summary)
242245
}
243246
fn serialize_module(module: ModuleCodegen<Self::Module>) -> (String, Self::ModuleBuffer) {
244247
(module.name, back::lto::ModuleBuffer::new(module.module_llvm.llmod()))

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2350,10 +2350,16 @@ extern "C" {
23502350
#[allow(improper_ctypes)]
23512351
pub fn LLVMRustModuleInstructionStats(M: &Module, Str: &RustString);
23522352

2353-
pub fn LLVMRustThinLTOBufferCreate(M: &Module, is_thin: bool) -> &'static mut ThinLTOBuffer;
2353+
pub fn LLVMRustThinLTOBufferCreate(
2354+
M: &Module,
2355+
is_thin: bool,
2356+
emit_summary: bool,
2357+
) -> &'static mut ThinLTOBuffer;
23542358
pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
23552359
pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
23562360
pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
2361+
pub fn LLVMRustThinLTOBufferThinLinkDataPtr(M: &ThinLTOBuffer) -> *const c_char;
2362+
pub fn LLVMRustThinLTOBufferThinLinkDataLen(M: &ThinLTOBuffer) -> size_t;
23572363
pub fn LLVMRustCreateThinLTOData(
23582364
Modules: *const ThinLTOModule,
23592365
NumModules: c_uint,

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ codegen_ssa_rlib_only_rmeta_found = could not find rlib for: `{$crate_name}`, fo
212212
213213
codegen_ssa_select_cpp_build_tool_workload = in the Visual Studio installer, ensure the "C++ build tools" workload is selected
214214
215+
codegen_ssa_self_contained_linker_missing = the self-contained linker was requested, but it wasn't found in the target's sysroot, or in rustc's sysroot
216+
215217
codegen_ssa_shuffle_indices_evaluation = could not evaluate shuffle_indices at compile time
216218
217219
codegen_ssa_specify_libraries_to_link = use the `-l` flag to specify native libraries to link

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3141,13 +3141,21 @@ fn add_lld_args(
31413141

31423142
let self_contained_linker = self_contained_cli || self_contained_target;
31433143
if self_contained_linker && !sess.opts.cg.link_self_contained.is_linker_disabled() {
3144+
let mut linker_path_exists = false;
31443145
for path in sess.get_tools_search_paths(false) {
3146+
let linker_path = path.join("gcc-ld");
3147+
linker_path_exists |= linker_path.exists();
31453148
cmd.arg({
31463149
let mut arg = OsString::from("-B");
3147-
arg.push(path.join("gcc-ld"));
3150+
arg.push(linker_path);
31483151
arg
31493152
});
31503153
}
3154+
if !linker_path_exists {
3155+
// As a sanity check, we emit an error if none of these paths exist: we want
3156+
// self-contained linking and have no linker.
3157+
sess.dcx().emit_fatal(errors::SelfContainedLinkerMissing);
3158+
}
31513159
}
31523160

31533161
// 2. Implement the "linker flavor" part of this feature by asking `cc` to use some kind of

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub struct ModuleConfig {
108108
pub emit_asm: bool,
109109
pub emit_obj: EmitObj,
110110
pub emit_thin_lto: bool,
111+
pub emit_thin_lto_summary: bool,
111112
pub bc_cmdline: String,
112113

113114
// Miscellaneous flags. These are mostly copied from command-line
@@ -232,6 +233,10 @@ impl ModuleConfig {
232233
),
233234
emit_obj,
234235
emit_thin_lto: sess.opts.unstable_opts.emit_thin_lto,
236+
emit_thin_lto_summary: if_regular!(
237+
sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode),
238+
false
239+
),
235240
bc_cmdline: sess.target.bitcode_llvm_cmdline.to_string(),
236241

237242
verify_llvm_ir: sess.verify_llvm_ir(),
@@ -283,6 +288,7 @@ impl ModuleConfig {
283288

284289
pub fn bitcode_needed(&self) -> bool {
285290
self.emit_bc
291+
|| self.emit_thin_lto_summary
286292
|| self.emit_obj == EmitObj::Bitcode
287293
|| self.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full)
288294
}
@@ -630,6 +636,9 @@ fn produce_final_output_artifacts(
630636
// them for making an rlib.
631637
copy_if_one_unit(OutputType::Bitcode, true);
632638
}
639+
OutputType::ThinLinkBitcode => {
640+
copy_if_one_unit(OutputType::ThinLinkBitcode, false);
641+
}
633642
OutputType::LlvmAssembly => {
634643
copy_if_one_unit(OutputType::LlvmAssembly, false);
635644
}
@@ -883,7 +892,7 @@ fn execute_optimize_work_item<B: ExtraBackendMethods>(
883892
match lto_type {
884893
ComputedLtoType::No => finish_intra_module_work(cgcx, module, module_config),
885894
ComputedLtoType::Thin => {
886-
let (name, thin_buffer) = B::prepare_thin(module);
895+
let (name, thin_buffer) = B::prepare_thin(module, false);
887896
if let Some(path) = bitcode {
888897
fs::write(&path, thin_buffer.data()).unwrap_or_else(|e| {
889898
panic!("Error writing pre-lto-bitcode file `{}`: {}", path.display(), e);

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ pub struct UnableToExeLinker {
413413
#[diag(codegen_ssa_msvc_missing_linker)]
414414
pub struct MsvcMissingLinker;
415415

416+
#[derive(Diagnostic)]
417+
#[diag(codegen_ssa_self_contained_linker_missing)]
418+
pub struct SelfContainedLinkerMissing;
419+
416420
#[derive(Diagnostic)]
417421
#[diag(codegen_ssa_check_installed_visual_studio)]
418422
pub struct CheckInstalledVisualStudio;

0 commit comments

Comments
 (0)