aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-07-21 23:05:16 -0700
committerFangrui Song <i@maskray.me>2025-07-21 23:05:16 -0700
commit8e4e1c104d88e193d5977e0136509f8c76dde43e (patch)
tree8574a311294c51ea51696c081c7bee54ae5df23e /llvm
parent3408f7b42f7af7c38d8054067c7dcad82df99b2f (diff)
downloadllvm-8e4e1c104d88e193d5977e0136509f8c76dde43e.zip
llvm-8e4e1c104d88e193d5977e0136509f8c76dde43e.tar.gz
llvm-8e4e1c104d88e193d5977e0136509f8c76dde43e.tar.bz2
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.
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index ad8f5f0..7abe9c9 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -385,11 +385,12 @@ void MipsELFObjectWriter::sortRelocs(std::vector<ELFRelocationEntry> &Relocs) {
if (hasRelocationAddend())
return;
- // Sort relocations by the address they are applied to.
- llvm::sort(Relocs,
- [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) {
- return A.Offset < B.Offset;
- });
+ // Sort relocations by r_offset. There might be more than one at an offset
+ // with composed relocations or .reloc directives.
+ llvm::stable_sort(
+ Relocs, [](const ELFRelocationEntry &A, const ELFRelocationEntry &B) {
+ return A.Offset < B.Offset;
+ });
// Place relocations in a list for reorder convenience. Hi16 contains the
// iterators of high-part relocations.