Skip to content

Commit bdcb222

Browse files
committed
Merging MIPS GOT changeset into 3.2 release branch.
Merging r168471: Mips direct object xgot support This patch provides support for the MIPS relocations: *) R_MIPS_GOT_HI16 *) R_MIPS_GOT_LO16 *) R_MIPS_CALL_HI16 *) R_MIPS_CALL_LO16 These are used for large GOT instruction sequences. Contributer: Jack Carter Merging r168460: [mips] Generate big GOT code. Merging r168458: [mips] Simplify lowering functions in MipsISelLowering.cpp by using the helper functions added in r168456. Merging r168456: [mips] Add helper functions that create nodes for computing address. Merging r168455: [mips] Add command line option "-mxgot". Merging r168453: [mips] When a node which loads from a GOT is created, pass a MachinePointerInfo referring to a GOT entry. Merging r168450: [mips] Add target operand flag enums for big GOT relocations. Merging r168448: Add relocations used for mips big GOT. git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_32@169294 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a902024 commit bdcb222

File tree

14 files changed

+278
-151
lines changed

14 files changed

+278
-151
lines changed

include/llvm/MC/MCExpr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,11 @@ class MCSymbolRefExpr : public MCExpr {
197197
VK_Mips_GOT_PAGE,
198198
VK_Mips_GOT_OFST,
199199
VK_Mips_HIGHER,
200-
VK_Mips_HIGHEST
200+
VK_Mips_HIGHEST,
201+
VK_Mips_GOT_HI16,
202+
VK_Mips_GOT_LO16,
203+
VK_Mips_CALL_HI16,
204+
VK_Mips_CALL_LO16
201205
};
202206

203207
private:

lib/MC/MCExpr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
229229
case VK_Mips_GOT_OFST: return "GOT_OFST";
230230
case VK_Mips_HIGHER: return "HIGHER";
231231
case VK_Mips_HIGHEST: return "HIGHEST";
232+
case VK_Mips_GOT_HI16: return "GOT_HI16";
233+
case VK_Mips_GOT_LO16: return "GOT_LO16";
234+
case VK_Mips_CALL_HI16: return "CALL_HI16";
235+
case VK_Mips_CALL_LO16: return "CALL_LO16";
232236
}
233237
llvm_unreachable("Invalid variant kind");
234238
}

lib/Target/Mips/InstPrinter/MipsInstPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ static void printExpr(const MCExpr *Expr, raw_ostream &OS) {
128128
case MCSymbolRefExpr::VK_Mips_GOT_OFST: OS << "%got_ofst("; break;
129129
case MCSymbolRefExpr::VK_Mips_HIGHER: OS << "%higher("; break;
130130
case MCSymbolRefExpr::VK_Mips_HIGHEST: OS << "%highest("; break;
131+
case MCSymbolRefExpr::VK_Mips_GOT_HI16: OS << "%got_hi("; break;
132+
case MCSymbolRefExpr::VK_Mips_GOT_LO16: OS << "%got_lo("; break;
133+
case MCSymbolRefExpr::VK_Mips_CALL_HI16: OS << "%call_hi("; break;
134+
case MCSymbolRefExpr::VK_Mips_CALL_LO16: OS << "%call_lo("; break;
131135
}
132136

133137
OS << SRE->getSymbol();

lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
4242
case Mips::fixup_Mips_GOT_PAGE:
4343
case Mips::fixup_Mips_GOT_OFST:
4444
case Mips::fixup_Mips_GOT_DISP:
45+
case Mips::fixup_Mips_GOT_LO16:
46+
case Mips::fixup_Mips_CALL_LO16:
4547
break;
4648
case Mips::fixup_Mips_PC16:
4749
// So far we are only using this type for branches.
@@ -60,6 +62,8 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) {
6062
break;
6163
case Mips::fixup_Mips_HI16:
6264
case Mips::fixup_Mips_GOT_Local:
65+
case Mips::fixup_Mips_GOT_HI16:
66+
case Mips::fixup_Mips_CALL_HI16:
6367
// Get the 2nd 16-bits. Also add 1 if bit 15 is 1.
6468
Value = ((Value + 0x8000) >> 16) & 0xffff;
6569
break;
@@ -179,7 +183,11 @@ class MipsAsmBackend : public MCAsmBackend {
179183
{ "fixup_Mips_GOT_OFST", 0, 16, 0 },
180184
{ "fixup_Mips_GOT_DISP", 0, 16, 0 },
181185
{ "fixup_Mips_HIGHER", 0, 16, 0 },
182-
{ "fixup_Mips_HIGHEST", 0, 16, 0 }
186+
{ "fixup_Mips_HIGHEST", 0, 16, 0 },
187+
{ "fixup_Mips_GOT_HI16", 0, 16, 0 },
188+
{ "fixup_Mips_GOT_LO16", 0, 16, 0 },
189+
{ "fixup_Mips_CALL_HI16", 0, 16, 0 },
190+
{ "fixup_Mips_CALL_LO16", 0, 16, 0 }
183191
};
184192

185193
if (Kind < FirstTargetFixupKind)

lib/Target/Mips/MCTargetDesc/MipsBaseInfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ namespace MipsII {
8484
/// MO_HIGHER/HIGHEST - Represents the highest or higher half word of a
8585
/// 64-bit symbol address.
8686
MO_HIGHER,
87-
MO_HIGHEST
87+
MO_HIGHEST,
88+
89+
/// MO_GOT_HI16/LO16, MO_CALL_HI16/LO16 - Relocations used for large GOTs.
90+
MO_GOT_HI16,
91+
MO_GOT_LO16,
92+
MO_CALL_HI16,
93+
MO_CALL_LO16
8894
};
8995

9096
enum {

lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@ unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target,
179179
case Mips::fixup_Mips_HIGHEST:
180180
Type = ELF::R_MIPS_HIGHEST;
181181
break;
182+
case Mips::fixup_Mips_GOT_HI16:
183+
Type = ELF::R_MIPS_GOT_HI16;
184+
break;
185+
case Mips::fixup_Mips_GOT_LO16:
186+
Type = ELF::R_MIPS_GOT_LO16;
187+
break;
188+
case Mips::fixup_Mips_CALL_HI16:
189+
Type = ELF::R_MIPS_CALL_HI16;
190+
break;
191+
case Mips::fixup_Mips_CALL_LO16:
192+
Type = ELF::R_MIPS_CALL_LO16;
193+
break;
182194
}
183195
return Type;
184196
}

lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ namespace Mips {
116116
// resulting in - R_MIPS_HIGHEST
117117
fixup_Mips_HIGHEST,
118118

119+
// resulting in - R_MIPS_GOT_HI16
120+
fixup_Mips_GOT_HI16,
121+
122+
// resulting in - R_MIPS_GOT_LO16
123+
fixup_Mips_GOT_LO16,
124+
125+
// resulting in - R_MIPS_CALL_HI16
126+
fixup_Mips_CALL_HI16,
127+
128+
// resulting in - R_MIPS_CALL_LO16
129+
fixup_Mips_CALL_LO16,
130+
119131
// Marker
120132
LastTargetFixupKind,
121133
NumTargetFixupKinds = LastTargetFixupKind - FirstTargetFixupKind

lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,18 @@ getMachineOpValue(const MCInst &MI, const MCOperand &MO,
287287
case MCSymbolRefExpr::VK_Mips_HIGHEST:
288288
FixupKind = Mips::fixup_Mips_HIGHEST;
289289
break;
290+
case MCSymbolRefExpr::VK_Mips_GOT_HI16:
291+
FixupKind = Mips::fixup_Mips_GOT_HI16;
292+
break;
293+
case MCSymbolRefExpr::VK_Mips_GOT_LO16:
294+
FixupKind = Mips::fixup_Mips_GOT_LO16;
295+
break;
296+
case MCSymbolRefExpr::VK_Mips_CALL_HI16:
297+
FixupKind = Mips::fixup_Mips_CALL_HI16;
298+
break;
299+
case MCSymbolRefExpr::VK_Mips_CALL_LO16:
300+
FixupKind = Mips::fixup_Mips_CALL_LO16;
301+
break;
290302
} // switch
291303

292304
Fixups.push_back(MCFixup::Create(0, MO.getExpr(), MCFixupKind(FixupKind)));

lib/Target/Mips/Mips64InstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,15 @@ def : MipsPat<(MipsHi tblockaddress:$in), (LUi64 tblockaddress:$in)>;
255255
def : MipsPat<(MipsHi tjumptable:$in), (LUi64 tjumptable:$in)>;
256256
def : MipsPat<(MipsHi tconstpool:$in), (LUi64 tconstpool:$in)>;
257257
def : MipsPat<(MipsHi tglobaltlsaddr:$in), (LUi64 tglobaltlsaddr:$in)>;
258+
def : MipsPat<(MipsHi texternalsym:$in), (LUi64 texternalsym:$in)>;
258259

259260
def : MipsPat<(MipsLo tglobaladdr:$in), (DADDiu ZERO_64, tglobaladdr:$in)>;
260261
def : MipsPat<(MipsLo tblockaddress:$in), (DADDiu ZERO_64, tblockaddress:$in)>;
261262
def : MipsPat<(MipsLo tjumptable:$in), (DADDiu ZERO_64, tjumptable:$in)>;
262263
def : MipsPat<(MipsLo tconstpool:$in), (DADDiu ZERO_64, tconstpool:$in)>;
263264
def : MipsPat<(MipsLo tglobaltlsaddr:$in),
264265
(DADDiu ZERO_64, tglobaltlsaddr:$in)>;
266+
def : MipsPat<(MipsLo texternalsym:$in), (DADDiu ZERO_64, texternalsym:$in)>;
265267

266268
def : MipsPat<(add CPU64Regs:$hi, (MipsLo tglobaladdr:$lo)),
267269
(DADDiu CPU64Regs:$hi, tglobaladdr:$lo)>;

0 commit comments

Comments
 (0)