summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/lib/csu
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/netbsd-tests/lib/csu')
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/alpha/h_initfini_align.S16
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/arm/h_initfini_align.S20
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/hppa/h_initfini_align.S12
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/i386/h_initfini_align.S12
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/ia64/h_initfini_align.S37
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/mips/h_initfini_align.S19
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/powerpc/h_initfini_align.S17
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/sparc/h_initfini_align.S10
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/sparc64/h_initfini_align.S11
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/vax/h_initfini_align.S17
-rw-r--r--contrib/netbsd-tests/lib/csu/arch/x86_64/h_initfini_align.S13
-rw-r--r--contrib/netbsd-tests/lib/csu/dso/h_initfini3_dso.cxx37
-rw-r--r--contrib/netbsd-tests/lib/csu/h_initfini1.cxx9
-rw-r--r--contrib/netbsd-tests/lib/csu/h_initfini3.cxx22
-rw-r--r--contrib/netbsd-tests/lib/csu/h_initfini_common.cxx37
-rwxr-xr-xcontrib/netbsd-tests/lib/csu/t_crt0.sh104
16 files changed, 393 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/csu/arch/alpha/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/alpha/h_initfini_align.S
new file mode 100644
index 0000000..b4382c1
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/alpha/h_initfini_align.S
@@ -0,0 +1,16 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:55 matt Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:55 matt Exp $")
+
+/*
+ * LINTSTUB: bool check_stack_alignment(void);
+ */
+
+LEAF_NOPROFILE(check_stack_alignment, 0)
+ ldiq v0, 0
+ and sp, 7, t0
+ cmoveq t0, 1, v0
+ ret
+END(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/arm/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/arm/h_initfini_align.S
new file mode 100644
index 0000000..2abc56f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/arm/h_initfini_align.S
@@ -0,0 +1,20 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $")
+
+/*
+ * LINTSTUB: bool check_stack_alignment(void);
+ */
+
+ARM_ENTRY(check_stack_alignment)
+#ifdef __ARM_EABI__
+ tst sp, #7
+#else
+ tst sp, #3
+#endif
+ movne r0, #0
+ moveq r0, #1
+ RET
+END(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/hppa/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/hppa/h_initfini_align.S
new file mode 100644
index 0000000..c297e90
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/hppa/h_initfini_align.S
@@ -0,0 +1,12 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/11/15 11:48:30 skrll Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/11/15 11:48:30 skrll Exp $")
+
+LEAF_ENTRY(check_stack_alignment)
+ extru %sp,31,6,%ret0
+ comiclr,<> 0, %ret0, %ret0
+ ldi 1,%ret0
+ bv,n %r0(%r2)
+EXIT(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/i386/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/i386/h_initfini_align.S
new file mode 100644
index 0000000..e212989
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/i386/h_initfini_align.S
@@ -0,0 +1,12 @@
+/* $NetBSD: h_initfini_align.S,v 1.2 2010/12/12 18:21:21 joerg Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.2 2010/12/12 18:21:21 joerg Exp $")
+
+_ENTRY(check_stack_alignment)
+ movl %esp, %eax
+ andl $3, %eax
+ setz %al
+ movzbl %al, %eax
+ ret
diff --git a/contrib/netbsd-tests/lib/csu/arch/ia64/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/ia64/h_initfini_align.S
new file mode 100644
index 0000000..f7612a8
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/ia64/h_initfini_align.S
@@ -0,0 +1,37 @@
+/* $NetBSD: h_initfini_align.S,v 1.2 2014/03/16 09:27:04 cherry Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.2 2014/03/16 09:27:04 cherry Exp $")
+
+ENTRY(check_stack_alignment, 0)
+ .prologue
+ .regstk 0, 2, 0, 0
+
+ alloc loc0 = ar.pfs, 0, 2, 0, 0
+
+ .body
+ mov ret0 = 1
+ ;;
+
+ /* ar.bsp has an 8-byte alignment requirement */
+ mov loc1 = ar.bsp
+ ;;
+
+ and loc1 = 7, loc1
+ ;;
+
+ cmp.eq p1, p0 = 0, loc1
+ (p0) mov ret0 = 0
+ ;;
+
+ /* sp has a 16-byte alignment requirement */
+ (p1) mov loc1 = sp
+ ;;
+ (p1) and loc1 = 15, loc1
+ ;;
+
+ (p1) cmp.eq p1, p0 = 0, loc1
+ (p0) mov ret0 = 0
+
+ br.ret.sptk.few rp
diff --git a/contrib/netbsd-tests/lib/csu/arch/mips/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/mips/h_initfini_align.S
new file mode 100644
index 0000000..d6782ac
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/mips/h_initfini_align.S
@@ -0,0 +1,19 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $")
+
+/*
+ * LINTSTUB: bool check_stack_alignment(void);
+ */
+
+LEAF_NOPROFILE(check_stack_alignment)
+#ifdef __mips_o32
+ andi v1,sp,3
+#else
+ andi v1,sp,7
+#endif
+ sltiu v0,v1,1
+ jr ra
+END(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/powerpc/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/powerpc/h_initfini_align.S
new file mode 100644
index 0000000..7abd9ea
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/powerpc/h_initfini_align.S
@@ -0,0 +1,17 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $")
+
+/*
+ * LINTSTUB: bool check_stack_alignment(void);
+ */
+
+_ENTRY(check_stack_alignment)
+ li %r3,0
+ andis. %r0,%r1,15
+ bnelr %cr0
+ li %r3,1
+ blr
+END(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/sparc/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/sparc/h_initfini_align.S
new file mode 100644
index 0000000..a770d39
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/sparc/h_initfini_align.S
@@ -0,0 +1,10 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/12 11:22:26 martin Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/12 11:22:26 martin Exp $")
+
+_ENTRY(check_stack_alignment)
+ and %sp, 7, %o1
+ retl
+ not %o1, %o0
diff --git a/contrib/netbsd-tests/lib/csu/arch/sparc64/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/sparc64/h_initfini_align.S
new file mode 100644
index 0000000..402ceb3
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/sparc64/h_initfini_align.S
@@ -0,0 +1,11 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/11/15 20:00:20 martin Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/11/15 20:00:20 martin Exp $")
+
+_ENTRY(check_stack_alignment)
+ add %sp, BIAS, %o1
+ and %o1, 15, %o2
+ retl
+ not %o2, %o0
diff --git a/contrib/netbsd-tests/lib/csu/arch/vax/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/vax/h_initfini_align.S
new file mode 100644
index 0000000..a751e1f
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/vax/h_initfini_align.S
@@ -0,0 +1,17 @@
+/* $NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2013/12/11 17:31:56 matt Exp $")
+
+/*
+ * LINTSTUB: bool check_stack_alignment(void);
+ */
+
+_ENTRY(check_stack_alignment, 0)
+ clrl %r0
+ bitl $3,%sp
+ bneq 1f
+ incl %r0
+1: ret
+END(check_stack_alignment)
diff --git a/contrib/netbsd-tests/lib/csu/arch/x86_64/h_initfini_align.S b/contrib/netbsd-tests/lib/csu/arch/x86_64/h_initfini_align.S
new file mode 100644
index 0000000..fbc1e56
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/arch/x86_64/h_initfini_align.S
@@ -0,0 +1,13 @@
+/* $NetBSD: h_initfini_align.S,v 1.2 2010/12/12 18:21:21 joerg Exp $ */
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.2 2010/12/12 18:21:21 joerg Exp $")
+
+_ENTRY(check_stack_alignment)
+ movl %esp, %eax
+ andl $15, %eax
+ subl $8, %eax
+ sete %al
+ movzbl %al, %eax
+ ret
diff --git a/contrib/netbsd-tests/lib/csu/dso/h_initfini3_dso.cxx b/contrib/netbsd-tests/lib/csu/dso/h_initfini3_dso.cxx
new file mode 100644
index 0000000..ff90ce6
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/dso/h_initfini3_dso.cxx
@@ -0,0 +1,37 @@
+#include <unistd.h>
+
+#ifdef CHECK_STACK_ALIGNMENT
+#include <stdlib.h>
+
+extern "C" int check_stack_alignment(void);
+#endif
+
+class Test2 {
+public:
+ Test2()
+ {
+ static const char msg[] = "constructor2 executed\n";
+ write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+ if (!check_stack_alignment()) {
+ static const char msg2[] = "stack unaligned \n";
+ write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+ exit(1);
+ }
+#endif
+ }
+ ~Test2()
+ {
+ static const char msg[] = "destructor2 executed\n";
+ write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+ if (!check_stack_alignment()) {
+ static const char msg2[] = "stack unaligned \n";
+ write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+ exit(1);
+ }
+#endif
+ }
+};
+
+Test2 test2;
diff --git a/contrib/netbsd-tests/lib/csu/h_initfini1.cxx b/contrib/netbsd-tests/lib/csu/h_initfini1.cxx
new file mode 100644
index 0000000..d410f70
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/h_initfini1.cxx
@@ -0,0 +1,9 @@
+#include <unistd.h>
+
+int
+main(void)
+{
+ static const char msg[] = "main executed\n";
+ write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/csu/h_initfini3.cxx b/contrib/netbsd-tests/lib/csu/h_initfini3.cxx
new file mode 100644
index 0000000..13f54ce
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/h_initfini3.cxx
@@ -0,0 +1,22 @@
+#include <dlfcn.h>
+#include <err.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ static const char msg1[] = "main started\n";
+ static const char msg2[] = "main after dlopen\n";
+ static const char msg3[] = "main terminated\n";
+
+ void *handle;
+
+ write(STDOUT_FILENO, msg1, sizeof(msg1) - 1);
+ handle = dlopen("h_initfini3_dso.so", RTLD_NOW | RTLD_LOCAL);
+ if (handle == NULL)
+ err(1, "dlopen");
+ write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+ dlclose(handle);
+ write(STDOUT_FILENO, msg3, sizeof(msg3) - 1);
+ return 0;
+}
diff --git a/contrib/netbsd-tests/lib/csu/h_initfini_common.cxx b/contrib/netbsd-tests/lib/csu/h_initfini_common.cxx
new file mode 100644
index 0000000..dd34983
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/h_initfini_common.cxx
@@ -0,0 +1,37 @@
+#include <unistd.h>
+
+#ifdef CHECK_STACK_ALIGNMENT
+#include <stdlib.h>
+
+extern "C" int check_stack_alignment(void);
+#endif
+
+class Test {
+public:
+ Test()
+ {
+ static const char msg[] = "constructor executed\n";
+ write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+ if (!check_stack_alignment()) {
+ static const char msg2[] = "stack unaligned \n";
+ write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+ exit(1);
+ }
+#endif
+ }
+ ~Test()
+ {
+ static const char msg[] = "destructor executed\n";
+ write(STDOUT_FILENO, msg, sizeof(msg) - 1);
+#ifdef CHECK_STACK_ALIGNMENT
+ if (!check_stack_alignment()) {
+ static const char msg2[] = "stack unaligned \n";
+ write(STDOUT_FILENO, msg2, sizeof(msg2) - 1);
+ exit(1);
+ }
+#endif
+ }
+};
+
+Test test;
diff --git a/contrib/netbsd-tests/lib/csu/t_crt0.sh b/contrib/netbsd-tests/lib/csu/t_crt0.sh
new file mode 100755
index 0000000..a36a9b7
--- /dev/null
+++ b/contrib/netbsd-tests/lib/csu/t_crt0.sh
@@ -0,0 +1,104 @@
+# $NetBSD: t_crt0.sh,v 1.4 2011/12/11 14:57:07 joerg Exp $
+#
+# Copyright (c) 2008 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.
+#
+
+atf_test_case initfini1
+initfini1_head()
+{
+ atf_set "descr" "Checks support for init/fini sections"
+}
+initfini1_body()
+{
+ cat >expout <<EOF
+constructor executed
+main executed
+destructor executed
+EOF
+
+ atf_check -o file:expout "$(atf_get_srcdir)/h_initfini1"
+}
+
+atf_test_case initfini2
+initfini2_head()
+{
+ atf_set "descr" "Checks support for init/fini sections in static binaries"
+}
+initfini2_body()
+{
+ cat >expout <<EOF
+constructor executed
+main executed
+destructor executed
+EOF
+
+ atf_check -o file:expout "$(atf_get_srcdir)/h_initfini2"
+}
+
+atf_test_case initfini3
+initfini3_head()
+{
+ atf_set "descr" "Checks support for init/fini sections in dlopen"
+}
+initfini3_body()
+{
+ cat >expout <<EOF
+constructor executed
+main started
+constructor2 executed
+main after dlopen
+destructor2 executed
+main terminated
+destructor executed
+EOF
+
+ atf_check -o file:expout "$(atf_get_srcdir)/h_initfini3"
+}
+
+atf_test_case initfini4
+initfini4_head()
+{
+ atf_set "descr" "Checks support for init/fini sections in LD_PRELOAD"
+}
+initfini4_body()
+{
+ cat >expout <<EOF
+constructor2 executed
+constructor executed
+main executed
+destructor executed
+destructor2 executed
+EOF
+
+ atf_check -o file:expout -x "env LD_PRELOAD=$(atf_get_srcdir)/h_initfini3_dso.so $(atf_get_srcdir)/h_initfini1"
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case initfini1
+ atf_add_test_case initfini2
+ atf_add_test_case initfini3
+ atf_add_test_case initfini4
+}
OpenPOWER on IntegriCloud