diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-01-13 11:29:45 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-01-13 11:29:45 +0000 |
commit | 253dbf540540ed0019ea0d6d2e9b38411688a47c (patch) | |
tree | 4817c290f4e53daecc2bb9056476f56531294a85 | |
parent | dd113648afe6f685539ba9b58c679f88ea5a9eb8 (diff) | |
download | bcm5719-llvm-253dbf540540ed0019ea0d6d2e9b38411688a47c.tar.gz bcm5719-llvm-253dbf540540ed0019ea0d6d2e9b38411688a47c.zip |
[ELF/AArch64] - Implemented R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 and R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC relocations
* R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 is calculated as Page(G(GTPREL(S+A))) – Page(P), set an ADRP immediate field to bits [32:12] of X; check –2^32 ≤ X < 2^32;
* R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC is calculated as G(GTPREL(S+A)), set an LD offset field to bits [11:3] of X. No overflow check; check that X&7 = 0.
Differential revision: http://reviews.llvm.org/D16117
llvm-svn: 257588
-rw-r--r-- | lld/ELF/Target.cpp | 31 | ||||
-rw-r--r-- | lld/test/ELF/aarch64-tls-ie.s | 49 |
2 files changed, 77 insertions, 3 deletions
diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 492f2dcaa88..6d42dbe86e5 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -198,6 +198,8 @@ public: void writePltEntry(uint8_t *Buf, uint64_t GotAddr, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; + unsigned getTlsGotReloc(unsigned Type = -1) const override; + bool isTlsDynReloc(unsigned Type, const SymbolBody &S) const override; bool needsCopyRel(uint32_t Type, const SymbolBody &S) const override; bool relocNeedsGot(uint32_t Type, const SymbolBody &S) const override; bool relocNeedsPlt(uint32_t Type, const SymbolBody &S) const override; @@ -1179,6 +1181,7 @@ AArch64TargetInfo::AArch64TargetInfo() { IRelativeReloc = R_AARCH64_IRELATIVE; GotReloc = R_AARCH64_GLOB_DAT; PltReloc = R_AARCH64_JUMP_SLOT; + TlsGotReloc = R_AARCH64_TLS_TPREL64; LazyRelocations = true; PltEntrySize = 16; PltZeroEntrySize = 32; @@ -1238,6 +1241,19 @@ void AArch64TargetInfo::writePltEntry(uint8_t *Buf, uint64_t GotAddr, GotEntryAddr); } +unsigned AArch64TargetInfo::getTlsGotReloc(unsigned Type) const { + if (Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 || + Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) + return Type; + return TlsGotReloc; +} + +bool AArch64TargetInfo::isTlsDynReloc(unsigned Type, + const SymbolBody &S) const { + return Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 || + Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC; +} + bool AArch64TargetInfo::needsCopyRel(uint32_t Type, const SymbolBody &S) const { if (Config->Shared) return false; @@ -1261,8 +1277,15 @@ bool AArch64TargetInfo::needsCopyRel(uint32_t Type, const SymbolBody &S) const { bool AArch64TargetInfo::relocNeedsGot(uint32_t Type, const SymbolBody &S) const { - return Type == R_AARCH64_ADR_GOT_PAGE || Type == R_AARCH64_LD64_GOT_LO12_NC || - relocNeedsPlt(Type, S); + switch (Type) { + case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: + case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: + case R_AARCH64_ADR_GOT_PAGE: + case R_AARCH64_LD64_GOT_LO12_NC: + return true; + default: + return relocNeedsPlt(Type, S); + } } bool AArch64TargetInfo::relocNeedsPlt(uint32_t Type, @@ -1328,7 +1351,8 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, updateAArch64Adr(Loc, X & 0x1FFFFF); break; } - case R_AARCH64_ADR_PREL_PG_HI21: { + case R_AARCH64_ADR_PREL_PG_HI21: + case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21: { uint64_t X = getAArch64Page(SA) - getAArch64Page(P); checkInt<33>(X, Type); updateAArch64Adr(Loc, (X >> 12) & 0x1FFFFF); // X[32:12] @@ -1348,6 +1372,7 @@ void AArch64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, break; } case R_AARCH64_LD64_GOT_LO12_NC: + case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC: checkAlignment<8>(SA, Type); or32le(Loc, (SA & 0xFF8) << 7); break; diff --git a/lld/test/ELF/aarch64-tls-ie.s b/lld/test/ELF/aarch64-tls-ie.s new file mode 100644 index 00000000000..477343c4be5 --- /dev/null +++ b/lld/test/ELF/aarch64-tls-ie.s @@ -0,0 +1,49 @@ +# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %p/Inputs/aarch64-tls-ie.s -o %tdso.o
+# RUN: llvm-mc -filetype=obj -triple=aarch64-unknown-freebsd %s -o %tmain.o
+# RUN: ld.lld -shared %tdso.o -o %tdso.so
+# RUN: ld.lld %tmain.o %tdso.so -o %tout
+# RUN: llvm-objdump -d %tout | FileCheck %s
+# RUN: llvm-readobj -s -r %tout | FileCheck -check-prefix=RELOC %s
+# REQUIRES: aarch64
+
+#RELOC: Section {
+#RELOC: Index:
+#RELOC: Name: .got
+#RELOC-NEXT: Type: SHT_PROGBITS
+#RELOC-NEXT: Flags [
+#RELOC-NEXT: SHF_ALLOC
+#RELOC-NEXT: SHF_WRITE
+#RELOC-NEXT: ]
+#RELOC-NEXT: Address: 0x120B0
+#RELOC-NEXT: Offset: 0x20B0
+#RELOC-NEXT: Size: 16
+#RELOC-NEXT: Link: 0
+#RELOC-NEXT: Info: 0
+#RELOC-NEXT: AddressAlignment: 8
+#RELOC-NEXT: EntrySize: 0
+#RELOC-NEXT: }
+#RELOC: Relocations [
+#RELOC-NEXT: Section ({{.*}}) .rela.dyn {
+#RELOC-NEXT: 0x120B0 R_AARCH64_TLS_TPREL64 foo 0x0
+#RELOC-NEXT: 0x120B8 R_AARCH64_TLS_TPREL64 bar 0x0
+#RELOC-NEXT: }
+#RELOC-NEXT:]
+
+# Page(0x120B0) - Page(0x11000) = 0x1000 = 4096
+# 0x120B0 & 0xff8 = 0xB0 = 176
+# Page(0x120B8) - Page(0x11000) = 0x1000 = 4096
+# 0x120B8 & 0xff8 = 0xB8 = 184
+#CHECK: Disassembly of section .text:
+#CHECK: _start:
+#CHECK: 11000: 00 00 00 b0 adrp x0, #4096
+#CHECK: 11004: 00 58 40 f9 ldr x0, [x0, #176]
+#CHECK: 11008: 00 00 00 b0 adrp x0, #4096
+#CHECK: 1100c: 00 5c 40 f9 ldr x0, [x0, #184]
+
+.globl _start
+_start:
+ adrp x0, :gottprel:foo
+ ldr x0, [x0, #:gottprel_lo12:foo]
+
+ adrp x0, :gottprel:bar
+ ldr x0, [x0, #:gottprel_lo12:bar]
|