Skip to content

Commit 98c858a

Browse files
committedApr 23, 2019
[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
1 parent 61ef919 commit 98c858a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎lld/ELF/Writer.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,24 +1094,27 @@ findOrphanPos(std::vector<BaseCommand *>::iterator B,
10941094
int Proximity = getRankProximity(Sec, *I);
10951095
for (; I != E; ++I) {
10961096
auto *CurSec = dyn_cast<OutputSection>(*I);
1097-
if (!CurSec)
1097+
if (!CurSec || !CurSec->Live)
10981098
continue;
10991099
if (getRankProximity(Sec, CurSec) != Proximity ||
11001100
Sec->SortRank < CurSec->SortRank)
11011101
break;
11021102
}
11031103

1104-
auto IsOutputSec = [](BaseCommand *Cmd) { return isa<OutputSection>(Cmd); };
1104+
auto IsLiveOutputSec = [](BaseCommand *Cmd) {
1105+
auto *OS = dyn_cast<OutputSection>(Cmd);
1106+
return OS && OS->Live;
1107+
};
11051108
auto J = std::find_if(llvm::make_reverse_iterator(I),
1106-
llvm::make_reverse_iterator(B), IsOutputSec);
1109+
llvm::make_reverse_iterator(B), IsLiveOutputSec);
11071110
I = J.base();
11081111

11091112
// As a special case, if the orphan section is the last section, put
11101113
// it at the very end, past any other commands.
11111114
// This matches bfd's behavior and is convenient when the linker script fully
11121115
// specifies the start of the file, but doesn't care about the end (the non
11131116
// alloc sections for example).
1114-
auto NextSec = std::find_if(I, E, IsOutputSec);
1117+
auto NextSec = std::find_if(I, E, IsLiveOutputSec);
11151118
if (NextSec == E)
11161119
return E;
11171120

0 commit comments

Comments
 (0)