From 5f2c3882308b84c81b8bfee159f4f9493ff0e07e Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Mon, 29 Oct 2018 17:13:12 +0000 Subject: Include the csu test directories in BSD.tests.dist MFC with: r339738 Sponsored by: DARPA, AFRL --- etc/mtree/BSD.tests.dist | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'etc') diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 24bad91a0fdf..33944a13664f 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -270,6 +270,12 @@ test-programs .. .. + csu + dynamic + .. + static + .. + .. libarchive .. libc -- cgit v1.3 From 6ec0ee844c8c6b720d91ed832db25191fcdf9f9d Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Tue, 30 Oct 2018 09:43:26 +0000 Subject: 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 --- etc/mtree/BSD.tests.dist | 2 ++ lib/csu/tests/Makefile | 2 ++ lib/csu/tests/cxx_constructors.cc | 17 +++++++++++-- lib/csu/tests/dso/Makefile | 25 ++++++++++++++++++ lib/csu/tests/dynamiclib/Makefile | 17 +++++++++++++ lib/csu/tests/fini_test.c | 39 +++++++++++++++++++++++++--- lib/csu/tests/init_test.c | 53 ++++++++++++++++++++++++++++++++------- 7 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 lib/csu/tests/dso/Makefile create mode 100644 lib/csu/tests/dynamiclib/Makefile (limited to 'etc') diff --git a/etc/mtree/BSD.tests.dist b/etc/mtree/BSD.tests.dist index 33944a13664f..7da2d745b1af 100644 --- a/etc/mtree/BSD.tests.dist +++ b/etc/mtree/BSD.tests.dist @@ -273,6 +273,8 @@ csu dynamic .. + dynamiclib + .. static .. .. diff --git a/lib/csu/tests/Makefile b/lib/csu/tests/Makefile index 021f5ac9ebb9..693aa503e932 100644 --- a/lib/csu/tests/Makefile +++ b/lib/csu/tests/Makefile @@ -1,6 +1,8 @@ # $FreeBSD$ +SUBDIR= dso TESTS_SUBDIRS= dynamic +TESTS_SUBDIRS+= dynamiclib TESTS_SUBDIRS+= static .include diff --git a/lib/csu/tests/cxx_constructors.cc b/lib/csu/tests/cxx_constructors.cc index f60b528d22d0..7cae887e3f56 100644 --- a/lib/csu/tests/cxx_constructors.cc +++ b/lib/csu/tests/cxx_constructors.cc @@ -39,10 +39,18 @@ __FBSDID("$FreeBSD$"); #include #include +#ifndef DSO_LIB #include +#endif + +extern volatile int constructor_run; +extern bool run_destructor_test; + +#ifndef DSO_BASE +volatile int constructor_run; +bool run_destructor_test = false; +#endif -static volatile int constructor_run; -static bool run_destructor_test = false; 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 diff --git a/lib/csu/tests/dso/Makefile b/lib/csu/tests/dso/Makefile new file mode 100644 index 000000000000..cdfea2031c99 --- /dev/null +++ b/lib/csu/tests/dso/Makefile @@ -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 diff --git a/lib/csu/tests/dynamiclib/Makefile b/lib/csu/tests/dynamiclib/Makefile new file mode 100644 index 000000000000..ef05648aa26c --- /dev/null +++ b/lib/csu/tests/dynamiclib/Makefile @@ -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 diff --git a/lib/csu/tests/fini_test.c b/lib/csu/tests/fini_test.c index df607dc5113d..ea825e51acf9 100644 --- a/lib/csu/tests/fini_test.c +++ b/lib/csu/tests/fini_test.c @@ -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 diff --git a/lib/csu/tests/init_test.c b/lib/csu/tests/init_test.c index afe479c3b3b5..75d07d9b490a 100644 --- a/lib/csu/tests/init_test.c +++ b/lib/csu/tests/init_test.c @@ -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 -- cgit v1.3 From 97dc79f29a49bbfe08c9e343e58c0ba18434659e Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 4 Nov 2018 06:47:21 +0000 Subject: Simplify a bit distrib-dirs target Reviewed by: bdrewery Differential Revision: https://reviews.freebsd.org/D3915 --- etc/Makefile | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'etc') diff --git a/etc/Makefile b/etc/Makefile index df8f99e4c3de..8fefeabe6767 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -157,35 +157,29 @@ distrib-cleanup: .PHONY done distrib-dirs: ${MTREES:N/*} distrib-cleanup .PHONY - @set ${MTREES}; \ - while test $$# -ge 2; do \ - m=${.CURDIR}/$$1; \ - shift; \ - d=${DESTDIR}$$1; \ - shift; \ - test -d $$d || mkdir -p $$d; \ - ${ECHO} ${MTREE_CMD} -deU ${MTREE_FSCHG} \ - ${MTREE_FOLLOWS_SYMLINKS} -f $$m -p $$d; \ - ${MTREE_FILTER} $$m | \ - ${MTREE_CMD} -deU ${MTREE_FSCHG} ${MTREE_FOLLOWS_SYMLINKS} \ - -p $$d; \ - done; true +.for _m _d in ${MTREES} + @m=${.CURDIR}/${_m}; \ + d=${DESTDIR}${_d}; \ + test -d $$d || mkdir -p $$d; \ + ${ECHO} ${MTREE_CMD} -deU ${MTREE_FSCHG} \ + ${MTREE_FOLLOWS_SYMLINKS} -f $$m -p $$d; \ + ${MTREE_FILTER} $$m | \ + ${MTREE_CMD} -deU ${MTREE_FSCHG} ${MTREE_FOLLOWS_SYMLINKS} \ + -p $$d; \ +.endfor .if defined(NO_ROOT) - @set ${MTREES}; \ - while test $$# -ge 2; do \ - m=${.CURDIR}/$$1; \ - shift; \ - d=$$1; \ - test "$$d" == "/" && d=""; \ - d=${DISTBASE}$$d; \ - shift; \ - test -d ${DESTDIR}/$$d || mkdir -p ${DESTDIR}/$$d; \ - ${ECHO} "${MTREE_CMD:N-W} -C -f $$m -K all | " \ - "sed s#^\.#.$$d# | ${METALOG.add}" ; \ - ${MTREE_FILTER} $$m | \ - ${MTREE_CMD:N-W} -C -K all | sed s#^\.#.$$d# | \ - ${METALOG.add} ; \ - done; true +.for _m _d in ${MTREES} + @m=${.CURDIR}/${_m}; \ + d=${_d}; \ + test "$$d" == "/" && d=""; \ + d=${DISTBASE}$$d; \ + test -d ${DESTDIR}/$$d || mkdir -p ${DESTDIR}/$$d; \ + ${ECHO} "${MTREE_CMD:N-W} -C -f $$m -K all | " \ + "sed s#^\.#.$$d# | ${METALOG.add}" ; \ + ${MTREE_FILTER} $$m | \ + ${MTREE_CMD:N-W} -C -K all | sed s#^\.#.$$d# | \ + ${METALOG.add} ; \ +.endfor .endif .if ${MK_NLS} != "no" set - `grep "^[a-zA-Z]" ${.CURDIR}/nls.alias`; \ -- cgit v1.3 From 4dd729a55b6818cbbe0bc9817d50f6293d76aadf Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 4 Nov 2018 06:59:13 +0000 Subject: Fix bad copy/paste --- etc/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'etc') diff --git a/etc/Makefile b/etc/Makefile index 8fefeabe6767..cc228bef0ab8 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -165,7 +165,7 @@ distrib-dirs: ${MTREES:N/*} distrib-cleanup .PHONY ${MTREE_FOLLOWS_SYMLINKS} -f $$m -p $$d; \ ${MTREE_FILTER} $$m | \ ${MTREE_CMD} -deU ${MTREE_FSCHG} ${MTREE_FOLLOWS_SYMLINKS} \ - -p $$d; \ + -p $$d .endfor .if defined(NO_ROOT) .for _m _d in ${MTREES} @@ -178,7 +178,7 @@ distrib-dirs: ${MTREES:N/*} distrib-cleanup .PHONY "sed s#^\.#.$$d# | ${METALOG.add}" ; \ ${MTREE_FILTER} $$m | \ ${MTREE_CMD:N-W} -C -K all | sed s#^\.#.$$d# | \ - ${METALOG.add} ; \ + ${METALOG.add} .endfor .endif .if ${MK_NLS} != "no" -- cgit v1.3 From 874e7db1f798100b6b4e0efa69ad91570f88b16b Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 4 Nov 2018 10:14:08 +0000 Subject: Simplify NLS alias handling by using native make(1) multi variable for loops --- etc/Makefile | 10 +++++----- etc/nls.alias | 4 ---- 2 files changed, 5 insertions(+), 9 deletions(-) delete mode 100644 etc/nls.alias (limited to 'etc') diff --git a/etc/Makefile b/etc/Makefile index cc228bef0ab8..4714b580cc82 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -4,6 +4,8 @@ .include FILESGROUPS= FILES +NLS_ALIASES= POSIX C \ + en_US.US_ASCII C # No need as it is empty and just causes rebuilds since this file does so much. UPDATE_DEPENDFILE= no @@ -182,11 +184,9 @@ distrib-dirs: ${MTREES:N/*} distrib-cleanup .PHONY .endfor .endif .if ${MK_NLS} != "no" - set - `grep "^[a-zA-Z]" ${.CURDIR}/nls.alias`; \ - while [ $$# -gt 0 ] ; do \ - ${INSTALL_SYMLINK} "$$2" "${DESTDIR}${SHAREDIR}/nls/$$1"; \ - shift; shift; \ - done +.for alias nls in ${NLS_ALIASES} + ${INSTALL_SYMLINK} "${nls}" "${DESTDIR}${SHAREDIR}/nls/${alias}" +.endfor .endif etc-examples: ${META_DEPS} diff --git a/etc/nls.alias b/etc/nls.alias deleted file mode 100644 index 805c34ab6b8a..000000000000 --- a/etc/nls.alias +++ /dev/null @@ -1,4 +0,0 @@ -# $FreeBSD$ - -POSIX C -en_US.US-ASCII C -- cgit v1.3