about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-12-11 22:32:08 +0000
committerbors <bors@rust-lang.org>2023-12-11 22:32:08 +0000
commite2a3c9b3f0895c866c104bd2fff2a8bf16eaf964 (patch)
treef7181fef792975fdc7192ba06047fdbcd8306b43 /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
parent21cce21d8c012f14cf74d5afddd795d324600dac (diff)
parent6aac62cdcb9ba84dddca920e8528dd4d62d78801 (diff)
downloadrust-e2a3c9b3f0895c866c104bd2fff2a8bf16eaf964.tar.gz
rust-e2a3c9b3f0895c866c104bd2fff2a8bf16eaf964.zip
Auto merge of #117962 - weihanglo:debug-name-table, r=wesleywiser
fix: stop emitting `.debug_pubnames` and `.debug_pubtypes`

A continuation of #94181.
Fixes #48762
MCP can be found in <https://github.com/rust-lang/compiler-team/issues/688>.

`.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.

Some other no-really-useful personal notes:

<details><summary>Details</summary>
<p>

## Pepole saying they are not useful

* https://github.com/rust-lang/rust/issues/48762
* https://rust-lang.zulipchat.com/#narrow/stream/317568-t-compiler.2Fwg-debugging/topic/investigating.20debuginfo.20size/near/342713604
* `DwarfCompileUnit::hasDwarfPubSections()` — https://github.com/llvm/llvm-project/blob/f633f325a1b808d33ca9653ed373353549ddcde6/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp#L1477-L1494
* clang default to no debug name table when no option provided — https://github.com/llvm/llvm-project/blob/f633f325a1b808d33ca9653ed373353549ddcde6/clang/lib/Frontend/CompilerInvocation.cpp#L1819-L1824
* GCC explicitly says GDB doesn't use pub sections (`TARGET_WANT_DEBUG_PUB_SECTIONS` only be true on Darwin) — https://github.com/gcc-mirror/gcc/blob/5d2a360f0a541646abb11efdbabc33c6a04de7ee/gcc/target.def#L6985-L6990 and https://github.com/bminor/binutils-gdb/blob/319b460545dc79280e2904dcc280057cf71fb753/gold/dwarf_reader.h#L424-L427
* Probably the only place that makes use of pub section in lldb — https://github.com/llvm/llvm-project/blob/725115d7bba2faf3d0c21442f4661dea77b8a77c/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp#L2117-L2135

* "The -gsplit-dwarf option requires -ggnu-pubnames." — https://github.com/gcc-mirror/gcc/blob/5d2a360f0a541646abb11efdbabc33c6a04de7ee/gcc/opts.cc#L1205

* LLVM: Always emit `.debug_names` with dwarf 5 for Apple platforms — https://reviews.llvm.org/D118754

</p>
</details>
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
-rw-r--r--compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
index b227dd76f02..0df7b7eed11 100644
--- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
+++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
@@ -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 {
   None,
   MD5,
@@ -765,13 +784,15 @@ 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<DIFile>(FileRef);
 
   return wrap(Builder->createCompileUnit(Lang, File, StringRef(Producer, ProducerLen),
                                          isOptimized, Flags, RuntimeVer,
                                          StringRef(SplitName, SplitNameLen),
-                                         fromRust(Kind), DWOId, SplitDebugInlining));
+                                         fromRust(Kind), DWOId, SplitDebugInlining,
+                                         false, fromRust(TableKind)));
 }
 
 extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateFile(