Index: lib/Makefile =================================================================== --- lib/Makefile +++ lib/Makefile @@ -32,6 +32,7 @@ libbsdstat \ libbsm \ libbz2 \ + libc_nosyscalls \ libcalendar \ libcam \ libcapsicum \ @@ -81,6 +82,7 @@ libsqlite3 \ libstdbuf \ libstdthreads \ + libsyscalls \ libsysdecode \ libtacplus \ libthread_db \ Index: lib/libc/Makefile =================================================================== --- lib/libc/Makefile +++ lib/libc/Makefile @@ -27,7 +27,7 @@ # below. Note: there are no IDs for syscall stubs whose sources are generated. # To include legacy CSRG sccsid strings, add -DLIBC_SCCS and -DSYSLIBC_SCCS # to CFLAGS below. -DSYSLIBC_SCCS affects just the system call stubs. -LIB=c +LIB?=c SHLIB_MAJOR= 7 .if ${MK_SSP} != "no" SHLIB_LDSCRIPT=libc.ldscript @@ -104,7 +104,16 @@ .include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc" .include "${LIBC_SRCTOP}/stdtime/Makefile.inc" .include "${LIBC_SRCTOP}/string/Makefile.inc" +.if !defined(NO_SYSCALLS) .include "${LIBC_SRCTOP}/sys/Makefile.inc" +.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64" +.include "${LIBC_SRCTOP}/x86/sys/Makefile.inc" +.endif +.else +.PATH: ${LIBC_SRCTOP}/sys +SRCS+= interposing_table.c +CFLAGS+= -DNO_SYSCALLS +.endif .include "${LIBC_SRCTOP}/secure/Makefile.inc" .include "${LIBC_SRCTOP}/rpc/Makefile.inc" .include "${LIBC_SRCTOP}/uuid/Makefile.inc" @@ -115,9 +124,6 @@ (${LIBC_ARCH} == "riscv" && ${MACHINE_ARCH:Mriscv*sf} != "") .include "${LIBC_SRCTOP}/softfloat/Makefile.inc" .endif -.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64" -.include "${LIBC_SRCTOP}/x86/sys/Makefile.inc" -.endif .if ${MK_NIS} != "no" CFLAGS+= -DYP .include "${LIBC_SRCTOP}/yp/Makefile.inc" @@ -174,7 +180,15 @@ .endif HAS_TESTS= -SUBDIR.${MK_TESTS}+= tests +.if ${MK_TESTS} != "no" && !defined(NO_SYSCALLS) +SUBDIR+= tests +.endif + +.if defined(NO_SYSCALLS) +MAN:= +MLINKS:= +NLS:= +.endif .include Index: lib/libc/amd64/sys/setlogin.S =================================================================== --- lib/libc/amd64/sys/setlogin.S +++ lib/libc/amd64/sys/setlogin.S @@ -46,7 +46,7 @@ mov $SYS_setlogin,%rax KERNCALL jb HIDENAME(cerror) - movl $0,CNAME(_logname_valid)(%rip) + movl $0,PIC_GOT(CNAME(_logname_valid)) ret /* setlogin(name) */ END(__sys_setlogin) Index: lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c =================================================================== --- lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c +++ lib/libc/gen/__pthread_mutex_init_calloc_cb_stub.c @@ -40,6 +40,7 @@ _pthread_mutex_init_calloc_cb_stub(pthread_mutex_t *mutex, void *(calloc_cb)(size_t, size_t)) { - + (void)mutex; + (void)calloc_cb; return (0); } Index: lib/libc/gen/errno.c =================================================================== --- lib/libc/gen/errno.c +++ lib/libc/gen/errno.c @@ -29,4 +29,5 @@ #include __FBSDID("$FreeBSD$"); +extern int errno; int errno; Index: lib/libc/sys/Makefile.inc =================================================================== --- lib/libc/sys/Makefile.inc +++ lib/libc/sys/Makefile.inc @@ -97,6 +97,9 @@ NOASM+= ${INTERPOSED:S/$/.o/} PSEUDO+= ${INTERPOSED:C/^.*$/_&.o/} +# Don't generate default assembly for PSEUDOs +NOASM+= ${PSEUDO:S/^_//} + # Add machine dependent asm sources: SRCS+=${MDASM} Index: lib/libc/sys/__error.c =================================================================== --- lib/libc/sys/__error.c +++ lib/libc/sys/__error.c @@ -34,6 +34,8 @@ #include "libc_private.h" +int *__error(void); + extern int errno; static int * Index: lib/libc/sys/clock_gettime.c =================================================================== --- lib/libc/sys/clock_gettime.c +++ lib/libc/sys/clock_gettime.c @@ -44,7 +44,7 @@ { int error; - if (__vdso_clock_gettime != NULL && __vdso_gettc != NULL) + if (&__vdso_clock_gettime != NULL && &__vdso_gettc != NULL) error = __vdso_clock_gettime(clock_id, ts); else error = ENOSYS; Index: lib/libc/sys/interposing_table.c =================================================================== --- lib/libc/sys/interposing_table.c +++ lib/libc/sys/interposing_table.c @@ -37,53 +37,73 @@ #include "libc_private.h" #define SLOT(a, b) \ - [INTERPOS_##a] = (interpos_func_t)b + [INTERPOS_##a] = (interpos_func_t)b, +#ifndef NO_SYSCALLS +#define SLOT_SYS(s) \ + [INTERPOS_##s] = (interpos_func_t)__sys_##s, +#else +#define SLOT_SYS(s) +#endif +#define SLOT_LIBC(s) \ + [INTERPOS_##s] = (interpos_func_t)__libc_##s, interpos_func_t __libc_interposing[INTERPOS_MAX] = { - SLOT(accept, __sys_accept), - SLOT(accept4, __sys_accept4), - SLOT(aio_suspend, __sys_aio_suspend), - SLOT(close, __sys_close), - SLOT(connect, __sys_connect), - SLOT(fcntl, __sys_fcntl), - SLOT(fsync, __sys_fsync), - SLOT(fork, __sys_fork), - SLOT(msync, __sys_msync), - SLOT(nanosleep, __sys_nanosleep), - SLOT(openat, __sys_openat), - SLOT(poll, __sys_poll), - SLOT(pselect, __sys_pselect), - SLOT(read, __sys_read), - SLOT(readv, __sys_readv), - SLOT(recvfrom, __sys_recvfrom), - SLOT(recvmsg, __sys_recvmsg), - SLOT(select, __sys_select), - SLOT(sendmsg, __sys_sendmsg), - SLOT(sendto, __sys_sendto), - SLOT(setcontext, __sys_setcontext), - SLOT(sigaction, __sys_sigaction), - SLOT(sigprocmask, __sys_sigprocmask), - SLOT(sigsuspend, __sys_sigsuspend), - SLOT(sigwait, __libc_sigwait), - SLOT(sigtimedwait, __sys_sigtimedwait), - SLOT(sigwaitinfo, __sys_sigwaitinfo), - SLOT(swapcontext, __sys_swapcontext), - SLOT(system, __libc_system), - SLOT(tcdrain, __libc_tcdrain), - SLOT(wait4, __sys_wait4), - SLOT(write, __sys_write), - SLOT(writev, __sys_writev), - SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub), - SLOT(spinlock, __libc_spinlock_stub), - SLOT(spinunlock, __libc_spinunlock_stub), - SLOT(kevent, __sys_kevent), - SLOT(wait6, __sys_wait6), - SLOT(ppoll, __sys_ppoll), - SLOT(map_stacks_exec, __libc_map_stacks_exec), - SLOT(fdatasync, __sys_fdatasync), - SLOT(clock_nanosleep, __sys_clock_nanosleep), + SLOT_SYS(accept) + SLOT_SYS(accept4) + SLOT_SYS(aio_suspend) + SLOT_SYS(close) + SLOT_SYS(connect) + SLOT_SYS(fcntl) + SLOT_SYS(fsync) + SLOT_SYS(fork) + SLOT_SYS(msync) + SLOT_SYS(nanosleep) + SLOT_SYS(openat) + SLOT_SYS(poll) + SLOT_SYS(pselect) + SLOT_SYS(read) + SLOT_SYS(readv) + SLOT_SYS(recvfrom) + SLOT_SYS(recvmsg) + SLOT_SYS(select) + SLOT_SYS(sendmsg) + SLOT_SYS(sendto) + SLOT_SYS(setcontext) + SLOT_SYS(sigaction) + SLOT_SYS(sigprocmask) + SLOT_SYS(sigsuspend) + SLOT_LIBC(sigwait) + SLOT_SYS(sigtimedwait) + SLOT_SYS(sigwaitinfo) + SLOT_SYS(swapcontext) +#ifndef INTERPOS_SYSCALLS_ONLY + SLOT_LIBC(system) + SLOT_LIBC(tcdrain) +#endif + SLOT_SYS(wait4) + SLOT_SYS(write) + SLOT_SYS(writev) +#ifndef INTERPOS_SYSCALLS_ONLY + SLOT(_pthread_mutex_init_calloc_cb, _pthread_mutex_init_calloc_cb_stub) + SLOT(spinlock, __libc_spinlock_stub) + SLOT(spinunlock, __libc_spinunlock_stub) +#endif + SLOT_SYS(kevent) + SLOT_SYS(wait6) + SLOT_SYS(ppoll) +#ifndef INTERPOS_SYSCALLS_ONLY + SLOT_LIBC(map_stacks_exec) +#endif + SLOT_SYS(fdatasync) + SLOT_SYS(clock_nanosleep) }; #undef SLOT +#undef SLOT_SYS +#undef SLOT_LIBC +#ifdef INTERPOS_SYSCALLS_ONLY +/* Prefer __libc_interposing_slot from libc if available */ +#pragma weak __libc_interposing_slot +#endif interpos_func_t * __libc_interposing_slot(int interposno) { Index: lib/libc/sys/pipe.c =================================================================== --- lib/libc/sys/pipe.c +++ lib/libc/sys/pipe.c @@ -37,6 +37,7 @@ __weak_reference(__sys_pipe, pipe); __weak_reference(__sys_pipe, _pipe); +int __sys_pipe(int fildes[2]); extern int __sys_pipe2(int fildes[2], int flags); int Index: lib/libc/sys/ptrace.c =================================================================== --- lib/libc/sys/ptrace.c +++ lib/libc/sys/ptrace.c @@ -38,6 +38,7 @@ #include #include "libc_private.h" +int _ptrace(int request, pid_t pid, caddr_t addr, int data); __weak_reference(_ptrace, ptrace); int Index: lib/libc_nosyscalls/Makefile =================================================================== --- /dev/null +++ lib/libc_nosyscalls/Makefile @@ -0,0 +1,12 @@ +NO_SYSCALLS=yes + +LIB=c_nosyscalls +SHLIB_LDSCRIPT= +SHLIB_LDSCRIPT_LINKS= + +LIBC_SRCTOP= ${.CURDIR}/../libc/ + +# Unbreak shared CHERI builds by disabling them here +NO_SHARED=yes + +.include "${LIBC_SRCTOP}/Makefile" Index: lib/libsyscalls/Makefile =================================================================== --- /dev/null +++ lib/libsyscalls/Makefile @@ -0,0 +1,47 @@ +LIB=syscalls + +LIBC_SRCTOP= ${.CURDIR}/../libc/ + +.if exists(${LIBC_SRCTOP}/${MACHINE_ARCH}) +LIBC_ARCH=${MACHINE_ARCH} +.else +LIBC_ARCH=${MACHINE_CPUARCH} +.endif + +SHLIB_MAJOR= 7 + +CFLAGS+=-I${LIBC_SRCTOP}/include -I${LIBC_SRCTOP}/../../include +CFLAGS+=-I${LIBC_SRCTOP}/${LIBC_ARCH} + +# Define (empty) variables so that make doesn't give substitution +# errors if the included makefiles don't change these: +MDSRCS= +MISRCS= +MDASM= +MIASM= +NOASM= + +.include "${LIBC_SRCTOP}/sys/Makefile.inc" +.include "${LIBC_SRCTOP}/${LIBC_ARCH}/sys/Makefile.inc" +.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64" +MK_HYPERV?= no +.include "${LIBC_SRCTOP}/x86/sys/Makefile.inc" +.endif + +.PATH: ${LIBC_SRCTOP}/gen +SRCS+= errno.c getlogin.c __vdso_gettimeofday.c __getosreldate.c +CFLAGS.interposing_table.c+= -DINTERPOS_SYSCALLS_ONLY=1 + +SYMBOL_MAPS= ${SYM_MAPS} +VERSION_DEF= ${LIBC_SRCTOP}/Versions.def +CFLAGS+= -DSYMBOL_VERSIONING + +MAN= +MLINKS= + +WARNS=2 + +#SOLINKOPTS+= -Wl.-undefined=report-all -Wl,-no-undefined +LDFLAGS+= -nostdlib -nodefaultlibs + +.include Index: share/mk/bsd.lib.mk =================================================================== --- share/mk/bsd.lib.mk +++ share/mk/bsd.lib.mk @@ -24,6 +24,8 @@ .if defined(NO_PIC) .undef SHLIB_NAME .undef INSTALL_PIC_ARCHIVE +.elif defined(NO_SHARED) +.undef SHLIB_NAME .else .if !defined(SHLIB) && defined(LIB) SHLIB= ${LIB} Index: share/mk/bsd.libnames.mk =================================================================== --- share/mk/bsd.libnames.mk +++ share/mk/bsd.libnames.mk @@ -31,6 +31,7 @@ LIBBSNMP?= ${LIBDESTDIR}${LIBDIR_BASE}/libbsnmp.a LIBBZ2?= ${LIBDESTDIR}${LIBDIR_BASE}/libbz2.a LIBC?= ${LIBDESTDIR}${LIBDIR_BASE}/libc.a +LIBC_NOSYSCALLS?= ${LIBDESTDIR}${LIBDIR_BASE}/libc_nosyscalls.a LIBCALENDAR?= ${LIBDESTDIR}${LIBDIR_BASE}/libcalendar.a LIBCAM?= ${LIBDESTDIR}${LIBDIR_BASE}/libcam.a LIBCAP_DNS?= ${LIBDESTDIR}${LIBDIR_BASE}/libcap_dns.a @@ -145,6 +146,7 @@ LIBSSP_NONSHARED?= ${LIBDESTDIR}${LIBDIR_BASE}/libssp_nonshared.a LIBSTDCPLUSPLUS?= ${LIBDESTDIR}${LIBDIR_BASE}/libstdc++.a LIBSTDTHREADS?= ${LIBDESTDIR}${LIBDIR_BASE}/libstdthreads.a +LIBSYSCALLS?= ${LIBDESTDIR}${LIBDIR_BASE}/libsyscalls.a LIBSYSDECODE?= ${LIBDESTDIR}${LIBDIR_BASE}/libsysdecode.a LIBTACPLUS?= ${LIBDESTDIR}${LIBDIR_BASE}/libtacplus.a LIBTERMCAP?= ${LIBDESTDIR}${LIBDIR_BASE}/libtermcap.a Index: share/mk/src.libnames.mk =================================================================== --- share/mk/src.libnames.mk +++ share/mk/src.libnames.mk @@ -68,6 +68,7 @@ bsnmp \ bz2 \ c \ + c_nosyscalls \ c_pic \ calendar \ cam \ @@ -160,6 +161,7 @@ ssp_nonshared \ stdthreads \ supcplusplus \ + syscalls \ sysdecode \ tacplus \ termcap \ @@ -312,8 +314,10 @@ # The libc dependencies are not strictly needed but are defined to make the # assert happy. _DP_c= compiler_rt +_DP_c_nosyscalls= compiler_rt .if ${MK_SSP} != "no" _DP_c+= ssp_nonshared +_DP_c_nosyscalls+= ssp_nonshared .endif _DP_stdthreads= pthread _DP_tacplus= md Index: sys/amd64/include/asm.h =================================================================== --- sys/amd64/include/asm.h +++ sys/amd64/include/asm.h @@ -45,6 +45,7 @@ #define PIC_GOT(x) x@GOTPCREL(%rip) #else #define PIC_PLT(x) x +#define PIC_GOT(x) x #endif /*