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,
936
936
}
937
937
938
938
// 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)
943
940
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
+ }
944
950
if (!isa<OutputDesc>(*i))
945
951
return e;
946
952
auto foundSec = &cast<OutputDesc>(*i)->osec ;
947
953
948
954
// Consider all existing sections with the same proximity.
949
- int proximity = getRankProximity (sec, *i);
950
955
unsigned sortRank = sec->sortRank ;
951
956
if (script->hasPhdrsCommands () || !script->memoryRegions .empty ())
952
957
// Prevent the orphan section to be placed before the found section. If
You can’t perform that action at this time.
0 commit comments