VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/compiler/vcc/tlsdir-vcc.c@ 96589

Last change on this file since 96589 was 96589, checked in by vboxsync, 3 years ago

IPRT/nocrt: Split the as much read-only data out of the .rdata segment and put it in a .rodata section when there's a posibility that we're targeting NT 3.x, as these older NT versions cannot deal with a read-only import table. The linker insists on putting the import table in the .rdata section. There are a couple of other structures it generates/manages that goes there too that and seems impossible to move out of it. bugref:10261

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/* $Id: tlsdir-vcc.c 96589 2022-09-03 02:54:22Z 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 and/or its affiliates.
10 *
11 * This file is part of VirtualBox base platform packages, as
12 * available from https://www.215389.xyz.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation, in version 3 of the
17 * License.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see <https://www.gnu.org/licenses>.
26 *
27 * The contents of this file may alternatively be used under the terms
28 * of the Common Development and Distribution License Version 1.0
29 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
30 * in the VirtualBox distribution, in which case the provisions of the
31 * CDDL are applicable instead of those of the GPL.
32 *
33 * You may elect to license modified versions of this file under the
34 * terms and conditions of either the GPL or the CDDL or both.
35 *
36 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
37 */
38
39
40/*********************************************************************************************************************************
41* Header Files *
42*********************************************************************************************************************************/
43#define IPRT_COMPILER_VCC_WITH_TLS_CALLBACK_SECTIONS
44#define IPRT_COMPILER_VCC_WITH_TLS_DATA_SECTIONS
45#include "internal/iprt.h"
46#include <iprt/win/windows.h>
47
48#include "internal/compiler-vcc.h"
49
50
51/*********************************************************************************************************************************
52* Global Variables *
53*********************************************************************************************************************************/
54/** @name TLS callback arrays.
55 *
56 * The important thing here are the section names, the linker is told to merge
57 * and sort all the .CRT* sections into .rdata.
58 *
59 * @{ */
60/** Start of the TLS callback array. */
61__declspec(allocate(".CRT$XLA")) PIMAGE_TLS_CALLBACK g_apfnRTVccTlsCallbacks_Start[] = { NULL, };
62/** End of the TLS callback array (not actually used, but seems to be
63 * traditional). */
64__declspec(allocate(".CRT$XLZ")) PIMAGE_TLS_CALLBACK g_apfnRTVccTlsCallbacks_End[] = { NULL, };
65
66/* Tell the linker to merge the .CRT* sections into .rdata */
67#ifdef IPRT_VCC_USING_RODATA_AS_CONST_SEG
68# pragma comment(linker, "/merge:.CRT=.rodata ")
69#else
70# pragma comment(linker, "/merge:.CRT=.rdata ")
71#endif
72/** @} */
73
74
75/** @name TLS data arrays.
76 *
77 * @{ */
78#pragma data_seg(".tls")
79
80/** Start of the TLS data.
81 * @note The linker has a reference to name '_tls_start' indicating a possible
82 * required naming convention here.
83 * @note Not sure if the byte here is ignored or not... In assembly we could
84 * optimize it out, I think... */
85extern __declspec(allocate(".tls")) char _tls_start = 0;
86
87/** End of the TLS callback array.
88 * @note The linker has a reference to name '_tls_end' indicating a possible
89 * required naming convention here. */
90extern __declspec(allocate(".tls$ZZZ")) char _tls_end = 0;
91
92#pragma data_seg ()
93/** @} */
94
95
96/** The TLS index for the module we're linked into.
97 * The linker has a reference to the name '_tls_start', so this is probably
98 * fixed in some way. */
99extern ULONG _tls_index = 0;
100
101
102/**
103 * The TLS directory for the PE image.
104 *
105 * The name of this is dictated by the linker, as it looks for a _tls_used
106 * symbol and puts it's address and (somehow) size in the TLS data dir entry.
107 */
108extern __declspec(".rdata$T") /* seems to be tranditional, doubt it is necessary */
109const RT_CONCAT(IMAGE_TLS_DIRECTORY, ARCH_BITS) _tls_used =
110{
111 /* .StartAddressOfRawData = */ (uintptr_t)&_tls_start,
112 /* .EndAddressOfRawData = */ (uintptr_t)&_tls_end,
113 /* .AddressOfIndex = */ (uintptr_t)&_tls_index,
114 /* .AddressOfCallBacks = */ (uintptr_t)&g_apfnRTVccTlsCallbacks_Start[1],
115 /* .SizeOfZeroFill = */ 0,
116 /* .Characteristics = */ 0,
117};
118
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette