[lld] r241426 - COFF: Set TLS table header field.

Rui Ueyama ruiu at google.com
Sun Jul 5 18:48:02 PDT 2015


Author: ruiu
Date: Sun Jul  5 20:48:01 2015
New Revision: 241426

URL: http://llvm.org/viewvc/llvm-project?rev=241426&view=rev
Log:
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.

Added:
    lld/trunk/test/COFF/tls.test
Modified:
    lld/trunk/COFF/Writer.cpp

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241426&r1=241425&r2=241426&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Sun Jul  5 20:48:01 2015
@@ -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

Added: lld/trunk/test/COFF/tls.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/tls.test?rev=241426&view=auto
==============================================================================
--- lld/trunk/test/COFF/tls.test (added)
+++ lld/trunk/test/COFF/tls.test Sun Jul  5 20:48:01 2015
@@ -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
+...





More information about the llvm-commits mailing list