From owner-svn-src-all@freebsd.org Tue Oct 30 09:43:28 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5724110DD12C; Tue, 30 Oct 2018 09:43:28 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F13C57A563; Tue, 30 Oct 2018 09:43:27 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CC8FD1BBFE; Tue, 30 Oct 2018 09:43:27 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9U9hRR0036010; Tue, 30 Oct 2018 09:43:27 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9U9hQxA036004; Tue, 30 Oct 2018 09:43:26 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201810300943.w9U9hQxA036004@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Tue, 30 Oct 2018 09:43:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339908 - in head: etc/mtree lib/csu/tests lib/csu/tests/dso lib/csu/tests/dynamiclib X-SVN-Group: head X-SVN-Commit-Author: andrew X-SVN-Commit-Paths: in head: etc/mtree lib/csu/tests lib/csu/tests/dso lib/csu/tests/dynamiclib X-SVN-Commit-Revision: 339908 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Oct 2018 09:43:28 -0000 Author: andrew Date: Tue Oct 30 09:43:26 2018 New Revision: 339908 URL: https://svnweb.freebsd.org/changeset/base/339908 Log: Run the csu tests on a DSO. This builds the tests into a shared library, then runs these from the base test programs. With this we can check crtbeginS.o and crtendS.o are working as expected. MFC with: r339738 Sponsored by: DARPA, AFRL Added: head/lib/csu/tests/dso/ head/lib/csu/tests/dso/Makefile (contents, props changed) head/lib/csu/tests/dynamiclib/ head/lib/csu/tests/dynamiclib/Makefile (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/lib/csu/tests/Makefile head/lib/csu/tests/cxx_constructors.cc head/lib/csu/tests/fini_test.c head/lib/csu/tests/init_test.c Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Tue Oct 30 09:36:31 2018 (r339907) +++ head/etc/mtree/BSD.tests.dist Tue Oct 30 09:43:26 2018 (r339908) @@ -273,6 +273,8 @@ csu dynamic .. + dynamiclib + .. static .. .. Modified: head/lib/csu/tests/Makefile ============================================================================== --- head/lib/csu/tests/Makefile Tue Oct 30 09:36:31 2018 (r339907) +++ head/lib/csu/tests/Makefile Tue Oct 30 09:43:26 2018 (r339908) @@ -1,6 +1,8 @@ # $FreeBSD$ +SUBDIR= dso TESTS_SUBDIRS= dynamic +TESTS_SUBDIRS+= dynamiclib TESTS_SUBDIRS+= static .include Modified: head/lib/csu/tests/cxx_constructors.cc ============================================================================== --- head/lib/csu/tests/cxx_constructors.cc Tue Oct 30 09:36:31 2018 (r339907) +++ head/lib/csu/tests/cxx_constructors.cc Tue Oct 30 09:43:26 2018 (r339908) @@ -39,10 +39,18 @@ __FBSDID("$FreeBSD$"); #include #include +#ifndef DSO_LIB #include +#endif -static volatile int constructor_run; -static bool run_destructor_test = false; +extern volatile int constructor_run; +extern bool run_destructor_test; + +#ifndef DSO_BASE +volatile int constructor_run; +bool run_destructor_test = false; +#endif + struct Foo { Foo() { constructor_run = 1; @@ -53,8 +61,12 @@ struct Foo { } }; extern Foo foo; + +#ifndef DSO_BASE Foo foo; +#endif +#ifndef DSO_LIB ATF_TEST_CASE_WITHOUT_HEAD(cxx_constructor); ATF_TEST_CASE_BODY(cxx_constructor) { @@ -90,3 +102,4 @@ ATF_INIT_TEST_CASES(tcs) ATF_ADD_TEST_CASE(tcs, cxx_constructor); ATF_ADD_TEST_CASE(tcs, cxx_destructor); } +#endif Added: head/lib/csu/tests/dso/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/csu/tests/dso/Makefile Tue Oct 30 09:43:26 2018 (r339908) @@ -0,0 +1,25 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR:H} +SHLIB= h_csu +SHLIB_NAME= libh_csu.so +SHLIB_MAJOR= 1 + +WITHOUT_STATIC= +WITHOUT_PROFILE= +WITHOUT_PIC= + +CFLAGS+= -DDSO_LIB + +.include "../Makefile.tests" +SRCS= +.for src in ${ATF_TESTS_C} +SRCS+= ${src}.c +.endfor +.for src in ${ATF_TESTS_CXX} +SRCS+= ${src}.cc +.endfor + +LIBDIR= ${TESTSBASE}/lib/csu/dynamiclib/ + +.include Added: head/lib/csu/tests/dynamiclib/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/csu/tests/dynamiclib/Makefile Tue Oct 30 09:43:26 2018 (r339908) @@ -0,0 +1,17 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR:H} +CFLAGS+= -DDSO_BASE +DPADD+= ${.OBJDIR:H}/dso/libh_csu.so +LDFLAGS+= -Wl,-rpath,${TESTSDIR} -L${.OBJDIR:H}/dso +LDADD+= -lh_csu + +.include "../Makefile.tests" + +.for test in ${ATF_TESTS_C} +ATF_TESTS_CXX+= ${test} +SRCS.${test}= ${test}.c +.endfor +ATF_TESTS_C:= + +.include Modified: head/lib/csu/tests/fini_test.c ============================================================================== --- head/lib/csu/tests/fini_test.c Tue Oct 30 09:36:31 2018 (r339907) +++ head/lib/csu/tests/fini_test.c Tue Oct 30 09:43:26 2018 (r339908) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include @@ -43,10 +44,16 @@ __FBSDID("$FreeBSD$"); #include +extern bool run_dtors_test; +extern bool run_fini_array_test; +void dso_handle_check(void); + + +#ifndef DSO_BASE typedef void (*func_ptr)(void); -static bool run_dtors_test = false; -static bool run_fini_array_test = false; +bool run_dtors_test = false; +bool run_fini_array_test = false; static void dtors_handler(void) @@ -57,7 +64,9 @@ dtors_handler(void) } __section(".dtors") __used static func_ptr dtors_func = &dtors_handler; +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(dtors_test); ATF_TC_BODY(dtors_test, tc) { @@ -85,7 +94,9 @@ ATF_TC_BODY(dtors_test, tc) break; } } +#endif +#ifndef DSO_BASE static void fini_array_handler(void) { @@ -95,7 +106,9 @@ fini_array_handler(void) } __section(".fini_array") __used static func_ptr fini_array_func = &fini_array_handler; +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(fini_array_test); ATF_TC_BODY(fini_array_test, tc) { @@ -118,15 +131,32 @@ ATF_TC_BODY(fini_array_test, tc) break; } } +#endif +#ifndef DSO_BASE extern void *__dso_handle; +void +dso_handle_check(void) +{ + void *dso = __dso_handle; + +#ifdef DSO_LIB + ATF_REQUIRE_MSG(dso != NULL, + "Null __dso_handle in DSO"); +#else + ATF_REQUIRE_MSG(dso == NULL, + "Invalid __dso_handle in non-DSO"); +#endif +} +#endif + +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(dso_handle_test); ATF_TC_BODY(dso_handle_test, tc) { - ATF_REQUIRE_MSG(__dso_handle == NULL, - "Invalid __dso_handle in non-DSO"); + dso_handle_check(); } ATF_TP_ADD_TCS(tp) @@ -138,3 +168,4 @@ ATF_TP_ADD_TCS(tp) return (atf_no_error()); } +#endif Modified: head/lib/csu/tests/init_test.c ============================================================================== --- head/lib/csu/tests/init_test.c Tue Oct 30 09:36:31 2018 (r339907) +++ head/lib/csu/tests/init_test.c Tue Oct 30 09:43:26 2018 (r339908) @@ -32,23 +32,36 @@ #include __FBSDID("$FreeBSD$"); +#ifndef DSO_LIB #include +#endif #include typedef void (*func_ptr)(void); -static volatile int jcr_run; -static const func_ptr *jcr_ptr; -static volatile int ctors_run; -static volatile int preinit_array_run; -static volatile int preinit_array_state = -1; -static volatile int init_array_run; -static volatile int init_array_state = -1; +extern volatile int jcr_run; +extern const func_ptr *jcr_ptr; +extern const void *jcr_func_ptr; +extern volatile int ctors_run; +extern volatile int preinit_array_run; +extern volatile int preinit_array_state; +extern volatile int init_array_run; +extern volatile int init_array_state; +#ifndef DSO_BASE +volatile int jcr_run; +const func_ptr *jcr_ptr; +volatile int ctors_run; +volatile int preinit_array_run; +volatile int preinit_array_state = -1; +volatile int init_array_run; +volatile int init_array_state = -1; + void _Jv_RegisterClasses(const func_ptr *); -__section(".jcr") __used static func_ptr jcr_func = (func_ptr)1; +__section(".jcr") __used func_ptr static jcr_func = (func_ptr)1; +const void *jcr_func_ptr = &jcr_func; void _Jv_RegisterClasses(const func_ptr *jcr) @@ -57,16 +70,20 @@ _Jv_RegisterClasses(const func_ptr *jcr) jcr_run = 1; jcr_ptr = jcr; } +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(jcr_test); ATF_TC_BODY(jcr_test, tc) { ATF_REQUIRE_MSG(jcr_run == 1, ".jcr not run"); - ATF_REQUIRE_MSG(jcr_ptr == &jcr_func, + ATF_REQUIRE_MSG(jcr_ptr == jcr_func_ptr, "Incorrect pointer passed to _Jv_RegisterClasses"); } +#endif +#ifndef DSO_BASE static void ctors_handler(void) { @@ -75,7 +92,9 @@ ctors_handler(void) } __section(".ctors") __used static func_ptr ctors_func = &ctors_handler; +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(ctors_test); ATF_TC_BODY(ctors_test, tc) { @@ -86,7 +105,9 @@ ATF_TC_BODY(ctors_test, tc) ATF_REQUIRE_MSG(ctors_run == 0, ".ctors run"); #endif } +#endif +#ifndef DSO_BASE static void preinit_array_handler(void) { @@ -96,16 +117,25 @@ preinit_array_handler(void) } __section(".preinit_array") __used static func_ptr preinit_array_func = &preinit_array_handler; +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(preinit_array_test); ATF_TC_BODY(preinit_array_test, tc) { +#ifdef DSO_BASE + /* Check .preinit_array wasn't run in a DSO */ + ATF_REQUIRE_MSG(preinit_array_run == 0, ".preinit_array run in DSO"); +#else ATF_REQUIRE_MSG(preinit_array_run == 1, ".preinit_array not run"); ATF_REQUIRE_MSG(preinit_array_state == 0, ".preinit_array was not run before .init_array"); +#endif } +#endif +#ifndef DSO_BASE static void init_array_handler(void) { @@ -115,14 +145,18 @@ init_array_handler(void) } __section(".init_array") __used static func_ptr init_array_func = &init_array_handler; +#endif +#ifndef DSO_LIB ATF_TC_WITHOUT_HEAD(init_array_test); ATF_TC_BODY(init_array_test, tc) { ATF_REQUIRE_MSG(init_array_run == 1, ".init_array not run"); +#ifndef DSO_BASE ATF_REQUIRE_MSG(init_array_state == 1, ".init_array was not run after .preinit_array"); +#endif } ATF_TP_ADD_TCS(tp) @@ -135,3 +169,4 @@ ATF_TP_ADD_TCS(tp) return (atf_no_error()); } +#endif