Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2974c3

Browse files
Rollup merge of #145014 - bjorn3:revert_preserve_debug_gdb_scripts, r=lqd
Revert "Preserve the .debug_gdb_scripts section" #143679 introduces a significant build time perf regression for ripgrep. Let's revert it such that we can investigate it without pressure.
2 parents bc3a3a5 + e02cc40 commit a2974c3

File tree

9 files changed

+75
-77
lines changed

9 files changed

+75
-77
lines changed

‎compiler/rustc_codegen_gcc/src/debuginfo.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
254254
// TODO(antoyo): implement.
255255
}
256256

257-
fn debuginfo_finalize(&mut self) {
258-
// TODO: emit section `.debug_gdb_scripts`.
257+
fn debuginfo_finalize(&self) {
259258
self.context.set_debug_info(true)
260259
}
261260

‎compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,11 @@ 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 below.
112+
// also be added to the `llvm.compiler.used` variable, created next.
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-
122117
// Create the llvm.used and llvm.compiler.used variables.
123118
if !cx.used_statics.is_empty() {
124119
cx.create_used_variable_impl(c"llvm.used", &cx.used_statics);
@@ -135,6 +130,11 @@ pub(crate) fn compile_codegen_unit(
135130
llvm::LLVMDeleteGlobal(old_g);
136131
}
137132
}
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/debuginfo/gdb.rs

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// .debug_gdb_scripts binary section.
22

3-
use std::collections::BTreeSet;
4-
use std::ffi::CString;
5-
3+
use rustc_codegen_ssa::base::collect_debugger_visualizers_transitive;
64
use rustc_codegen_ssa::traits::*;
75
use rustc_hir::def_id::LOCAL_CRATE;
86
use rustc_middle::bug;
97
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerType;
10-
use rustc_session::config::DebugInfo;
8+
use rustc_session::config::{CrateType,DebugInfo};
119

1210
use crate::builder::Builder;
1311
use crate::common::CodegenCx;
@@ -33,12 +31,7 @@ pub(crate) fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Buil
3331
pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
3432
cx: &CodegenCx<'ll, '_>,
3533
) -> &'ll Value {
36-
let c_section_var_name = CString::new(format!(
37-
"__rustc_debug_gdb_scripts_section_{}_{:08x}",
38-
cx.tcx.crate_name(LOCAL_CRATE),
39-
cx.tcx.stable_crate_id(LOCAL_CRATE),
40-
))
41-
.unwrap();
34+
let c_section_var_name = c"__rustc_debug_gdb_scripts_section__";
4235
let section_var_name = c_section_var_name.to_str().unwrap();
4336

4437
let section_var = unsafe { llvm::LLVMGetNamedGlobal(cx.llmod, c_section_var_name.as_ptr()) };
@@ -51,14 +44,10 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
5144

5245
// Next, add the pretty printers that were specified via the `#[debugger_visualizer]`
5346
// attribute.
54-
let visualizers = cx
55-
.tcx
56-
.debugger_visualizers(LOCAL_CRATE)
57-
.iter()
58-
.filter(|visualizer| {
59-
visualizer.visualizer_type == DebuggerVisualizerType::GdbPrettyPrinter
60-
})
61-
.collect::<BTreeSet<_>>();
47+
let visualizers = collect_debugger_visualizers_transitive(
48+
cx.tcx,
49+
DebuggerVisualizerType::GdbPrettyPrinter,
50+
);
6251
let crate_name = cx.tcx.crate_name(LOCAL_CRATE);
6352
for (index, visualizer) in visualizers.iter().enumerate() {
6453
// The initial byte `4` instructs GDB that the following pretty printer
@@ -95,5 +84,35 @@ pub(crate) fn get_or_insert_gdb_debug_scripts_section_global<'ll>(
9584
}
9685

9786
pub(crate) fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
98-
cx.sess().opts.debuginfo != DebugInfo::None && cx.sess().target.emit_debug_gdb_scripts
87+
// To ensure the section `__rustc_debug_gdb_scripts_section__` will not create
88+
// ODR violations at link time, this section will not be emitted for rlibs since
89+
// each rlib could produce a different set of visualizers that would be embedded
90+
// in the `.debug_gdb_scripts` section. For that reason, we make sure that the
91+
// section is only emitted for leaf crates.
92+
let embed_visualizers = cx.tcx.crate_types().iter().any(|&crate_type| match crate_type {
93+
CrateType::Executable
94+
| CrateType::Dylib
95+
| CrateType::Cdylib
96+
| CrateType::Staticlib
97+
| CrateType::Sdylib => {
98+
// These are crate types for which we will embed pretty printers since they
99+
// are treated as leaf crates.
100+
true
101+
}
102+
CrateType::ProcMacro => {
103+
// We could embed pretty printers for proc macro crates too but it does not
104+
// seem like a good default, since this is a rare use case and we don't
105+
// want to slow down the common case.
106+
false
107+
}
108+
CrateType::Rlib => {
109+
// As per the above description, embedding pretty printers for rlibs could
110+
// lead to ODR violations so we skip this crate type as well.
111+
false
112+
}
113+
});
114+
115+
cx.sess().opts.debuginfo != DebugInfo::None
116+
&& cx.sess().target.emit_debug_gdb_scripts
117+
&& embed_visualizers
99118
}

