From 99ea67573164637d633e8051eb0a5d52f1f9488e Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Mon, 19 Feb 2024 22:44:08 +0000 Subject: [PATCH] lib{c,sys}: move auxargs more firmly into libsys Continue to filter the public interface (elf_aux_info()), but entierly relocate the private interfaces (_elf_aux_info(), __init_elf_aux_vector(), and __elf_aux_vector) to libsys. This ensures that rtld updates the correct (only) copy of __elf_aux_vector. After 968a18975adc9c2a619bb52aa2f009de99fc9e24 updates were confused and __getosreldate was failing, causing the system to fall back to compat compat12 syscalls in some cases. Return to explicitly linking libc to libsys and link libthr with libc and libsys (in that order). Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D43910 --- lib/libc/Makefile | 1 + lib/libc/tests/ssp/Makefile | 1 + lib/libsys/Makefile | 3 +++ lib/libsys/Makefile.sys | 10 ++++++++-- lib/libsys/Symbol.map | 5 +++++ lib/libsys/Symbol.sys.map | 2 -- lib/libsys/libc_stubs.c | 11 +++++++++++ lib/libthr/Makefile | 2 ++ share/mk/bsd.libnames.mk | 5 ++++- share/mk/src.libnames.mk | 6 +++++- 10 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 lib/libsys/Symbol.map create mode 100644 lib/libsys/libc_stubs.c diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 54748abfeff..41cf0f6de72 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -62,6 +62,7 @@ CFLAGS+= -ftls-model=initial-exec # LDFLAGS+= -nodefaultlibs LIBADD+= compiler_rt +LIBADD+= sys LDFLAGS+=-Wl,--auxiliary,libsys.so.7 diff --git a/lib/libc/tests/ssp/Makefile b/lib/libc/tests/ssp/Makefile index c6f850ec1a3..22f48d7dfe5 100644 --- a/lib/libc/tests/ssp/Makefile +++ b/lib/libc/tests/ssp/Makefile @@ -10,6 +10,7 @@ CFLAGS.h_raw+= -fstack-protector-all -Wstack-protector # override the sanitizer runtime libraries to be the ones installed on the # target system. CFLAGS.h_raw+= -fsanitize=bounds +LIBADD+=sys .elif ${COMPILER_TYPE} == "gcc" CFLAGS.h_raw+= --param ssp-buffer-size=1 LDADD+= -lssp diff --git a/lib/libsys/Makefile b/lib/libsys/Makefile index 897e033267a..598962185dc 100644 --- a/lib/libsys/Makefile +++ b/lib/libsys/Makefile @@ -57,6 +57,9 @@ MDASM= MIASM= NOASM= +SYM_MAPS+= ${LIBSYS_SRCTOP}/Symbol.map +SRCS+= auxv.c + .include "${LIBSYS_SRCTOP}/Makefile.sys" SYM_MAPS+= ${LIBSYS_SRCTOP}/Symbol.thr.map diff --git a/lib/libsys/Makefile.sys b/lib/libsys/Makefile.sys index b45aa3cf1aa..cb9ca1749ba 100644 --- a/lib/libsys/Makefile.sys +++ b/lib/libsys/Makefile.sys @@ -47,8 +47,6 @@ SRCS+= recv.c recvmmsg.c send.c sendmmsg.c NOASM+= sched_getcpu.o PSEUDO+= _sched_getcpu.o -SRCS+= auxv.c - SRCS+= brk.c SRCS+= closefrom.c SRCS+= pipe.c @@ -58,6 +56,14 @@ SRCS+= POSIX2x_Fork.c SRCS+= compat-stub.c +.if ${LIB} == "c" +# Trapping stubs in dynamic libc to be filtered by libsys. +SOBJS+= libc_stubs.pico + +# Link the full implementation of ELF auxargs for static libc. +STATICOBJS+= auxv.o +.endif + INTERPOSED = \ accept \ accept4 \ diff --git a/lib/libsys/Symbol.map b/lib/libsys/Symbol.map new file mode 100644 index 00000000000..4f72ea20403 --- /dev/null +++ b/lib/libsys/Symbol.map @@ -0,0 +1,5 @@ +FBSDprivate_1.0 { + __elf_aux_vector; + __init_elf_aux_vector; + _elf_aux_info; +}; diff --git a/lib/libsys/Symbol.sys.map b/lib/libsys/Symbol.sys.map index 73a1cf297ca..d59ac867466 100644 --- a/lib/libsys/Symbol.sys.map +++ b/lib/libsys/Symbol.sys.map @@ -433,12 +433,10 @@ FBSD_1.8 { FBSDprivate_1.0 { /* Add entries in sort(1) order */ - __elf_aux_vector; __libc_sigwait; __libsys_interposing_slot; __set_error_selector; __sigwait; - _elf_aux_info; gssd_syscall; nlm_syscall; rpctls_syscall; diff --git a/lib/libsys/libc_stubs.c b/lib/libsys/libc_stubs.c new file mode 100644 index 00000000000..41d69a9355c --- /dev/null +++ b/lib/libsys/libc_stubs.c @@ -0,0 +1,11 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 SRI International + */ + +#define STUB_FUNC(f) \ + void (f)(void); \ + void (f)(void) { __builtin_trap(); } + +STUB_FUNC(elf_aux_info); diff --git a/lib/libthr/Makefile b/lib/libthr/Makefile index 932650885de..325a320d55e 100644 --- a/lib/libthr/Makefile +++ b/lib/libthr/Makefile @@ -7,6 +7,8 @@ PACKAGE= clibs SHLIBDIR?= /lib +LIBADD= c sys + .include MK_SSP= no diff --git a/share/mk/bsd.libnames.mk b/share/mk/bsd.libnames.mk index 414ae316406..4177a1ef0e4 100644 --- a/share/mk/bsd.libnames.mk +++ b/share/mk/bsd.libnames.mk @@ -174,7 +174,7 @@ LIBZFSBOOTENV?= ${LIBDESTDIR}${LIBDIR_BASE}/libzfsbootenv.a LIBZPOOL?= ${LIBDESTDIR}${LIBDIR_BASE}/libzpool.a LIBZUTIL?= ${LIBDESTDIR}${LIBDIR_BASE}/libzutil.a -# enforce the 2 -lpthread and -lc to always be the last in that exact order +# enforce -lpthread, -lc, and -lsys to always be the last in that exact order .if defined(LDADD) .if ${LDADD:M-lpthread} LDADD:= ${LDADD:N-lpthread} -lpthread @@ -182,6 +182,9 @@ LDADD:= ${LDADD:N-lpthread} -lpthread .if ${LDADD:M-lc} LDADD:= ${LDADD:N-lc} -lc .endif +.if ${LDADD:M-lsys} +LDADD:= ${LDADD:N-lsys} -lsys +.endif .endif # Only do this for src builds. diff --git a/share/mk/src.libnames.mk b/share/mk/src.libnames.mk index 658dd1c3d69..0fd349d0d00 100644 --- a/share/mk/src.libnames.mk +++ b/share/mk/src.libnames.mk @@ -394,7 +394,7 @@ _DP_xo= util _DP_ztest= geom m nvpair umem zpool pthread avl zfs_core spl zutil zfs uutil icp # The libc dependencies are not strictly needed but are defined to make the # assert happy. -_DP_c= compiler_rt +_DP_c= compiler_rt sys # Use libssp_nonshared only on i386 and power*. Other archs emit direct calls # to __stack_chk_fail, not __stack_chk_fail_local provided by libssp_nonshared. .if ${MK_SSP} != "no" && \ @@ -410,6 +410,10 @@ _DP_sys= compiler_rt (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH:Mpower*} != "") _DP_sys+= ssp_nonshared .endif +.if !defined(BOOTSTRAPPING) +_DP_thr= c sys +_DP_pthread= ${_DP_thr} +.endif _DP_tacplus= md pam _DP_ncursesw= tinfow _DP_formw= ncursesw