Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib Instead of compiling files with -fcommon, create an incl...
details: https://anonhg.NetBSD.org/src/rev/e4a97e98ae30
branches: trunk
changeset: 982649:e4a97e98ae30
user: christos <christos%NetBSD.org@localhost>
date: Tue Apr 20 21:42:31 2021 +0000
description:
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@
diffstat:
lib/csu/Makefile | 5 +----
lib/csu/common/crt0-common.c | 14 ++++++++------
lib/csu/common/csu-common.h | 38 ++++++++++++++++++++++++++++++++++++++
lib/libc/Makefile.inc | 4 +++-
lib/libc/gen/Makefile.inc | 7 +------
lib/libc/gen/getprogname.c | 7 +++----
lib/libc/gen/setproctitle.c | 11 +++--------
lib/libc/misc/Makefile.inc | 5 +----
lib/libc/misc/initfini.c | 9 ++++++---
lib/libc/stdlib/_env.c | 7 +++----
10 files changed, 67 insertions(+), 40 deletions(-)
diffs (298 lines):
diff -r 1565c35676a1 -r e4a97e98ae30 lib/csu/Makefile
--- a/lib/csu/Makefile Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/csu/Makefile Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
.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 -r 1565c35676a1 -r e4a97e98ae30 lib/csu/common/crt0-common.c
--- a/lib/csu/common/crt0-common.c Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/csu/common/crt0-common.c Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
#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 unsigned char __etext, __eprol;
#endif /* MCRT0 */
-char **environ;
-struct ps_strings *__ps_strings = 0;
+static char empty_string[] = "";
-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 -r 1565c35676a1 -r e4a97e98ae30 lib/csu/common/csu-common.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/csu/common/csu-common.h Tue Apr 20 21:42:31 2021 +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 __common;
+extern char **environ __common;
+extern struct ps_strings *__ps_strings __common;
diff -r 1565c35676a1 -r e4a97e98ae30 lib/libc/Makefile.inc
--- a/lib/libc/Makefile.inc Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/Makefile.inc Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
.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 -r 1565c35676a1 -r e4a97e98ae30 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/gen/Makefile.inc Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
${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 -r 1565c35676a1 -r e4a97e98ae30 lib/libc/gen/getprogname.c
--- a/lib/libc/gen/getprogname.c Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/gen/getprogname.c Tue Apr 20 21:42:31 2021 +0000
@@ -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)
{
diff -r 1565c35676a1 -r e4a97e98ae30 lib/libc/gen/setproctitle.c
--- a/lib/libc/gen/setproctitle.c Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/gen/setproctitle.c Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "csu-common.h"
#ifdef __weak_alias
__weak_alias(setproctitle,_setproctitle)
@@ -54,12 +55,6 @@
#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 -r 1565c35676a1 -r e4a97e98ae30 lib/libc/misc/Makefile.inc
--- a/lib/libc/misc/Makefile.inc Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/misc/Makefile.inc Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
# 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 -r 1565c35676a1 -r e4a97e98ae30 lib/libc/misc/initfini.c
--- a/lib/libc/misc/initfini.c Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/misc/initfini.c Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
#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 @@
* 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 -r 1565c35676a1 -r e4a97e98ae30 lib/libc/stdlib/_env.c
--- a/lib/libc/stdlib/_env.c Tue Apr 20 21:20:24 2021 +0000
+++ b/lib/libc/stdlib/_env.c Tue Apr 20 21:42:31 2021 +0000
@@ -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 @@
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
+#include "csu-common.h"
#include "env.h"
#include "local.h"
@@ -94,8 +95,6 @@
/* 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)
Home |
Main Index |
Thread Index |
Old Index