Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src ld.elf_so: Test TLS abuse of static def, dynamic use and vic...
details: https://anonhg.NetBSD.org/src/rev/c9db6d8123e2
branches: trunk
changeset: 376119:c9db6d8123e2
user: riastradh <riastradh%NetBSD.org@localhost>
date: Thu Jun 01 22:26:40 2023 +0000
description:
ld.elf_so: Test TLS abuse of static def, dynamic use and vice versa.
XXX pullup-10
diffstat:
distrib/sets/lists/tests/shl.mi | 6 +-
tests/libexec/ld.elf_so/Makefile | 4 +-
tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile | 22 ++
tests/libexec/ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c | 37 ++++
tests/libexec/ld.elf_so/helper_abuse_static/Makefile | 22 ++
tests/libexec/ld.elf_so/helper_abuse_static/h_abuse_static.c | 37 ++++
tests/libexec/ld.elf_so/t_tls_extern.c | 80 +++++++++-
7 files changed, 205 insertions(+), 3 deletions(-)
diffs (283 lines):
diff -r 9a166499bc83 -r c9db6d8123e2 distrib/sets/lists/tests/shl.mi
--- a/distrib/sets/lists/tests/shl.mi Thu Jun 01 22:24:52 2023 +0000
+++ b/distrib/sets/lists/tests/shl.mi Thu Jun 01 22:26:40 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.13 2023/06/01 20:50:18 riastradh Exp $
+# $NetBSD: shl.mi,v 1.14 2023/06/01 22:26:40 riastradh Exp $
#
./usr/tests/lib/csu/h_initfini3_dso.so tests-lib-tests compattestfile,atf
./usr/tests/lib/csu/h_initfini3_dso.so.1 tests-lib-tests compattestfile,atf
@@ -16,6 +16,10 @@
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso1/libh_helper_symver_dso.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_helper_symver_dso.so tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/h_helper_symver_dso2/libh_helper_symver_dso.so.1 tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_abuse_dynamic.so tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_abuse_dynamic.so.1 tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_abuse_static.so tests-libexec-tests compattestfile,atf
+./usr/tests/libexec/ld.elf_so/libh_abuse_static.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_def_dynamic.so tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_def_dynamic.so.1 tests-libexec-tests compattestfile,atf
./usr/tests/libexec/ld.elf_so/libh_def_static.so tests-libexec-tests compattestfile,atf
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/Makefile
--- a/tests/libexec/ld.elf_so/Makefile Thu Jun 01 22:24:52 2023 +0000
+++ b/tests/libexec/ld.elf_so/Makefile Thu Jun 01 22:26:40 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.16 2023/06/01 20:50:18 riastradh Exp $
+# $NetBSD: Makefile,v 1.17 2023/06/01 22:26:40 riastradh Exp $
#
NOMAN= # defined
@@ -16,6 +16,8 @@ SUBDIR+= helper_dso1 helper_dso3 .WAIT h
SUBDIR+= helper_def_dynamic
SUBDIR+= helper_def_static
SUBDIR+= .WAIT
+SUBDIR+= helper_abuse_dynamic
+SUBDIR+= helper_abuse_static
SUBDIR+= helper_use_dynamic
SUBDIR+= helper_use_static
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_abuse_dynamic/Makefile Thu Jun 01 22:26:40 2023 +0000
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2023/06/01 22:26:40 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_abuse_dynamic
+SRCS= h_abuse_dynamic.c
+
+DEF_DIR!= cd ${.CURDIR}/../helper_def_dynamic && ${PRINTOBJDIR}
+LDADD+= -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_def_dynamic
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+.include <bsd.lib.mk>
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_abuse_dynamic/h_abuse_dynamic.c Thu Jun 01 22:26:40 2023 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: h_abuse_dynamic.c,v 1.1 2023/06/01 22:26:40 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+extern __thread int mydynsym __attribute__((tls_model("initial-exec")));
+
+int *fuse(void);
+int *
+fuse(void)
+{
+
+ return &mydynsym;
+}
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/helper_abuse_static/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_abuse_static/Makefile Thu Jun 01 22:26:40 2023 +0000
@@ -0,0 +1,22 @@
+# $NetBSD: Makefile,v 1.1 2023/06/01 22:26:40 riastradh Exp $
+
+.include <bsd.own.mk>
+
+LIB= h_abuse_static
+SRCS= h_abuse_static.c
+
+DEF_DIR!= cd ${.CURDIR}/../helper_def_static && ${PRINTOBJDIR}
+LDADD+= -Wl,-rpath,${TESTSDIR} -L${DEF_DIR} -lh_def_static
+
+LIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIBDIR= ${TESTSBASE}/libexec/ld.elf_so
+SHLIB_MAJOR= 1
+
+MKSTATICLIB= no
+MKPROFILE= no
+MKPICINSTALL= no
+MKLINT= no
+
+NOMAN= # defined
+
+.include <bsd.lib.mk>
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/helper_abuse_static/h_abuse_static.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/libexec/ld.elf_so/helper_abuse_static/h_abuse_static.c Thu Jun 01 22:26:40 2023 +0000
@@ -0,0 +1,37 @@
+/* $NetBSD: h_abuse_static.c,v 1.1 2023/06/01 22:26:40 riastradh Exp $ */
+
+/*-
+ * Copyright (c) 2023 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+extern __thread int mysym;
+
+int *fuse(void);
+int *
+fuse(void)
+{
+
+ return &mysym;
+}
diff -r 9a166499bc83 -r c9db6d8123e2 tests/libexec/ld.elf_so/t_tls_extern.c
--- a/tests/libexec/ld.elf_so/t_tls_extern.c Thu Jun 01 22:24:52 2023 +0000
+++ b/tests/libexec/ld.elf_so/t_tls_extern.c Thu Jun 01 22:26:40 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_tls_extern.c,v 1.5 2023/06/01 22:24:52 riastradh Exp $ */
+/* $NetBSD: t_tls_extern.c,v 1.6 2023/06/01 22:26:40 riastradh Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -78,6 +78,42 @@ tls_extern(const char *libdef, const cha
pdef, puse);
}
+ATF_TC(tls_extern_dynamic_abusedef);
+ATF_TC_HEAD(tls_extern_dynamic_abusedef, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading static use than dynamic def");
+}
+ATF_TC_BODY(tls_extern_dynamic_abusedef, tc)
+{
+ tls_extern("libh_def_dynamic.so", "libh_abuse_dynamic.so",
+ USE_DEF, /*xfail*/true);
+}
+
+ATF_TC(tls_extern_dynamic_abusedefnoload);
+ATF_TC_HEAD(tls_extern_dynamic_abusedefnoload, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading static use then dynamic def with RTLD_NOLOAD");
+}
+ATF_TC_BODY(tls_extern_dynamic_abusedefnoload, tc)
+{
+ tls_extern("libh_def_dynamic.so", "libh_abuse_dynamic.so",
+ USE_DEF_NOLOAD, /*xfail*/true);
+}
+
+ATF_TC(tls_extern_dynamic_defabuse);
+ATF_TC_HEAD(tls_extern_dynamic_defabuse, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading dynamic def then static use");
+}
+ATF_TC_BODY(tls_extern_dynamic_defabuse, tc)
+{
+ tls_extern("libh_def_dynamic.so", "libh_abuse_dynamic.so",
+ DEF_USE, /*xfail*/true);
+}
+
ATF_TC(tls_extern_dynamic_defuse);
ATF_TC_HEAD(tls_extern_dynamic_defuse, tc)
{
@@ -114,6 +150,42 @@ ATF_TC_BODY(tls_extern_dynamic_usedefnol
USE_DEF_NOLOAD, /*xfail*/false);
}
+ATF_TC(tls_extern_static_abusedef);
+ATF_TC_HEAD(tls_extern_static_abusedef, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading dynamic use then static def");
+}
+ATF_TC_BODY(tls_extern_static_abusedef, tc)
+{
+ tls_extern("libh_def_static.so", "libh_abuse_static.so",
+ USE_DEF, /*xfail*/true);
+}
+
+ATF_TC(tls_extern_static_abusedefnoload);
+ATF_TC_HEAD(tls_extern_static_abusedefnoload, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading dynamic use then static def with RTLD_NOLOAD");
+}
+ATF_TC_BODY(tls_extern_static_abusedefnoload, tc)
+{
+ tls_extern("libh_def_static.so", "libh_abuse_static.so",
+ USE_DEF_NOLOAD, /*xfail*/true);
+}
+
+ATF_TC(tls_extern_static_defabuse);
+ATF_TC_HEAD(tls_extern_static_defabuse, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "extern __thread for TLS works,"
+ " loading static def then dynamic use");
+}
+ATF_TC_BODY(tls_extern_static_defabuse, tc)
+{
+ tls_extern("libh_def_static.so", "libh_abuse_static.so",
+ DEF_USE, /*xfail*/true);
+}
+
ATF_TC(tls_extern_static_defuse);
ATF_TC_HEAD(tls_extern_static_defuse, tc)
{
@@ -153,9 +225,15 @@ ATF_TC_BODY(tls_extern_static_usedefnolo
ATF_TP_ADD_TCS(tp)
{
+ ATF_TP_ADD_TC(tp, tls_extern_dynamic_abusedef);
+ ATF_TP_ADD_TC(tp, tls_extern_dynamic_abusedefnoload);
+ ATF_TP_ADD_TC(tp, tls_extern_dynamic_defabuse);
ATF_TP_ADD_TC(tp, tls_extern_dynamic_defuse);
ATF_TP_ADD_TC(tp, tls_extern_dynamic_usedef);
ATF_TP_ADD_TC(tp, tls_extern_dynamic_usedefnoload);
+ ATF_TP_ADD_TC(tp, tls_extern_static_abusedef);
+ ATF_TP_ADD_TC(tp, tls_extern_static_abusedefnoload);
+ ATF_TP_ADD_TC(tp, tls_extern_static_defabuse);
ATF_TP_ADD_TC(tp, tls_extern_static_defuse);
ATF_TP_ADD_TC(tp, tls_extern_static_usedef);
ATF_TP_ADD_TC(tp, tls_extern_static_usedefnoload);
Home |
Main Index |
Thread Index |
Old Index