diff options
Diffstat (limited to 'lib/csu')
34 files changed, 133 insertions, 105 deletions
diff --git a/lib/csu/Makefile b/lib/csu/Makefile index 1f8a403eb2c5..1e7a17bd35e9 100644 --- a/lib/csu/Makefile +++ b/lib/csu/Makefile @@ -1,4 +1,3 @@ - .include <src.opts.mk> .if exists(${.CURDIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/}) diff --git a/lib/csu/Makefile.inc b/lib/csu/Makefile.inc index faf01b293b92..c4a1f90b173f 100644 --- a/lib/csu/Makefile.inc +++ b/lib/csu/Makefile.inc @@ -1,3 +1,4 @@ +PACKAGE?= clibs-dev NO_WMISSING_VARIABLE_DECLARATIONS= # Can't instrument these files since that breaks non-sanitized programs. @@ -21,7 +22,8 @@ ACFLAGS+= -DLOCORE CFLAGS+= -DSTRIP_FBSDID CFLAGS+= -fno-omit-frame-pointer CFLAGS+= -I${.CURDIR:H}/common \ - -I${SRCTOP}/lib/libc/include + -I${SRCTOP}/lib/libc/include \ + -I${SRCTOP}/lib/libsys \ CFLAGS_CRTS= -DSHARED ${PICFLAG} @@ -54,6 +56,9 @@ Scrt1_c.o: ${CRT1SRC} Scrt1.o: Scrt1_c.o ${CRT1OBJS} ${CRT1OBJ} ${LD} ${_LDFLAGS} -o ${.TARGET} -r ${.ALLSRC:M*.o} +# __FreeBSD_version is recorded in crt1.o et al via crtbrand. +crtbrand.o: ${SRCTOP}/sys/sys/param.h + crtbegin.o: crtbegin.c crtbeginS.o: crtbegin.c crtbeginT.o: crtbegin.c diff --git a/lib/csu/aarch64/Makefile b/lib/csu/aarch64/Makefile index 0ea681ced6b4..24abd0b47585 100644 --- a/lib/csu/aarch64/Makefile +++ b/lib/csu/aarch64/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} diff --git a/lib/csu/aarch64/Makefile.depend b/lib/csu/aarch64/Makefile.depend new file mode 100644 index 000000000000..993ab0638f4a --- /dev/null +++ b/lib/csu/aarch64/Makefile.depend @@ -0,0 +1,11 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/aarch64/crt1_s.S b/lib/csu/aarch64/crt1_s.S index 97b4bff35a0b..1fb60f756a7a 100644 --- a/lib/csu/aarch64/crt1_s.S +++ b/lib/csu/aarch64/crt1_s.S @@ -30,6 +30,8 @@ */ #include <machine/asm.h> +#include <sys/elf_common.h> + /* * The program entry point * void _start(char **ap, void (*cleanup)(void)) __dead2 @@ -42,8 +44,8 @@ ENTRY(_start) add x2, x1, x0, lsl #3 /* env is after argv */ add x2, x2, #8 /* argv is null terminated */ #ifdef PIC - adrp x4, main - add x4, x4, :lo12:main + adrp x4, :got:main + ldr x4, [x4, :got_lo12:main] #else ldr x4, =main #endif @@ -62,3 +64,5 @@ eprol: END(_start) .section .note.GNU-stack,"",@progbits + +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/aarch64/crti.S b/lib/csu/aarch64/crti.S index 0a20f4c5e314..8bd2dfac1494 100644 --- a/lib/csu/aarch64/crti.S +++ b/lib/csu/aarch64/crti.S @@ -28,11 +28,14 @@ */ #include <machine/asm.h> +#include <sys/elf_common.h> + .section .init,"ax",@progbits .align 4 .globl _init .type _init,@function _init: + PAC_LR_SIGN stp x29, x30, [sp, #-16]! mov x29, sp @@ -41,6 +44,8 @@ _init: .globl _fini .type _fini,@function _fini: + PAC_LR_SIGN stp x29, x30, [sp, #-16]! mov x29, sp +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/aarch64/crtn.S b/lib/csu/aarch64/crtn.S index 924aa36aa045..441411f0ab83 100644 --- a/lib/csu/aarch64/crtn.S +++ b/lib/csu/aarch64/crtn.S @@ -28,13 +28,19 @@ */ #include <machine/asm.h> +#include <sys/elf_common.h> + .section .init,"ax",@progbits ldp x29, x30, [sp], #16 + PAC_LR_AUTH ret .section .fini,"ax",@progbits ldp x29, x30, [sp], #16 + PAC_LR_AUTH ret .section .note.GNU-stack,"",%progbits + +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) diff --git a/lib/csu/amd64/Makefile b/lib/csu/amd64/Makefile index 8dd4084f8633..80ae5484d662 100644 --- a/lib/csu/amd64/Makefile +++ b/lib/csu/amd64/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} diff --git a/lib/csu/amd64/crt1_s.S b/lib/csu/amd64/crt1_s.S index f7ea076d94f1..3ceea9289330 100644 --- a/lib/csu/amd64/crt1_s.S +++ b/lib/csu/amd64/crt1_s.S @@ -49,15 +49,12 @@ _start: #ifdef GCRT subq $16, %rsp #endif - movq %rsi, %rcx - movq %rdi, %rsi /* argv = ap */ - addq $8, %rsi /* argv += 1 */ - movq %rdi, %rdx /* env = ap */ - addq $16, %rdx /* env += 2 */ - movslq (%rdi), %rax - movl %eax, %edi /* argc = *(long *)(void *)ap */ - shlq $3, %rax - addq %rax, %rdx /* env += argc */ + movq %rsi, %rcx /* cleanup */ + movslq (%rdi), %rax /* long *ap; tmpargc = *ap */ + leaq 0x8(%rdi), %rsi /* argv = ap + 1 */ + leaq 0x10(%rdi, %rax, 8), %rdx /* env = ap + 2 + tmpargc */ + movl %eax, %edi /* argc = tmpargc */ + #ifdef PIC /* * XXX. %rip relative addressing is not intended for use in the diff --git a/lib/csu/arm/Makefile b/lib/csu/arm/Makefile index 96b361b0656c..5f5de9f9c61a 100644 --- a/lib/csu/arm/Makefile +++ b/lib/csu/arm/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common CRT1OBJS+= crt1_s.o diff --git a/lib/csu/arm/crt1_c.c b/lib/csu/arm/crt1_c.c index 7de2d333a598..bb40f262f5c2 100644 --- a/lib/csu/arm/crt1_c.c +++ b/lib/csu/arm/crt1_c.c @@ -41,7 +41,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> #include <sys/param.h> #include <sys/elf_common.h> diff --git a/lib/csu/common/crtbegin.c b/lib/csu/common/crtbegin.c index ddeec986a431..8ef9b8923c21 100644 --- a/lib/csu/common/crtbegin.c +++ b/lib/csu/common/crtbegin.c @@ -21,7 +21,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> #include <sys/param.h> #include "crt.h" @@ -67,19 +66,27 @@ static crt_func __DTOR_LIST__[] __section(".dtors") __used = { (crt_func)-1 }; +extern const char startof_dtors[] __asm(".startof..dtors") + __weak_symbol __hidden; +extern const char sizeof_dtors[] __asm(".sizeof..dtors") + __weak_symbol __hidden; + static void __do_global_dtors_aux(void) { crt_func fn; + uintptr_t dtors_end; int n; #ifdef SHARED run_cxa_finalize(); #endif + dtors_end = (uintptr_t)&startof_dtors + (uintptr_t)&sizeof_dtors; for (n = 1;; n++) { fn = __DTOR_LIST__[n]; - if (fn == (crt_func)0 || fn == (crt_func)-1) + if (fn == (crt_func)0 || fn == (crt_func)-1 || (dtors_end > 0 && + (uintptr_t)&__DTOR_LIST__[n] >= dtors_end)) break; fn(); } @@ -91,36 +98,3 @@ asm ( ".popsection \n" ); #endif - -/* - * Handler for gcj. These provide a _Jv_RegisterClasses function and fill - * out the .jcr section. We just need to call this function with a pointer - * to the appropriate section. - */ -extern void _Jv_RegisterClasses(void *) __weak_symbol; -static void register_classes(void) __used; - -static crt_func __JCR_LIST__[] __section(".jcr") __used = { }; - -#ifndef CTORS_CONSTRUCTORS -__attribute__((constructor)) -#endif -static void -register_classes(void) -{ - - if (_Jv_RegisterClasses != NULL && __JCR_LIST__[0] != 0) - _Jv_RegisterClasses(__JCR_LIST__); -} - -/* - * We can't use constructors when they use the .ctors section as they may be - * placed before __CTOR_LIST__. - */ -#ifdef CTORS_CONSTRUCTORS -asm ( - ".pushsection .init \n" - "\t" INIT_CALL_SEQ(register_classes) "\n" - ".popsection \n" -); -#endif diff --git a/lib/csu/common/crtbrand.S b/lib/csu/common/crtbrand.S index 0ed86bfba2b2..a06f72daa99d 100644 --- a/lib/csu/common/crtbrand.S +++ b/lib/csu/common/crtbrand.S @@ -36,7 +36,7 @@ * for more information. */ - .section .note.tag,"aG",%note,.freebsd.noteG,comdat + .section .note.tag,"aGR",%note,.freebsd.noteG,comdat .p2align 2 .4byte 2f-1f .4byte 4f-3f @@ -47,3 +47,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif diff --git a/lib/csu/common/crtend.c b/lib/csu/common/crtend.c index d9259729bb0e..9eb75de2ef60 100644 --- a/lib/csu/common/crtend.c +++ b/lib/csu/common/crtend.c @@ -21,15 +21,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include <sys/cdefs.h> +#include <sys/types.h> #include "crt.h" typedef void (*crt_func)(void); -static crt_func __JCR_END__[] __section(".jcr") __used = { - (crt_func)0 -}; - #ifdef HAVE_CTORS /* @@ -45,15 +41,22 @@ static crt_func __DTOR_END__[] __section(".dtors") __used = { (crt_func)0 }; +extern const char startof_ctors[] __asm(".startof..ctors") + __weak_symbol __hidden; + static void __do_global_ctors_aux(void) { crt_func fn; + uintptr_t ctors_start; int n; + ctors_start = (uintptr_t)&startof_ctors; for (n = 1;; n++) { fn = __CTOR_END__[-n]; - if (fn == (crt_func)0 || fn == (crt_func)-1) + if (fn == (crt_func)0 || fn == (crt_func)-1 || + (ctors_start > 0 && + (uintptr_t)&__CTOR_END__[-n] < ctors_start)) break; fn(); } diff --git a/lib/csu/common/feature_note.S b/lib/csu/common/feature_note.S index 343d2a9262e2..fb9f6141699e 100644 --- a/lib/csu/common/feature_note.S +++ b/lib/csu/common/feature_note.S @@ -29,7 +29,7 @@ #include <sys/elf_common.h> #include "notes.h" - .section .note.tag,"a",%note + .section .note.tag,"aR",%note .p2align 2 .4byte 2f-1f .4byte 4f-3f @@ -40,3 +40,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif diff --git a/lib/csu/common/ignore_init_note.S b/lib/csu/common/ignore_init_note.S index fa37a8990538..d78be61f17a9 100644 --- a/lib/csu/common/ignore_init_note.S +++ b/lib/csu/common/ignore_init_note.S @@ -30,7 +30,7 @@ #include "notes.h" - .section .note.tag,"a",%note + .section .note.tag,"aR",%note .p2align 2 .4byte 2f-1f .4byte 4f-3f @@ -41,3 +41,8 @@ 4: .section .note.GNU-stack,"",%progbits + +#ifdef __aarch64__ +/* This is needed in all objects for BTI to be used in the linked elf file */ +GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL) +#endif diff --git a/lib/csu/i386/Makefile b/lib/csu/i386/Makefile index 0ea681ced6b4..24abd0b47585 100644 --- a/lib/csu/i386/Makefile +++ b/lib/csu/i386/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common CFLAGS+= -I${.CURDIR} diff --git a/lib/csu/powerpc/Makefile b/lib/csu/powerpc/Makefile index 5e0cc7ff6ed5..b6928446d005 100644 --- a/lib/csu/powerpc/Makefile +++ b/lib/csu/powerpc/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common OBJS+= crtsavres.o diff --git a/lib/csu/powerpc64/Makefile b/lib/csu/powerpc64/Makefile index 763cebbaa483..97df3f389115 100644 --- a/lib/csu/powerpc64/Makefile +++ b/lib/csu/powerpc64/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common OBJS+= crtsavres.o diff --git a/lib/csu/riscv/Makefile b/lib/csu/riscv/Makefile index 96b361b0656c..5f5de9f9c61a 100644 --- a/lib/csu/riscv/Makefile +++ b/lib/csu/riscv/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H}/common CRT1OBJS+= crt1_s.o diff --git a/lib/csu/riscv/Makefile.depend b/lib/csu/riscv/Makefile.depend new file mode 100644 index 000000000000..993ab0638f4a --- /dev/null +++ b/lib/csu/riscv/Makefile.depend @@ -0,0 +1,11 @@ +# Autogenerated - do NOT edit! + +DIRDEPS = \ + include \ + + +.include <dirdeps.mk> + +.if ${DEP_RELDIR} == ${_DEP_RELDIR} +# local dependencies - needed for -jN in clean tree +.endif diff --git a/lib/csu/tests/Makefile b/lib/csu/tests/Makefile index 3f95193420ea..b76ef590c88f 100644 --- a/lib/csu/tests/Makefile +++ b/lib/csu/tests/Makefile @@ -1,8 +1,10 @@ +PACKAGE= tests SUBDIR= dso TESTS_SUBDIRS= dynamic TESTS_SUBDIRS+= dynamiclib TESTS_SUBDIRS+= dynamicpie +TESTS_SUBDIRS+= errno TESTS_SUBDIRS+= static SUBDIR_DEPEND_dynamiclib=dso diff --git a/lib/csu/tests/Makefile.inc b/lib/csu/tests/Makefile.inc index 9904a82f1baf..2cb85b8d5d43 100644 --- a/lib/csu/tests/Makefile.inc +++ b/lib/csu/tests/Makefile.inc @@ -1,2 +1 @@ - TESTSDIR:= ${TESTSBASE}/${RELDIR:C/csu\/tests/csu/} diff --git a/lib/csu/tests/Makefile.tests b/lib/csu/tests/Makefile.tests index 12926d5e38a6..52179057b2a3 100644 --- a/lib/csu/tests/Makefile.tests +++ b/lib/csu/tests/Makefile.tests @@ -1,4 +1,3 @@ - ATF_TESTS_C+= init_test ATF_TESTS_C+= fini_test ATF_TESTS_CXX+= cxx_constructors diff --git a/lib/csu/tests/cxx_constructors.cc b/lib/csu/tests/cxx_constructors.cc index 3568c4528c36..3c04053884d2 100644 --- a/lib/csu/tests/cxx_constructors.cc +++ b/lib/csu/tests/cxx_constructors.cc @@ -29,7 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> #include <sys/types.h> #include <sys/wait.h> diff --git a/lib/csu/tests/dso/Makefile b/lib/csu/tests/dso/Makefile index 6975e64c5dfe..431168de0328 100644 --- a/lib/csu/tests/dso/Makefile +++ b/lib/csu/tests/dso/Makefile @@ -1,5 +1,6 @@ - .PATH: ${.CURDIR:H} + +PACKAGE= tests SHLIB= h_csu SHLIB_NAME= libh_csu.so SHLIB_MAJOR= 1 @@ -19,6 +20,6 @@ SRCS+= ${src}.c SRCS+= ${src}.cc .endfor -LIBDIR= ${TESTSBASE}/lib/csu/dynamiclib/ +LIBDIR= ${TESTSBASE}/lib/csu/dynamiclib .include <bsd.lib.mk> diff --git a/lib/csu/tests/dynamic/Makefile b/lib/csu/tests/dynamic/Makefile index 1ceeb385b5e9..e9e57201cb9a 100644 --- a/lib/csu/tests/dynamic/Makefile +++ b/lib/csu/tests/dynamic/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H} .include <src.opts.mk> diff --git a/lib/csu/tests/dynamiclib/Makefile b/lib/csu/tests/dynamiclib/Makefile index ced5bbb4e935..13a9b837684e 100644 --- a/lib/csu/tests/dynamiclib/Makefile +++ b/lib/csu/tests/dynamiclib/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H} CFLAGS+= -DDSO_BASE DPADD+= ${.OBJDIR:H}/dso/libh_csu.so diff --git a/lib/csu/tests/dynamicpie/Makefile b/lib/csu/tests/dynamicpie/Makefile index b5c0356001db..204bef0c7d10 100644 --- a/lib/csu/tests/dynamicpie/Makefile +++ b/lib/csu/tests/dynamicpie/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H} .include <src.opts.mk> diff --git a/lib/csu/tests/errno/Makefile b/lib/csu/tests/errno/Makefile new file mode 100644 index 000000000000..eae54a936294 --- /dev/null +++ b/lib/csu/tests/errno/Makefile @@ -0,0 +1,18 @@ +PLAIN_TESTS_C= errno_test \ + errno_static_test \ + errno_thr_test \ + errno_thr_static_test + +SRCS.errno_static_test= errno_test.c +LDFLAGS.errno_static_test= -static + +SRCS.errno_thr_test= errno_test.c +LIBADD.errno_thr_test= pthread + +SRCS.errno_thr_static_test= errno_test.c +LDFLAGS.errno_thr_static_test= -static +LIBADD.errno_thr_static_test= pthread + +MK_PIE:= no + +.include <bsd.test.mk> diff --git a/lib/csu/tests/errno/errno_test.c b/lib/csu/tests/errno/errno_test.c new file mode 100644 index 000000000000..d190c7fd2959 --- /dev/null +++ b/lib/csu/tests/errno/errno_test.c @@ -0,0 +1,23 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 Mark Johnston <markj@FreeBSD.org> + */ + +#include <errno.h> +#include <stdlib.h> + +static void __attribute__((constructor)) +f(void) +{ + errno = 42; +} + +int +main(void) +{ + /* errno must be zero upon program startup. */ + if (errno != 0) + exit(1); + exit(0); +} diff --git a/lib/csu/tests/fini_test.c b/lib/csu/tests/fini_test.c index 9475b40f4271..79dbceb8a37c 100644 --- a/lib/csu/tests/fini_test.c +++ b/lib/csu/tests/fini_test.c @@ -29,7 +29,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> #include <sys/types.h> #include <sys/wait.h> diff --git a/lib/csu/tests/init_test.c b/lib/csu/tests/init_test.c index 47bd9b7e64d7..2d4484735f76 100644 --- a/lib/csu/tests/init_test.c +++ b/lib/csu/tests/init_test.c @@ -38,9 +38,6 @@ typedef void (*func_ptr)(void); -extern volatile int jcr_run; -extern const func_ptr *jcr_ptr; -extern const void *jcr_func_ptr; extern volatile int ctors_run; extern volatile int preinit_array_run; extern volatile int preinit_array_state; @@ -48,37 +45,11 @@ extern volatile int init_array_run; extern volatile int init_array_state; #ifndef DSO_BASE -volatile int jcr_run; -const func_ptr *jcr_ptr; volatile int ctors_run; volatile int preinit_array_run; volatile int preinit_array_state = -1; volatile int init_array_run; volatile int init_array_state = -1; - -void _Jv_RegisterClasses(const func_ptr *); - -__section(".jcr") __used static func_ptr jcr_func = (func_ptr)1; -const void *jcr_func_ptr = &jcr_func; - -void -_Jv_RegisterClasses(const func_ptr *jcr) -{ - - jcr_run = 1; - jcr_ptr = jcr; -} -#endif - -#ifndef DSO_LIB -ATF_TC_WITHOUT_HEAD(jcr_test); -ATF_TC_BODY(jcr_test, tc) -{ - - ATF_REQUIRE_MSG(jcr_run == 1, ".jcr not run"); - ATF_REQUIRE_MSG(jcr_ptr == jcr_func_ptr, - "Incorrect pointer passed to _Jv_RegisterClasses"); -} #endif #ifndef DSO_BASE @@ -160,7 +131,6 @@ ATF_TC_BODY(init_array_test, tc) ATF_TP_ADD_TCS(tp) { - ATF_TP_ADD_TC(tp, jcr_test); ATF_TP_ADD_TC(tp, ctors_test); ATF_TP_ADD_TC(tp, preinit_array_test); ATF_TP_ADD_TC(tp, init_array_test); diff --git a/lib/csu/tests/static/Makefile b/lib/csu/tests/static/Makefile index c3f87641c8ef..e76c49c93a1a 100644 --- a/lib/csu/tests/static/Makefile +++ b/lib/csu/tests/static/Makefile @@ -1,4 +1,3 @@ - .PATH: ${.CURDIR:H} NO_SHARED= |