From: Andrew Ng Date: Tue, 23 Apr 2019 12:17:15 +0000 (+0000) Subject: [ELF] Change findOrphanPos to only consider live sections X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98c858a23be102964b6e61d58749c56bbe2dec5f;p=platform%2Fupstream%2Fllvm.git [ELF] Change findOrphanPos to only consider live sections This patch changes the behaviour of findOrphanPos to only consider live sections when placing orphan sections. This used to be how it behaved in the past. Differential Revision: https://reviews.llvm.org/D60273 llvm-svn: 358979 --- diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 2903664..c7d63969 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1094,16 +1094,19 @@ findOrphanPos(std::vector::iterator B, int Proximity = getRankProximity(Sec, *I); for (; I != E; ++I) { auto *CurSec = dyn_cast(*I); - if (!CurSec) + if (!CurSec || !CurSec->Live) continue; if (getRankProximity(Sec, CurSec) != Proximity || Sec->SortRank < CurSec->SortRank) break; } - auto IsOutputSec = [](BaseCommand *Cmd) { return isa(Cmd); }; + auto IsLiveOutputSec = [](BaseCommand *Cmd) { + auto *OS = dyn_cast(Cmd); + return OS && OS->Live; + }; auto J = std::find_if(llvm::make_reverse_iterator(I), - llvm::make_reverse_iterator(B), IsOutputSec); + llvm::make_reverse_iterator(B), IsLiveOutputSec); I = J.base(); // As a special case, if the orphan section is the last section, put @@ -1111,7 +1114,7 @@ findOrphanPos(std::vector::iterator B, // This matches bfd's behavior and is convenient when the linker script fully // specifies the start of the file, but doesn't care about the end (the non // alloc sections for example). - auto NextSec = std::find_if(I, E, IsOutputSec); + auto NextSec = std::find_if(I, E, IsLiveOutputSec); if (NextSec == E) return E;