From ca6dee30a352a58b5764e3c299e93d34f9e08bad Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Mon, 10 Nov 2003 17:04:55 +0000 Subject: [PATCH] Add initial support for TLS sections in PE format files. --- bfd/ChangeLog | 6 ++++++ bfd/peXXigen.c | 19 ++++++++++++++++--- ld/ChangeLog | 4 ++++ ld/scripttempl/pe.sc | 9 +++++++++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index b45ea437928..73cabd8e750 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2003-11-10 Jonathan Wilson + + * peXXigen.c (_bfd_XXi_swap_aouthdr_out): Swap out tls pointer. + (_bfd_XXi_final_link_postscript): Look for __tks_used symbol. If + found initialise the tls data directory entry. + 2003-11-07 Alan Modra * elf32-ppc.c (ppc_elf_install_value): Delete. diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index cd0a91c5aac..f3b3a96d760 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -570,8 +570,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out) struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr; PEAOUTHDR *aouthdr_out = (PEAOUTHDR *) out; bfd_vma sa, fa, ib; - IMAGE_DATA_DIRECTORY idata2, idata5; - + IMAGE_DATA_DIRECTORY idata2, idata5, tls; if (pe->force_minimum_alignment) { @@ -590,6 +589,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out) idata2 = pe->pe_opthdr.DataDirectory[1]; idata5 = pe->pe_opthdr.DataDirectory[12]; + tls = pe->pe_opthdr.DataDirectory[9]; if (aouthdr_in->tsize) { @@ -641,6 +641,7 @@ _bfd_XXi_swap_aouthdr_out (abfd, in, out) a final link is going to be performed, it can overwrite them. */ extra->DataDirectory[1] = idata2; extra->DataDirectory[12] = idata5; + extra->DataDirectory[9] = tls; if (extra->DataDirectory[1].VirtualAddress == 0) /* Until other .idata fixes are made (pending patch), the entry for @@ -2025,7 +2026,19 @@ _bfd_XXi_final_link_postscript (abfd, pfinfo) + h1->root.u.def.section->output_offset) - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress); } - + + h1 = coff_link_hash_lookup (coff_hash_table (info), + "__tls_used", FALSE, FALSE, TRUE); + if (h1 != NULL) + { + pe_data (abfd)->pe_opthdr.DataDirectory[9].VirtualAddress = + (h1->root.u.def.value + + h1->root.u.def.section->output_section->vma + + h1->root.u.def.section->output_offset + - pe_data (abfd)->pe_opthdr.ImageBase); + pe_data (abfd)->pe_opthdr.DataDirectory[9].Size = 0x18; + } + /* If we couldn't find idata$2, we either have an excessively trivial program or are in DEEP trouble; we have to assume trivial program.... */ diff --git a/ld/ChangeLog b/ld/ChangeLog index edcd312fc7a..d0d747f0397 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,7 @@ +2003-11-10 Jonathan Wilson + + * scripttempl/pe.sc: Add support for TLS sections. + 2003-11-09 Alan Modra * configure.host (HOSTING_LIBS): Group libgcc and libc with diff --git a/ld/scripttempl/pe.sc b/ld/scripttempl/pe.sc index 2fd27f93d26..da09eb43048 100644 --- a/ld/scripttempl/pe.sc +++ b/ld/scripttempl/pe.sc @@ -25,6 +25,10 @@ if test "${RELOCATING}"; then SORT(*)(.idata$6) SORT(*)(.idata$7)' R_CRT='*(SORT(.CRT$*))' + R_TLS=' + *(.tls) + *(.tls$) + *(SORT(.tls$*))' R_RSRC='*(SORT(.rsrc$*))' else R_TEXT= @@ -129,6 +133,11 @@ SECTIONS ${R_CRT} } + .tls ${RELOCATING+BLOCK(__section_alignment__)} : + { + ${R_TLS} + } + .endjunk ${RELOCATING+BLOCK(__section_alignment__)} : { /* end is deprecated, don't use it */ -- 2.34.1