1 | /* $Id: tlsdir-vcc.c 95834 2022-07-26 14:46:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Visual C++ Compiler - PE/Windows TLS Directory.
|
---|
4 | *
|
---|
5 | * @note Doing this as a C file for same reasons as loadcfg-vcc.c.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2022 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.alldomusa.eu.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | *
|
---|
19 | * The contents of this file may alternatively be used under the terms
|
---|
20 | * of the Common Development and Distribution License Version 1.0
|
---|
21 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
22 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
23 | * CDDL are applicable instead of those of the GPL.
|
---|
24 | *
|
---|
25 | * You may elect to license modified versions of this file under the
|
---|
26 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | /*********************************************************************************************************************************
|
---|
31 | * Header Files *
|
---|
32 | *********************************************************************************************************************************/
|
---|
33 | #define IPRT_COMPILER_VCC_WITH_TLS_CALLBACK_SECTIONS
|
---|
34 | #define IPRT_COMPILER_VCC_WITH_TLS_DATA_SECTIONS
|
---|
35 | #include "internal/iprt.h"
|
---|
36 | #include <iprt/win/windows.h>
|
---|
37 |
|
---|
38 | #include "internal/compiler-vcc.h"
|
---|
39 |
|
---|
40 |
|
---|
41 | /*********************************************************************************************************************************
|
---|
42 | * Global Variables *
|
---|
43 | *********************************************************************************************************************************/
|
---|
44 | /** @name TLS callback arrays.
|
---|
45 | *
|
---|
46 | * The important thing here are the section names, the linker is told to merge
|
---|
47 | * and sort all the .CRT* sections into .rdata.
|
---|
48 | *
|
---|
49 | * @{ */
|
---|
50 | /** Start of the TLS callback array. */
|
---|
51 | __declspec(allocate(".CRT$XLA")) PIMAGE_TLS_CALLBACK g_apfnRTVccTlsCallbacks_Start[] = { NULL, };
|
---|
52 | /** End of the TLS callback array (not actually used, but seems to be
|
---|
53 | * traditional). */
|
---|
54 | __declspec(allocate(".CRT$XLZ")) PIMAGE_TLS_CALLBACK g_apfnRTVccTlsCallbacks_End[] = { NULL, };
|
---|
55 |
|
---|
56 | /* Tell the linker to merge the .CRT* sections into .rdata */
|
---|
57 | #pragma comment(linker, "/merge:.CRT=.rdata ")
|
---|
58 | /** @} */
|
---|
59 |
|
---|
60 |
|
---|
61 | /** @name TLS data arrays.
|
---|
62 | *
|
---|
63 | * @{ */
|
---|
64 | #pragma data_seg(".tls")
|
---|
65 |
|
---|
66 | /** Start of the TLS data.
|
---|
67 | * @note The linker has a reference to name '_tls_start' indicating a possible
|
---|
68 | * required naming convention here.
|
---|
69 | * @note Not sure if the byte here is ignored or not... In assembly we could
|
---|
70 | * optimize it out, I think... */
|
---|
71 | extern __declspec(allocate(".tls")) char _tls_start = 0;
|
---|
72 |
|
---|
73 | /** End of the TLS callback array.
|
---|
74 | * @note The linker has a reference to name '_tls_end' indicating a possible
|
---|
75 | * required naming convention here. */
|
---|
76 | extern __declspec(allocate(".tls$ZZZ")) char _tls_end = 0;
|
---|
77 |
|
---|
78 | #pragma data_seg ()
|
---|
79 | /** @} */
|
---|
80 |
|
---|
81 |
|
---|
82 | /** The TLS index for the module we're linked into.
|
---|
83 | * The linker has a reference to the name '_tls_start', so this is probably
|
---|
84 | * fixed in some way. */
|
---|
85 | extern ULONG _tls_index = 0;
|
---|
86 |
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * The TLS directory for the PE image.
|
---|
90 | *
|
---|
91 | * The name of this is dictated by the linker, as it looks for a _tls_used
|
---|
92 | * symbol and puts it's address and (somehow) size in the TLS data dir entry.
|
---|
93 | */
|
---|
94 | extern __declspec(".rdata$T") /* seems to be tranditional, doubt it is necessary */
|
---|
95 | const RT_CONCAT(IMAGE_TLS_DIRECTORY, ARCH_BITS) _tls_used =
|
---|
96 | {
|
---|
97 | /* .StartAddressOfRawData = */ (uintptr_t)&_tls_start,
|
---|
98 | /* .EndAddressOfRawData = */ (uintptr_t)&_tls_end,
|
---|
99 | /* .AddressOfIndex = */ (uintptr_t)&_tls_index,
|
---|
100 | /* .AddressOfCallBacks = */ (uintptr_t)&g_apfnRTVccTlsCallbacks_Start[1],
|
---|
101 | /* .SizeOfZeroFill = */ 0,
|
---|
102 | /* .Characteristics = */ 0,
|
---|
103 | };
|
---|
104 |
|
---|