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@
This commit is contained in:
christos 2021-04-20 21:42:31 +00:00
parent 105b25615a
commit c510facea2
10 changed files with 67 additions and 40 deletions

View File

@ -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"

View File

@ -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 2018/12/28 20:12:35 christos Exp $");
#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 *);

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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 2008/01/03 04:26:27 christos Exp $");
#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, ...)
{

View File

@ -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

View File

@ -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/06/17 15:26:44 joerg Exp $");
#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

View File

@ -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/22 10:05:12 kamil Exp $");
#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)