diff --git a/lib/csu/Makefile b/lib/csu/Makefile index dea4fdae9727..68299b387db5 100644 --- a/lib/csu/Makefile +++ b/lib/csu/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.40 2020/04/22 23:32:25 joerg Exp $ +# $NetBSD: Makefile,v 1.41 2021/04/20 21:42:31 christos Exp $ NOLIBCSANITIZER= # defined NOSANITIZER= # defined @@ -18,9 +18,6 @@ ARCHDIR:= ${.CURDIR}/arch/${CSU_MACHINE_CPU} .error Architecture (${CSU_MACHINE_ARCH} or ${CSU_MACHINE_CPU}) unsupported .endif -# Ownership of globals from crt0.o is shared with libc for historic reasons -COPTS+= -fcommon - .PATH: ${ARCHDIR} .include "${ARCHDIR}/Makefile.inc" .include "${.CURDIR}/common/Makefile.inc" diff --git a/lib/csu/common/crt0-common.c b/lib/csu/common/crt0-common.c index 8100acf38004..6c182d8eb2b9 100644 --- a/lib/csu/common/crt0-common.c +++ b/lib/csu/common/crt0-common.c @@ -1,4 +1,4 @@ -/* $NetBSD: crt0-common.c,v 1.23 2018/12/28 20:12:35 christos Exp $ */ +/* $NetBSD: crt0-common.c,v 1.24 2021/04/20 21:42:31 christos Exp $ */ /* * Copyright (c) 1998 Christos Zoulas @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: crt0-common.c,v 1.23 2018/12/28 20:12:35 christos Exp $"); +__RCSID("$NetBSD: crt0-common.c,v 1.24 2021/04/20 21:42:31 christos Exp $"); #include #include @@ -46,6 +46,8 @@ __RCSID("$NetBSD: crt0-common.c,v 1.23 2018/12/28 20:12:35 christos Exp $"); #include #include +#include "csu-common.h" + extern int main(int, char **, char **); typedef void (*fptr_t)(void); @@ -70,11 +72,11 @@ extern void _mcleanup(void); extern unsigned char __etext, __eprol; #endif /* MCRT0 */ -char **environ; -struct ps_strings *__ps_strings = 0; - static char empty_string[] = ""; -char *__progname = empty_string; + +char **environ __common; +struct ps_strings *__ps_strings __common = 0; +char *__progname __common = empty_string; __dead __dso_hidden void ___start(void (*)(void), struct ps_strings *); diff --git a/lib/csu/common/csu-common.h b/lib/csu/common/csu-common.h new file mode 100644 index 000000000000..786ad0355a82 --- /dev/null +++ b/lib/csu/common/csu-common.h @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2021 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. + */ + +/* + * For historical reasons the following symbols are defined both in libc + * and csu and need to be common + */ +#if __has_attribute(__common__) +#define __common __attribute((__common__)) +#else +#define __common +#endif +extern char *__progname __common; +extern char **environ __common; +extern struct ps_strings *__ps_strings __common; diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc index 2583c815933f..38f76b425e11 100644 --- a/lib/libc/Makefile.inc +++ b/lib/libc/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.19 2018/06/09 22:41:55 christos Exp $ +# $NetBSD: Makefile.inc,v 1.20 2021/04/20 21:42:31 christos Exp $ # @(#)Makefile 8.2 (Berkeley) 2/3/94 # # All library objects contain sccsid strings by default; they may be @@ -34,6 +34,8 @@ CPPFLAGS+= -D_DIAGNOSTIC .if defined(MLIBDIR) CPPFLAGS+= -DMLIBDIR=\"${MLIBDIR}\" .endif +# needed for csu_common.h +CPPFLAGS+= -I${NETBSDSRCDIR}/lib/csu/common .if (${USE_HESIOD} != "no") CPPFLAGS+= -DHESIOD diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 85231e88f09d..0e2d46ad779a 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.211 2021/04/12 03:57:07 mrg Exp $ +# $NetBSD: Makefile.inc,v 1.212 2021/04/20 21:42:32 christos Exp $ # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # gen sources @@ -207,8 +207,3 @@ errlist.c: errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h ${TOOL_AWK} -f ${.ALLSRC} > ${.TARGET} CLEANFILES+= errlist.c - -# Ownership of globals from crt0.o is shared with libc for historic reasons. -# __progname is also necessary as global here for the nbcompat case. -COPTS.getprogname.c+= -fcommon -COPTS.setproctitle.c+= -fcommon diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c index 6904fad6f4ab..7727437961d7 100644 --- a/lib/libc/gen/getprogname.c +++ b/lib/libc/gen/getprogname.c @@ -1,4 +1,4 @@ -/* $NetBSD: getprogname.c,v 1.4 2011/10/06 20:31:41 christos Exp $ */ +/* $NetBSD: getprogname.c,v 1.5 2021/04/20 21:42:32 christos Exp $ */ /* * Copyright (c) 2001 Christopher G. Demetriou @@ -36,19 +36,18 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getprogname.c,v 1.4 2011/10/06 20:31:41 christos Exp $"); +__RCSID("$NetBSD: getprogname.c,v 1.5 2021/04/20 21:42:32 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include +#include "csu-common.h" #ifdef __weak_alias __weak_alias(getprogname,_getprogname) #endif -const char *__progname; - const char * getprogname(void) { diff --git a/lib/libc/gen/setproctitle.c b/lib/libc/gen/setproctitle.c index 5138922648c9..fac164b8de7b 100644 --- a/lib/libc/gen/setproctitle.c +++ b/lib/libc/gen/setproctitle.c @@ -1,4 +1,4 @@ -/* $NetBSD: setproctitle.c,v 1.22 2008/01/03 04:26:27 christos Exp $ */ +/* $NetBSD: setproctitle.c,v 1.23 2021/04/20 21:42:32 christos Exp $ */ /* * Copyright (c) 1994, 1995 Christopher G. Demetriou @@ -36,7 +36,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: setproctitle.c,v 1.22 2008/01/03 04:26:27 christos Exp $"); +__RCSID("$NetBSD: setproctitle.c,v 1.23 2021/04/20 21:42:32 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -47,6 +47,7 @@ __RCSID("$NetBSD: setproctitle.c,v 1.22 2008/01/03 04:26:27 christos Exp $"); #include #include #include +#include "csu-common.h" #ifdef __weak_alias __weak_alias(setproctitle,_setproctitle) @@ -54,12 +55,6 @@ __weak_alias(setproctitle,_setproctitle) #define MAX_PROCTITLE 2048 -/* - * For compatibility with old versions of crt0 that didn't define __ps_strings, - * define it as a common here. - */ -struct ps_strings *__ps_strings; - void setproctitle(const char *fmt, ...) { diff --git a/lib/libc/misc/Makefile.inc b/lib/libc/misc/Makefile.inc index 21ba1b0a1be5..ac4c795e8396 100644 --- a/lib/libc/misc/Makefile.inc +++ b/lib/libc/misc/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.4 2020/04/22 23:32:25 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.5 2021/04/20 21:42:32 christos Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 .PATH: ${ARCHDIR}/misc ${.CURDIR}/misc @@ -13,6 +13,3 @@ SRCS+= initfini.c # for -fstack-protector SRCS+= stack_protector.c - -# Ownership of globals from crt0.o is shared with libc for historic reasons -COPTS.initfini.c+= -fcommon diff --git a/lib/libc/misc/initfini.c b/lib/libc/misc/initfini.c index c24c7cdda3a8..9f5cec1d2cce 100644 --- a/lib/libc/misc/initfini.c +++ b/lib/libc/misc/initfini.c @@ -1,4 +1,4 @@ -/* $NetBSD: initfini.c,v 1.14 2017/06/17 15:26:44 joerg Exp $ */ +/* $NetBSD: initfini.c,v 1.15 2021/04/20 21:42:32 christos Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: initfini.c,v 1.14 2017/06/17 15:26:44 joerg Exp $"); +__RCSID("$NetBSD: initfini.c,v 1.15 2021/04/20 21:42:32 christos Exp $"); #ifdef _LIBC #include "namespace.h" @@ -40,6 +40,7 @@ __RCSID("$NetBSD: initfini.c,v 1.14 2017/06/17 15:26:44 joerg Exp $"); #include #include #include +#include "csu-common.h" void _libc_init(void) __attribute__((__constructor__, __used__)); @@ -75,7 +76,9 @@ void _libc_init(void); * Declare as common symbol to allow new libc with older binaries to * not trigger an undefined reference. */ -struct ps_strings *__ps_strings; +struct ps_strings *__ps_strings __common; +char *__progname __common; +char **environ __common; /* * _libc_init is called twice. One call comes explicitly from crt0.o diff --git a/lib/libc/stdlib/_env.c b/lib/libc/stdlib/_env.c index bade54e6b175..627db85ca41b 100644 --- a/lib/libc/stdlib/_env.c +++ b/lib/libc/stdlib/_env.c @@ -1,4 +1,4 @@ -/* $NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $ */ +/* $NetBSD: _env.c,v 1.11 2021/04/20 21:42:32 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $"); +__RCSID("$NetBSD: _env.c,v 1.11 2021/04/20 21:42:32 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -44,6 +44,7 @@ __RCSID("$NetBSD: _env.c,v 1.10 2020/02/22 10:05:12 kamil Exp $"); #include #include #include +#include "csu-common.h" #include "env.h" #include "local.h" @@ -94,8 +95,6 @@ __warn_references(__findenv, /* Our initialization function. */ void __libc_env_init(void); -char **environ; - /*ARGSUSED*/ static signed int env_tree_compare_nodes(void *ctx, const void *node_a, const void *node_b)