Skip to content

Commit 7f01dc1

Browse files
committed
Auto merge of #143755 - tgross35:rollup-clvq7yu, r=tgross35
Rollup of 8 pull requests Successful merges: - #140136 (Add an aarch64-msvc build running on ARM64 Windows) - #143642 (stdarch subtree update) - #143679 (Preserve the .debug_gdb_scripts section) - #143707 (Fix `--skip-std-check-if-no-download-rustc`) - #143722 (Make some "safe" llvm ops actually sound) - #143728 (Resolve refactor: extraction of `finalize_module_binding` and `single_import_can_define_name`) - #143742 (Rework borrowing suggestions to use `Expr` instead of just `Span`) - #143744 (Properly track the depth when expanding free alias types) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2a023bf + fba04fa commit 7f01dc1

File tree

70 files changed

+855
-846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+855
-846
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ jobs:
152152
- name: show the current environment
153153
run: src/ci/scripts/dump-environment.sh
154154

155+
- name: install rust
156+
run: src/ci/scripts/install-rust.sh
157+
155158
- name: install awscli
156159
run: src/ci/scripts/install-awscli.sh
157160

compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
3636
_variable_alloca.set_location(_dbg_loc);
3737
}
3838

39-
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
40-
// TODO(antoyo): insert reference to gdb debug scripts section global.
41-
}
42-
4339
/// FIXME(tempdragon): Currently, this function is not yet implemented. It seems that the
4440
/// debug name and the mangled name should both be included in the LValues.
4541
/// Besides, a function to get the rvalue type(m_is_lvalue) should also be included.
@@ -254,7 +250,8 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
254250
// TODO(antoyo): implement.
255251
}
256252

257-
fn debuginfo_finalize(&self) {
253+
fn debuginfo_finalize(&mut self) {
254+
// TODO: emit section `.debug_gdb_scripts`.
258255
self.context.set_debug_info(true)
259256
}
260257

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ fn create_msvc_imps(
11821182
.filter_map(|val| {
11831183
// Exclude some symbols that we know are not Rust symbols.
11841184
let name = llvm::get_value_name(val);
1185-
if ignored(name) { None } else { Some((val, name)) }
1185+
if ignored(&name) { None } else { Some((val, name)) }
11861186
})
11871187
.map(move |(val, name)| {
11881188
let mut imp_name = prefix.as_bytes().to_vec();

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,16 @@ pub(crate) fn compile_codegen_unit(
109109
}
110110

111111
// Finalize code coverage by injecting the coverage map. Note, the coverage map will
112-
// also be added to the `llvm.compiler.used` variable, created next.
112+
// also be added to the `llvm.compiler.used` variable, created below.
113113
if cx.sess().instrument_coverage() {
114114
cx.coverageinfo_finalize();
115115
}
116116

117+
// Finalize debuginfo. This adds to `llvm.used`, created below.
118+
if cx.sess().opts.debuginfo != DebugInfo::None {
119+
cx.debuginfo_finalize();
120+
}
121+
117122
// Create the llvm.used and llvm.compiler.used variables.
118123
if !cx.used_statics.is_empty() {
119124
cx.create_used_variable_impl(c"llvm.used", &cx.used_statics);
@@ -130,11 +135,6 @@ pub(crate) fn compile_codegen_unit(
130135
llvm::LLVMDeleteGlobal(old_g);
131136
}
132137
}
133-
134-
// Finalize debuginfo
135-
if cx.sess().opts.debuginfo != DebugInfo::None {
136-
cx.debuginfo_finalize();
137-
}
138138
}
139139

140140
ModuleCodegen::new_regular(cgu_name.to_string(), llvm_module)

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ fn generate_enzyme_call<'ll>(
306306
// add outer_fn name to ad_name to make it unique, in case users apply autodiff to multiple
307307
// functions. Unwrap will only panic, if LLVM gave us an invalid string.
308308
let name = llvm::get_value_name(outer_fn);
309-
let outer_fn_name = std::str::from_utf8(name).unwrap();
309+
let outer_fn_name = std::str::from_utf8(&name).unwrap();
310310
ad_name.push_str(outer_fn_name);
311311

312312
// Let us assume the user wrote the following function square:

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'ll> CodegenCx<'ll, '_> {
429429
// specific rules on what can be cast. So instead of adding a new way to
430430
// generate static initializers that match the static's type, we picked
431431
// the easier option and retroactively change the type of the static item itself.
432-
let name = llvm::get_value_name(g).to_vec();
432+
let name = llvm::get_value_name(g);
433433
llvm::set_value_name(g, b"");
434434

435435
let linkage = llvm::get_linkage(g);

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// .debug_gdb_scripts binary section.
22

3+
use std::ffi::CString;
4+
35
use rustc_ast::attr;
46
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
57
use rustc_codegen_ssa::traits::*;
@@ -9,31 +11,21 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
911
use rustc_session::config::{CrateType, DebugInfo};
1012
use rustc_span::sym;
1113

12-
use crate::builder::Builder;
1314
use crate::common::CodegenCx;
1415
use crate::llvm;
1516
use crate::value::Value;
1617

17-
/// Inserts a side-effect free instruction sequence that makes sure that the
18-
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
19-
pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) {
20-
if needs_gdb_debug_scripts_section(bx) {
21-
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx);
22-
// Load just the first byte as that's all that's necessary to force
23-
// LLVM to keep around the reference to the global.
24-
let volatile_load_instruction = bx.volatile_load(bx.type_i8(), gdb_debug_scripts_section);
25-
unsafe {
26-
llvm::LLVMSetAlignment(volatile_load_instruction, 1);
27-
}
28-
}
29-
}
30-
3118
/// Allocates the global variable responsible for the .debug_gdb_scripts binary
3219
/// section.
3320
pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
34-
cx: &CodegenCx<'ll, '_>,
21+
cx: &mut CodegenCx<'ll, '_>,
3522
) -> &'ll Value {
36-
let c_section_var_name = c"__rustc_debug_gdb_scripts_section__";
23+
let c_section_var_name = CString::new(format!(
24+
"__rustc_debug_gdb_scripts_section_{}_{:08x}",
25+
cx.tcx.crate_name(LOCAL_CRATE),
26+
cx.tcx.stable_crate_id(LOCAL_CRATE),
27+
))
28+
.unwrap();
3729
let section_var_name = c_section_var_name.to_str().unwrap();
3830

