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.
This commit is contained in:
Weihang Lo 2023-11-15 23:07:37 -05:00
parent a2d328fa12
commit 1667f3d2cc
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
4 changed files with 44 additions and 5 deletions

View File

@ -17,6 +17,7 @@ use crate::debuginfo::utils::FatPtrKind;
use crate::llvm; use crate::llvm;
use crate::llvm::debuginfo::{ use crate::llvm::debuginfo::{
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind, DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
DebugNameTableKind,
}; };
use crate::value::Value; use crate::value::Value;
@ -878,6 +879,12 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
let split_name = split_name.to_str().unwrap(); let split_name = split_name.to_str().unwrap();
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo); let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
let dwarf_version =
tcx.sess.opts.unstable_opts.dwarf_version.unwrap_or(tcx.sess.target.default_dwarf_version);
// Don't emit `.debug_pubnames` and `.debug_pubtypes` on DWARFv4 or lower.
let debug_name_table_kind =
if dwarf_version > 4 { DebugNameTableKind::Default } else { DebugNameTableKind::None };
unsafe { unsafe {
let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile( let compile_unit_file = llvm::LLVMRustDIBuilderCreateFile(
debug_context.builder, debug_context.builder,
@ -907,6 +914,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
kind, kind,
0, 0,
tcx.sess.opts.unstable_opts.split_dwarf_inlining, tcx.sess.opts.unstable_opts.split_dwarf_inlining,
debug_name_table_kind,
); );
if tcx.sess.opts.unstable_opts.profile { if tcx.sess.opts.unstable_opts.profile {

View File

@ -5,7 +5,7 @@ use super::debuginfo::{
DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator,
DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace,
DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable,
DebugEmissionKind, DebugEmissionKind, DebugNameTableKind,
}; };
use libc::{c_char, c_int, c_uint, size_t}; use libc::{c_char, c_int, c_uint, size_t};
@ -794,6 +794,15 @@ pub mod debuginfo {
} }
} }
} }
/// LLVMRustDebugNameTableKind
#[derive(Clone, Copy)]
#[repr(C)]
pub enum DebugNameTableKind {
Default,
Gnu,
None,
}
} }
use bitflags::bitflags; use bitflags::bitflags;
@ -1812,6 +1821,7 @@ extern "C" {
kind: DebugEmissionKind, kind: DebugEmissionKind,
DWOId: u64, DWOId: u64,
SplitDebugInlining: bool, SplitDebugInlining: bool,
DebugNameTableKind: DebugNameTableKind,
) -> &'a DIDescriptor; ) -> &'a DIDescriptor;
pub fn LLVMRustDIBuilderCreateFile<'a>( pub fn LLVMRustDIBuilderCreateFile<'a>(

View File

@ -697,6 +697,25 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind)
} }
} }
enum class LLVMRustDebugNameTableKind {
Default,
GNU,
None,
};
static DICompileUnit::DebugNameTableKind fromRust(LLVMRustDebugNameTableKind Kind) {
switch (Kind) {
case LLVMRustDebugNameTableKind::Default:
return DICompileUnit::DebugNameTableKind::Default;
case LLVMRustDebugNameTableKind::GNU:
return DICompileUnit::DebugNameTableKind::GNU;
case LLVMRustDebugNameTableKind::None:
return DICompileUnit::DebugNameTableKind::None;
default:
report_fatal_error("bad DebugNameTableKind.");
}
}
enum class LLVMRustChecksumKind { enum class LLVMRustChecksumKind {
None, None,
MD5, MD5,
@ -765,13 +784,15 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit(
const char *Flags, unsigned RuntimeVer, const char *Flags, unsigned RuntimeVer,
const char *SplitName, size_t SplitNameLen, const char *SplitName, size_t SplitNameLen,
LLVMRustDebugEmissionKind Kind, LLVMRustDebugEmissionKind Kind,
uint64_t DWOId, bool SplitDebugInlining) { uint64_t DWOId, bool SplitDebugInlining,
LLVMRustDebugNameTableKind TableKind) {
auto *File = unwrapDI<DIFile>(FileRef); auto *File = unwrapDI<DIFile>(FileRef);
return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen), return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen),
isOptimized, Flags, RuntimeVer, isOptimized, Flags, RuntimeVer,
StringRef(SplitName, SplitNameLen), StringRef(SplitName, SplitNameLen),
fromRust(Kind), DWOId, SplitDebugInlining)); fromRust(Kind), DWOId, SplitDebugInlining,
false, fromRust(TableKind)));
} }
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile( extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(

View File

@ -20,5 +20,5 @@ pub struct X;
// CHECK-NOT: .short 2 // CHECK-NOT: .short 2
// CHECK-NOT: .short 5 // CHECK-NOT: .short 5
// CHECK: .short 4 // CHECK: .short 4
// CHECK: .section .debug_pubnames // CHECK-NOT: .section .debug_pubnames
// CHECK: .section .debug_pubtypes // CHECK-NOT: .section .debug_pubtypes