Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lld
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-07-06 04:48:01 +0300
committerRui Ueyama <ruiu@google.com>2015-07-06 04:48:01 +0300
commit92a8c82076f7e6a840af99a3bf19fabe1275eb5b (patch)
tree33ca3e367b28e44c53d8338c265c9793270ae37c /lld
parent88fe69ce210ecbec9f4850aed2c56074ef310437 (diff)
COFF: Set TLS table header field.
TLS table header field is supposed to have address and size of TLS table. The linker doesn't have to understand what TLS table is. TLS table's name is always "_tls_used", so if there's that symbol, the linker simply sets that symbol's RVA to the header. The size of the TLS table is always 40 bytes. llvm-svn: 241426
Diffstat (limited to 'lld')
-rw-r--r--lld/COFF/Writer.cpp6
-rw-r--r--lld/test/COFF/tls.test43
2 files changed, 49 insertions, 0 deletions
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 8814a4df79ff..34cd4732f1ba 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -415,6 +415,12 @@ void Writer::writeHeader() {
Dir[EXCEPTION_TABLE].RelativeVirtualAddress = Sec->getRVA();
Dir[EXCEPTION_TABLE].Size = Sec->getVirtualSize();
}
+ if (Symbol *Sym = Symtab->find("_tls_used")) {
+ if (Defined *B = dyn_cast<Defined>(Sym->Body.load())) {
+ Dir[TLS_TABLE].RelativeVirtualAddress = B->getRVA();
+ Dir[TLS_TABLE].Size = 40;
+ }
+ }
// Section table
// Name field in the section table is 8 byte long. Longer names need
diff --git a/lld/test/COFF/tls.test b/lld/test/COFF/tls.test
new file mode 100644
index 000000000000..8c9381cafaf2
--- /dev/null
+++ b/lld/test/COFF/tls.test
@@ -0,0 +1,43 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: lld -flavor link2 /out:%t.exe /entry:main %t.obj
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: TLSTableRVA: 0x1000
+# CHECK: TLSTableSize: 0x28
+
+---
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: 00000000
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 4
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ Selection: IMAGE_COMDAT_SELECT_ANY
+ - Name: main
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+ - Name: _tls_used
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_FUNCTION
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...