diff options
author | Richard Lowe <richlowe@richlowe.net> | 2014-04-16 20:03:15 +0100 |
---|---|---|
committer | Richard Lowe <richlowe@richlowe.net> | 2017-10-02 15:55:19 -0400 |
commit | 3e76f9d6851ef6c63217178eb67278ec2809b944 (patch) | |
tree | 8c8e1172a6bdbce8420f12d2af84d19f658bbae1 /usr/src/lib/crt/common | |
parent | 2aca6c63d5cd09b4015887c19fcacf9df90967b0 (diff) | |
download | illumos-gate-3e76f9d6851ef6c63217178eb67278ec2809b944.tar.gz |
8609 want a position independent CRT
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Albert Lee <trisk@forkgnu.org>
Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/lib/crt/common')
-rw-r--r-- | usr/src/lib/crt/common/common-crt.c | 100 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-Xa.c | 43 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-Xc.c | 43 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-Xs.c | 45 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-Xt.c | 45 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-xpg4.c | 34 | ||||
-rw-r--r-- | usr/src/lib/crt/common/values-xpg6.c | 55 |
7 files changed, 365 insertions, 0 deletions
diff --git a/usr/src/lib/crt/common/common-crt.c b/usr/src/lib/crt/common/common-crt.c new file mode 100644 index 0000000000..5598c1f6fa --- /dev/null +++ b/usr/src/lib/crt/common/common-crt.c @@ -0,0 +1,100 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016, Richard Lowe. + */ + +/* + * That of the CRT startup routine which itself may be implemented in C. + */ + +#include <sys/feature_tests.h> +#include <sys/types.h> + +#include <stdlib.h> +#include <synch.h> +#include <unistd.h> + +#pragma weak _DYNAMIC +extern uintptr_t _DYNAMIC; + +#pragma weak environ = _environ +char **_environ = NULL; +char **___Argv = NULL; + +extern int main(int argc, char **argv, char **envp); +extern void _init(void); +extern void _fini(void); + +#pragma weak _start_crt_compiler +extern void _start_crt_compiler(int argc, char **argv); + +#if defined(__x86) +int __longdouble_used = 0; +extern void __fpstart(void); +#endif + +#if defined(__i386) /* Not amd64 */ +#pragma weak __fsr_init_value +extern long __fsr_init_value; +extern void __fsr(uintptr_t); +#endif + + +/* + * Defined here for ABI reasons, must match the definition in libc. + * If it cannot, a new symbol must be created. + */ +mutex_t __environ_lock = DEFAULTMUTEX; + +void +_start_crt(int argc, char **argv, void (*exit_handler)(void)) +{ + int ret = 0; + + /* + * On x86, we check whether we're a dynamic executable to see whether + * we'll receive an exit_handler. + * + * On SPARC, we just need to check whether the handler was NULL. + */ +#if defined(__x86) + if (&_DYNAMIC != NULL) + (void) atexit(exit_handler); +#elif defined(__sparc) + if (exit_handler != NULL) + (void) atexit(exit_handler); +#endif + + (void) atexit(_fini); + + _environ = argv + (argc + 1); + ___Argv = argv; + + if (&_start_crt_compiler != NULL) + _start_crt_compiler(argc, argv); + +#if defined(__x86) + __fpstart(); +#endif +#if defined(__i386) /* Not amd64 */ + /* + * Note that Studio cc(1) sets the _value of the symbol_, that is, its + * address. Not the value _at_ that address. + */ + __fsr((uintptr_t)&__fsr_init_value); +#endif + _init(); + ret = main(argc, argv, _environ); + exit(ret); + _exit(ret); +} diff --git a/usr/src/lib/crt/common/values-Xa.c b/usr/src/lib/crt/common/values-Xa.c new file mode 100644 index 0000000000..041a6dc8b0 --- /dev/null +++ b/usr/src/lib/crt/common/values-Xa.c @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#include <sys/types.h> +#include <math.h> + +/* + * variables which differ depending on the + * compilation mode + * + * ANSI conforming mode + * This file is linked into the a.out immediately following + * the startup routine if the -Xa compilation mode is selected + */ + +const enum version _lib_version = ansi_1; diff --git a/usr/src/lib/crt/common/values-Xc.c b/usr/src/lib/crt/common/values-Xc.c new file mode 100644 index 0000000000..ef70ae97a7 --- /dev/null +++ b/usr/src/lib/crt/common/values-Xc.c @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#include <sys/types.h> +#include <math.h> + +/* + * variables which differ depending on the + * compilation mode + * + * Strict ANSI mode + * This file is linked into the a.out immediately following + * the startup routine if the -Xc compilation mode is selected + */ + +const enum version _lib_version = strict_ansi; diff --git a/usr/src/lib/crt/common/values-Xs.c b/usr/src/lib/crt/common/values-Xs.c new file mode 100644 index 0000000000..b876d90724 --- /dev/null +++ b/usr/src/lib/crt/common/values-Xs.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#include <sys/types.h> +#include <math.h> + +/* + * variables which differ depending on the + * compilation mode + * + * C Issue 4.2 compatibility mode + * This file is linked into the a.out by default if + * no compilation mode was specified or if the -Xt option + * was specified - the linking occurs if there is an unresolved + * reference to _lib_version + */ + +const enum version _lib_version = c_issue_4; diff --git a/usr/src/lib/crt/common/values-Xt.c b/usr/src/lib/crt/common/values-Xt.c new file mode 100644 index 0000000000..b876d90724 --- /dev/null +++ b/usr/src/lib/crt/common/values-Xt.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +#include <sys/types.h> +#include <math.h> + +/* + * variables which differ depending on the + * compilation mode + * + * C Issue 4.2 compatibility mode + * This file is linked into the a.out by default if + * no compilation mode was specified or if the -Xt option + * was specified - the linking occurs if there is an unresolved + * reference to _lib_version + */ + +const enum version _lib_version = c_issue_4; diff --git a/usr/src/lib/crt/common/values-xpg4.c b/usr/src/lib/crt/common/values-xpg4.c new file mode 100644 index 0000000000..54b5afc883 --- /dev/null +++ b/usr/src/lib/crt/common/values-xpg4.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <sys/types.h> +/* + * Setting thie value to 1 enables XPG4 mode for APIs + * which have differing runtime behaviour from XPG3 to XPG4. + * See usr/src/lib/libc/port/gen/xpg4.c for the default value. + */ + +int __xpg4 = 1; diff --git a/usr/src/lib/crt/common/values-xpg6.c b/usr/src/lib/crt/common/values-xpg6.c new file mode 100644 index 0000000000..2e9e64efc2 --- /dev/null +++ b/usr/src/lib/crt/common/values-xpg6.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * __xpg6 (C99/SUSv3) was first introduced in Solaris 10. + * + * This file is NOT linked into libc. See xpg6.c. + * This value is linked into an application when the application is + * requesting conforming C99/SUSv3 behavior. This is usually done + * with the c99 utility. + * + * __xpg6 is used to control certain behaviors between the C99 standard, + * the SUSv3 standard, and Solaris. More explanation in inc/xpg6.h. + * The XPG6 C compiler utility (c99) will add an object file that contains an + * alternate definition for __xpg6. The symbol interposition provided + * by the linker will allow libc to find that symbol instead. + * + * Possible settings are available and documented in inc/xpg6.h. + */ + +/* + * This setting enables strictly conforming C99/SUSv3 behavior. + */ + +#include "xpg6.h" + +unsigned int __xpg6 = _C99SUSv3_mode_ON; + +/* + * Also turn on XPG4 mode. + */ +int __xpg4 = 1; |