diff options
| author | Konstantin Belousov <kib@FreeBSD.org> | 2022-10-30 23:47:44 +0000 |
|---|---|---|
| committer | Konstantin Belousov <kib@FreeBSD.org> | 2023-03-11 22:50:03 +0000 |
| commit | 51015e6d0f570239b0c2088dc6cf2b018928375d (patch) | |
| tree | bac148baabfb85020f64956855b2e2c7c2cab1cd /lib/csu | |
| parent | 3c3a434f8ee867e6e4a69de07bf0811f2ae0c46e (diff) | |
Diffstat (limited to 'lib/csu')
| -rw-r--r-- | lib/csu/aarch64/Makefile | 1 | ||||
| -rw-r--r-- | lib/csu/aarch64/crt1_c.c | 33 | ||||
| -rw-r--r-- | lib/csu/aarch64/reloc.c | 46 | ||||
| -rw-r--r-- | lib/csu/amd64/Makefile | 2 | ||||
| -rw-r--r-- | lib/csu/amd64/crt1_c.c | 30 | ||||
| -rw-r--r-- | lib/csu/amd64/reloc.c | 63 | ||||
| -rw-r--r-- | lib/csu/arm/Makefile | 2 | ||||
| -rw-r--r-- | lib/csu/arm/crt1_c.c | 31 | ||||
| -rw-r--r-- | lib/csu/common/csu_common.h | 50 | ||||
| -rw-r--r-- | lib/csu/common/ignore_init.c | 140 | ||||
| -rw-r--r-- | lib/csu/i386/Makefile | 1 | ||||
| -rw-r--r-- | lib/csu/i386/crt1_c.c | 30 | ||||
| -rw-r--r-- | lib/csu/i386/reloc.c | 85 | ||||
| -rw-r--r-- | lib/csu/powerpc/Makefile | 1 | ||||
| -rw-r--r-- | lib/csu/powerpc/crt1_c.c | 28 | ||||
| -rw-r--r-- | lib/csu/powerpc64/Makefile | 2 | ||||
| -rw-r--r-- | lib/csu/powerpc64/crt1_c.c | 61 | ||||
| -rw-r--r-- | lib/csu/powerpc64/reloc.c | 43 | ||||
| -rw-r--r-- | lib/csu/riscv/Makefile | 2 | ||||
| -rw-r--r-- | lib/csu/riscv/crt1_c.c | 29 |
20 files changed, 90 insertions, 590 deletions
diff --git a/lib/csu/aarch64/Makefile b/lib/csu/aarch64/Makefile index e4c9029fcacc..d8d0d3fd8f99 100644 --- a/lib/csu/aarch64/Makefile +++ b/lib/csu/aarch64/Makefile @@ -3,7 +3,6 @@ .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} -CFLAGS+= -DCRT_IRELOC_RELA CRT1OBJS+= crt1_s.o diff --git a/lib/csu/aarch64/crt1_c.c b/lib/csu/aarch64/crt1_c.c index 9b3ffbff22d0..7f4fea37ba1a 100644 --- a/lib/csu/aarch64/crt1_c.c +++ b/lib/csu/aarch64/crt1_c.c @@ -32,42 +32,19 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdlib.h> - #include "libc_private.h" -#include "ignore_init.c" - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif - -extern long * _end; +#include "csu_common.h" -void __start(int, char **, char **, void (*)(void)); +void __start(int, char **, char **, void (*)(void)) __dead2; /* The entry function. */ void __start(int argc, char *argv[], char *env[], void (*cleanup)(void)) { - - handle_argv(argc, argv, env); - - if (&_DYNAMIC != NULL) - atexit(cleanup); - else { - process_irelocs(); - _init_tls(); - } - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); __asm__("eprol:"); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } diff --git a/lib/csu/aarch64/reloc.c b/lib/csu/aarch64/reloc.c deleted file mode 100644 index f3dbf3e3b570..000000000000 --- a/lib/csu/aarch64/reloc.c +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * Copyright (c) 2019 Leandro Lupori - * Copyright (c) 2021 The FreeBSD Foundation - * - * Portions of this software were developed by Andrew Turner - * under sponsorship from the FreeBSD Foundation. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -static void -crt1_handle_rela(const Elf_Rela *r) -{ - typedef Elf_Addr (*ifunc_resolver_t)( - uint64_t, uint64_t, uint64_t, uint64_t, - uint64_t, uint64_t, uint64_t, uint64_t); - Elf_Addr *ptr, *where, target; - - switch (ELF_R_TYPE(r->r_info)) { - case R_AARCH64_IRELATIVE: - ptr = (Elf_Addr *)r->r_addend; - where = (Elf_Addr *)r->r_offset; - target = ((ifunc_resolver_t)ptr)(0, 0, 0, 0, 0, 0, 0, 0); - *where = target; - break; - } -} diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile index 19610749b59c..9f3afb4cc1a0 100644 --- a/lib/csu/amd64/Makefile +++ b/lib/csu/amd64/Makefile @@ -3,6 +3,6 @@ .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} -CFLAGS+= -fno-omit-frame-pointer -DCRT_IRELOC_RELA +CFLAGS+= -fno-omit-frame-pointer .include <bsd.lib.mk> diff --git a/lib/csu/amd64/crt1_c.c b/lib/csu/amd64/crt1_c.c index f1c99de9ffe0..a7b3213e4b9b 100644 --- a/lib/csu/amd64/crt1_c.c +++ b/lib/csu/amd64/crt1_c.c @@ -29,19 +29,10 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdlib.h> - #include "libc_private.h" -#include "ignore_init.c" - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif +#include "csu_common.h" -void _start(char **, void (*)(void)); +void _start(char **, void (*)(void)) __dead2; /* The entry function. */ void @@ -54,21 +45,10 @@ _start(char **ap, void (*cleanup)(void)) argc = *(long *)(void *)ap; argv = ap + 1; env = ap + 2 + argc; - handle_argv(argc, argv, env); - - if (&_DYNAMIC != NULL) { - atexit(cleanup); - } else { - process_irelocs(); - _init_tls(); - } - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); __asm__("eprol:"); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } diff --git a/lib/csu/amd64/reloc.c b/lib/csu/amd64/reloc.c deleted file mode 100644 index adb52e42a32c..000000000000 --- a/lib/csu/amd64/reloc.c +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * Copyright (c) 2018 The FreeBSD Foundation - * - * This software was developed by Konstantin Belousov <kib@FreeBSD.org> - * under sponsorship from the FreeBSD Foundation. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <machine/specialreg.h> -#include <machine/cpufunc.h> - -static void -crt1_handle_rela(const Elf_Rela *r) -{ - Elf_Addr *ptr, *where, target; - u_int p[4]; - uint32_t cpu_feature, cpu_feature2; - uint32_t cpu_stdext_feature, cpu_stdext_feature2; - - do_cpuid(1, p); - cpu_feature = p[3]; - cpu_feature2 = p[2]; - do_cpuid(0, p); - if (p[0] >= 7) { - cpuid_count(7, 0, p); - cpu_stdext_feature = p[1]; - cpu_stdext_feature2 = p[2]; - } else { - cpu_stdext_feature = 0; - cpu_stdext_feature2 = 0; - } - - switch (ELF_R_TYPE(r->r_info)) { - case R_X86_64_IRELATIVE: - ptr = (Elf_Addr *)r->r_addend; - where = (Elf_Addr *)r->r_offset; - target = ((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, - uint32_t))ptr)(cpu_feature, cpu_feature2, - cpu_stdext_feature, cpu_stdext_feature2); - *where = target; - break; - } -} diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile index 666bf569b786..a39afde66300 100644 --- a/lib/csu/arm/Makefile +++ b/lib/csu/arm/Makefile @@ -2,8 +2,6 @@ .PATH: ${.CURDIR:H}/common -CFLAGS+= -DCRT_IRELOC_SUPPRESS - CRT1OBJS+= crt1_s.o .include <bsd.lib.mk> diff --git a/lib/csu/arm/crt1_c.c b/lib/csu/arm/crt1_c.c index 9725f173ff78..8a4abf491bb3 100644 --- a/lib/csu/arm/crt1_c.c +++ b/lib/csu/arm/crt1_c.c @@ -46,50 +46,33 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/elf_common.h> -#include <stdlib.h> #include "libc_private.h" -#include "ignore_init.c" +#include "csu_common.h" struct Struct_Obj_Entry; struct ps_strings; -extern void _start(int, char **, char **, const struct Struct_Obj_Entry *, - void (*)(void), struct ps_strings *); - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif +void _start(int, char **, char **, const struct Struct_Obj_Entry *, + void (*)(void), struct ps_strings *) __dead2; struct ps_strings *__ps_strings; void __start(int, char **, char **, struct ps_strings *, - const struct Struct_Obj_Entry *, void (*)(void)); + const struct Struct_Obj_Entry *, void (*)(void)) __dead2; -/* ARGSUSED */ void __start(int argc, char **argv, char **env, struct ps_strings *ps_strings, const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void)) { - - handle_argv(argc, argv, env); - if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; - if (&_DYNAMIC != NULL) - atexit(cleanup); - else - _init_tls(); #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } #ifdef GCRT diff --git a/lib/csu/common/csu_common.h b/lib/csu/common/csu_common.h new file mode 100644 index 000000000000..76f192f72885 --- /dev/null +++ b/lib/csu/common/csu_common.h @@ -0,0 +1,50 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright 1996-1998 John D. Polstra. + * 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 AUTHOR ``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 AUTHOR 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. + */ + +#ifdef _CSU_COMMON_H_ + +/* + * This file includes both definitions and declarations, it can be + * included only into one compilation unit for csu objects. We cannot + * practically check this, but at least guard against + * double-inclusion. + */ +#error "Include this file only once" +#else +#define _CSU_COMMON_H_ + +char **environ; +const char *__progname = ""; + +#ifdef GCRT +extern int eprol; +extern int etext; +#endif + +int main(int, char **, char **); + +#endif /* _CSU_COMMON_H_ */ diff --git a/lib/csu/common/ignore_init.c b/lib/csu/common/ignore_init.c deleted file mode 100644 index 2cdb869c4a87..000000000000 --- a/lib/csu/common/ignore_init.c +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-1-Clause - * - * Copyright 2012 Konstantin Belousov <kib@FreeBSD.org> - * Copyright (c) 2018 The FreeBSD Foundation - * - * Parts of this software was developed by Konstantin Belousov - * <kib@FreeBSD.org> under sponsorship from the FreeBSD Foundation. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/elf.h> -#include <sys/elf_common.h> - -extern int main(int, char **, char **); - -extern void (*__preinit_array_start[])(int, char **, char **) __hidden; -extern void (*__preinit_array_end[])(int, char **, char **) __hidden; -extern void (*__init_array_start[])(int, char **, char **) __hidden; -extern void (*__init_array_end[])(int, char **, char **) __hidden; -extern void (*__fini_array_start[])(void) __hidden; -extern void (*__fini_array_end[])(void) __hidden; -extern void _fini(void) __hidden; -extern void _init(void) __hidden; - -extern int _DYNAMIC; -#pragma weak _DYNAMIC - -#if defined(CRT_IRELOC_RELA) -extern const Elf_Rela __rela_iplt_start[] __weak_symbol __hidden; -extern const Elf_Rela __rela_iplt_end[] __weak_symbol __hidden; - -#include "reloc.c" - -static void -process_irelocs(void) -{ - const Elf_Rela *r; - - for (r = &__rela_iplt_start[0]; r < &__rela_iplt_end[0]; r++) - crt1_handle_rela(r); -} -#elif defined(CRT_IRELOC_REL) -extern const Elf_Rel __rel_iplt_start[] __weak_symbol __hidden; -extern const Elf_Rel __rel_iplt_end[] __weak_symbol __hidden; - -#include "reloc.c" - -static void -process_irelocs(void) -{ - const Elf_Rel *r; - - for (r = &__rel_iplt_start[0]; r < &__rel_iplt_end[0]; r++) - crt1_handle_rel(r); -} -#elif defined(CRT_IRELOC_SUPPRESS) -#else -#error "Define platform reloc type" -#endif - -char **environ; -const char *__progname = ""; - -static void -finalizer(void) -{ - void (*fn)(void); - size_t array_size, n; - - array_size = __fini_array_end - __fini_array_start; - for (n = array_size; n > 0; n--) { - fn = __fini_array_start[n - 1]; - if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) - (fn)(); - } - _fini(); -} - -static inline void -handle_static_init(int argc, char **argv, char **env) -{ - void (*fn)(int, char **, char **); - size_t array_size, n; - - if (&_DYNAMIC != NULL) - return; - - atexit(finalizer); - - array_size = __preinit_array_end - __preinit_array_start; - for (n = 0; n < array_size; n++) { - fn = __preinit_array_start[n]; - if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) - fn(argc, argv, env); - } - _init(); - array_size = __init_array_end - __init_array_start; - for (n = 0; n < array_size; n++) { - fn = __init_array_start[n]; - if ((uintptr_t)fn != 0 && (uintptr_t)fn != 1) - fn(argc, argv, env); - } -} - -static inline void -handle_argv(int argc, char *argv[], char **env) -{ - const char *s; - - if (environ == NULL) - environ = env; - if (argc > 0 && argv[0] != NULL) { - __progname = argv[0]; - for (s = __progname; *s != '\0'; s++) { - if (*s == '/') - __progname = s + 1; - } - } -} diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile index cfa7b4d5b399..d8d0d3fd8f99 100644 --- a/lib/csu/i386/Makefile +++ b/lib/csu/i386/Makefile @@ -3,7 +3,6 @@ .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} -CFLAGS+= -DCRT_IRELOC_REL CRT1OBJS+= crt1_s.o diff --git a/lib/csu/i386/crt1_c.c b/lib/csu/i386/crt1_c.c index b39134824f7e..d49c763749a3 100644 --- a/lib/csu/i386/crt1_c.c +++ b/lib/csu/i386/crt1_c.c @@ -29,20 +29,10 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdlib.h> - #include "libc_private.h" -#include "ignore_init.c" - -extern void _start(char *, ...); - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif +#include "csu_common.h" +void _start(char *, ...); void _start1(void (*)(void), int, char *[]) __dead2; /* The entry function, C part. */ @@ -52,22 +42,12 @@ _start1(void (*cleanup)(void), int argc, char *argv[]) char **env; env = argv + argc + 1; - handle_argv(argc, argv, env); - if (&_DYNAMIC != NULL) { - atexit(cleanup); - } else { - process_irelocs(); - _init_tls(); - } - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); __asm__("eprol:"); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } __asm(".hidden _start1"); diff --git a/lib/csu/i386/reloc.c b/lib/csu/i386/reloc.c deleted file mode 100644 index 13438035841d..000000000000 --- a/lib/csu/i386/reloc.c +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * Copyright (c) 2018 The FreeBSD Foundation - * - * This software was developed by Konstantin Belousov <kib@FreeBSD.org> - * under sponsorship from the FreeBSD Foundation. - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <machine/specialreg.h> -#include <machine/cpufunc.h> - -static void -crt1_handle_rel(const Elf_Rel *r) -{ - Elf_Addr *where, target; - u_int cpuid_supported, p[4]; - uint32_t cpu_feature, cpu_feature2; - uint32_t cpu_stdext_feature, cpu_stdext_feature2; - - __asm __volatile( - " pushfl\n" - " popl %%eax\n" - " movl %%eax,%%ecx\n" - " xorl $0x200000,%%eax\n" - " pushl %%eax\n" - " popfl\n" - " pushfl\n" - " popl %%eax\n" - " xorl %%eax,%%ecx\n" - " je 1f\n" - " movl $1,%0\n" - " jmp 2f\n" - "1: movl $0,%0\n" - "2:\n" - : "=r" (cpuid_supported) : : "eax", "ecx", "cc"); - if (cpuid_supported) { - do_cpuid(1, p); - cpu_feature = p[3]; - cpu_feature2 = p[2]; - do_cpuid(0, p); - if (p[0] >= 7) { - cpuid_count(7, 0, p); - cpu_stdext_feature = p[1]; - cpu_stdext_feature2 = p[2]; - } else { - cpu_stdext_feature = 0; - cpu_stdext_feature2 = 0; - } - } else { - cpu_feature = 0; - cpu_feature2 = 0; - cpu_stdext_feature = 0; - cpu_stdext_feature2 = 0; - } - - switch (ELF_R_TYPE(r->r_info)) { - case R_386_IRELATIVE: - where = (Elf_Addr *)r->r_offset; - target = ((Elf_Addr (*)(uint32_t, uint32_t, uint32_t, - uint32_t))*where)(cpu_feature, cpu_feature2, - cpu_stdext_feature, cpu_stdext_feature2); - *where = target; - break; - } -} diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile index 44be804c7c3f..a4d7846b8574 100644 --- a/lib/csu/powerpc/Makefile +++ b/lib/csu/powerpc/Makefile @@ -3,6 +3,5 @@ .PATH: ${.CURDIR:H}/common OBJS+= crtsavres.o -CFLAGS+= -DCRT_IRELOC_SUPPRESS .include <bsd.lib.mk> diff --git a/lib/csu/powerpc/crt1_c.c b/lib/csu/powerpc/crt1_c.c index 8ad291bb4f4d..72fc7040e237 100644 --- a/lib/csu/powerpc/crt1_c.c +++ b/lib/csu/powerpc/crt1_c.c @@ -47,22 +47,15 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include "libc_private.h" -#include "ignore_init.c" +#include "csu_common.h" struct Struct_Obj_Entry; struct ps_strings; -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif - struct ps_strings *__ps_strings; void _start(int, char **, char **, const struct Struct_Obj_Entry *, - void (*)(void), struct ps_strings *); + void (*)(void), struct ps_strings *) __dead2; /* The entry function. */ /* @@ -75,25 +68,14 @@ _start(int argc, char **argv, char **env, const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), struct ps_strings *ps_strings) { - - - handle_argv(argc, argv, env); - if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; - if (&_DYNAMIC != NULL) - atexit(cleanup); - else - _init_tls(); - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } #ifdef GCRT diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile index 564e8dfbf288..0101b516a055 100644 --- a/lib/csu/powerpc64/Makefile +++ b/lib/csu/powerpc64/Makefile @@ -4,7 +4,7 @@ OBJS+= crtsavres.o CFLAGS+= -I${.CURDIR} \ - -mlongcall -DCRT_IRELOC_RELA + -mlongcall CLEANFILES+= crtsavres.S diff --git a/lib/csu/powerpc64/crt1_c.c b/lib/csu/powerpc64/crt1_c.c index c9115be75fba..c7b9e89a23a8 100644 --- a/lib/csu/powerpc64/crt1_c.c +++ b/lib/csu/powerpc64/crt1_c.c @@ -44,87 +44,38 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdlib.h> #include <stdint.h> #include <sys/elf.h> -static uint32_t cpu_features; -static uint32_t cpu_features2; - #include "libc_private.h" -#include "ignore_init.c" +#include "csu_common.h" struct Struct_Obj_Entry; struct ps_strings; -extern void _start(int, char **, char **, const struct Struct_Obj_Entry *, - void (*)(void), struct ps_strings *); - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif +void _start(int, char **, char **, const struct Struct_Obj_Entry *, + void (*)(void), struct ps_strings *) __dead2; struct ps_strings *__ps_strings; -static void -init_cpu_features(char **env) -{ - const Elf_Auxinfo *aux; - - /* Find the auxiliary vector on the stack. */ - while (*env++ != 0) /* Skip over environment, and NULL terminator */ - ; - aux = (const Elf_Auxinfo *)env; - - /* Digest the auxiliary vector. */ - for (; aux->a_type != AT_NULL; aux++) { - switch (aux->a_type) { - case AT_HWCAP: - cpu_features = (uint32_t)aux->a_un.a_val; - break; - case AT_HWCAP2: - cpu_features2 = (uint32_t)aux->a_un.a_val; - break; - } - } -} - - /* The entry function. */ /* * First 5 arguments are specified by the PowerPC SVR4 ABI. * The last argument, ps_strings, is a BSD extension. */ -/* ARGSUSED */ void _start(int argc, char **argv, char **env, const struct Struct_Obj_Entry *obj __unused, void (*cleanup)(void), struct ps_strings *ps_strings) { - - handle_argv(argc, argv, env); - if (ps_strings != (struct ps_strings *)0) __ps_strings = ps_strings; - if (&_DYNAMIC != NULL) - atexit(cleanup); - else { - init_cpu_features(env); - process_irelocs(); - _init_tls(); - } - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } #ifdef GCRT diff --git a/lib/csu/powerpc64/reloc.c b/lib/csu/powerpc64/reloc.c deleted file mode 100644 index afa3f2fbec18..000000000000 --- a/lib/csu/powerpc64/reloc.c +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * Copyright (c) 2019 Leandro Lupori - * - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -static void -crt1_handle_rela(const Elf_Rela *r) -{ - typedef Elf_Addr (*ifunc_resolver_t)( - uint32_t, uint32_t, uint64_t, uint64_t, - uint64_t, uint64_t, uint64_t, uint64_t); - Elf_Addr *ptr, *where, target; - - switch (ELF_R_TYPE(r->r_info)) { - case R_PPC_IRELATIVE: - ptr = (Elf_Addr *)r->r_addend; - where = (Elf_Addr *)r->r_offset; - target = ((ifunc_resolver_t)ptr)(cpu_features, cpu_features2, - 0, 0, 0, 0, 0, 0); - *where = target; - break; - } -} diff --git a/lib/csu/riscv/Makefile b/lib/csu/riscv/Makefile index 666bf569b786..a39afde66300 100644 --- a/lib/csu/riscv/Makefile +++ b/lib/csu/riscv/Makefile @@ -2,8 +2,6 @@ .PATH: ${.CURDIR:H}/common -CFLAGS+= -DCRT_IRELOC_SUPPRESS - CRT1OBJS+= crt1_s.o .include <bsd.lib.mk> diff --git a/lib/csu/riscv/crt1_c.c b/lib/csu/riscv/crt1_c.c index 11519e46c7f3..e08359e388f8 100644 --- a/lib/csu/riscv/crt1_c.c +++ b/lib/csu/riscv/crt1_c.c @@ -36,37 +36,18 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <stdlib.h> - #include "libc_private.h" -#include "ignore_init.c" - -#ifdef GCRT -extern void _mcleanup(void); -extern void monstartup(void *, void *); -extern int eprol; -extern int etext; -#endif +#include "csu_common.h" -void __start(int argc, char **argv, char **env, void (*cleanup)(void)); +void __start(int argc, char **argv, char **env, void (*cleanup)(void)) __dead2; void __start(int argc, char **argv, char **env, void (*cleanup)(void)) { - - handle_argv(argc, argv, env); - - if (&_DYNAMIC != NULL) - atexit(cleanup); - else - _init_tls(); - #ifdef GCRT - atexit(_mcleanup); - monstartup(&eprol, &etext); + __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext); __asm__("eprol:"); +#else + __libc_start1(argc, argv, env, cleanup, main); #endif - - handle_static_init(argc, argv, env); - exit(main(argc, argv, env)); } |
