1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2024 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This program needs to be compiled with preprocessor symbol set to
a small integer, e.g. "gcc -DN=1 ..." With N defined, the CONCAT2
and CONCAT3 macros will construct suitable names for the global
variables and functions. */
#define CONCAT2(a,b) CONCAT2_(a,b)
#define CONCAT2_(a,b) a ## b
#define CONCAT3(a,b,c) CONCAT3_(a,b,c)
#define CONCAT3_(a,b,c) a ## b ## c
/* For N=1, this ends up being...
__thread int tls_lib1_tbss_1;
__thread int tls_lib1_tbss_2;
__thread int tls_lib1_tdata_1 = 196;
__thread int tls_lib1_tdata_2 = 197; */
__thread int CONCAT3(tls_lib, N, _tbss_1);
__thread int CONCAT3(tls_lib, N, _tbss_2);
__thread int CONCAT3(tls_lib, N, _tdata_1) = CONCAT2(N, 96);
__thread int CONCAT3(tls_lib, N, _tdata_2) = CONCAT2(N, 97);
/* Substituting for N, define function:
int get_tls_libN_var (int which) . */
int
CONCAT3(get_tls_lib, N, _var) (int which)
{
switch (which)
{
case 0:
return -1;
case 1:
return CONCAT3(tls_lib, N, _tbss_1);
case 2:
return CONCAT3(tls_lib, N, _tbss_2);
case 3:
return CONCAT3(tls_lib, N, _tdata_1);
case 4:
return CONCAT3(tls_lib, N, _tdata_2);
}
return -1;
}
/* Substituting for N, define function:
void set_tls_libN_var (int which, int val) . */
void
CONCAT3(set_tls_lib, N, _var) (int which, int val)
{
switch (which)
{
case 0:
break;
case 1:
CONCAT3(tls_lib, N, _tbss_1) = val;
break;
case 2:
CONCAT3(tls_lib, N, _tbss_2) = val;
break;
case 3:
CONCAT3(tls_lib, N, _tdata_1) = val;
break;
case 4:
CONCAT3(tls_lib, N, _tdata_2) = val;
break;
}
}
|