Index: lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp |
diff --git a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp |
index 50f0893fce7e2defdde30787b81c77bc3f361ea3..e00647cb025484bb0c45805187c6a4488e115df6 100644 |
--- a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp |
+++ b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp |
@@ -14,7 +14,12 @@ |
#include "MipsFixupKinds.h" |
#include "MCTargetDesc/MipsMCTargetDesc.h" |
-#include "MCTargetDesc/MipsMCNaCl.h" // @LOCALMOD |
+// @LOCALMOD-START |
+#include "MCTargetDesc/MipsMCNaCl.h" |
+#include "llvm/MC/MCAsmLayout.h" |
+#include "llvm/MC/MCExpr.h" |
+#include "llvm/MC/MCValue.h" |
+// @LOCALMOD-END |
#include "llvm/MC/MCAsmBackend.h" |
#include "llvm/MC/MCAssembler.h" |
#include "llvm/MC/MCDirectives.h" |
@@ -98,6 +103,44 @@ public: |
MCELFObjectTargetWriter::getOSABI(OSType), IsLittle, Is64Bit); |
} |
+ // @LOCALMOD-START |
+ /// processFixupValue - Target hook to process the literal value of a fixup |
+ /// if necessary. |
+ void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout, |
Mark Seaborn
2013/11/28 03:37:02
Can you send this part to upstream LLVM? You can
|
+ const MCFixup &Fixup, const MCFragment *DF, |
+ MCValue &Target, uint64_t &Value, |
+ bool &IsResolved) { |
+ if ((unsigned)Fixup.getKind() == Mips::fixup_Mips_HI16 |
+ || (unsigned)Fixup.getKind() == Mips::fixup_Mips_LO16) { |
+ |
+ // Check for expressions %hi(tmp) and %lo(tmp), where tmp = sym1-sym2. |
Mark Seaborn
2013/11/28 03:37:02
This part isn't MIPS specific, so I wonder if you
|
+ if (Target.getSymA() != NULL && Target.getSymA()->getSymbol().isVariable() |
+ && Target.getSymB() == NULL && Target.getConstant() == 0) { |
+ const MCExpr *SymValue = Target.getSymA()->getSymbol() |
+ .getVariableValue(); |
+ const MCBinaryExpr *BE = dyn_cast<MCBinaryExpr>(SymValue); |
+ if (BE && BE->getOpcode() == MCBinaryExpr::Sub) { |
+ const MCSymbolRefExpr *LHS = dyn_cast<MCSymbolRefExpr>(BE->getLHS()); |
+ const MCSymbolRefExpr *RHS = dyn_cast<MCSymbolRefExpr>(BE->getRHS()); |
+ if (LHS != NULL && LHS->getSymbol().isDefined() |
+ && RHS != NULL && RHS->getSymbol().isDefined()) { |
+ // Don't emit relocation for expressions %hi(tmp) and %lo(tmp), |
+ // where tmp = sym1-sym2. |
+ IsResolved = true; |
+ |
+ // Calculate symbol value. |
+ uint64_t Value1 = |
+ Layout.getSymbolOffset(&Asm.getSymbolData(LHS->getSymbol())); |
+ uint64_t Value2 = |
+ Layout.getSymbolOffset(&Asm.getSymbolData(RHS->getSymbol())); |
+ Value = Value1 - Value2; |
+ } |
+ } |
+ } |
+ } |
+ } |
+ // @LOCALMOD-END |
+ |
/// ApplyFixup - Apply the \p Value for given \p Fixup into the provided |
/// data fragment, at the offset specified by the fixup and following the |
/// fixup kind as appropriate. |