[llvm] [llvm-objcopy] Add --compress-sections (PR #85036)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 26 20:56:06 PDT 2024


================
@@ -215,23 +215,39 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
 }
 
 Error Object::compressOrDecompressSections(const CommonConfig &Config) {
-  // Build a list of the debug sections we are going to replace.
+  // Build a list of sections we are going to replace.
   // We can't call `AddSection` while iterating over sections,
   // because it would mutate the sections array.
   SmallVector<std::pair<SectionBase *, std::function<SectionBase *()>>, 0>
       ToReplace;
   for (SectionBase &Sec : sections()) {
-    if ((Sec.Flags & SHF_ALLOC) || !StringRef(Sec.Name).starts_with(".debug"))
+    std::optional<DebugCompressionType> CType;
+    for (auto &[Matcher, T] : Config.compressSections)
----------------
MaskRay wrote:

With recent GNU objcopy, --compress-debug-sections=zstd on a zlib-compressed section will recompress the content with zstd. This is whether our behavior is different from GNU. I've actually tried implementing this behavior, but in the end the benefit doesn't feel clear and the complexity seems quite high (I don't even find a good way to implement it related to our `CompressedSection` abstraction).

I think the scenario is likely very rare and users might not expect a specific behavior.

https://github.com/llvm/llvm-project/pull/85036


More information about the llvm-commits mailing list