[lld] [lld-macho][arm64] Enhance safe ICF with thunk-based deduplication (PR #106573)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 19:18:41 PDT 2024
================
@@ -251,6 +252,63 @@ void ICF::forEachClassRange(size_t begin, size_t end,
}
}
+// Given a range of identical icfInputs's, replace address significant functions
+// with a thunk that is just a direct branch to the first function in the
+// series. This way we end up we keep only one main body of the function but we
+// still retain address uniqueness of rellevant functions by having them be a
+// direct branch thunk rather than contain a full copy of the actual function
+// body.
+void ICF::applySafeThunksToRange(size_t begin, size_t end) {
+ // If we need to create a unique ICF thunk, use the first section as the
+ // section that all thunks will branch to.
+ ConcatInputSection *masterIsec = icfInputs[begin];
+ uint32_t thunkSize = target->getICFSafeThunkSize();
+ static std::mutex thunkInsertionMutex;
+
+ uint32_t keepUniqueCount = masterIsec->keepUnique ? 1 : 0;
+ for (size_t i = begin + 1; i < end; ++i) {
+ ConcatInputSection *isec = icfInputs[i];
+ if (isec->keepUnique)
+ ++keepUniqueCount;
+
+ // We create thunks for the 2nd, 3rd, ... keepUnique sections. The first
----------------
alx32 wrote:
Great catch - fixed in latest revision.
https://github.com/llvm/llvm-project/pull/106573
More information about the llvm-commits
mailing list