From 22a19a9aceeaa5fa0560d58f701b01e7b753a1b0 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Tue, 15 Mar 2016 06:41:02 +0000 Subject: [PATCH] [COFF] Use the correct size of the TLS directory The TLS directory has a different layout depending on the bitness of the machine the image will run on. LLD would always use the 64-bit TLS directory for the data directory entry instead of an appropriately sized TLS directory. llvm-svn: 263539 --- lld/COFF/Writer.cpp | 4 +++- lld/test/COFF/tls32.test | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index a3e5c203700b..5f5adaad8eaf 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -596,7 +596,9 @@ template void Writer::writeHeader() { if (Symbol *Sym = Symtab->findUnderscore("_tls_used")) { if (Defined *B = dyn_cast(Sym->Body)) { Dir[TLS_TABLE].RelativeVirtualAddress = B->getRVA(); - Dir[TLS_TABLE].Size = 40; + Dir[TLS_TABLE].Size = Config->is64() + ? sizeof(object::coff_tls_directory64) + : sizeof(object::coff_tls_directory32); } } if (Symbol *Sym = Symtab->findUnderscore("_load_config_used")) { diff --git a/lld/test/COFF/tls32.test b/lld/test/COFF/tls32.test index 4fe020eb9e10..a16af052a767 100644 --- a/lld/test/COFF/tls32.test +++ b/lld/test/COFF/tls32.test @@ -3,7 +3,7 @@ # RUN: llvm-readobj -file-headers %t.exe | FileCheck %s # CHECK: TLSTableRVA: 0x1000 -# CHECK: TLSTableSize: 0x28 +# CHECK: TLSTableSize: 0x18 --- header: