Skip to content

Commit 943baf3

Browse files
committed
[ELF] Make compareByFilePosition a strict weak order
This fixes the new test linkerscript/enable-non-contiguous-regions.test from #90007 in -stdlib=libc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG builds. adjustOutputSections does not discard the output section .potential_a because it contained .a (which would be spilled to .actual_a). .potential_a and .bc have the same address and will cause an assertion failure.
1 parent 8960078 commit 943baf3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lld/ELF/Writer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,9 +1338,11 @@ static bool compareByFilePosition(InputSection *a, InputSection *b) {
13381338
OutputSection *aOut = la->getParent();
13391339
OutputSection *bOut = lb->getParent();
13401340

1341-
if (aOut != bOut)
1342-
return aOut->addr < bOut->addr;
1343-
return la->outSecOff < lb->outSecOff;
1341+
if (aOut == bOut)
1342+
return la->outSecOff < lb->outSecOff;
1343+
if (aOut->addr == bOut->addr)
1344+
return aOut->sectionIndex < bOut->sectionIndex;
1345+
return aOut->addr < bOut->addr;
13441346
}
13451347

13461348
template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {

0 commit comments

Comments
 (0)