[llvm-branch-commits] [llvm-objcopy] Simplify --[de]compress-debug-sections and don't compress SHF_ALLOC sections (PR #84885)
Fangrui Song via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 12 10:10:43 PDT 2024
================
@@ -214,33 +214,34 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
SecName.str().c_str());
}
-static bool isCompressable(const SectionBase &Sec) {
- return !(Sec.Flags & ELF::SHF_COMPRESSED) &&
- StringRef(Sec.Name).starts_with(".debug");
-}
-
-static Error replaceDebugSections(
- Object &Obj, function_ref<bool(const SectionBase &)> ShouldReplace,
- function_ref<Expected<SectionBase *>(const SectionBase *)> AddSection) {
+Error Object::compressOrDecompressSections(const CommonConfig &Config) {
// Build a list of the debug sections we are going to replace.
// We can't call `AddSection` while iterating over sections,
// because it would mutate the sections array.
- SmallVector<SectionBase *, 13> ToReplace;
- for (auto &Sec : Obj.sections())
- if (ShouldReplace(Sec))
- ToReplace.push_back(&Sec);
-
- // Build a mapping from original section to a new one.
- DenseMap<SectionBase *, SectionBase *> FromTo;
- for (SectionBase *S : ToReplace) {
- Expected<SectionBase *> NewSection = AddSection(S);
- if (!NewSection)
- return NewSection.takeError();
-
- FromTo[S] = *NewSection;
+ SmallVector<std::pair<SectionBase *, std::function<SectionBase *()>>, 0>
----------------
MaskRay wrote:
The default is a smart value to keep `sizeof(SmallVector<T>)` around 64 bytes. Someone might send a RFC to change the default to 0 and have another mechanism to use the default. I believe `, 0` is used much more than the smart default, since in many cases people don't care about extra heap allocations at runtime, but I care about code size and the smaller structure of `SmallVector`.
https://github.com/llvm/llvm-project/pull/84885
More information about the llvm-branch-commits
mailing list