Skip to content

Commit 1667f3d

Browse files
committed
fix: stop emitting .debug_pubnames and .debug_pubtypes
`.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 tells LLVM stop emitting those sections on DWARFv4 or lower. DWARFv5 use `.debug_names` which is more concise in size and performant for name lookup.
1 parent a2d328f commit 1667f3d

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+8
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

@@ -878,6 +879,12 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
878879
let split_name = split_name.to_str().unwrap();
879880
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
880881

882+
let dwarf_version =
883+
tcx.sess.opts.unstable_opts.dwarf_version.unwrap_or(tcx.sess.target.default_dwarf_version);
884+
// Don't emit `.debug_pubnames` and `.debug_pubtypes` on DWARFv4 or lower.
885+
let debug_name_table_kind =
886+
if dwarf_version > 4 { DebugNameTableKind::Default } else { DebugNameTableKind::None };
887+
881888
unsafe {
882889
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
883890
debug_context.builder,
@@ -907,6 +914,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
907914
kind,
908915
0,
909916
tcx.sess.opts.unstable_opts.split_dwarf_inlining,
917+
debug_name_table_kind,
910918
);
911919

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

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+11-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};
@@ -794,6 +794,15 @@ pub mod debuginfo {
794794
}
795795
}
796796
}
797+
798+
/// LLVMRustDebugNameTableKind
799+
#[derive(Clone, Copy)]
800+
#[repr(C)]
801+
pub enum DebugNameTableKind {
802+
Default,
803+
Gnu,
804+
None,
805+
}
797806
}
798807

799808
use bitflags::bitflags;
@@ -1812,6 +1821,7 @@ extern "C" {
18121821
kind: DebugEmissionKind,
18131822
DWOId: u64,
18141823
SplitDebugInlining: bool,
1824+
DebugNameTableKind: DebugNameTableKind,
18151825
) -> &'a DIDescriptor;
18161826

18171827
pub fn LLVMRustDIBuilderCreateFile<'a>(

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+23-2
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,25 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind)
697697
}
698698
}
699699

700+
enum class LLVMRustDebugNameTableKind {
701+
Default,
702+
GNU,
703+
None,
704+
};
705+
706+
static DICompileUnit::DebugNameTableKind fromRust(LLVMRustDebugNameTableKind Kind) {
707+
switch (Kind) {
708+
case LLVMRustDebugNameTableKind::Default:
709+
return DICompileUnit::DebugNameTableKind::Default;
710+
case LLVMRustDebugNameTableKind::GNU:
711+
return DICompileUnit::DebugNameTableKind::GNU;
712+
case LLVMRustDebugNameTableKind::None:
713+
return DICompileUnit::DebugNameTableKind::None;
714+
default:
715+
report_fatal_error("bad DebugNameTableKind.");
716+
}
717+
}
718+
700719
enum class LLVMRustChecksumKind {
701720
None,
702721
MD5,
@@ -765,13 +784,15 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
765784
const char *Flags, unsigned RuntimeVer,
766785
const char *SplitName, size_t SplitNameLen,
767786
LLVMRustDebugEmissionKind Kind,
768-
uint64_t DWOId, bool SplitDebugInlining) {
787+
uint64_t DWOId, bool SplitDebugInlining,
788+
LLVMRustDebugNameTableKind TableKind) {
769789
auto *File = unwrapDI<DIFile>(FileRef);
770790

771791
return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen),
772792
isOptimized, Flags, RuntimeVer,
773793
StringRef(SplitName, SplitNameLen),
774-
fromRust(Kind), DWOId, SplitDebugInlining));
794+
fromRust(Kind), DWOId, SplitDebugInlining,
795+
false, fromRust(TableKind)));
775796
}
776797

777798
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(

tests/assembly/dwarf4.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pub struct X;
2020
// CHECK-NOT: .short 2
2121
// CHECK-NOT: .short 5
2222
// CHECK: .short 4
23-
// CHECK: .section .debug_pubnames
24-
// CHECK: .section .debug_pubtypes
23+
// CHECK-NOT: .section .debug_pubnames
24+
// CHECK-NOT: .section .debug_pubtypes

0 commit comments

Comments
 (0)