Module Name:    src
Committed By:   joerg
Date:           Tue Nov 30 18:38:54 UTC 2010

Modified Files:
        src/tests/lib/csu: Makefile h_initfini_common.cxx
        src/tests/lib/csu/dso: Makefile h_initfini3_dso.cxx
        src/tests/lib/libpthread: Makefile t_join.c
Added Files:
        src/tests/lib/csu: Makefile.check_stack
        src/tests/lib/csu/dso: h_initfini_align.S h_initfini_align.S

Log Message:
Test alignment of constructor / destructor calls as well as the stack
of new threads. Currently implement for i386 and AMD64.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/csu/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/lib/csu/Makefile.check_stack
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/csu/h_initfini_common.cxx
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/csu/dso/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/lib/csu/dso/h_initfini3_dso.cxx
cvs rdiff -u -r0 -r1.1 src/tests/lib/csu/dso/h_initfini_align.S
cvs rdiff -u -r0 -r1.2 src/tests/lib/csu/dso/h_initfini_align.S
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libpthread/Makefile
cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libpthread/t_join.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/csu/Makefile
diff -u src/tests/lib/csu/Makefile:1.2 src/tests/lib/csu/Makefile:1.3
--- src/tests/lib/csu/Makefile:1.2	Wed Jul 28 13:51:38 2010
+++ src/tests/lib/csu/Makefile	Tue Nov 30 18:38:53 2010
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2010/07/28 13:51:38 joerg Exp $
+# $NetBSD: Makefile,v 1.3 2010/11/30 18:38:53 joerg Exp $
 
 NOMAN=			# defined
 
@@ -9,12 +9,19 @@
 TESTS_SUBDIRS=
 SUBDIR+=		dso
 
+.include "Makefile.check_stack"
+
+CPPFLAGS+=	${CPPFLAGS_CHECK_STACK}
+
 BINDIR=			${TESTSDIR}
 PROG_CXX=		h_initfini1 h_initfini2 h_initfini3
-SRCS.h_initfini1=	h_initfini1.cxx h_initfini_common.cxx
-SRCS.h_initfini2=	h_initfini1.cxx h_initfini_common.cxx
+SRCS.h_initfini1=	h_initfini1.cxx h_initfini_common.cxx \
+			${SRCS_CHECK_STACK}
+SRCS.h_initfini2=	h_initfini1.cxx h_initfini_common.cxx \
+			${SRCS_CHECK_STACK}
 LDADD.h_initfini2+=	-static
-SRCS.h_initfini3=	h_initfini3.cxx h_initfini_common.cxx
+SRCS.h_initfini3=	h_initfini3.cxx h_initfini_common.cxx \
+			${SRCS_CHECK_STACK}
 LDADD.h_initfini3+=	-Wl,-rpath,${TESTSDIR}
 
 .include <bsd.test.mk>

Index: src/tests/lib/csu/h_initfini_common.cxx
diff -u src/tests/lib/csu/h_initfini_common.cxx:1.1 src/tests/lib/csu/h_initfini_common.cxx:1.2
--- src/tests/lib/csu/h_initfini_common.cxx:1.1	Wed Jul 28 13:51:38 2010
+++ src/tests/lib/csu/h_initfini_common.cxx	Tue Nov 30 18:38:53 2010
@@ -1,16 +1,36 @@
 #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
 	}
 };
 

Index: src/tests/lib/csu/dso/Makefile
diff -u src/tests/lib/csu/dso/Makefile:1.3 src/tests/lib/csu/dso/Makefile:1.4
--- src/tests/lib/csu/dso/Makefile:1.3	Wed Aug  4 13:56:10 2010
+++ src/tests/lib/csu/dso/Makefile	Tue Nov 30 18:38:53 2010
@@ -1,11 +1,14 @@
-# $NetBSD: Makefile,v 1.3 2010/08/04 13:56:10 joerg Exp $
+# $NetBSD: Makefile,v 1.4 2010/11/30 18:38:53 joerg Exp $
 
 NOMAN=		# defined
 
 .include <bsd.own.mk>
 
+.include "${.PARSEDIR}/../Makefile.check_stack"
+
 LIB=		h_initfini3_dso
-SRCS=		h_initfini3_dso.cxx
+SRCS=		h_initfini3_dso.cxx ${SRCS_CHECK_STACK}
+CPPFLAGS+=	${CPPFLAGS_CHECK_STACK}
 
 LIBDIR=		${TESTSBASE}/lib/csu
 SHLIBDIR=	${TESTSBASE}/lib/csu
@@ -14,4 +17,5 @@
 LIBISMODULE=	yes
 LIBISCXX=	yes
 
+
 .include <bsd.lib.mk>

Index: src/tests/lib/csu/dso/h_initfini3_dso.cxx
diff -u src/tests/lib/csu/dso/h_initfini3_dso.cxx:1.1 src/tests/lib/csu/dso/h_initfini3_dso.cxx:1.2
--- src/tests/lib/csu/dso/h_initfini3_dso.cxx:1.1	Wed Jul 28 13:51:40 2010
+++ src/tests/lib/csu/dso/h_initfini3_dso.cxx	Tue Nov 30 18:38:54 2010
@@ -1,16 +1,36 @@
 #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
 	}
 };
 

