From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Reilly Brogan <reilly@reillybrogan.com>
Date: Thu, 12 Dec 2024 20:50:14 -0600
Subject: [PATCH] Solus: Use zstd compression for debug symbols by default

---
 clang/include/clang/Driver/Options.td  | 4 ++--
 clang/tools/driver/cc1as_main.cpp      | 4 ++--
 lld/ELF/Config.h                       | 2 +-
 lld/ELF/Driver.cpp                     | 8 ++++----
 lld/ELF/Options.td                     | 2 +-
 lld/ELF/OutputSections.cpp             | 4 ++--
 llvm/tools/llvm-objcopy/ObjcopyOpts.td | 4 ++--
 7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ed2973435afc..f5aecdfecf5c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -7079,9 +7079,9 @@ def record_command_line : Separate<["-"], "record-command-line">,
 def compress_debug_sections_EQ : Joined<["-", "--"], "compress-debug-sections=">,
     HelpText<"DWARF debug sections compression type">, Values<"none,zlib,zstd">,
     NormalizedValuesScope<"llvm::DebugCompressionType">, NormalizedValues<["None", "Zlib", "Zstd"]>,
-    MarshallingInfoEnum<CodeGenOpts<"CompressDebugSections">, "None">;
+    MarshallingInfoEnum<CodeGenOpts<"CompressDebugSections">, "Zstd">;
 def compress_debug_sections : Flag<["-", "--"], "compress-debug-sections">,
-  Alias<compress_debug_sections_EQ>, AliasArgs<["zlib"]>;
+  Alias<compress_debug_sections_EQ>, AliasArgs<["zstd"]>;
 def mno_exec_stack : Flag<["-"], "mnoexecstack">,
   HelpText<"Mark the file as not needing an executable stack">,
   MarshallingInfoFlag<CodeGenOpts<"NoExecStack">>;
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index b661a43c88b0..22debfe3bff0 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -107,7 +107,7 @@ struct AssemblerInvocation {
   std::string DebugCompilationDir;
   llvm::SmallVector<std::pair<std::string, std::string>, 0> DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
-      llvm::DebugCompressionType::None;
+      llvm::DebugCompressionType::Zstd;
   std::string MainFileName;
   std::string SplitDwarfOutput;
 
@@ -287,7 +287,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
             .Case("none", llvm::DebugCompressionType::None)
             .Case("zlib", llvm::DebugCompressionType::Zlib)
             .Case("zstd", llvm::DebugCompressionType::Zstd)
-            .Default(llvm::DebugCompressionType::None);
+            .Default(llvm::DebugCompressionType::Zstd);
   }
 
   Opts.RelaxELFRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h
index 5b2a1541e529..6846a56a95ea 100644
--- a/lld/ELF/Config.h
+++ b/lld/ELF/Config.h
@@ -229,7 +229,7 @@ struct Config {
   CGProfileSortKind callGraphProfileSort;
   bool checkSections;
   bool checkDynamicRelocs;
-  std::optional<llvm::DebugCompressionType> compressDebugSections;
+  llvm::DebugCompressionType compressDebugSections = llvm::DebugCompressionType::Zstd;
   llvm::SmallVector<
       std::tuple<llvm::GlobPattern, llvm::DebugCompressionType, unsigned>, 0>
       compressSections;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 7a0a4006a099..a15ca77f446e 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1124,10 +1124,10 @@ static CGProfileSortKind getCGProfileSortKind(opt::InputArgList &args) {
 static DebugCompressionType getCompressionType(StringRef s, StringRef option) {
   DebugCompressionType type = StringSwitch<DebugCompressionType>(s)
                                   .Case("zlib", DebugCompressionType::Zlib)
-                                  .Case("zstd", DebugCompressionType::Zstd)
-                                  .Default(DebugCompressionType::None);
-  if (type == DebugCompressionType::None) {
-    if (s != "none")
+                                  .Case("none", DebugCompressionType::None)
+                                  .Default(DebugCompressionType::Zstd);
+  if (type == DebugCompressionType::Zstd) {
+    if (s != "zstd")
       error("unknown " + option + " value: " + s);
   } else if (const char *reason = compression::getReasonIfUnsupported(
                  compression::formatFor(type))) {
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 72f35eec9d65..b94f03e43360 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -64,7 +64,7 @@ defm check_sections: B<"check-sections",
     "Do not check section addresses for overlaps">;
 
 defm compress_debug_sections:
-  Eq<"compress-debug-sections", "Compress DWARF debug sections">,
+  Eq<"compress-debug-sections", "Compress DWARF debug sections (default: zstd)">,
   MetaVarName<"[none,zlib,zstd]">;
 
 defm compress_sections: EEq<"compress-sections",
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 29f18f89274f..acff113ca1e2 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -357,9 +357,9 @@ template <class ELFT> void OutputSection::maybeCompress() {
   DebugCompressionType ctype = DebugCompressionType::None;
   size_t compressedSize = sizeof(Elf_Chdr);
   unsigned level = 0; // default compression level
-  if (!(flags & SHF_ALLOC) && config->compressDebugSections &&
+  if (!(flags & SHF_ALLOC) &&
       name.starts_with(".debug_"))
-    ctype = *config->compressDebugSections;
+    ctype = config->compressDebugSections;
   for (auto &[glob, t, l] : config->compressSections)
     if (glob.match(name))
       std::tie(ctype, level) = {t, l};
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOpts.td b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
index b26c497ca399..927c59bbed51 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOpts.td
+++ b/llvm/tools/llvm-objcopy/ObjcopyOpts.td
@@ -35,9 +35,9 @@ def compress_debug_sections
     : Joined<["--"], "compress-debug-sections=">,
       MetaVarName<"format">,
       HelpText<"Compress DWARF debug sections using specified format. Supported "
-               "formats: zlib, zstd. Select zlib if <format> is omitted">;
+               "formats: zlib, zstd. Select zstd if <format> is omitted.">;
 def : Flag<["--"], "compress-debug-sections">, Alias<compress_debug_sections>,
-      AliasArgs<["zlib"]>;
+      AliasArgs<["zstd"]>;
 def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">,
                                 HelpText<"Decompress DWARF debug sections">;
 defm compress_sections
