[llvm] r269196 - [mips][ias] Work around incorrect microMIPS relocation evaluation exposed by r268900

Daniel Sanders via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 08:44:23 PDT 2016


Author: dsanders
Date: Wed May 11 10:44:23 2016
New Revision: 269196

URL: http://llvm.org/viewvc/llvm-project?rev=269196&view=rev
Log:
[mips][ias] Work around incorrect microMIPS relocation evaluation exposed by r268900

microMIPS has a special case that is not correctly implemented in LLVM. If we
have a symbol 'foo' which is equivalent to '.text+0x10'. The value of an
R_MICROMIPS_LO16 relocation using 'foo' is 'foo+0x11' and not 'foo+0x10'. The
in-place addend should therefore be 0x11.

Work around this by partially reverting the effect of r268900 by keeping the
symbol when the STO_MIPS_MICROMIPS flag is set. This fixes
SingleSource/Regression/C/PR640 for microMIPS.


Added:
    llvm/trunk/test/MC/Mips/relocation-xfail.s
Modified:
    llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp?rev=269196&r1=269195&r2=269196&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp Wed May 11 10:44:23 2016
@@ -507,6 +507,11 @@ bool MipsELFObjectWriter::needsRelocateW
   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.
+    if (cast<MCSymbolELF>(Sym).getOther() & ELF::STO_MIPS_MICROMIPS)
+      return true;
     return false;
 
   case ELF::R_MIPS_16:

Added: llvm/trunk/test/MC/Mips/relocation-xfail.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/relocation-xfail.s?rev=269196&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/relocation-xfail.s (added)
+++ llvm/trunk/test/MC/Mips/relocation-xfail.s Wed May 11 10:44:23 2016
@@ -0,0 +1,20 @@
+// RUN: llvm-mc -filetype=obj -triple mips-unknown-linux -mattr=+micromips < %s \
+// RUN:     | llvm-readobj -sections -section-data \
+// RUN:     | FileCheck -check-prefix=DATA %s
+//
+// XFAIL: *
+
+// Please merge this with relocation.s when it passes.
+
+// baz is equivalent to .text+0x8 and is recorded in the symbol table as such
+// but it refers to microMIPS code so the addend must indicate this in the LSB.
+// The addend must therefore be 0x9.
+// DATA:       0000: 30430000 30420009
+        addiu $2, $3, %got(baz)
+        addiu $2, $2, %lo(baz)
+baz:
+
+	.data
+	.word 0
+bar:
+	.word 1




More information about the llvm-commits mailing list