From: Jez Ng Date: Wed, 14 Sep 2022 21:46:41 +0000 (-0400) Subject: [lld-macho][nfc] Clean up ICF code X-Git-Tag: upstream/17.0.6~33496 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d4ca09d068d66d13b258ebccdb9470b50fff881;p=platform%2Fupstream%2Fllvm.git [lld-macho][nfc] Clean up ICF code Split these changes out from https://reviews.llvm.org/D133780. --- diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp index d06fbc6..e782260 100644 --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -411,28 +411,29 @@ void macho::foldIdenticalSections(bool onlyCfStrings) { // coexist with equivalence-class IDs, this is not necessary, but might help // someone keep the numbers straight in case we ever need to debug the // ICF::segregate() - std::vector hashable; + std::vector foldable; uint64_t icfUniqueID = inputSections.size(); for (ConcatInputSection *isec : inputSections) { - // FIXME: consider non-code __text sections as hashable? - bool isHashable = - (!onlyCfStrings || isCfStringSection(isec)) && - (isCodeSection(isec) || isCfStringSection(isec) || - isClassRefsSection(isec) || isGccExceptTabSection(isec)) && - !isec->keepUnique && !isec->shouldOmitFromOutput() && - sectionType(isec->getFlags()) == MachO::S_REGULAR; - if (isHashable) { - hashable.push_back(isec); + bool isFoldableWithAddendsRemoved = + isCfStringSection(isec) || isClassRefsSection(isec); + // FIXME: consider non-code __text sections as foldable? + bool isFoldable = (!onlyCfStrings || isCfStringSection(isec)) && + (isCodeSection(isec) || isGccExceptTabSection(isec) || + isFoldableWithAddendsRemoved) && + !isec->keepUnique && !isec->shouldOmitFromOutput() && + sectionType(isec->getFlags()) == MachO::S_REGULAR; + if (isFoldable) { + foldable.push_back(isec); for (Defined *d : isec->symbols) if (d->unwindEntry) - hashable.push_back(d->unwindEntry); + foldable.push_back(d->unwindEntry); // __cfstring has embedded addends that foil ICF's hashing / equality // checks. (We can ignore embedded addends when doing ICF because the same // information gets recorded in our Reloc structs.) We therefore create a // mutable copy of the CFString and zero out the embedded addends before // performing any hashing / equality checks. - if (isCfStringSection(isec) || isClassRefsSection(isec)) { + if (isFoldableWithAddendsRemoved) { // We have to do this copying serially as the BumpPtrAllocator is not // thread-safe. FIXME: Make a thread-safe allocator. MutableArrayRef copy = isec->data.copy(bAlloc()); @@ -442,12 +443,12 @@ void macho::foldIdenticalSections(bool onlyCfStrings) { isec->data = copy; } } else if (!isEhFrameSection(isec)) { - // EH frames are gathered as hashables from unwindEntry above; give a + // EH frames are gathered as foldable from unwindEntry above; give a // unique ID to everything else. isec->icfEqClass[0] = ++icfUniqueID; } } - parallelForEach(hashable, [](ConcatInputSection *isec) { + parallelForEach(foldable, [](ConcatInputSection *isec) { assert(isec->icfEqClass[0] == 0); // don't overwrite a unique ID! // Turn-on the top bit to guarantee that valid hashes have no collisions // with the small-integer unique IDs for ICF-ineligible sections @@ -455,5 +456,5 @@ void macho::foldIdenticalSections(bool onlyCfStrings) { }); // Now that every input section is either hashed or marked as unique, run the // segregation algorithm to detect foldable subsections. - ICF(hashable).run(); + ICF(foldable).run(); }