aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/mips
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/libc/mips
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/libc/mips')
-rw-r--r--lib/libc/mips/static_tls.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/libc/mips/static_tls.h b/lib/libc/mips/static_tls.h
new file mode 100644
index 000000000000..67ee8afe14c6
--- /dev/null
+++ b/lib/libc/mips/static_tls.h
@@ -0,0 +1,64 @@
+/*-
+ * 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 _LIBC_MIPS_STATIC_TLS_H
+#define _LIBC_MIPS_STATIC_TLS_H
+
+#include <machine/tls.h>
+
+static __inline uintptr_t
+_libc_get_static_tls_base(size_t offset)
+{
+ uintptr_t tlsbase;
+
+#if defined(__mips_n64)
+ __asm__ __volatile__ (
+ ".set\tpush\n\t"
+ ".set\tmips64r2\n\t"
+ "rdhwr\t%0, $29\n\t"
+ ".set\tpop"
+ : "=r" (tlsbase));
+ tlsbase -= TLS_TP_OFFSET + TLS_TCB_SIZE;
+#else /* mips 32 */
+ __asm__ __volatile__ (
+ ".set\tpush\n\t"
+ ".set\tmips32r2\n\t"
+ "rdhwr\t%0, $29\n\t"
+ ".set\tpop"
+ : "=r" (tlsbase));
+ tlsbase -= TLS_TP_OFFSET + TLS_TCB_SIZE;
+#endif /* ! __mips_n64 */
+ tlsbase += offset;
+ return (tlsbase);
+}
+
+#endif