[lld] r239615 - [Mips] Handle TLS relocations in -static linking mode
Simon Atanasyan
simon at atanasyan.com
Fri Jun 12 09:13:14 PDT 2015
Author: atanasyan
Date: Fri Jun 12 11:13:14 2015
New Revision: 239615
URL: http://llvm.org/viewvc/llvm-project?rev=239615&view=rev
Log:
[Mips] Handle TLS relocations in -static linking mode
Added:
lld/trunk/test/elf/Mips/tls-2-64-static.test
lld/trunk/test/elf/Mips/tls-2-static.test
lld/trunk/test/elf/Mips/tls-3-64-static.test
lld/trunk/test/elf/Mips/tls-3-static.test
lld/trunk/test/elf/Mips/tls-4-64-static.test
lld/trunk/test/elf/Mips/tls-4-static.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp?rev=239615&r1=239614&r2=239615&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp Fri Jun 12 11:13:14 2015
@@ -70,13 +70,14 @@ bool MipsLinkingContext::isDynamicReloca
switch (r.kindValue()) {
case llvm::ELF::R_MIPS_COPY:
case llvm::ELF::R_MIPS_REL32:
+ return true;
case llvm::ELF::R_MIPS_TLS_DTPMOD32:
case llvm::ELF::R_MIPS_TLS_DTPREL32:
case llvm::ELF::R_MIPS_TLS_TPREL32:
case llvm::ELF::R_MIPS_TLS_DTPMOD64:
case llvm::ELF::R_MIPS_TLS_DTPREL64:
case llvm::ELF::R_MIPS_TLS_TPREL64:
- return true;
+ return isDynamic();
default:
return false;
}
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=239615&r1=239614&r2=239615&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Fri Jun 12 11:13:14 2015
@@ -172,12 +172,11 @@ static MipsRelocationParams getRelocatio
case R_MIPS_TLS_DTPMOD32:
case R_MIPS_TLS_DTPREL32:
case R_MIPS_TLS_TPREL32:
- // Ignore runtime relocations.
- return {4, 0x0, 0, false, dummyCheck};
+ return {4, 0xffffffff, 0, false, dummyCheck};
case R_MIPS_TLS_DTPMOD64:
case R_MIPS_TLS_DTPREL64:
case R_MIPS_TLS_TPREL64:
- return {8, 0x0, 0, false, dummyCheck};
+ return {8, 0xffffffffffffffffull, 0, false, dummyCheck};
case LLD_R_MIPS_GLOBAL_GOT:
case LLD_R_MIPS_STO_PLT:
// Do nothing.
@@ -365,6 +364,16 @@ static int64_t relocMaskLow16(uint64_t S
return maskLow16(S + A);
}
+/// R_MIPS_TLS_TPREL32, R_MIPS_TLS_TPREL64
+static int64_t relocTlsTpRel(uint64_t S, int64_t A) {
+ return S + A - 0x7000;
+}
+
+/// R_MIPS_TLS_DTPREL32, R_MIPS_TLS_DTPREL64
+static int64_t relocTlsDTpRel(uint64_t S, int64_t A) {
+ return S + A - 0x8000;
+}
+
static int64_t relocRel32(int64_t A) {
// If output relocation format is REL and the input one is RELA, the only
// method to transfer the relocation addend from the input relocation
@@ -430,7 +439,7 @@ static ErrorOr<int64_t> calculateRelocat
Reference::Addend addend,
uint64_t tgtAddr, uint64_t relAddr,
uint64_t gpAddr, bool isGP,
- bool isCrossJump) {
+ bool isCrossJump, bool isDynamic) {
switch (kind) {
case R_MIPS_NONE:
return 0;
@@ -527,18 +536,23 @@ static ErrorOr<int64_t> calculateRelocat
return relocRel32(addend);
case R_MIPS_JUMP_SLOT:
case R_MIPS_COPY:
+ // Ignore runtime relocations.
+ return 0;
case R_MIPS_TLS_DTPMOD32:
- case R_MIPS_TLS_DTPREL32:
- case R_MIPS_TLS_TPREL32:
case R_MIPS_TLS_DTPMOD64:
+ return isDynamic ? 0 : 1;
+ case R_MIPS_TLS_DTPREL32:
case R_MIPS_TLS_DTPREL64:
+ if (isDynamic)
+ return 0;
+ return relocTlsDTpRel(tgtAddr, addend);
+ case R_MIPS_TLS_TPREL32:
case R_MIPS_TLS_TPREL64:
- // Ignore runtime relocations.
- return 0;
+ if (isDynamic)
+ return 0;
+ return relocTlsTpRel(tgtAddr, addend);
case R_MIPS_PC32:
return relocpc32(relAddr, tgtAddr, addend);
- case LLD_R_MIPS_GLOBAL_GOT:
- // Do nothing.
case LLD_R_MIPS_32_HI16:
case LLD_R_MIPS_64_HI16:
return relocMaskLow16(tgtAddr, addend);
@@ -551,6 +565,7 @@ static ErrorOr<int64_t> calculateRelocat
case LLD_R_MIPS_LO16:
return relocLo16(0, tgtAddr, 0, false, false);
case LLD_R_MIPS_STO_PLT:
+ case LLD_R_MIPS_GLOBAL_GOT:
// Do nothing.
return 0;
default:
@@ -643,7 +658,7 @@ std::error_code RelocationHandler<ELFT>:
break;
auto params = getRelocationParams(kind);
res = calculateRelocation(kind, *res, sym, relAddr, gpAddr, isGpDisp,
- isCrossJump);
+ isCrossJump, _ctx.isDynamic());
if (auto ec = res.getError())
return ec;
// Check result for the last relocation only.
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=239615&r1=239614&r2=239615&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Fri Jun 12 11:13:14 2015
@@ -389,8 +389,8 @@ private:
const GOTAtom *getLocalGOTEntry(const Reference &ref);
const GOTAtom *getLocalGOTPageEntry(const Reference &ref);
const GOTAtom *getGlobalGOTEntry(const Atom *a);
- const GOTAtom *getTLSGOTEntry(const Atom *a);
- const GOTAtom *getTLSGdGOTEntry(const Atom *a);
+ const GOTAtom *getTLSGOTEntry(const Atom *a, Reference::Addend addend);
+ const GOTAtom *getTLSGdGOTEntry(const Atom *a, Reference::Addend addend);
const GOTAtom *getTLSLdmGOTEntry(const Atom *a);
const GOTPLTAtom *getGOTPLTEntry(const Atom *a);
const PLTAtom *getPLTEntry(const Atom *a);
@@ -588,7 +588,7 @@ void RelocationPass<ELFT>::handleReferen
break;
case R_MIPS_TLS_GD:
case R_MICROMIPS_TLS_GD:
- ref.setTarget(getTLSGdGOTEntry(ref.target()));
+ ref.setTarget(getTLSGdGOTEntry(ref.target(), ref.addend()));
break;
case R_MIPS_TLS_LDM:
case R_MICROMIPS_TLS_LDM:
@@ -596,7 +596,7 @@ void RelocationPass<ELFT>::handleReferen
break;
case R_MIPS_TLS_GOTTPREL:
case R_MICROMIPS_TLS_GOTTPREL:
- ref.setTarget(getTLSGOTEntry(ref.target()));
+ ref.setTarget(getTLSGOTEntry(ref.target(), ref.addend()));
break;
}
}
@@ -932,7 +932,8 @@ const GOTAtom *RelocationPass<ELFT>::get
}
template <typename ELFT>
-const GOTAtom *RelocationPass<ELFT>::getTLSGOTEntry(const Atom *a) {
+const GOTAtom *RelocationPass<ELFT>::getTLSGOTEntry(const Atom *a,
+ Reference::Addend addend) {
auto got = _gotTLSMap.find(a);
if (got != _gotTLSMap.end())
return got->second;
@@ -943,13 +944,15 @@ const GOTAtom *RelocationPass<ELFT>::get
_tlsGotVector.push_back(ga);
Reference::KindValue relKind =
ELFT::Is64Bits ? R_MIPS_TLS_TPREL64 : R_MIPS_TLS_TPREL32;
- ga->addReferenceELF_Mips(relKind, 0, a, 0);
+ ga->addReferenceELF_Mips(relKind, 0, a, addend);
return ga;
}
template <typename ELFT>
-const GOTAtom *RelocationPass<ELFT>::getTLSGdGOTEntry(const Atom *a) {
+const GOTAtom *
+RelocationPass<ELFT>::getTLSGdGOTEntry(const Atom *a,
+ Reference::Addend addend) {
auto got = _gotTLSGdMap.find(a);
if (got != _gotTLSGdMap.end())
return got->second;
@@ -959,11 +962,11 @@ const GOTAtom *RelocationPass<ELFT>::get
_tlsGotVector.push_back(ga);
if (ELFT::Is64Bits) {
- ga->addReferenceELF_Mips(R_MIPS_TLS_DTPMOD64, 0, a, 0);
- ga->addReferenceELF_Mips(R_MIPS_TLS_DTPREL64, 8, a, 0);
+ ga->addReferenceELF_Mips(R_MIPS_TLS_DTPMOD64, 0, a, addend);
+ ga->addReferenceELF_Mips(R_MIPS_TLS_DTPREL64, 8, a, addend);
} else {
- ga->addReferenceELF_Mips(R_MIPS_TLS_DTPMOD32, 0, a, 0);
- ga->addReferenceELF_Mips(R_MIPS_TLS_DTPREL32, 4, a, 0);
+ ga->addReferenceELF_Mips(R_MIPS_TLS_DTPMOD32, 0, a, addend);
+ ga->addReferenceELF_Mips(R_MIPS_TLS_DTPREL32, 4, a, addend);
}
return ga;
Added: lld/trunk/test/elf/Mips/tls-2-64-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-2-64-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-2-64-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-2-64-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,71 @@
+# Check handling of R_MIPS_TLS_GD relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 30800000
+# ^ -32736 ^ -32720
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 01000000 00000000 0480ffff ffffffff
+# CHECK-NEXT: 120002020 01000000 00000000 0c80ffff ffffffff
+# D1 0x120001000 + 4 - (0x120001000 + 0x8000) = 0xffff8004 => 0480ffff
+# D2 0x120001040 + 8 - (0x120001000 + 0x8000) = 0xffff800c => 0c80ffff
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ Addend: 4
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GD
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+...
Added: lld/trunk/test/elf/Mips/tls-2-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-2-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-2-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-2-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,125 @@
+# Check handling of R_MIPS_TLS_GD relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -docnum 1 -o %t1.o %s
+# RUN: yaml2obj -format=elf -docnum 2 -o %t2.o %s
+# RUN: lld -flavor gnu -target mipsel -e T0 -static -o %t.exe %t1.o %t2.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 20800000 28800000 30800000
+# ^ -32744 ^ -32736 ^ -32728 ^ -32720
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 01000000 0480ffff
+# CHECK-NEXT: 402010 01000000 0c80ffff 01000000 0c80ffff
+# CHECK-NEXT: 402020 01000000 1480ffff
+# D1 0x401000 + 4 - (0x401000 + 0x8000) = 0xffff8004 => 0480ffff
+# D2 0x401004 + 8 - (0x401000 + 0x8000) = 0xffff800c => 0c80ffff
+# D3 0x401008 + 4 - (0x401000 + 0x8000) = 0xffff800c => 0c80ffff
+# D4 0x40100c + 8 - (0x401000 + 0x8000) = 0xffff8014 => 1480ffff
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GD
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D3
+ Type: R_MIPS_TLS_GD
+ - Offset: 4
+ Symbol: D4
+ Type: R_MIPS_TLS_GD
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D3
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D4
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+...
Added: lld/trunk/test/elf/Mips/tls-3-64-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-3-64-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-3-64-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-3-64-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,70 @@
+# Check handling of R_MIPS_TLS_GOTTPREL relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 28800000
+# ^ -32736 ^ -32728
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 0490ffff ffffffff 0c90ffff ffffffff
+# D1 0x120001000 + 4 - (0x120001000 + 0x7000) = 0xffff9004 => 0490ffff
+# D2 0x120001004 + 8 - (0x120001000 + 0x7000) = 0xffff900c => 0c90ffff
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 4
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
Added: lld/trunk/test/elf/Mips/tls-3-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-3-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-3-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-3-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,67 @@
+# Check handling of R_MIPS_TLS_GOTTPREL relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor gnu -target mipsel -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 1c800000
+# ^ -32744 ^ -32740
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 0490ffff 0c90ffff
+# D1 0x401000 + 4 - (0x401000 + 0x7000) = 0xffff9004 => 0490ffff
+# D2 0x401004 + 8 - (0x401000 + 0x7000) = 0xffff900c => 0c90ffff
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GOTTPREL
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GOTTPREL
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
Added: lld/trunk/test/elf/Mips/tls-4-64-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-4-64-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-4-64-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-4-64-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,71 @@
+# Check handling of R_MIPS_TLS_LDM relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 20800000
+# ^ -32736 ^ -32736
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 01000000 00000000 00000000 00000000
+# ^ R_MIPS_TLS_DTPMOD64
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_TLS_LDM
+ Addend: 4
+ - Offset: 4
+ Symbol: L2
+ Type: R_MIPS_TLS_LDM
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
Added: lld/trunk/test/elf/Mips/tls-4-static.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/tls-4-static.test?rev=239615&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/tls-4-static.test (added)
+++ lld/trunk/test/elf/Mips/tls-4-static.test Fri Jun 12 11:13:14 2015
@@ -0,0 +1,68 @@
+# Check handling of R_MIPS_TLS_LDM relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor gnu -target mipsel -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 18800000
+# ^ -32744 ^ -32744
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 01000000 00000000
+# ^ R_MIPS_TLS_DTPMOD32
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_TLS_LDM
+ - Offset: 4
+ Symbol: L2
+ Type: R_MIPS_TLS_LDM
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
More information about the llvm-commits
mailing list