Skip to content

Commit c6d6a04

Browse files
committed
Make various error-related globals thread-local
This changes bfd_error et al to be thread-local. * Makefile.in: Regenerate. * aclocal.m4: Include ax_tls.m4. * ax_tls.m4: New file. * bfd.c: (bfd_error, input_error, input_bfd, _bfd_error_buf): Now thread-local. (bfd_asprintf): Update docs. * config.in, configure: Regenerate. * configure.ac: Call AX_TLS. * po/bfd.pot: Regenerate.
1 parent 426931b commit c6d6a04

File tree

8 files changed

+166
-36
lines changed

8 files changed

+166
-36
lines changed

bfd/Makefile.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
129129
$(top_srcdir)/../config/zstd.m4 $(top_srcdir)/../libtool.m4 \
130130
$(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
131131
$(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
132-
$(top_srcdir)/bfd.m4 $(top_srcdir)/warning.m4 \
133-
$(top_srcdir)/acinclude.m4 $(top_srcdir)/version.m4 \
134-
$(top_srcdir)/configure.ac
132+
$(top_srcdir)/ax_tls.m4 $(top_srcdir)/bfd.m4 \
133+
$(top_srcdir)/warning.m4 $(top_srcdir)/acinclude.m4 \
134+
$(top_srcdir)/version.m4 $(top_srcdir)/configure.ac
135135
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
136136
$(ACLOCAL_M4)
137137
DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \

bfd/aclocal.m4

+1
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ m4_include([../ltoptions.m4])
11871187
m4_include([../ltsugar.m4])
11881188
m4_include([../ltversion.m4])
11891189
m4_include([../lt~obsolete.m4])
1190+
m4_include([ax_tls.m4])
11901191
m4_include([bfd.m4])
11911192
m4_include([warning.m4])
11921193
m4_include([acinclude.m4])

bfd/ax_tls.m4

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# ===========================================================================
2+
# https://www.gnu.org/software/autoconf-archive/ax_tls.html
3+
# ===========================================================================
4+
#
5+
# SYNOPSIS
6+
#
7+
# AX_TLS([action-if-found], [action-if-not-found])
8+
#
9+
# DESCRIPTION
10+
#
11+
# Provides a test for the compiler support of thread local storage (TLS)
12+
# extensions. Defines TLS if it is found. Currently knows about C++11,
13+
# GCC/ICC, and MSVC. I think SunPro uses the same as GCC, and Borland
14+
# apparently supports either.
15+
#
16+
# LICENSE
17+
#
18+
# Copyright (c) 2008 Alan Woodland <[email protected]>
19+
# Copyright (c) 2010 Diego Elio Petteno` <[email protected]>
20+
#
21+
# This program is free software: you can redistribute it and/or modify it
22+
# under the terms of the GNU General Public License as published by the
23+
# Free Software Foundation, either version 3 of the License, or (at your
24+
# option) any later version.
25+
#
26+
# This program is distributed in the hope that it will be useful, but
27+
# WITHOUT ANY WARRANTY; without even the implied warranty of
28+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
29+
# Public License for more details.
30+
#
31+
# You should have received a copy of the GNU General Public License along
32+
# with this program. If not, see <https://www.gnu.org/licenses/>.
33+
#
34+
# As a special exception, the respective Autoconf Macro's copyright owner
35+
# gives unlimited permission to copy, distribute and modify the configure
36+
# scripts that are the output of Autoconf when processing the Macro. You
37+
# need not follow the terms of the GNU General Public License when using
38+
# or distributing such scripts, even though portions of the text of the
39+
# Macro appear in them. The GNU General Public License (GPL) does govern
40+
# all other use of the material that constitutes the Autoconf Macro.
41+
#
42+
# This special exception to the GPL applies to versions of the Autoconf
43+
# Macro released by the Autoconf Archive. When you make and distribute a
44+
# modified version of the Autoconf Macro, you may extend this special
45+
# exception to the GPL to apply to your modified version as well.
46+
47+
#serial 15
48+
49+
AC_DEFUN([AX_TLS], [
50+
AC_MSG_CHECKING([for thread local storage (TLS) class])
51+
AC_CACHE_VAL([ac_cv_tls],
52+
[for ax_tls_keyword in thread_local _Thread_local __thread '__declspec(thread)' none; do
53+
AS_CASE([$ax_tls_keyword],
54+
[none], [ac_cv_tls=none ; break],
55+
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
56+
[#include <stdlib.h>],
57+
[static $ax_tls_keyword int bar;]
58+
)],
59+
[ac_cv_tls=$ax_tls_keyword ; break],
60+
[ac_cv_tls=none]
61+
)]
62+
)
63+
done ]
64+
)
65+
AC_MSG_RESULT([$ac_cv_tls])
66+
67+
AS_IF([test "$ac_cv_tls" != "none"],
68+
[AC_DEFINE_UNQUOTED([TLS],[$ac_cv_tls],[If the compiler supports a TLS storage class, define it to that here])
69+
m4_ifnblank([$1],[$1],[[:]])],
70+
[m4_ifnblank([$2],[$2],[[:]])])
71+
])

bfd/bfd.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ SECTION
691691
The easiest way to report a BFD error to the user is to
692692
use <<bfd_perror>>.
693693
694+
The BFD error is thread-local.
695+
694696
SUBSECTION
695697
Type <<bfd_error_type>>
696698
@@ -728,10 +730,10 @@ CODE_FRAGMENT
728730
.
729731
*/
730732

731-
static bfd_error_type bfd_error;
732-
static bfd_error_type input_error;
733-
static bfd *input_bfd;
734-
static char *_bfd_error_buf;
733+
static TLS bfd_error_type bfd_error;
734+
static TLS bfd_error_type input_error;
735+
static TLS bfd *input_bfd;
736+
static TLS char *_bfd_error_buf;
735737

736738
const char *const bfd_errmsgs[] =
737739
{
@@ -920,7 +922,7 @@ DESCRIPTION
920922
Primarily for error reporting, this function is like
921923
libiberty's xasprintf except that it can return NULL on no
922924
memory and the returned string should not be freed. Uses a
923-
single malloc'd buffer managed by libbfd, _bfd_error_buf.
925+
thread-local malloc'd buffer managed by libbfd, _bfd_error_buf.
924926
Be aware that a call to this function frees the result of any
925927
previous call. bfd_errmsg (bfd_error_on_input) also calls
926928
this function.

bfd/config.in

+3
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@
285285
/* Define to 1 if you have the ANSI C header files. */
286286
#undef STDC_HEADERS
287287

288+
/* If the compiler supports a TLS storage class, define it to that here */
289+
#undef TLS
290+
288291
/* Name of host specific header file to include in trad-core.c. */
289292
#undef TRAD_HEADER
290293

bfd/configure

+51
Original file line numberDiff line numberDiff line change
@@ -13283,6 +13283,57 @@ $as_echo "#define USE_BINARY_FOPEN 1" >>confdefs.h
1328313283
;;
1328413284
esac
1328513285

13286+
13287+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for thread local storage (TLS) class" >&5
13288+
$as_echo_n "checking for thread local storage (TLS) class... " >&6; }
13289+
if ${ac_cv_tls+:} false; then :
13290+
$as_echo_n "(cached) " >&6
13291+
else
13292+
for ax_tls_keyword in thread_local _Thread_local __thread '__declspec(thread)' none; do
13293+
case $ax_tls_keyword in #(
13294+
none) :
13295+
ac_cv_tls=none ; break ;; #(
13296+
*) :
13297+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
13298+
/* end confdefs.h. */
13299+
#include <stdlib.h>
13300+
int
13301+
main ()
13302+
{
13303+
static $ax_tls_keyword int bar;
13304+
13305+
;
13306+
return 0;
13307+
}
13308+
_ACEOF
13309+
if ac_fn_c_try_compile "$LINENO"; then :
13310+
ac_cv_tls=$ax_tls_keyword ; break
13311+
else
13312+
ac_cv_tls=none
13313+
13314+
fi
13315+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
13316+
;;
13317+
esac
13318+
done
13319+
13320+
fi
13321+
13322+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_tls" >&5
13323+
$as_echo "$ac_cv_tls" >&6; }
13324+
13325+
if test "$ac_cv_tls" != "none"; then :
13326+
13327+
cat >>confdefs.h <<_ACEOF
13328+
#define TLS $ac_cv_tls
13329+
_ACEOF
13330+
13331+
:
13332+
else
13333+
:
13334+
fi
13335+
13336+
1328613337
# Link in zlib/zstd if we can. This allows us to read compressed debug sections.
1328713338
# This is used only by compress.c.
1328813339

bfd/configure.ac

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ AC_CHECK_DECLS([___lc_codepage_func], [], [], [[#include <locale.h>]])
233233

234234
BFD_BINARY_FOPEN
235235

236+
AX_TLS
237+
236238
# Link in zlib/zstd if we can. This allows us to read compressed debug sections.
237239
# This is used only by compress.c.
238240
AM_ZLIB

bfd/po/bfd.pot

+28-28
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: https://sourceware.org/bugzilla/\n"
11-
"POT-Creation-Date: 2023-11-07 17:27-0700\n"
11+
"POT-Creation-Date: 2023-11-07 17:40-0700\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -138,115 +138,115 @@ msgstr ""
138138
msgid "Writing updated armap timestamp"
139139
msgstr ""
140140

141-
#: bfd.c:738
141+
#: bfd.c:740
142142
msgid "no error"
143143
msgstr ""
144144

145-
#: bfd.c:739
145+
#: bfd.c:741
146146
msgid "system call error"
147147
msgstr ""
148148

149-
#: bfd.c:740
149+
#: bfd.c:742
150150
msgid "invalid bfd target"
151151
msgstr ""
152152

153-
#: bfd.c:741
153+
#: bfd.c:743
154154
msgid "file in wrong format"
155155
msgstr ""
156156

157-
#: bfd.c:742
157+
#: bfd.c:744
158158
msgid "archive object file in wrong format"
159159
msgstr ""
160160

161-
#: bfd.c:743
161+
#: bfd.c:745
162162
msgid "invalid operation"
163163
msgstr ""
164164

165-
#: bfd.c:744
165+
#: bfd.c:746
166166
msgid "memory exhausted"
167167
msgstr ""
168168

169-
#: bfd.c:745
169+
#: bfd.c:747
170170
msgid "no symbols"
171171
msgstr ""
172172

173-
#: bfd.c:746
173+
#: bfd.c:748
174174
msgid "archive has no index; run ranlib to add one"
175175
msgstr ""
176176

177-
#: bfd.c:747
177+
#: bfd.c:749
178178
msgid "no more archived files"
179179
msgstr ""
180180

181-
#: bfd.c:748
181+
#: bfd.c:750
182182
msgid "malformed archive"
183183
msgstr ""
184184

185-
#: bfd.c:749
185+
#: bfd.c:751
186186
msgid "DSO missing from command line"
187187
msgstr ""
188188

189-
#: bfd.c:750
189+
#: bfd.c:752
190190
msgid "file format not recognized"
191191
msgstr ""
192192

193-
#: bfd.c:751
193+
#: bfd.c:753
194194
msgid "file format is ambiguous"
195195
msgstr ""
196196

197-
#: bfd.c:752
197+
#: bfd.c:754
198198
msgid "section has no contents"
199199
msgstr ""
200200

201-
#: bfd.c:753
201+
#: bfd.c:755
202202
msgid "nonrepresentable section on output"
203203
msgstr ""
204204

205-
#: bfd.c:754
205+
#: bfd.c:756
206206
msgid "symbol needs debug section which does not exist"
207207
msgstr ""
208208

209-
#: bfd.c:755
209+
#: bfd.c:757
210210
msgid "bad value"
211211
msgstr ""
212212

213-
#: bfd.c:756
213+
#: bfd.c:758
214214
msgid "file truncated"
215215
msgstr ""
216216

217-
#: bfd.c:757
217+
#: bfd.c:759
218218
msgid "file too big"
219219
msgstr ""
220220

221-
#: bfd.c:758
221+
#: bfd.c:760
222222
msgid "sorry, cannot handle this file"
223223
msgstr ""
224224

225-
#: bfd.c:759
225+
#: bfd.c:761
226226
#, c-format
227227
msgid "error reading %s: %s"
228228
msgstr ""
229229

230-
#: bfd.c:760
230+
#: bfd.c:762
231231
msgid "#<invalid error code>"
232232
msgstr ""
233233

234-
#: bfd.c:1890
234+
#: bfd.c:1892
235235
#, c-format
236236
msgid "BFD %s assertion fail %s:%d"
237237
msgstr ""
238238

239-
#: bfd.c:1903
239+
#: bfd.c:1905
240240
#, c-format
241241
msgid "BFD %s internal error, aborting at %s:%d in %s\n"
242242
msgstr ""
243243

244-
#: bfd.c:1908
244+
#: bfd.c:1910
245245
#, c-format
246246
msgid "BFD %s internal error, aborting at %s:%d\n"
247247
msgstr ""
248248

249-
#: bfd.c:1910
249+
#: bfd.c:1912
250250
msgid "Please report this bug.\n"
251251
msgstr ""
252252

0 commit comments

Comments
 (0)