diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp index acba0a2a824b4..9b8aa1837a4aa 100644 --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -297,16 +297,25 @@ static Symbol *getThunkTargetSymbol(ConcatInputSection *isec) { // direct branch thunk rather than containing a full copy of the actual function // body. void ICF::applySafeThunksToRange(size_t begin, size_t end) { + // When creating a unique ICF thunk, use the first section as the section that + // all thunks will branch to. + ConcatInputSection *masterIsec = icfInputs[begin]; + + // If the first section is not address significant, sorting guarantees that + // there are no address significant functions. So we can skip this range. + if (!masterIsec->keepUnique) + return; + + // Skip anything that is not a code section. + if (!isCodeSection(masterIsec)) + return; + // If the functions we're dealing with are smaller than the thunk size, then // just leave them all as-is - creating thunks would be a net loss. uint32_t thunkSize = target->getICFSafeThunkSize(); - if (icfInputs[begin]->data.size() <= thunkSize) + if (masterIsec->data.size() <= thunkSize) return; - // When creating a unique ICF thunk, use the first section as the section that - // all thunks will branch to. - ConcatInputSection *masterIsec = icfInputs[begin]; - // Get the symbol that all thunks will branch to. Symbol *masterSym = getThunkTargetSymbol(masterIsec);