Skip to content

Commit

Permalink
Support for microMIPS TLS relocations.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197685 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Zoran Jovanovic committed Dec 19, 2013
1 parent d4cf97b commit 44dc232
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/llvm/Support/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,8 @@ enum {
R_MICROMIPS_GOT_DISP = 145,
R_MICROMIPS_GOT_PAGE = 146,
R_MICROMIPS_GOT_OFST = 147,
R_MICROMIPS_TLS_GD = 162,
R_MICROMIPS_TLS_LDM = 163,
R_MICROMIPS_TLS_DTPREL_HI16 = 164,
R_MICROMIPS_TLS_DTPREL_LO16 = 165,
R_MICROMIPS_TLS_TPREL_HI16 = 169,
Expand Down
2 changes: 2 additions & 0 deletions lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ StringRef getELFRelocationTypeName(uint32_t Machine, uint32_t Type) {
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_DISP);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_PAGE);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_GOT_OFST);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_GD);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_LDM);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_DTPREL_HI16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_DTPREL_LO16);
LLVM_ELF_SWITCH_RELOC_TYPE_NAME(R_MICROMIPS_TLS_TPREL_HI16);
Expand Down
2 changes: 2 additions & 0 deletions lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ class MipsAsmBackend : public MCAsmBackend {
{ "fixup_MICROMIPS_GOT_DISP", 0, 16, 0 },
{ "fixup_MICROMIPS_GOT_PAGE", 0, 16, 0 },
{ "fixup_MICROMIPS_GOT_OFST", 0, 16, 0 },
{ "fixup_MICROMIPS_TLS_GD", 0, 16, 0 },
{ "fixup_MICROMIPS_TLS_LDM", 0, 16, 0 },
{ "fixup_MICROMIPS_TLS_DTPREL_HI16", 0, 16, 0 },
{ "fixup_MICROMIPS_TLS_DTPREL_LO16", 0, 16, 0 },
{ "fixup_MICROMIPS_TLS_TPREL_HI16", 0, 16, 0 },
Expand Down
6 changes: 6 additions & 0 deletions lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target,
case Mips::fixup_MICROMIPS_GOT_OFST:
Type = ELF::R_MICROMIPS_GOT_OFST;
break;
case Mips::fixup_MICROMIPS_TLS_GD:
Type = ELF::R_MICROMIPS_TLS_GD;
break;
case Mips::fixup_MICROMIPS_TLS_LDM:
Type = ELF::R_MICROMIPS_TLS_LDM;
break;
case Mips::fixup_MICROMIPS_TLS_DTPREL_HI16:
Type = ELF::R_MICROMIPS_TLS_DTPREL_HI16;
break;
Expand Down
6 changes: 6 additions & 0 deletions lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ namespace Mips {
// resulting in - R_MICROMIPS_GOT_OFST
fixup_MICROMIPS_GOT_OFST,

// resulting in - R_MICROMIPS_TLS_GD
fixup_MICROMIPS_TLS_GD,

// resulting in - R_MICROMIPS_TLS_LDM
fixup_MICROMIPS_TLS_LDM,

// resulting in - R_MICROMIPS_TLS_DTPREL_HI16
fixup_MICROMIPS_TLS_DTPREL_HI16,

Expand Down
6 changes: 4 additions & 2 deletions lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,12 @@ getExprOpValue(const MCExpr *Expr,SmallVectorImpl<MCFixup> &Fixups) const {
: Mips::fixup_Mips_LO16;
break;
case MCSymbolRefExpr::VK_Mips_TLSGD:
FixupKind = Mips::fixup_Mips_TLSGD;
FixupKind = IsMicroMips ? Mips::fixup_MICROMIPS_TLS_GD
: Mips::fixup_Mips_TLSGD;
break;
case MCSymbolRefExpr::VK_Mips_TLSLDM:
FixupKind = Mips::fixup_Mips_TLSLDM;
FixupKind = IsMicroMips ? Mips::fixup_MICROMIPS_TLS_LDM
: Mips::fixup_Mips_TLSLDM;
break;
case MCSymbolRefExpr::VK_Mips_DTPREL_HI:
FixupKind = IsMicroMips ? Mips::fixup_MICROMIPS_TLS_DTPREL_HI16
Expand Down
12 changes: 12 additions & 0 deletions test/MC/Mips/micromips-relocations.s
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
# CHECK-FIXUP: # fixup A - offset: 0,
# CHECK-FIXUP: value: _gp_disp@TPREL_LO,
# CHECK-FIXUP: kind: fixup_MICROMIPS_TLS_TPREL_LO16
# CHECK-FIXUP: addiu $4, $gp, %tlsgd(a)
# CHECK-FIXUP: # encoding: [0x9c'A',0x30'A',0x00,0x00]
# CHECK-FIXUP: # fixup A - offset: 0,
# CHECK-FIXUP: value: a@TLSGD, kind: fixup_MICROMIPS_TLS_GD
# CHECK-FIXUP: addiu $4, $gp, %tlsldm(f.i)
# CHECK-FIXUP: # encoding: [0x9c'A',0x30'A',0x00,0x00]
# CHECK-FIXUP: # fixup A - offset: 0,
# CHECK-FIXUP: value: f.i@TLSLDM, kind: fixup_MICROMIPS_TLS_LDM
#------------------------------------------------------------------------------
# Check that the appropriate relocations were created.
#------------------------------------------------------------------------------
Expand All @@ -83,6 +91,8 @@
# CHECK-ELF: 0x{{[0-9,A-F]+}} R_MICROMIPS_GOT_OFST
# CHECK-ELF: 0x{{[0-9,A-F]+}} R_MICROMIPS_TLS_TPREL_HI16
# CHECK-ELF: 0x{{[0-9,A-F]+}} R_MICROMIPS_TLS_TPREL_LO16
# CHECK-ELF: 0x{{[0-9,A-F]+}} R_MICROMIPS_TLS_GD
# CHECK-ELF: 0x{{[0-9,A-F]+}} R_MICROMIPS_TLS_LDM
# CHECK-ELF: ]

lui $2, %hi(_gp_disp)
Expand All @@ -97,3 +107,5 @@
lw $6, %got_ofst(loop_4)($5)
lui $2, %tprel_hi(_gp_disp)
addiu $2, $2, %tprel_lo(_gp_disp)
addiu $4, $gp, %tlsgd(a)
addiu $4, $gp, %tlsldm(f.i)

0 comments on commit 44dc232

Please sign in to comment.