Skip to content

Commit 42c9797

Browse files
committed
feat: -Zdebug-name-table to turn debug pub sections off
`.debug_pubnames` and `.debug_pubtypes` are poorly designed and people seldom use them. However, they take a considerable portion of size in the final binary. This `-Zdebug-name-table` flag make it possible to tell to LLVM stop emitting those sections.
1 parent 9144d51 commit 42c9797

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::debuginfo::utils::FatPtrKind;
1717
use crate::llvm;
1818
use crate::llvm::debuginfo::{
1919
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
20+
DebugNameTableKind,
2021
};
2122
use crate::value::Value;
2223

@@ -877,6 +878,11 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
877878
.unwrap_or_default();
878879
let split_name = split_name.to_str().unwrap();
879880
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
881+
let debug_name_table_kind = if tcx.sess.opts.unstable_opts.debug_name_table {
882+
DebugNameTableKind::Default
883+
} else {
884+
DebugNameTableKind::None
885+
};
880886

881887
unsafe {
882888
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
@@ -907,6 +913,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
907913
kind,
908914
0,
909915
tcx.sess.opts.unstable_opts.split_dwarf_inlining,
916+
debug_name_table_kind,
910917
);
911918

912919
if tcx.sess.opts.unstable_opts.profile {

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use super::debuginfo::{
55
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
66
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
77
DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
8-
DebugEmissionKind,
8+
DebugEmissionKind, DebugNameTableKind,
99
};
1010

1111
use libc::{c_char, c_int, c_uint, size_t};
@@ -793,6 +793,16 @@ pub mod debuginfo {
793793
}
794794
}
795795
}
796+
797+
/// LLVMRustDebugNameTableKind
798+
#[derive(Clone, Copy)]
799+
#[repr(C)]
800+
pub enum DebugNameTableKind {
801+
Default,
802+
Gnu,
803+
None,
804+
Apple,
805+
}
796806
}
797807

798808
use bitflags::bitflags;
@@ -1783,6 +1793,7 @@ extern "C" {
17831793
kind: DebugEmissionKind,
17841794
DWOId: u64,
17851795
SplitDebugInlining: bool,
1796+
DebugNameTableKind: DebugNameTableKind,
17861797
) -> &'a DIDescriptor;
17871798

17881799
pub fn LLVMRustDIBuilderCreateFile<'a>(

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ fn test_unstable_options_tracking_hash() {
749749
tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
750750
tracked!(debug_info_for_profiling, true);
751751
tracked!(debug_macros, true);
752+
tracked!(debug_name_table, false);
752753
tracked!(dep_info_omit_d_target, true);
753754
tracked!(dual_proc_macros, true);
754755
tracked!(dwarf_version, Some(5));

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,28 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind)
719719
}
720720
}
721721

722+
enum class LLVMRustDebugNameTableKind {
723+
Default,
724+
GNU,
725+
None,
726+
Apple,
727+
};
728+
729+
static DICompileUnit::DebugNameTableKind fromRust(LLVMRustDebugNameTableKind Kind) {
730+
switch (Kind) {
731+
case LLVMRustDebugNameTableKind::Default:
732+
return DICompileUnit::DebugNameTableKind::Default;
733+
case LLVMRustDebugNameTableKind::GNU:
734+
return DICompileUnit::DebugNameTableKind::GNU;
735+
case LLVMRustDebugNameTableKind::None:
736+
return DICompileUnit::DebugNameTableKind::None;
737+
case LLVMRustDebugNameTableKind::Apple:
738+
return DICompileUnit::DebugNameTableKind::Apple;
739+
default:
740+
report_fatal_error("bad DebugNameTableKind.");
741+
}
742+
}
743+
722744
enum class LLVMRustChecksumKind {
723745
None,
724746
MD5,
@@ -795,13 +817,15 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
795817
const char *Flags, unsigned RuntimeVer,
796818
const char *SplitName, size_t SplitNameLen,
797819
LLVMRustDebugEmissionKind Kind,
798-
uint64_t DWOId, bool SplitDebugInlining) {
820+
uint64_t DWOId, bool SplitDebugInlining,
821+
LLVMRustDebugNameTableKind TableKind) {
799822
auto *File = unwrapDI<DIFile>(FileRef);
800823

801824
return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen),
802825
isOptimized, Flags, RuntimeVer,
803826
StringRef(SplitName, SplitNameLen),
804-
fromRust(Kind), DWOId, SplitDebugInlining));
827+
fromRust(Kind), DWOId, SplitDebugInlining,
828+
false, fromRust(TableKind)));
805829
}
806830

807831
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(

compiler/rustc_session/src/options.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,8 @@ options! {
15341534
"emit discriminators and other data necessary for AutoFDO"),
15351535
debug_macros: bool = (false, parse_bool, [TRACKED],
15361536
"emit line numbers debug info inside macros (default: no)"),
1537+
debug_name_table: bool = (false, parse_bool, [TRACKED],
1538+
"emit debug name accelerator table to facilitate name lookup in debug info (default: no)"),
15371539
debuginfo_compression: DebugInfoCompression = (DebugInfoCompression::None, parse_debuginfo_compression, [TRACKED],
15381540
"compress debug info sections (none, zlib, zstd, default: none)"),
15391541
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],

0 commit comments

Comments
 (0)