Files
binutils-gdb/gdb/testsuite/gdb.base/tls-dlobj-lib.c
Kevin Buettner e4a5126ec0 New test - gdb.base/tls-dlobj.exp
This test exercises musl_link_map_to_tls_module_id() and
glibc_link_map_to_tls_module_id(), both of which are in solib-svr4.c.

Prior to writing this test, I had only written what is now named
'musl_link_map_to_tls_module_id' and it worked for both GLIBC and
MUSL.  Once I wrote this new test, tls-dlobj.exp, there were a number
of tests which didn't work with GLIBC.  This led me to write a
GLIBC-specific link map to module id function, i.e,
'glibc_link_map_to_tls_module_id'.

It only has one compilation scenario, in which the pthread(s) library
is used - as noted in a comment, it became too much of a hassle to try
to KFAIL things, though it certainly could have been done in much the
same was as was done in gdb.base/multiobj.exp.  It didn't seem that
important to do so, however, since I believe that the other tests
have adequate coverage for different compilation scenarios.

Tested-By: Luis Machado <luis.machado@arm.com>
Approved-By: Luis Machado <luis.machado@arm.com>
2025-04-24 09:54:43 -07:00

88 lines
2.4 KiB
C

/* 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;
}
}