Skip to content

Commit 8e4e1c1

Browse files
committed
MIPS: Stable sort relocations
There might be more than one relocations at an offset with composed relocations or .reloc directive. llvm::sort output is unstable, and if EXPENSIVE_CHECKS, also undeterministic, causing MC/Mips/reloc-directive.s to fail.
1 parent 3408f7b commit 8e4e1c1

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,12 @@ void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
385385
if (hasRelocationAddend())
386386
return;
387387

388-
// Sort relocations by the address they are applied to.
389-
llvm::sort(Relocs,
390-
[](const ELFRelocationEntry &A, const ELFRelocationEntry &B) {
391-
return A.Offset < B.Offset;
392-
});
388+
// Sort relocations by r_offset. There might be more than one at an offset
389+
// with composed relocations or .reloc directives.
390+
llvm::stable_sort(
391+
Relocs, [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) {
392+
return A.Offset < B.Offset;
393+
});
393394

394395
// Place relocations in a list for reorder convenience. Hi16 contains the
395396
// iterators of high-part relocations.

0 commit comments

Comments
 (0)