‎compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 14 additions & 22 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, debug_context,is_node_local_to_unit};
33+
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
3434
use crate::builder::Builder;
3535
use crate::common::{AsCCharPtr, CodegenCx};
3636
use crate::llvm;
@@ -131,28 +131,20 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
131131
}
132132

133133
/// Creates any deferred debug metadata nodes
134-
pub(crate) fn finalize(cx: &mut CodegenCx<'_, '_>) {
135-
if cx.dbg_cx.is_none() {
136-
return;
137-
}
138-
139-
debug!("finalize");
140-
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-
let section_var = gdb::get_or_insert_gdb_debug_scripts_section_global(cx);
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+
}
147145

148-
// Make sure that the linker doesn't optimize the global away. Adding
149-
// it to `llvm.used` has the advantage that it works even in no_std
150-
// binaries, where we don't have a main shim and thus don't emit a
151-
// volatile load to preserve the global.
152-
cx.add_used_global(section_var);
146+
dbg_cx.finalize(cx.sess());
153147
}
154-
155-
debug_context(cx).finalize(cx.sess());
156148
}
157149

158150
impl<'ll> Builder<'_, 'll, '_> {
@@ -622,7 +614,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
622614
metadata::extend_scope_to_file(self, scope_metadata, file)
623615
}
624616

625-
fn debuginfo_finalize(&mutself) {
617+
fn debuginfo_finalize(&self) {
626618
finalize(self)
627619
}
628620

‎compiler/rustc_codegen_ssa/src/traits/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub trait DebugInfoCodegenMethods<'tcx>: BackendTypes {
5050
scope_metadata: Self::DIScope,
5151
file: &SourceFile,
5252
) -> Self::DIScope;
53-
fn debuginfo_finalize(&mutself);
53+
fn debuginfo_finalize(&self);
5454

5555
// FIXME(eddyb) find a common convention for all of the debuginfo-related
5656
// names (choose between `dbg`, `debug`, `debuginfo`, `debug_info` etc.).

‎src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
6868
"ignore-gnu",
6969
"ignore-haiku",
7070
"ignore-horizon",
71-
"ignore-i586-unknown-linux-gnu",
7271
"ignore-i686-pc-windows-gnu",
7372
"ignore-i686-pc-windows-msvc",
7473
"ignore-illumos",

‎tests/codegen-llvm/gdb_debug_script_load.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#![feature(lang_items)]
1010
#![no_std]
1111

12-
// CHECK: @llvm.used = {{.+}} @__rustc_debug_gdb_scripts_section
13-
1412
#[panic_handler]
1513
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
1614
loop {}
@@ -24,7 +22,7 @@ extern "C" fn rust_eh_personality() {
2422
// Needs rustc to generate `main` as that's where the magic load is inserted.
2523
// IOW, we cannot write this test with `#![no_main]`.
2624
// CHECK-LABEL: @main
27-
// CHECK: load volatile i8, {{.+}} @__rustc_debug_gdb_scripts_section
25+
// CHECK: load volatile i8, {{.+}} @__rustc_debug_gdb_scripts_section__
2826

2927
#[lang = "start"]
3028
fn lang_start<T: 'static>(

‎tests/debuginfo/embedded-visualizer.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ compile-flags:-g
22
//@ ignore-lldb
33
//@ ignore-windows-gnu: #128981
4-
//@ ignore-musl: linker too old in CI
5-
//@ ignore-i586-unknown-linux-gnu: linker too old in CI
64

75
// === CDB TESTS ==================================================================================
86

‎tests/run-make/symbols-all-mangled/rmake.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ fn symbols_check_archive(path: &str) {
3535
continue; // All compiler-builtins symbols must remain unmangled
3636
}
3737

38-
if symbol_ok_everywhere(name) {
38+
if name.contains("rust_eh_personality") {
39+
continue; // Unfortunately LLVM doesn't allow us to mangle this symbol
40+
}
41+
42+
if name.contains(".llvm.") {
43+
// Starting in LLVM 21 we get various implementation-detail functions which
44+
// contain .llvm. that are not a problem.
3945
continue;
4046
}
4147

@@ -65,7 +71,13 @@ fn symbols_check(path: &str) {
6571
continue;
6672
}
6773

68-
if symbol_ok_everywhere(name) {
74+
if name.contains("rust_eh_personality") {
75+
continue; // Unfortunately LLVM doesn't allow us to mangle this symbol
76+
}
77+
78+
if name.contains(".llvm.") {
79+
// Starting in LLVM 21 we get various implementation-detail functions which
80+
// contain .llvm. that are not a problem.
6981
continue;
7082
}
7183

@@ -76,22 +88,3 @@ fn symbols_check(path: &str) {
7688
fn strip_underscore_if_apple(symbol: &str) -> &str {
7789
if cfg!(target_vendor = "apple") { symbol.strip_prefix("_").unwrap() } else { symbol }
7890
}
79-
80-
fn symbol_ok_everywhere(name: &str) -> bool {
81-
if name.contains("rust_eh_personality") {
82-
return true; // Unfortunately LLVM doesn't allow us to mangle this symbol
83-
}
84-
85-
if name.contains(".llvm.") {
86-
// Starting in LLVM 21 we get various implementation-detail functions which
87-
// contain .llvm. that are not a problem.
88-
return true;
89-
}
90-
91-
if name.starts_with("__rustc_debug_gdb_scripts_section") {
92-
// These symbols are fine; they're made unique by the crate ID.
93-
return true;
94-
}
95-
96-
return false;
97-
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /