aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr/arch/sparc64
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2019-03-29 17:52:57 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2019-03-29 17:52:57 +0000
commit5d00c5a6571cdf533228338fa7ca532c91af1d66 (patch)
tree56c529711cd8f3d7791fa3caf99f1256719fabbf /lib/libthr/arch/sparc64
parent9f701172635d755151f24e15e78c357d3378bd09 (diff)
downloadsrc-5d00c5a6571cdf533228338fa7ca532c91af1d66.tar.gz
src-5d00c5a6571cdf533228338fa7ca532c91af1d66.zip
Fix initial exec TLS mode for dynamically loaded shared objects.
If dso uses initial exec TLS mode, rtld tries to allocate TLS in static space. If there is no space left, the dlopen(3) fails. If space if allocated, initial content from PT_TLS segment is distributed to all threads' pcbs, which was missed and caused un-initialized TLS segment for such dso after dlopen(3). The mode is auto-detected either due to the relocation used, or if the DF_STATIC_TLS dynamic flag is set. In the later case, the TLS segment is tried to allocate earlier, which increases chance of the dlopen(3) to succeed. LLD was recently fixed to properly emit the flag, ld.bdf did it always. Initial test by: dumbbell Tested by: emaste (amd64), ian (arm) Tested by: Gerald Aryeetey <aryeeteygerald_rogers.com> (arm64) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D19072
Notes
Notes: svn path=/head/; revision=345703
Diffstat (limited to 'lib/libthr/arch/sparc64')
-rw-r--r--lib/libthr/arch/sparc64/include/pthread_tls.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/libthr/arch/sparc64/include/pthread_tls.h b/lib/libthr/arch/sparc64/include/pthread_tls.h
new file mode 100644
index 000000000000..7dd194f08604
--- /dev/null
+++ b/lib/libthr/arch/sparc64/include/pthread_tls.h
@@ -0,0 +1,46 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 The FreeBSD Foundation
+ *
+ * This software was developed by Konstantin Belousov <kib@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _ARCH_SPARC64_PTHREAD_TLS_H
+#define _ARCH_SPARC64_PTHREAD_TLS_H
+
+static __inline uintptr_t
+_get_static_tls_base(struct pthread *thr, size_t offset)
+{
+ uintptr_t tlsbase;
+
+ tlsbase = (uintptr_t)thr->tcb;
+ tlsbase -= offset;
+ return (tlsbase);
+}
+
+#endif