From 44dc232eae2aaeafed79221f66ae6c69e5de8a21 Mon Sep 17 00:00:00 2001 From: Zoran Jovanovic Date: Thu, 19 Dec 2013 16:02:32 +0000 Subject: [PATCH] Support for microMIPS TLS relocations. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197685 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/ELF.h | 2 ++ lib/Object/ELF.cpp | 2 ++ lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp | 2 ++ lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp | 6 ++++++ lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h | 6 ++++++ lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp | 6 ++++-- test/MC/Mips/micromips-relocations.s | 12 ++++++++++++ 7 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/llvm/Support/ELF.h b/include/llvm/Support/ELF.h index 2868f35a01a1..f1d885eaf7ff 100644 --- a/include/llvm/Support/ELF.h +++ b/include/llvm/Support/ELF.h @@ -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, diff --git a/lib/Object/ELF.cpp b/lib/Object/ELF.cpp index 7c80d41942f9..c39e1e1805cc 100644 --- a/lib/Object/ELF.cpp +++ b/lib/Object/ELF.cpp @@ -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); diff --git a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp index 25ce9c7365ca..e8c40048387d 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp @@ -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 }, diff --git a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 83c7d4bcc3c6..aa9b42337cb1 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -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; diff --git a/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h b/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h index 6ed44b74cc4b..dc6192c20506 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h +++ b/lib/Target/Mips/MCTargetDesc/MipsFixupKinds.h @@ -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, diff --git a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp index 669e48a78b30..06e8dd82f6f9 100644 --- a/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp +++ b/lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp @@ -413,10 +413,12 @@ getExprOpValue(const MCExpr *Expr,SmallVectorImpl &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 diff --git a/test/MC/Mips/micromips-relocations.s b/test/MC/Mips/micromips-relocations.s index 804dd2f595f7..1633845444f2 100644 --- a/test/MC/Mips/micromips-relocations.s +++ b/test/MC/Mips/micromips-relocations.s @@ -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. #------------------------------------------------------------------------------ @@ -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) @@ -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)