Index: csu/Makefile =================================================================== RCS file: /cvsroot/src/lib/csu/Makefile,v retrieving revision 1.40 diff -u -p -r1.40 Makefile --- csu/Makefile 22 Apr 2020 23:32:25 -0000 1.40 +++ csu/Makefile 20 Apr 2021 21:33:55 -0000 @@ -18,9 +18,6 @@ ARCHDIR:= ${.CURDIR}/arch/${CSU_MACHINE_ .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" Index: csu/common/crt0-common.c =================================================================== RCS file: /cvsroot/src/lib/csu/common/crt0-common.c,v retrieving revision 1.23 diff -u -p -r1.23 crt0-common.c --- csu/common/crt0-common.c 28 Dec 2018 20:12:35 -0000 1.23 +++ csu/common/crt0-common.c 20 Apr 2021 21:33:55 -0000 @@ -46,6 +46,8 @@ __RCSID("$NetBSD: crt0-common.c,v 1.23 2 #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 *); Index: csu/common/csu-common.h =================================================================== RCS file: csu/common/csu-common.h diff -N csu/common/csu-common.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ csu/common/csu-common.h 20 Apr 2021 21:33:55 -0000 @@ -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; +extern char **environ; +extern struct ps_strings *__ps_strings; Index: libc/Makefile.inc =================================================================== RCS file: /cvsroot/src/lib/libc/Makefile.inc,v retrieving revision 1.19 diff -u -p -r1.19 Makefile.inc --- libc/Makefile.inc 9 Jun 2018 22:41:55 -0000 1.19 +++ libc/Makefile.inc 20 Apr 2021 21:33:55 -0000 @@ -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 Index: libc/gen/Makefile.inc =================================================================== RCS file: /cvsroot/src/lib/libc/gen/Makefile.inc,v retrieving revision 1.211 diff -u -p -r1.211 Makefile.inc --- libc/gen/Makefile.inc 12 Apr 2021 03:57:07 -0000 1.211 +++ libc/gen/Makefile.inc 20 Apr 2021 21:33:55 -0000 @@ -207,8 +207,3 @@ errlist.c: errlist.awk ${NETBSDSRCDIR}/s ${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 Index: libc/gen/getprogname.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/getprogname.c,v retrieving revision 1.4 diff -u -p -r1.4 getprogname.c --- libc/gen/getprogname.c 6 Oct 2011 20:31:41 -0000 1.4 +++ libc/gen/getprogname.c 20 Apr 2021 21:33:55 -0000 @@ -42,13 +42,12 @@ __RCSID("$NetBSD: getprogname.c,v 1.4 20 #include "namespace.h" #include +#include "csu-common.h" #ifdef __weak_alias __weak_alias(getprogname,_getprogname) #endif -const char *__progname; - const char * getprogname(void) { Index: libc/gen/setproctitle.c =================================================================== RCS file: /cvsroot/src/lib/libc/gen/setproctitle.c,v retrieving revision 1.22 diff -u -p -r1.22 setproctitle.c --- libc/gen/setproctitle.c 3 Jan 2008 04:26:27 -0000 1.22 +++ libc/gen/setproctitle.c 20 Apr 2021 21:33:55 -0000 @@ -47,6 +47,7 @@ __RCSID("$NetBSD: setproctitle.c,v 1.22 #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, ...) { Index: libc/misc/Makefile.inc =================================================================== RCS file: /cvsroot/src/lib/libc/misc/Makefile.inc,v retrieving revision 1.4 diff -u -p -r1.4 Makefile.inc --- libc/misc/Makefile.inc 22 Apr 2020 23:32:25 -0000 1.4 +++ libc/misc/Makefile.inc 20 Apr 2021 21:33:55 -0000 @@ -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 Index: libc/misc/initfini.c =================================================================== RCS file: /cvsroot/src/lib/libc/misc/initfini.c,v retrieving revision 1.14 diff -u -p -r1.14 initfini.c --- libc/misc/initfini.c 17 Jun 2017 15:26:44 -0000 1.14 +++ libc/misc/initfini.c 20 Apr 2021 21:33:55 -0000 @@ -40,6 +40,7 @@ __RCSID("$NetBSD: initfini.c,v 1.14 2017 #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 Index: libc/stdlib/_env.c =================================================================== RCS file: /cvsroot/src/lib/libc/stdlib/_env.c,v retrieving revision 1.10 diff -u -p -r1.10 _env.c --- libc/stdlib/_env.c 22 Feb 2020 10:05:12 -0000 1.10 +++ libc/stdlib/_env.c 20 Apr 2021 21:33:55 -0000 @@ -44,6 +44,7 @@ __RCSID("$NetBSD: _env.c,v 1.10 2020/02/ #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)