3931
let section_var = unsafe { llvm::LLVMGetNamedGlobal(cx.llmod, c_section_var_name.as_ptr()) };
@@ -80,6 +72,8 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
8072
// This should make sure that the whole section is not larger than
8173
// the string it contains. Otherwise we get a warning from GDB.
8274
llvm::LLVMSetAlignment(section_var, 1);
75+
// Make sure that the linker doesn't optimize the global away.
76+
cx.add_used_global(section_var);
8377
section_var
8478
}
8579
})

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tracing::debug;
3030

3131
use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, type_di_node};
3232
use self::namespace::mangled_name_of_instance;
33-
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
33+
use self::utils::{DIB, create_DIArray, debug_context, is_node_local_to_unit};
3434
use crate::builder::Builder;
3535
use crate::common::{AsCCharPtr, CodegenCx};
3636
use crate::llvm;
@@ -131,20 +131,22 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
131131
}
132132

133133
/// Creates any deferred debug metadata nodes
134-
pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
135-
if let Some(dbg_cx) = &cx.dbg_cx {
136-
debug!("finalize");
137-
138-
if gdb::needs_gdb_debug_scripts_section(cx) {
139-
// Add a .debug_gdb_scripts section to this compile-unit. This will
140-
// cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
141-
// which activates the Rust pretty printers for binary this section is
142-
// contained in.
143-
gdb::get_or_insert_gdb_debug_scripts_section_global(cx);
144-
}
134+
pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
135+
if cx.dbg_cx.is_none() {
136+
return;
137+
}
138+
139+
debug!("finalize");
145140

146-
dbg_cx.finalize(cx.sess());
141+
if gdb::needs_gdb_debug_scripts_section(cx) {
142+
// Add a .debug_gdb_scripts section to this compile-unit. This will
143+
// cause GDB to try and load the gdb_load_rust_pretty_printers.py file,
144+
// which activates the Rust pretty printers for binary this section is
145+
// contained in.
146+
gdb::get_or_insert_gdb_debug_scripts_section_global(cx);
147147
}
148+
149+
debug_context(cx).finalize(cx.sess());
148150
}
149151

150152
impl<'ll> Builder<'_, 'll, '_> {
@@ -215,10 +217,6 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
215217
}
216218
}
217219

218-
fn insert_reference_to_gdb_debug_scripts_section_global(&mut self) {
219-
gdb::insert_reference_to_gdb_debug_scripts_section_global(self)
220-
}
221-
222220
fn set_var_name(&mut self, value: &'ll Value, name: &str) {
223221
// Avoid wasting time if LLVM value names aren't even enabled.
224222
if self.sess().fewer_names() {
@@ -614,7 +612,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
614612
metadata::extend_scope_to_file(self, scope_metadata, file)
615613
}
616614

617-
fn debuginfo_finalize(&self) {
615+
fn debuginfo_finalize(&mut self) {
618616
finalize(self)
619617
}
620618

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
211211
// function.
212212
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
213213
pub(crate) fn SetUniqueComdat(llmod: &Module, val: &Value) {
214-
let name_buf = get_value_name(val).to_vec();
214+
let name_buf = get_value_name(val);
215215
let name =
216216
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
217217
set_comdat(llmod, val, &name);
@@ -319,12 +319,14 @@ pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
319319
}
320320
}
321321

322-
/// Safe wrapper for `LLVMGetValueName2` into a byte slice
323-
pub(crate) fn get_value_name(value: &Value) -> &[u8] {
322+
/// Safe wrapper for `LLVMGetValueName2`
323+
/// Needs to allocate the value, because `set_value_name` will invalidate
324+
/// the pointer.
325+
pub(crate) fn get_value_name(value: &Value) -> Vec<u8> {
324326
unsafe {
325327
let mut len = 0;
326328
let data = LLVMGetValueName2(value, &mut len);
327-
std::slice::from_raw_parts(data.cast(), len)
329+
std::slice::from_raw_parts(data.cast(), len).to_vec()
328330
}
329331
}
330332

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,6 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
528528
let llbb = Bx::append_block(cx, llfn, "top");
529529
let mut bx = Bx::build(cx, llbb);
530530

531-
bx.insert_reference_to_gdb_debug_scripts_section_global();
532-
533531
let isize_ty = cx.type_isize();
534532
let ptr_ty = cx.type_ptr();
535533
let (arg_argc, arg_argv) = get_argc_argv(&mut bx);

0 commit comments

Comments
 (0)