Index: src/tests/lib/libpthread/Makefile
diff -u src/tests/lib/libpthread/Makefile:1.2 src/tests/lib/libpthread/Makefile:1.3
--- src/tests/lib/libpthread/Makefile:1.2	Wed Jul 28 21:29:15 2010
+++ src/tests/lib/libpthread/Makefile	Tue Nov 30 18:38:54 2010
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2 2010/07/28 21:29:15 jruoho Exp $
+# $NetBSD: Makefile,v 1.3 2010/11/30 18:38:54 joerg Exp $
 
 NOMAN=		# defined
 
@@ -7,6 +7,11 @@
 TESTSDIR=	${TESTSBASE}/lib/libpthread
 LDADD+=		-lpthread
 
+.include "${.PARSEDIR}/../csu/Makefile.check_stack"
+
+SRCS.t_join=	t_join.c ${SRCS_CHECK_STACK}
+CPPFLAGS.t_join.c+=	${CPPFLAGS_CHECK_STACK}
+
 TESTS_SH+=	t_atexit
 TESTS_C+=	t_barrier
 TESTS_SH+=	t_cancel

Index: src/tests/lib/libpthread/t_join.c
diff -u src/tests/lib/libpthread/t_join.c:1.4 src/tests/lib/libpthread/t_join.c:1.5
--- src/tests/lib/libpthread/t_join.c:1.4	Thu Jul 29 12:56:16 2010
+++ src/tests/lib/libpthread/t_join.c	Tue Nov 30 18:38:54 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $ */
+/* $NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_join.c,v 1.4 2010/07/29 12:56:16 hans Exp $");
+__RCSID("$NetBSD: t_join.c,v 1.5 2010/11/30 18:38:54 joerg Exp $");
 
 #include <errno.h>
 #include <pthread.h>
@@ -38,6 +38,10 @@
 
 #include "h_common.h"
 
+#ifdef CHECK_STACK_ALIGNMENT
+extern int check_stack_alignment(void);
+#endif
+
 static bool error;
 
 static void *threadfunc1(void *);
@@ -70,6 +74,13 @@
 
 	caller = pthread_self();
 
+#ifdef CHECK_STACK_ALIGNMENT
+	/*
+	 * Check alignment of thread stack, if supported.
+	 */
+	ATF_REQUIRE(check_stack_alignment());
+#endif
+
 	/*
 	 * The behavior is undefined, but should error
 	 * out, if we try to join the calling thread.

Added files:

Index: src/tests/lib/csu/Makefile.check_stack
diff -u /dev/null src/tests/lib/csu/Makefile.check_stack:1.1
--- /dev/null	Tue Nov 30 18:38:54 2010
+++ src/tests/lib/csu/Makefile.check_stack	Tue Nov 30 18:38:53 2010
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile.check_stack,v 1.1 2010/11/30 18:38:53 joerg Exp $
+
+.include <bsd.own.mk>
+
+CSU_ARCHDIR=	${.PARSEDIR}/arch/${MACHINE_ARCH}
+.PATH: ${CSU_ARCHDIR}
+.if exists(${CSU_ARCHDIR}/h_initfini_align.S)
+SRCS_CHECK_STACK=	h_initfini_align.S
+CPPFLAGS_CHECK_STACK+=	-DCHECK_STACK_ALIGNMENT
+.endif

Index: src/tests/lib/csu/dso/h_initfini_align.S
diff -u /dev/null src/tests/lib/csu/dso/h_initfini_align.S:1.1
--- /dev/null	Tue Nov 30 18:38:54 2010
+++ src/tests/lib/csu/dso/h_initfini_align.S	Tue Nov 30 18:38:53 2010
@@ -0,0 +1,15 @@
+/*	$NetBSD: h_initfini_align.S,v 1.1 2010/11/30 18:38:53 joerg Exp $	*/
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.1 2010/11/30 18:38:53 joerg Exp $")
+
+_ENTRY(check_stack_alignment)
+	movl	%esp, %eax
+	andl	$3, %eax
+	jz 1f
+	xorl	%eax, %eax
+	ret
+1:
+	incl	%eax
+	ret

Index: src/tests/lib/csu/dso/h_initfini_align.S
diff -u /dev/null src/tests/lib/csu/dso/h_initfini_align.S:1.2
--- /dev/null	Tue Nov 30 18:38:54 2010
+++ src/tests/lib/csu/dso/h_initfini_align.S	Tue Nov 30 18:38:53 2010
@@ -0,0 +1,16 @@
+/*	$NetBSD: h_initfini_align.S,v 1.2 2010/11/30 18:38:53 joerg Exp $	*/
+
+#include <machine/asm.h>
+
+RCSID("$NetBSD: h_initfini_align.S,v 1.2 2010/11/30 18:38:53 joerg Exp $")
+
+_ENTRY(check_stack_alignment)
+	movl	%esp, %eax
+	andl	$15, %eax
+	subl	$8, %eax
+	jz 1f
+	xorl	%eax, %eax
+	ret
+1:
+	incl	%eax
+	ret

Reply via email to