From 598bd00e979376c0d9374bc82a0200cc79f6a9b5 Mon Sep 17 00:00:00 2001 From: csmoe Date: Sun, 20 Feb 2022 20:33:48 +0800 Subject: [PATCH] cherry-pick from @tromey: do not emit .debug_pubnames .debug_pubtypes on linux --- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 23 +++++++++++++++- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 26 +++++++++++++++++-- compiler/rustc_session/src/config.rs | 7 +++++ compiler/rustc_session/src/options.rs | 17 ++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index a1c7d2b4f6156..a5075a5b3aaf5 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -7,7 +7,7 @@ use super::debuginfo::{ DIArray, DIBasicType, DIBuilder, DICompositeType, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags, DIGlobalVariableExpression, DILexicalBlock, DILocation, DINameSpace, DISPFlags, DIScope, DISubprogram, DISubrange, DITemplateTypeParameter, DIType, DIVariable, - DebugEmissionKind, + DebugEmissionKind, DebugNameTableKind, }; use libc::{c_char, c_int, c_uint, size_t}; @@ -955,6 +955,26 @@ pub mod debuginfo { } } } + + /// LLVMRustDebugNameTableKind + #[derive(Clone, Copy)] + #[repr(C)] + pub enum DebugNameTableKind { + Default, + None, + Gnu, + } + + impl DebugNameTableKind { + pub fn from_generic(kind: rustc_session::config::DebugNameTableKind) -> DebugNameTableKind { + use rustc_session::config; + match kind { + config::DebugNameTableKind::None => DebugNameTableKind::None, + config::DebugNameTableKind::Default => DebugNameTableKind::Default, + config::DebugNameTableKind::Gnu => DebugNameTableKind::Gnu, + } + } + } } extern "C" { @@ -1919,6 +1939,7 @@ extern "C" { kind: DebugEmissionKind, DWOId: u64, SplitDebugInlining: bool, + DebugNameTableKind: DebugNameTableKind, ) -> &'a DIDescriptor; pub fn LLVMRustDIBuilderCreateFile<'a>( diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index c21e4acbefec0..1eab00dabed6d 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -682,6 +682,25 @@ static DICompileUnit::DebugEmissionKind fromRust(LLVMRustDebugEmissionKind Kind) } } +enum class LLVMRustDebugNameTableKind { + Default, + None, + Gnu, +}; + +static DICompileUnit::DebugNameTableKind fromRust(LLVMRustDebugNameTableKind Kind) { + switch (Kind) { + case LLVMRustDebugNameTableKind::Default: + return DICompileUnit::DebugNameTableKind::Default; + case LLVMRustDebugNameTableKind::None: + return DICompileUnit::DebugNameTableKind::None; + case LLVMRustDebugNameTableKind::Gnu: + return DICompileUnit::DebugNameTableKind::Gnu; + default: + report_fatal_error("bad DebugNameTableKind."); + } +} + enum class LLVMRustChecksumKind { None, MD5, @@ -749,13 +768,16 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateCompileUnit( const char *Flags, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMRustDebugEmissionKind Kind, - uint64_t DWOId, bool SplitDebugInlining) { + uint64_t DWOId, bool SplitDebugInlining, + LLVMRustDebugNameTableKind TableKind) { auto *File = unwrapDI(FileRef); + bool DebugInfoForProfiling = false; return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen), isOptimized, Flags, RuntimeVer, StringRef(SplitName, SplitNameLen), - fromRust(Kind), DWOId, SplitDebugInlining)); + fromRust(Kind), DWOId, SplitDebugInlining, + DebugInfoForProfiling, fromRust(TableKind)); } extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile( diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 92ad0723f4879..8f34761bc02a8 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -231,6 +231,13 @@ pub enum DebugInfo { Full, } +#[derive(Clone, Copy, Debug, PartialEq, Hash)] +pub enum DebugNameTableKind { + Default, + None, + Gnu, +} + /// Split debug-information is enabled by `-C split-debuginfo`, this enum is only used if split /// debug-information is enabled (in either `Packed` or `Unpacked` modes), and the platform /// uses DWARF for debug-information. diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index e7ab8fffdf35c..5cb27a281e9af 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -811,6 +811,21 @@ mod parse { } } + crate fn parse_debug_name_table_kind(slot: &mut DebugNameTableKind, v: Option<&str>) -> bool { + match v { + None => false, + Some(s) => { + *slot = match s { + "none" => DebugNameTableKind::None, + "gnu" => DebugNameTableKind::Gnu, + _ => DebugNameTableKind::Default, + }; + true + } + _ => false, + } + } + crate fn parse_lto(slot: &mut LtoCli, v: Option<&str>) -> bool { if v.is_some() { let mut bool_arg = None; @@ -1151,6 +1166,8 @@ options! { "inject the given attribute in the crate"), debug_info_for_profiling: bool = (false, parse_bool, [TRACKED], "emit discriminators and other data necessary for AutoFDO"), + debug_name_table_kind: DebugNameTableKind = (DebugNameTableKind::Default, parse_debug_name_table_kind, [TRACKED], + "emit .debug_pubnames .debug_pubtypes(default: default)"), debug_macros: bool = (false, parse_bool, [TRACKED], "emit line numbers debug info inside macros (default: no)"), deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],