[mips][ias] Fix R_MICROMIPS_GOT16 evaluation and eliminate symbol for R_MICROMIPS_(GOT|HI|LO)16

Summary:
The failure r269410 worked around turned out to be caused by an incorrect
evaluation of R_MICROMIPS_GOT16 which then caused the GOT entries to be
incorrect.

This patch fixes the evaluation and reverts r269410.

Reviewers: sdardis, vkalintiris, rafael

Subscribers: rafael, dsanders, sdardis, llvm-commits

Differential Revision: http://reviews.llvm.org/D20242

llvm-svn: 269641
This commit is contained in:
Daniel Sanders 2016-05-16 09:33:59 +00:00
parent 57a77118ba
commit a2bde88e62
3 changed files with 84 additions and 8 deletions

View File

@ -91,6 +91,7 @@ static unsigned adjustFixupValue(const MCFixup &Fixup, uint64_t Value,
break;
case Mips::fixup_Mips_HI16:
case Mips::fixup_Mips_GOT:
case Mips::fixup_MICROMIPS_GOT16:
case Mips::fixup_Mips_GOT_HI16:
case Mips::fixup_Mips_CALL_HI16:
case Mips::fixup_MICROMIPS_HI16:

View File

@ -502,10 +502,13 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
// are not supported yet but can be added as required.
case ELF::R_MIPS_GOT16:
case ELF::R_MIPS16_GOT16:
case ELF::R_MICROMIPS_GOT16:
case ELF::R_MIPS_HI16:
case ELF::R_MIPS16_HI16:
case ELF::R_MICROMIPS_HI16:
case ELF::R_MIPS_LO16:
case ELF::R_MIPS16_LO16:
case ELF::R_MICROMIPS_LO16:
// FIXME: It should be safe to return false for the STO_MIPS_MICROMIPS but
// we neglect to handle the adjustment to the LSB of the addend that
// it causes in applyFixup() and similar.
@ -513,13 +516,6 @@ bool MipsELFObjectWriter::needsRelocateWithSymbol(const MCSymbol &Sym,
return true;
return false;
// FIXME: These three belong in the previous group but applyFixup() and
// similar do not get the addend correct at the moment.
case ELF::R_MICROMIPS_GOT16:
case ELF::R_MICROMIPS_HI16:
case ELF::R_MICROMIPS_LO16:
return true;
case ELF::R_MIPS_16:
case ELF::R_MIPS_32:
case ELF::R_MIPS_GPREL32:

View File

@ -20,6 +20,7 @@
// unknown.
// FIXME - Placeholder. Generation method is known but doesn't work.
// RELOC-LABEL: .rel.text {
// DATA-LABEL: Name: .text
// DATA: SectionData (
@ -264,4 +265,82 @@ baz: .long foo // RELOC: R_MIPS_32 foo
.word 0
bar:
.word 1
// DATA-LABEL: Section {
.section .text_mm, "ax", @progbits
.set micromips
mm:
// RELOC-LABEL: .rel.text_mm {
// ENCBE-LABEL: mm:
// ENCLE-LABEL: mm:
// DATA-LABEL: Name: .text_mm
// DATA: SectionData (
// DATA-NEXT: 0000: 30430000 30420000 30430000 30420004
addiu $2, $3, %got(foo_mm) // RELOC: R_MICROMIPS_GOT16 foo_mm
// ENCBE: addiu $2, $3, %got(foo_mm) # encoding: [0x30,0x43,A,A]
// The placement of the 'A' annotations is incorrect. They use 32-bit little endian instead of 2x 16-bit little endian.
// ENCLE: addiu $2, $3, %got(foo_mm) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %got(foo_mm), kind: fixup_MICROMIPS_GOT16
// %got requires a %lo pair
addiu $2, $2, %lo(foo_mm) // RELOC: R_MICROMIPS_LO16 foo_mm
// ENCBE: addiu $2, $2, %lo(foo_mm) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(foo_mm) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(foo_mm), kind: fixup_MICROMIPS_LO16
foo_mm:
addiu $2, $3, %got(bar) // RELOC: R_MICROMIPS_GOT16 .data
// ENCBE: addiu $2, $3, %got(bar) # encoding: [0x30,0x43,A,A]
// ENCLE: addiu $2, $3, %got(bar) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %got(bar), kind: fixup_MICROMIPS_GOT16
// %got requires a %lo pair
addiu $2, $2, %lo(bar) // RELOC: R_MICROMIPS_LO16 .data
// ENCBE: addiu $2, $2, %lo(bar) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(bar) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(bar), kind: fixup_MICROMIPS_LO16
// DATA-NEXT: 0010: 30430000 30420004 30430001 30420030
addiu $2, $3, %got(baz) // RELOC: R_MICROMIPS_GOT16 .text
// ENCBE: addiu $2, $3, %got(baz) # encoding: [0x30,0x43,A,A]
// The placement of the 'A' annotations is incorrect. They use 32-bit little endian instead of 2x 16-bit little endian.
// ENCLE: addiu $2, $3, %got(baz) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %got(baz), kind: fixup_MICROMIPS_GOT16
// %got requires a %lo pair
addiu $2, $2, %lo(baz) // RELOC: R_MICROMIPS_LO16 .text
// ENCBE: addiu $2, $2, %lo(baz) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(baz) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(baz), kind: fixup_MICROMIPS_LO16
addiu $2, $3, %got(long_mm) // RELOC: R_MICROMIPS_GOT16 .text
// ENCBE: addiu $2, $3, %got(long_mm) # encoding: [0x30,0x43,A,A]
// The placement of the 'A' annotations is incorrect. They use 32-bit little endian instead of 2x 16-bit little endian.
// ENCLE: addiu $2, $3, %got(long_mm) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %got(long_mm), kind: fixup_MICROMIPS_GOT16
// %got requires a %lo pair
addiu $2, $2, %lo(long_mm) // RELOC: R_MICROMIPS_LO16 .text
// ENCBE: addiu $2, $2, %lo(long_mm) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(long_mm) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(long_mm), kind: fixup_MICROMIPS_LO16
// DATA-NEXT: 0020: 30430000 30420000 30430000 30420004
addiu $2, $3, %hi(foo_mm) // RELOC: R_MICROMIPS_HI16 foo_mm
// ENCBE: addiu $2, $3, %hi(foo_mm) # encoding: [0x30,0x43,A,A]
// ENCLE: addiu $2, $3, %hi(foo_mm) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %hi(foo_mm), kind: fixup_MICROMIPS_HI16
addiu $2, $2, %lo(foo_mm) // RELOC: R_MICROMIPS_LO16 foo_mm
// ENCBE: addiu $2, $2, %lo(foo_mm) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(foo_mm) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(foo_mm), kind: fixup_MICROMIPS_LO16
addiu $2, $3, %hi(bar) // RELOC: R_MICROMIPS_HI16 .data
// ENCBE: addiu $2, $3, %hi(bar) # encoding: [0x30,0x43,A,A]
// ENCLE: addiu $2, $3, %hi(bar) # encoding: [0x43'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %hi(bar), kind: fixup_MICROMIPS_HI16
addiu $2, $2, %lo(bar) // RELOC: R_MICROMIPS_LO16 .data
// ENCBE: addiu $2, $2, %lo(bar) # encoding: [0x30,0x42,A,A]
// ENCLE: addiu $2, $2, %lo(bar) # encoding: [0x42'A',0x30'A',0x00,0x00]
// FIXUP: # fixup A - offset: 0, value: %lo(bar), kind: fixup_MICROMIPS_LO16
.space 65536, 0
long_mm: