Skip to content

Commit 4a2a5df

Browse files
author
Simon Dardis
committed
[mips][ias] N32/N64 must not sort the relocation table.
Doing so changes the evaluation order for relocation composition. Patch By: Daniel Sanders Reviewers: vkalintiris, atanasyan Differential Revision: https://reviews.llvm.org/D26401 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288666 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 26d70f7 commit 4a2a5df

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ unsigned MipsELFObjectWriter::getRelocType(MCContext &Ctx,
419419
/// always match using the expressions from the source.
420420
void MipsELFObjectWriter::sortRelocs(const MCAssembler &Asm,
421421
std::vector<ELFRelocationEntry> &Relocs) {
422+
423+
// We do not need to sort the relocation table for RELA relocations which
424+
// N32/N64 uses as the relocation addend contains the value we require,
425+
// rather than it being split across a pair of relocations.
426+
if (hasRelocationAddend())
427+
return;
428+
422429
if (Relocs.size() < 2)
423430
return;
424431

test/MC/Mips/reloc-directive.s

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,24 @@ foo:
4343
# OBJ-N32: 0000: 00000000 00000000 00000000
4444
# OBJ-N32-LABEL: }
4545
# OBJ-N32-LABEL: Relocations [
46-
# OBJ-N32: 0x0 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x4
46+
4747
# OBJ-N32: 0x4 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x0
48+
# OBJ-N32: 0x0 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x4
4849
# OBJ-N32: 0x8 R_MIPS_32/R_MIPS_NONE/R_MIPS_NONE .text 0x8
4950
# OBJ-N32: 0xC R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE - 0x0
5051

52+
# FIXME:This is the correct output for reference.
53+
54+
# OBJ-N32-FIXME: 0x4 R_MIPS_NONE .text 0x0
55+
# OBJ-N32-FIXME: 0x0 R_MIPS_NONE .text 0x4
56+
# OBJ-N32-FIXME: 0x8 R_MIPS_32 .text 0x8
57+
# OBJ-N32-FIXME: 0xC R_MIPS_NONE - 0x0
58+
5159
# OBJ-N64-LABEL: Name: .text
5260
# OBJ-N64: 0000: 00000000 00000000 00000000
5361
# OBJ-N64-LABEL: }
5462
# OBJ-N64-LABEL: Relocations [
55-
# OBJ-N64: 0x0 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x4
5663
# OBJ-N64: 0x4 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x0
64+
# OBJ-N64: 0x0 R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE .text 0x4
5765
# OBJ-N64: 0x8 R_MIPS_32/R_MIPS_NONE/R_MIPS_NONE .text 0x8
5866
# OBJ-N64: 0xC R_MIPS_NONE/R_MIPS_NONE/R_MIPS_NONE - 0x0

0 commit comments

Comments
 (0)