Module Name: src Committed By: christos Date: Tue Apr 20 21:42:32 UTC 2021
Modified Files: src/lib/csu: Makefile src/lib/csu/common: crt0-common.c src/lib/libc: Makefile.inc src/lib/libc/gen: Makefile.inc getprogname.c setproctitle.c src/lib/libc/misc: Makefile.inc initfini.c src/lib/libc/stdlib: _env.c Added Files: src/lib/csu/common: csu-common.h Log Message: Instead of compiling files with -fcommon, create an include file and declare the 3 symbols that need to be common using an attribute. Put all the 3 symbol definitions in libc in one place (initfini.c). Reviewed by joerg@ To generate a diff of this commit: cvs rdiff -u -r1.40 -r1.41 src/lib/csu/Makefile cvs rdiff -u -r1.23 -r1.24 src/lib/csu/common/crt0-common.c cvs rdiff -u -r0 -r1.1 src/lib/csu/common/csu-common.h cvs rdiff -u -r1.19 -r1.20 src/lib/libc/Makefile.inc cvs rdiff -u -r1.211 -r1.212 src/lib/libc/gen/Makefile.inc cvs rdiff -u -r1.4 -r1.5 src/lib/libc/gen/getprogname.c cvs rdiff -u -r1.22 -r1.23 src/lib/libc/gen/setproctitle.c cvs rdiff -u -r1.4 -r1.5 src/lib/libc/misc/Makefile.inc cvs rdiff -u -r1.14 -r1.15 src/lib/libc/misc/initfini.c cvs rdiff -u -r1.10 -r1.11 src/lib/libc/stdlib/_env.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/csu/Makefile diff -u src/lib/csu/Makefile:1.40 src/lib/csu/Makefile:1.41 --- src/lib/csu/Makefile:1.40 Wed Apr 22 19:32:25 2020 +++ src/lib/csu/Makefile Tue Apr 20 17:42:31 2021 @@ -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_ .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: src/lib/csu/common/crt0-common.c diff -u src/lib/csu/common/crt0-common.c:1.23 src/lib/csu/common/crt0-common.c:1.24 --- src/lib/csu/common/crt0-common.c:1.23 Fri Dec 28 15:12:35 2018 +++ src/lib/csu/common/crt0-common.c Tue Apr 20 17:42:31 2021 @@ -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 <sys/cdefs.h> -__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 <sys/types.h> #include <sys/exec.h> @@ -46,6 +46,8 @@ __RCSID("$NetBSD: crt0-common.c,v 1.23 2 #include <stdlib.h> #include <unistd.h> +#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: src/lib/libc/Makefile.inc diff -u src/lib/libc/Makefile.inc:1.19 src/lib/libc/Makefile.inc:1.20 --- src/lib/libc/Makefile.inc:1.19 Sat Jun 9 18:41:55 2018 +++ src/lib/libc/Makefile.inc Tue Apr 20 17:42:31 2021 @@ -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 Index: src/lib/libc/gen/Makefile.inc diff -u src/lib/libc/gen/Makefile.inc:1.211 src/lib/libc/gen/Makefile.inc:1.212 --- src/lib/libc/gen/Makefile.inc:1.211 Sun Apr 11 23:57:07 2021 +++ src/lib/libc/gen/Makefile.inc Tue Apr 20 17:42:32 2021 @@ -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}/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: src/lib/libc/gen/getprogname.c diff -u src/lib/libc/gen/getprogname.c:1.4 src/lib/libc/gen/getprogname.c:1.5 --- src/lib/libc/gen/getprogname.c:1.4 Thu Oct 6 16:31:41 2011 +++ src/lib/libc/gen/getprogname.c Tue Apr 20 17:42:32 2021 @@ -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 <sys/cdefs.h> #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 <stdlib.h> +#include "csu-common.h" #ifdef __weak_alias __weak_alias(getprogname,_getprogname) #endif -const char *__progname; - const char * getprogname(void) { Index: src/lib/libc/gen/setproctitle.c diff -u src/lib/libc/gen/setproctitle.c:1.22 src/lib/libc/gen/setproctitle.c:1.23 --- src/lib/libc/gen/setproctitle.c:1.22 Wed Jan 2 23:26:27 2008 +++ src/lib/libc/gen/setproctitle.c Tue Apr 20 17:42:32 2021 @@ -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 <sys/cdefs.h> #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 #include <stdio.h> #include <stdlib.h> #include <string.h> +#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: src/lib/libc/misc/Makefile.inc diff -u src/lib/libc/misc/Makefile.inc:1.4 src/lib/libc/misc/Makefile.inc:1.5 --- src/lib/libc/misc/Makefile.inc:1.4 Wed Apr 22 19:32:25 2020 +++ src/lib/libc/misc/Makefile.inc Tue Apr 20 17:42:32 2021 @@ -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 Index: src/lib/libc/misc/initfini.c diff -u src/lib/libc/misc/initfini.c:1.14 src/lib/libc/misc/initfini.c:1.15 --- src/lib/libc/misc/initfini.c:1.14 Sat Jun 17 11:26:44 2017 +++ src/lib/libc/misc/initfini.c Tue Apr 20 17:42:32 2021 @@ -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 <sys/cdefs.h> -__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 #include <sys/exec.h> #include <sys/tls.h> #include <stdbool.h> +#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: src/lib/libc/stdlib/_env.c diff -u src/lib/libc/stdlib/_env.c:1.10 src/lib/libc/stdlib/_env.c:1.11 --- src/lib/libc/stdlib/_env.c:1.10 Sat Feb 22 05:05:12 2020 +++ src/lib/libc/stdlib/_env.c Tue Apr 20 17:42:32 2021 @@ -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 <sys/cdefs.h> #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/ #include <stdlib.h> #include <stddef.h> #include <string.h> +#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) Added files: Index: src/lib/csu/common/csu-common.h diff -u /dev/null src/lib/csu/common/csu-common.h:1.1 --- /dev/null Tue Apr 20 17:42:32 2021 +++ src/lib/csu/common/csu-common.h Tue Apr 20 17:42:31 2021 @@ -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;