File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -936,17 +936,22 @@ findOrphanPos(SmallVectorImpl<SectionCommand *>::iterator b,
936936 }
937937
938938 // Find the first element that has as close a rank as possible.
939- auto i = std::max_element (b, e, [=](SectionCommand *a, SectionCommand *b) {
940- return getRankProximity (sec, a) < getRankProximity (sec, b);
941- });
942- if (i == e)
939+ if (b == e)
943940 return e;
941+ int proximity = getRankProximity (sec, *b);
942+ auto i = b;
943+ for (auto j = b; ++j != e;) {
944+ int p = getRankProximity (sec, *j);
945+ if (p > proximity) {
946+ proximity = p;
947+ i = j;
948+ }
949+ }
944950 if (!isa<OutputDesc>(*i))
945951 return e;
946952 auto foundSec = &cast<OutputDesc>(*i)->osec ;
947953
948954 // Consider all existing sections with the same proximity.
949- int proximity = getRankProximity (sec, *i);
950955 unsigned sortRank = sec->sortRank ;
951956 if (script->hasPhdrsCommands () || !script->memoryRegions .empty ())
952957 // Prevent the orphan section to be placed before the found section. If
You can’t perform that action at this time.
0 commit comments