Index: head/lib/libc/gen/arc4random.h =================================================================== --- head/lib/libc/gen/arc4random.h (revision 364758) +++ head/lib/libc/gen/arc4random.h (revision 364759) @@ -1,74 +1,76 @@ /* $OpenBSD: arc4random.h,v 1.4 2015/01/15 06:57:18 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres * Copyright (c) 2008, Damien Miller * Copyright (c) 2013, Markus Friedl * Copyright (c) 2014, Theo de Raadt * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $FreeBSD$ */ /* * Stub functions for portability. */ #include #include static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; #define _ARC4_LOCK() \ do { \ if (__isthreaded) \ _pthread_mutex_lock(&arc4random_mtx); \ } while (0) #define _ARC4_UNLOCK() \ do { \ if (__isthreaded) \ _pthread_mutex_unlock(&arc4random_mtx); \ } while (0) static inline void _getentropy_fail(void) { raise(SIGKILL); } static inline int _rs_allocate(struct _rs **rsp, struct _rsx **rsxp) { struct { struct _rs rs; struct _rsx rsx; } *p; if ((p = mmap(NULL, sizeof(*p), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) return (-1); + /* Allow bootstrapping arc4random.c on Linux/macOS */ +#ifdef INHERIT_ZERO if (minherit(p, sizeof(*p), INHERIT_ZERO) == -1) { munmap(p, sizeof(*p)); return (-1); } - +#endif *rsp = &p->rs; *rsxp = &p->rsx; return (0); } static inline void _rs_forkdetect(void) { } Index: head/lib/libcapsicum/capsicum_helpers.h =================================================================== --- head/lib/libcapsicum/capsicum_helpers.h (revision 364758) +++ head/lib/libcapsicum/capsicum_helpers.h (revision 364759) @@ -1,188 +1,198 @@ /*- * Copyright (c) 2016 Mariusz Zaborski * 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 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. * * $FreeBSD$ */ #ifndef _CAPSICUM_HELPERS_H_ #define _CAPSICUM_HELPERS_H_ #include #include #include #include #include #include #include #include #include #define CAPH_IGNORE_EBADF 0x0001 #define CAPH_READ 0x0002 #define CAPH_WRITE 0x0004 #define CAPH_LOOKUP 0x0008 __BEGIN_DECLS static const unsigned long caph_stream_cmds[] = - { TIOCGETA, TIOCGWINSZ, FIODTYPE }; + { +#ifdef TIOCGETA + TIOCGETA, +#endif +#ifdef TIOCGWINSZ + TIOCGWINSZ, +#endif +#ifdef FIODTYPE + FIODTYPE, +#endif + }; static const uint32_t caph_stream_fcntls = CAP_FCNTL_GETFL; static __inline void caph_stream_rights(cap_rights_t *rights, int flags) { cap_rights_init(rights, CAP_EVENT, CAP_FCNTL, CAP_FSTAT, CAP_IOCTL, CAP_SEEK); if ((flags & CAPH_READ) != 0) cap_rights_set(rights, CAP_READ); if ((flags & CAPH_WRITE) != 0) cap_rights_set(rights, CAP_WRITE); if ((flags & CAPH_LOOKUP) != 0) cap_rights_set(rights, CAP_LOOKUP); } static __inline int caph_limit_stream(int fd, int flags) { cap_rights_t rights; caph_stream_rights(&rights, flags); if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS) { if (errno == EBADF && (flags & CAPH_IGNORE_EBADF) != 0) return (0); return (-1); } if (cap_ioctls_limit(fd, caph_stream_cmds, nitems(caph_stream_cmds)) < 0 && errno != ENOSYS) return (-1); if (cap_fcntls_limit(fd, caph_stream_fcntls) < 0 && errno != ENOSYS) return (-1); return (0); } static __inline int caph_limit_stdin(void) { return (caph_limit_stream(STDIN_FILENO, CAPH_READ)); } static __inline int caph_limit_stderr(void) { return (caph_limit_stream(STDERR_FILENO, CAPH_WRITE)); } static __inline int caph_limit_stdout(void) { return (caph_limit_stream(STDOUT_FILENO, CAPH_WRITE)); } static __inline int caph_limit_stdio(void) { const int iebadf = CAPH_IGNORE_EBADF; if (caph_limit_stream(STDIN_FILENO, CAPH_READ | iebadf) == -1 || caph_limit_stream(STDOUT_FILENO, CAPH_WRITE | iebadf) == -1 || caph_limit_stream(STDERR_FILENO, CAPH_WRITE | iebadf) == -1) return (-1); return (0); } static __inline void caph_cache_tzdata(void) { tzset(); } static __inline void caph_cache_catpages(void) { (void)catopen("libc", NL_CAT_LOCALE); } static __inline int caph_enter(void) { if (cap_enter() < 0 && errno != ENOSYS) return (-1); return (0); } static __inline int caph_rights_limit(int fd, const cap_rights_t *rights) { if (cap_rights_limit(fd, rights) < 0 && errno != ENOSYS) return (-1); return (0); } static __inline int caph_ioctls_limit(int fd, const unsigned long *cmds, size_t ncmds) { if (cap_ioctls_limit(fd, cmds, ncmds) < 0 && errno != ENOSYS) return (-1); return (0); } static __inline int caph_fcntls_limit(int fd, uint32_t fcntlrights) { if (cap_fcntls_limit(fd, fcntlrights) < 0 && errno != ENOSYS) return (-1); return (0); } static __inline int caph_enter_casper(void) { return (CASPER_SUPPORT == 0 ? 0 : caph_enter()); } __END_DECLS #endif /* _CAPSICUM_HELPERS_H_ */ Index: head/tools/build/Makefile =================================================================== --- head/tools/build/Makefile (revision 364758) +++ head/tools/build/Makefile (revision 364759) @@ -1,185 +1,345 @@ # $FreeBSD$ .PATH: ${.CURDIR}/../../include LIB= egacy SRC= INCSGROUPS= INCS SYSINCS CASPERINC UFSINCS FFSINCS MSDOSFSINCS DISKINCS +INCSGROUPS+= MACHINESYSINCS RPCINCS INCS= SYSINCSDIR= ${INCLUDEDIR}/sys CASPERINCDIR= ${INCLUDEDIR}/casper # Also add ufs/ffs/msdosfs/disk headers to allow building makefs as a bootstrap tool UFSINCSDIR= ${INCLUDEDIR}/ufs/ufs FFSINCSDIR= ${INCLUDEDIR}/ufs/ffs MSDOSFSINCSDIR= ${INCLUDEDIR}/fs/msdosfs DISKINCSDIR= ${INCLUDEDIR}/sys/disk +MACHINESYSINCSDIR= ${INCLUDEDIR}/machine +RPCINCSDIR= ${INCLUDEDIR}/rpc BOOTSTRAPPING?= 0 -_WITH_PWCACHEDB!= grep -c pwcache_groupdb /usr/include/grp.h || true + +.if ${.MAKE.OS} == "Darwin" +_XCODE_ROOT!=xcode-select -p +# since macOS 10.14 C headers are no longer installed in /usr but only +# provided via the SDK +.if ${_XCODE_ROOT} == "/Library/Developer/CommandLineTools" +# Only command line tools installed -> host headers are in the SDKs directory +_MACOS_SDK_DIR=${_XCODE_ROOT}/SDKs/MacOSX.sdk/ +.else +# Full XCode installed -> host headers are below Platforms/MacOSX.platform +_MACOS_SDK_DIR=${_XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk +.endif +HOST_INCLUDE_ROOT=${_MACOS_SDK_DIR}/usr/include +.if !exists(${HOST_INCLUDE_ROOT}/stdio.h) +.error "You must install the macOS SDK (try xcode-select --install)" +.endif +.else +HOST_INCLUDE_ROOT=/usr/include +.endif + +# Allow building libc-internal files (also on non-FreeBSD hosts) +CFLAGS+= -I${.CURDIR}/libc-bootstrap +# Symbol versioning is not required for -legacy (and macOS bootstrap) +MK_SYMVER= no + +_WITH_PWCACHEDB!= grep -c pwcache_groupdb ${HOST_INCLUDE_ROOT}/grp.h || true .if ${_WITH_PWCACHEDB} == 0 .PATH: ${.CURDIR}/../../contrib/libc-pwcache -CFLAGS+= -I${.CURDIR}/../../contrib/libc-pwcache \ - -I${.CURDIR}/../../lib/libc/include +CFLAGS.pwcache.c+= -I${.CURDIR}/../../contrib/libc-pwcache SRCS+= pwcache.c .endif -_WITH_STRSVIS!= grep -c strsvis /usr/include/vis.h || true +_WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true .if ${_WITH_STRSVIS} == 0 .PATH: ${.CURDIR}/../../contrib/libc-vis -SRCS+= vis.c -CFLAGS+= -I${.CURDIR}/../../contrib/libc-vis \ - -I${.CURDIR}/../../lib/libc/include +INCS+= vis.h +SRCS+= vis.c unvis.c +CFLAGS.vis.c+= -I${.CURDIR}/../../contrib/libc-vis +CFLAGS.unvis.c+= -I${.CURDIR}/../../contrib/libc-vis .endif -_WITH_REALLOCARRAY!= grep -c reallocarray /usr/include/stdlib.h || true +_WITH_REALLOCARRAY!= grep -c reallocarray ${HOST_INCLUDE_ROOT}/stdlib.h || true .if ${_WITH_REALLOCARRAY} == 0 .PATH: ${.CURDIR}/../../lib/libc/stdlib INCS+= stdlib.h SRCS+= reallocarray.c -CFLAGS+= -I${.CURDIR}/../../lib/libc/include .endif -_WITH_UTIMENS!= grep -c utimensat /usr/include/sys/stat.h || true +_WITH_UTIMENS!= grep -c utimensat ${HOST_INCLUDE_ROOT}/sys/stat.h || true .if ${_WITH_UTIMENS} == 0 SYSINCS+= stat.h SRCS+= futimens.c utimensat.c .endif -_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero /usr/include/strings.h || true +_WITH_EXPLICIT_BZERO!= grep -c explicit_bzero ${HOST_INCLUDE_ROOT}/strings.h || true .if ${_WITH_EXPLICIT_BZERO} == 0 -.PATH: ${SRCTOP}/sys/libkern +# .PATH: ${SRCTOP}/sys/libkern +# Adding sys/libkern to .PATH breaks building the cross-build compat library +# since that attempts to build strlcpy.c from libc and adding libkern here will +# cause it to pick the file from libkern instead (which won't compile). +# Avoid modifying .PATH by creating a copy in the build directory instead. +explicit_bzero.c: ${SRCTOP}/sys/libkern/explicit_bzero.c + cp ${.ALLSRC} ${.TARGET} +CLEANFILES+= explicit_bzero.c INCS+= strings.h SRCS+= explicit_bzero.c .endif -.if exists(/usr/include/capsicum_helpers.h) -_WITH_CAPH_ENTER!= grep -c caph_enter /usr/include/capsicum_helpers.h || true -_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit /usr/include/capsicum_helpers.h || true + +.if exists(${HOST_INCLUDE_ROOT}/capsicum_helpers.h) +_WITH_CAPH_ENTER!= grep -c caph_enter ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true +_WITH_CAPH_RIGHTS_LIMIT!= grep -c caph_rights_limit ${HOST_INCLUDE_ROOT}/capsicum_helpers.h || true .endif .if !defined(_WITH_CAPH_ENTER) || ${_WITH_CAPH_ENTER} == 0 || ${_WITH_CAPH_RIGHTS_LIMIT} == 0 .PATH: ${SRCTOP}/lib/libcapsicum INCS+= capsicum_helpers.h .PATH: ${SRCTOP}/lib/libcasper/libcasper INCS+= libcasper.h .endif +# rpcgen should build against the source tree rpc/types.h and not the host. +# This is especially important on non-FreeBSD systems where the types may +# not match. +RPCINCS+= ${SRCTOP}/sys/rpc/types.h + +.if ${.MAKE.OS} != "FreeBSD" +.PATH: ${.CURDIR}/cross-build + +INCS+= ${SRCTOP}/include/mpool.h +INCS+= ${SRCTOP}/include/ndbm.h +INCS+= ${SRCTOP}/include/err.h +INCS+= ${SRCTOP}/include/stringlist.h + +# Needed to build arc4random.c +INCSGROUPS+= CHACHA20INCS +CHACHA20INCSDIR= ${INCLUDEDIR}/crypto/chacha20 +CHACHA20INCS+= ${SRCTOP}/sys/crypto/chacha20/_chacha.h \ + ${SRCTOP}/sys/crypto/chacha20/chacha.h + +_host_arch=${MACHINE} +.if ${_host_arch} == "x86_64" +# bmake on Linux/mac often prints that instead of amd64 +_host_arch=amd64 +.endif +.if ${_host_arch} == "unknown" +# HACK: If MACHINE is unknown, assume we are building on x86 +_host_arch=amd64 +.endif +MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/elf.h +.if ${_host_arch} == "amd64" || ${_host_arch} == "i386" +INCSGROUPS+= X86INCS +X86INCSDIR= ${INCLUDEDIR}/x86 +X86INCS+= ${SRCTOP}/sys/x86/include/elf.h +.endif + +# needed for btxld: +MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/exec.h +MACHINESYSINCS+= ${SRCTOP}/sys/${_host_arch}/include/reloc.h +INCS+= ${SRCTOP}/include/a.out.h +INCS+= ${SRCTOP}/include/nlist.h +SYSINCS+= ${SRCTOP}/sys/sys/imgact_aout.h +SYSINCS+= ${SRCTOP}/sys/sys/nlist_aout.h + +# dbopen() behaves differently on Linux and FreeBSD so we ensure that we +# bootstrap the FreeBSD db code. The cross-build headers #define dbopen() to +# __freebsd_dbopen() so that we don't ever use the host version +INCS+= ${SRCTOP}/include/db.h +LIBC_SRCTOP= ${SRCTOP}/lib/libc/ +.include "${LIBC_SRCTOP}/db/Makefile.inc" +# Do the same as we did for dbopen() for getopt() on since it's not compatible +# on Linux (and to avoid surprises also compile the FreeBSD code on macOS) +.PATH: ${LIBC_SRCTOP}/stdlib +SRCS+= getopt.c getopt_long.c +INCS+= ${SRCTOP}/include/getopt.h + +# getcap.c is needed for cap_mkdb: +.PATH: ${LIBC_SRCTOP}/gen +SRCS+= getcap.c +# Add various libbc functions that are not available in glibc: +SRCS+= stringlist.c setmode.c +SRCS+= strtonum.c merge.c heapsort.c reallocf.c +.PATH: ${LIBC_SRCTOP}/locale +SRCS+= rpmatch.c + +.if ${.MAKE.OS} == "Linux" +# On Linux, glibc does not provide strlcpy,strlcat or strmode. +.PATH: ${LIBC_SRCTOP}/string +SRCS+= strlcpy.c strlcat.c strmode.c +# Compile the fgetln/fgetwln/closefrom fallback code from libbsd: +SRCS+= fgetln_fallback.c fgetwln_fallback.c closefrom.c +CFLAGS.closefrom.c+= -DSTDC_HEADERS -DHAVE_SYS_DIR_H -DHAVE_DIRENT_H \ + -DHAVE_DIRFD -DHAVE_SYSCONF +# Provide warnc/errc/getprogname/setprograme +SRCS+= err.c progname.c +.endif +# Provide the same arc4random implementation on Linux/macOS +CFLAGS.arc4random.c+= -I${SRCTOP}/sys/crypto/chacha20 -D__isthreaded=1 +SRCS+= arc4random.c arc4random_uniform.c + +# expand_number() is not provided by either Linux or MacOS libutil +.PATH: ${SRCTOP}/lib/libutil +SRCS+= expand_number.c +# Linux libutil also doesn't have fparseln +SRCS+= fparseln.c +# A dummy sysctl for tzsetup: +SRCS+= fake_sysctl.c + +# capsicum support +SYSINCS+= ${SRCTOP}/sys/sys/capsicum.h +SYSINCS+= ${SRCTOP}/sys/sys/caprights.h +SRCS+= capsicum_stubs.c +# XXX: we can't add ${SRCTOP}/sys/kern to .PATH since that will causes +# conflicts with other files. Instead copy subr_capability to the build dir. +subr_capability.c: ${SRCTOP}/sys/kern/subr_capability.c + cp ${.ALLSRC} ${.TARGET} +SRCS+= subr_capability.c +CLEANFILES+= subr_capability.c +.endif + CASPERINC+= ${SRCTOP}/lib/libcasper/services/cap_fileargs/cap_fileargs.h .if empty(SRCS) SRCS= dummy.c .endif .if defined(CROSS_BUILD_TESTING) SUBDIR= cross-build .endif # To allow bootstrapping makefs on FreeBSD 11 or non-FreeBSD systems: UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dinode.h UFSINCS+= ${SRCTOP}/sys/ufs/ufs/dir.h FFSINCS+= ${SRCTOP}/sys/ufs/ffs/fs.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bootsect.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/bpb.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/denode.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/direntry.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/fat.h MSDOSFSINCS+= ${SRCTOP}/sys/fs/msdosfs/msdosfsmount.h DISKINCS+= ${SRCTOP}/sys/sys/disk/bsd.h # Needed to build config (since it uses libnv) SYSINCS+= ${SRCTOP}/sys/sys/nv.h ${SRCTOP}/sys/sys/cnv.h \ ${SRCTOP}/sys/sys/dnv.h # Needed when bootstrapping ldd (since it uses DF_1_PIE) SYSINCS+= ${SRCTOP}/sys/sys/elf32.h SYSINCS+= ${SRCTOP}/sys/sys/elf64.h SYSINCS+= ${SRCTOP}/sys/sys/elf_common.h SYSINCS+= ${SRCTOP}/sys/sys/elf_generic.h +SYSINCS+= ${SRCTOP}/sys/sys/queue.h +SYSINCS+= ${SRCTOP}/sys/sys/md5.h +SYSINCS+= ${SRCTOP}/sys/sys/sbuf.h +SYSINCS+= ${SRCTOP}/sys/sys/tree.h # vtfontcvt is using sys/font.h SYSINCS+= ${SRCTOP}/sys/sys/font.h +# For mkscrfil.c: +SYSINCS+= ${SRCTOP}/sys/sys/consio.h +# for gencat: +INCS+= ${SRCTOP}/include/nl_types.h +# for vtfontcvt: +SYSINCS+= ${SRCTOP}/sys/sys/fnv_hash.h +# opensolaris compatibility +INCS+= ${SRCTOP}/include/elf.h +SYSINCS+= ${SRCTOP}/sys/sys/elf.h # We want to run the build with only ${WORLDTMP} in $PATH to ensure we don't # accidentally run tools that are incompatible but happen to be in $PATH. # This is especially important when building on Linux/MacOS where many of the # programs used during the build accept different flags or generate different # output. On those platforms we only symlink the tools known to be compatible # (e.g. basic utilities such as mkdir) into ${WORLDTMP} and build all others # from the FreeBSD sources during the bootstrap-tools stage. # basic commands: It is fine to use the host version for all of these even on # Linux/MacOS since we only use flags that are supported by all of them. _host_tools_to_symlink= basename bzip2 bunzip2 chmod chown cmp comm cp date dd \ dirname echo env false find fmt gzip gunzip head hostname id ln ls \ mkdir mv nice patch rm realpath sh sleep stat tee touch tr true \ uname uniq wc which # We also need a symlink to the absolute path to the make binary used for # the toplevel makefile. This is not necessarily the same as `which make` # since e.g. on Linux and MacOS that will be GNU make. _make_abs!= which "${MAKE}" _host_abs_tools_to_symlink= ${_make_abs}:make ${_make_abs}:bmake + +.if ${.MAKE.OS} != "FreeBSD" +_make_abs!= which "${MAKE}" +_host_abs_tools_to_symlink+= ${_make_abs}:make ${_make_abs}:bmake +.if ${.MAKE.OS} == "Darwin" +# /usr/bin/cpp may invoke xcrun: +_host_tools_to_symlink+=xcrun +.endif # ${.MAKE.OS} == "Darwin" +# On Ubuntu /bin/sh is dash which is totally useless. Let's just link bash +# as the build sh since that will work fine. +_host_abs_tools_to_symlink+= /bin/bash:sh +_host_tools_to_symlink:=${_host_tools_to_symlink:Nsh} +.endif host-symlinks: @echo "Linking host tools into ${DESTDIR}/bin" .for _tool in ${_host_tools_to_symlink} @source_path=`which ${_tool}`; \ if [ ! -e "$${source_path}" ] ; then \ echo "Cannot find host tool '${_tool}'"; false; \ fi; \ rm -f "${DESTDIR}/bin/${_tool}"; \ cp -pf "$${source_path}" "${DESTDIR}/bin/${_tool}" .endfor .for _tool in ${_host_abs_tools_to_symlink} @source_path="${_tool:S/:/ /:[1]}"; \ target_path="${DESTDIR}/bin/${_tool:S/:/ /:[2]}"; \ if [ ! -e "$${source_path}" ] ; then \ echo "Host tool '${src_path}' is missing"; false; \ fi; \ rm -f "$${target_path}"; \ cp -pf "$${source_path}" "$${target_path}" .endfor .if exists(/usr/libexec/flua) rm -f ${DESTDIR}/usr/libexec/flua cp -pf /usr/libexec/flua ${DESTDIR}/usr/libexec/flua .endif # Create all the directories that are needed during the legacy, bootstrap-tools # and cross-tools stages. We do this here using mkdir since mtree may not exist # yet (this happens if we are crossbuilding from Linux/Mac). INSTALLDIR_LIST= \ bin \ lib/casper \ lib/geom \ usr/include/casper \ usr/include/private/ucl \ usr/include/private/zstd \ usr/lib \ usr/libexec installdirs: mkdir -p ${INSTALLDIR_LIST:S,^,${DESTDIR}/,} # Link usr/bin, sbin, and usr/sbin to bin so that it doesn't matter whether a # bootstrap tool was added to WORLTMP with a symlink or by building it in the # bootstrap-tools phase. We could also overrride BINDIR when building bootstrap # tools but adding the symlinks is easier and means all tools are also # in the directory that they are installed to normally. .for _dir in sbin usr/sbin usr/bin # delete existing directories from before r340157 @if [ ! -L ${DESTDIR}/${_dir} ]; then \ echo "removing old non-symlink ${DESTDIR}/${_dir}"; \ rm -rf "${DESTDIR}/${_dir}"; \ fi .endfor ln -sfn bin ${DESTDIR}/sbin ln -sfn ../bin ${DESTDIR}/usr/bin ln -sfn ../bin ${DESTDIR}/usr/sbin .for _group in ${INCSGROUPS:NINCS} mkdir -p "${DESTDIR}/${${_group}DIR}" .endfor .include Index: head/tools/build/cross-build/capsicum_stubs.c =================================================================== --- head/tools/build/cross-build/capsicum_stubs.c (nonexistent) +++ head/tools/build/cross-build/capsicum_stubs.c (revision 364759) @@ -0,0 +1,67 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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 +__FBSDID("$FreeBSD$"); + +#include +#include + +#include + +int +cap_ioctls_limit(int fd, const cap_ioctl_t *cmds, size_t ncmds) +{ + return 0; /* Just pretend that it succeeded */ +} + +int +cap_fcntls_limit(int fd, uint32_t fcntlrights) +{ + return 0; /* Just pretend that it succeeded */ +} + +int +cap_rights_limit(int fd, const cap_rights_t *rights) +{ + return 0; /* Just pretend that it succeeded */ +} + +int +cap_enter(void) +{ + errno = ENOSYS; + return -1; +} Property changes on: head/tools/build/cross-build/capsicum_stubs.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/closefrom.c =================================================================== --- head/tools/build/cross-build/closefrom.c (nonexistent) +++ head/tools/build/cross-build/closefrom.c (revision 364759) @@ -0,0 +1,192 @@ +/* + * Copyright (c) 2004-2005, 2007, 2010, 2012-2014 + * Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +// #include + +#include +#include +#include +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif /* STDC_HEADERS */ +#include +#include +#ifdef HAVE_PSTAT_GETPROC +# include +# include +#else +# ifdef HAVE_DIRENT_H +# include +# define NAMLEN(dirent) strlen((dirent)->d_name) +# else +# define dirent direct +# define NAMLEN(dirent) (dirent)->d_namlen +# ifdef HAVE_SYS_NDIR_H +# include +# endif +# ifdef HAVE_SYS_DIR_H +# include +# endif +# ifdef HAVE_NDIR_H +# include +# endif +# endif +#endif + +#ifndef OPEN_MAX +# define OPEN_MAX 256 +#endif + +#if defined(HAVE_FCNTL_CLOSEM) && !defined(HAVE_DIRFD) +# define closefrom closefrom_fallback +#endif + +static inline void +closefrom_close(int fd) +{ +#ifdef __APPLE__ + /* Avoid potential libdispatch crash when we close its fds. */ + (void)fcntl(fd, F_SETFD, FD_CLOEXEC); +#else + (void)close(fd); +#endif +} + +/* + * Close all file descriptors greater than or equal to lowfd. + * This is the expensive (fallback) method. + */ +void +closefrom_fallback(int lowfd) +{ + long fd, maxfd; + + /* + * Fall back on sysconf() or getdtablesize(). We avoid checking + * resource limits since it is possible to open a file descriptor + * and then drop the rlimit such that it is below the open fd. + */ +#ifdef HAVE_SYSCONF + maxfd = sysconf(_SC_OPEN_MAX); +#else + maxfd = getdtablesize(); +#endif /* HAVE_SYSCONF */ + if (maxfd < 0) + maxfd = OPEN_MAX; + + for (fd = lowfd; fd < maxfd; fd++) + closefrom_close(fd); +} + +/* + * Close all file descriptors greater than or equal to lowfd. + * We try the fast way first, falling back on the slow method. + */ +#if defined(HAVE_FCNTL_CLOSEM) +void +closefrom(int lowfd) +{ + if (fcntl(lowfd, F_CLOSEM, 0) == -1) + closefrom_fallback(lowfd); +} +#elif defined(HAVE_PSTAT_GETPROC) +void +closefrom(int lowfd) +{ + struct pst_status pstat; + int fd; + + if (pstat_getproc(&pstat, sizeof(pstat), 0, getpid()) != -1) { + for (fd = lowfd; fd <= pstat.pst_highestfd; fd++) + (void)close(fd); + } else { + closefrom_fallback(lowfd); + } +} +#elif defined(HAVE_DIRFD) +static int +closefrom_procfs(int lowfd) +{ + const char *path; + DIR *dirp; + struct dirent *dent; + int *fd_array = NULL; + int fd_array_used = 0; + int fd_array_size = 0; + int ret = 0; + int i; + + /* Use /proc/self/fd (or /dev/fd on FreeBSD) if it exists. */ +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__) + path = "/dev/fd"; +# else + path = "/proc/self/fd"; +# endif + dirp = opendir(path); + if (dirp == NULL) + return -1; + + while ((dent = readdir(dirp)) != NULL) { + const char *errstr; + int fd; + + fd = strtonum(dent->d_name, lowfd, INT_MAX, &errstr); + if (errstr != NULL || fd == dirfd(dirp)) + continue; + + if (fd_array_used >= fd_array_size) { + int *ptr; + + if (fd_array_size > 0) + fd_array_size *= 2; + else + fd_array_size = 32; + + ptr = reallocarray(fd_array, fd_array_size, sizeof(int)); + if (ptr == NULL) { + ret = -1; + break; + } + fd_array = ptr; + } + + fd_array[fd_array_used++] = fd; + } + + for (i = 0; i < fd_array_used; i++) + closefrom_close(fd_array[i]); + + free(fd_array); + (void)closedir(dirp); + + return ret; +} + +void +closefrom(int lowfd) +{ + if (closefrom_procfs(lowfd) == 0) + return; + + closefrom_fallback(lowfd); +} +#endif /* HAVE_FCNTL_CLOSEM */ Property changes on: head/tools/build/cross-build/closefrom.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/fake_sysctl.c =================================================================== --- head/tools/build/cross-build/fake_sysctl.c (nonexistent) +++ head/tools/build/cross-build/fake_sysctl.c (revision 364759) @@ -0,0 +1,58 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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. + */ +/* This file contains wrappers for sysctls used during build/install */ +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +int +__freebsd_sysctlbyname( + const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) +{ + if (strcmp(name, "kern.vm_guest") == 0) { + if (!oldp || !oldlenp) + errx(EX_USAGE, "Missing arguments for kern.vm_guest"); + + if (newp || newlen) + errx(EX_USAGE, "kern.vm_guest is read-only"); + strlcpy(oldp, "none", *oldlenp); + *oldlenp = strlen("none"); + } + errx(EX_USAGE, "fatal: unknown sysctl %s\n", name); +} Property changes on: head/tools/build/cross-build/fake_sysctl.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/fgetln_fallback.c =================================================================== --- head/tools/build/cross-build/fgetln_fallback.c (nonexistent) +++ head/tools/build/cross-build/fgetln_fallback.c (revision 364759) @@ -0,0 +1,84 @@ +/* + * Copyright © 2005 Hector Garcia Alvarez + * Copyright © 2005, 2008-2012 Guillem Jover + * + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 +#include +#include +#include + +#include "local-link.h" + +#define HAVE_GETLINE 1 +#ifdef HAVE_GETLINE +struct filebuf { + FILE *fp; + char *buf; + size_t len; +}; + +#define FILEBUF_POOL_ITEMS 32 + +static struct filebuf fb_pool[FILEBUF_POOL_ITEMS]; +static int fb_pool_cur; + +char * +fgetln(FILE *stream, size_t *len) +{ + struct filebuf *fb; + ssize_t nread; + + flockfile(stream); + + /* Try to diminish the possibility of several fgetln() calls being + * used on different streams, by using a pool of buffers per file. */ + fb = &fb_pool[fb_pool_cur]; + if (fb->fp != stream && fb->fp != NULL) { + fb_pool_cur++; + fb_pool_cur %= FILEBUF_POOL_ITEMS; + fb = &fb_pool[fb_pool_cur]; + } + fb->fp = stream; + + nread = getline(&fb->buf, &fb->len, stream); + + funlockfile(stream); + + /* Note: the getdelim/getline API ensures nread != 0. */ + if (nread == -1) { + *len = 0; + return NULL; + } else { + *len = (size_t)nread; + return fb->buf; + } +} +libbsd_link_warning(fgetln, + "This function cannot be safely ported, use getline(3) " + "instead, as it is supported by GNU and POSIX.1-2008.") +#else +#error "Function fgetln() needs to be ported." +#endif Property changes on: head/tools/build/cross-build/fgetln_fallback.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/fgetwln_fallback.c =================================================================== --- head/tools/build/cross-build/fgetwln_fallback.c (nonexistent) +++ head/tools/build/cross-build/fgetwln_fallback.c (revision 364759) @@ -0,0 +1,93 @@ +/* + * Copyright 2012 Guillem Jover + * + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 + +#include +#include +#include + +#include "local-link.h" + +struct filewbuf { + FILE *fp; + wchar_t *wbuf; + size_t len; +}; + +#define FILEWBUF_INIT_LEN 128 +#define FILEWBUF_POOL_ITEMS 32 + +static struct filewbuf fb_pool[FILEWBUF_POOL_ITEMS]; +static int fb_pool_cur; + +wchar_t * +fgetwln(FILE *stream, size_t *lenp) +{ + struct filewbuf *fb; + wint_t wc; + size_t wused = 0; + + /* Try to diminish the possibility of several fgetwln() calls being + * used on different streams, by using a pool of buffers per file. */ + fb = &fb_pool[fb_pool_cur]; + if (fb->fp != stream && fb->fp != NULL) { + fb_pool_cur++; + fb_pool_cur %= FILEWBUF_POOL_ITEMS; + fb = &fb_pool[fb_pool_cur]; + } + fb->fp = stream; + + while ((wc = fgetwc(stream)) != WEOF) { + if (!fb->len || wused >= fb->len) { + wchar_t *wp; + + if (fb->len) + fb->len *= 2; + else + fb->len = FILEWBUF_INIT_LEN; + + wp = reallocarray(fb->wbuf, fb->len, sizeof(wchar_t)); + if (wp == NULL) { + wused = 0; + break; + } + fb->wbuf = wp; + } + + fb->wbuf[wused++] = wc; + + if (wc == L'\n') + break; + } + + *lenp = wused; + return wused ? fb->wbuf : NULL; +} + +libbsd_link_warning(fgetwln, + "This function cannot be safely ported, use fgetwc(3) " + "instead, as it is supported by C99 and POSIX.1-2001.") Property changes on: head/tools/build/cross-build/fgetwln_fallback.c ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/local-link.h =================================================================== --- head/tools/build/cross-build/local-link.h (nonexistent) +++ head/tools/build/cross-build/local-link.h (revision 364759) @@ -0,0 +1,38 @@ +/* + * Copyright © 2015 Guillem Jover + * + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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. + */ + +#ifndef LIBBSD_LOCAL_LINK_H +#define LIBBSD_LOCAL_LINK_H + +#ifdef notyet +#define libbsd_link_warning(symbol, msg) \ + static const char libbsd_emit_link_warning_##symbol[] \ + __attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg; +#else +#define libbsd_link_warning(symbol, msg) +#endif + +#endif Property changes on: head/tools/build/cross-build/local-link.h ___________________________________________________________________ Added: fbsd:nokeywords ## -0,0 +1 ## +yes \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/cross-build/progname.c =================================================================== --- head/tools/build/cross-build/progname.c (nonexistent) +++ head/tools/build/cross-build/progname.c (revision 364759) @@ -0,0 +1,53 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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 +__FBSDID("$FreeBSD$"); + +#include + +#ifdef __GLIBC__ +extern const char *__progname; +const char * +getprogname(void) +{ + return (__progname); +} +void +setprogname(const char *progname) +{ + __progname = progname; +} +#endif /* __GLIBC__ */ Property changes on: head/tools/build/cross-build/progname.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/libc-bootstrap/libc_private.h =================================================================== --- head/tools/build/libc-bootstrap/libc_private.h (nonexistent) +++ head/tools/build/libc-bootstrap/libc_private.h (revision 364759) @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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. + * + * $FreeBSD$ + */ +#pragma once + +#define __libc_sigprocmask(a, b, c) sigprocmask(a, b, c) Property changes on: head/tools/build/libc-bootstrap/libc_private.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/libc-bootstrap/namespace.h =================================================================== --- head/tools/build/libc-bootstrap/namespace.h (nonexistent) +++ head/tools/build/libc-bootstrap/namespace.h (revision 364759) @@ -0,0 +1,52 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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. + * + * $FreeBSD$ + */ +#pragma once + +#define _open(...) open(__VA_ARGS__) +#define _close(a) close(a) +#define _fstat(a, b) fstat(a, b) +#define _read(a, b, c) read(a, b, c) +#define _write(a, b, c) write(a, b, c) +#define _writev(a, b, c) writev(a, b, c) +#define _fsync(a) fsync(a) +#define _getprogname() getprogname() +#define _err(...) err(__VA_ARGS__) + +#define _pthread_mutex_unlock pthread_mutex_unlock +#define _pthread_mutex_lock pthread_mutex_lock + Property changes on: head/tools/build/libc-bootstrap/namespace.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/libc-bootstrap/un-namespace.h =================================================================== --- head/tools/build/libc-bootstrap/un-namespace.h (nonexistent) +++ head/tools/build/libc-bootstrap/un-namespace.h (revision 364759) @@ -0,0 +1,40 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2018-2020 Alex Richardson + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory (Department of Computer Science and + * Technology) under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the + * DARPA SSITH research programme. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * 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 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. + * + * $FreeBSD$ + */ +#pragma once +/* This can be empty when building the FreeBSD compatible bootstrap files */ + Property changes on: head/tools/build/libc-bootstrap/un-namespace.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/mk/Makefile.boot =================================================================== --- head/tools/build/mk/Makefile.boot (revision 364758) +++ head/tools/build/mk/Makefile.boot (revision 364759) @@ -1,30 +1,98 @@ # $FreeBSD$ CFLAGS+= -I${WORLDTMP}/legacy/usr/include DPADD+= ${WORLDTMP}/legacy/usr/lib/libegacy.a LDADD+= -legacy LDFLAGS+= -L${WORLDTMP}/legacy/usr/lib +.if ${.MAKE.OS} != "FreeBSD" +# On MacOS using a non-mac ar will fail the build, similarly on Linux using +# nm may not work as expected if the nm for the target architecture comes in +# $PATH before a nm that supports the host architecture. +# To ensure that host binary compile as expected we use the tools from /usr/bin. +AR:= /usr/bin/ar +RANLIB:= /usr/bin/ranlib +NM:= /usr/bin/nm + +# Don't use lorder and tsort since lorder is not installed by default on most +# Linux systems and the FreeBSD lorder does not work on Linux. For the bootstrap +# tools the order of the .o files should not matter since we only care about +# a few individual files (and might soon require linking with lld anyway) +LORDER:=echo +TSORT:=cat +# When using cat as tsort we can't pass -q: +TSORTFLAGS:= + +# Avoid stale dependecy warnings: +LIBC:= +LIBZ:= +LIBM:= +LIBUTIL:= +LIBCPLUSPLUS:= +LIBARCHIVE:= +LIBPTHREAD:= +LIBMD:=${WORLDTMP}/legacy/usr/lib/libmd.a +LIBNV:=${WORLDTMP}/legacy/usr/lib/libmd.a +LIBSBUF:=${WORLDTMP}/legacy/usr/lib/libsbuf.a +LIBY:=${WORLDTMP}/legacy/usr/lib/liby.a +LIBL:=${WORLDTMP}/legacy/usr/lib/libl.a +LIBROKEN:=${WORLDTMP}/legacy/usr/lib/libroken.a +LIBDWARF:=${WORLDTMP}/legacy/usr/lib/libdwarf.a +LIBELF:=${WORLDTMP}/legacy/usr/lib/libelf.a + +# Add various -Werror flags to catch missing function declarations +CFLAGS+= -Werror=implicit-function-declaration -Werror=implicit-int \ + -Werror=return-type -Wundef +CFLAGS+= -DHAVE_NBTOOL_CONFIG_H=1 +CFLAGS+= -D__BSD_VISIBLE=1 +CFLAGS+= -I${SRCTOP}/tools/build/cross-build/include/common + +# b64_pton and b64_ntop is in libresolv on MacOS and Linux: +# TODO: only needed for uuencode and uudecode +LDADD+=-lresolv + +.if ${.MAKE.OS} == "Linux" +CFLAGS+= -I${SRCTOP}/tools/build/cross-build/include/linux +CFLAGS+= -std=gnu99 -D_GNU_SOURCE=1 +# Needed for sem_init, etc. on Linux (used by usr.bin/sort) +LDADD+= -pthread + +.elif ${.MAKE.OS} == "Darwin" +CFLAGS+= -D_DARWIN_C_SOURCE=1 +CFLAGS+= -I${SRCTOP}/tools/build/cross-build/include/mac +# The macOS ar and ranlib don't understand all the flags supported by the +# FreeBSD and Linux ar/ranlib +ARFLAGS:= -crs +RANLIBFLAGS:= + +# to get libarchive (needed for elftoolchain) +# MacOS ships /usr/lib/libarchive.dylib but doesn't provide the headers +CFLAGS+= -idirafter ${SRCTOP}/contrib/libarchive/libarchive +.else +.error "Unsupported build OS: ${.MAKE.OS}" +.endif +.endif # ${.MAKE.OS} != "FreeBSD" + # we do not want to capture dependencies referring to the above UPDATE_DEPENDFILE= no # When building host tools we should never pull in headers from the source sys # directory to avoid any ABI issues that might cause the built binary to crash. # The only exceptions to this are sys/cddl/compat for dtrace bootstrap tools and # sys/crypto for libmd bootstrap. # We have to skip this check during make obj since bsd.crunchgen.mk will run # make obj on every directory during the build-tools phase. .if !make(obj) .if !empty(CFLAGS:M*${SRCTOP}/sys) .error Do not include $${SRCTOP}/sys when building bootstrap tools. \ Copy the header to $${WORLDTMP}/legacy in tools/build/Makefile instead. \ Error was caused by Makefile in ${.CURDIR} .endif # ${SRCTOP}/include should also never be used to avoid ABI issues .if !empty(CFLAGS:M*${SRCTOP}/include*) .error Do not include $${SRCTOP}/include when building bootstrap tools. \ Copy the header to $${WORLDTMP}/legacy in tools/build/Makefile instead. \ Error was caused by Makefile in ${.CURDIR} .endif .endif Index: head/tools/build/mk/Makefile.boot.pre =================================================================== --- head/tools/build/mk/Makefile.boot.pre (nonexistent) +++ head/tools/build/mk/Makefile.boot.pre (revision 364759) @@ -0,0 +1,12 @@ +# $FreeBSD$ + +# Various MK_* options need to be set before including bsd.prog.mk/bsd.lib.mk +.if ${.MAKE.OS} != "FreeBSD" +# Most Linux distributions don't ship the .a files for static linking. +# And on macOS it is impossible to create a statically linked binary. +NO_SHARED:= no +MK_PIE:= no +MK_RETPOLINE= no +# There is no objcopy on macOS so we can't do the MK_DEBUG_FILES objcopy magic. +MK_DEBUG_FILES:=no +.endif Property changes on: head/tools/build/mk/Makefile.boot.pre ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/tools/build/mk/bsd.lib.mk =================================================================== --- head/tools/build/mk/bsd.lib.mk (revision 364758) +++ head/tools/build/mk/bsd.lib.mk (revision 364759) @@ -1,4 +1,7 @@ # $FreeBSD$ +.include "Makefile.boot.pre" +# Don't build shared libraries during bootstrap +NO_PIC= yes .include "../../../share/mk/bsd.lib.mk" .include "Makefile.boot" Index: head/tools/build/mk/bsd.prog.mk =================================================================== --- head/tools/build/mk/bsd.prog.mk (revision 364758) +++ head/tools/build/mk/bsd.prog.mk (revision 364759) @@ -1,4 +1,5 @@ # $FreeBSD$ +.include "Makefile.boot.pre" .include "../../../share/mk/bsd.prog.mk" .include "Makefile.boot"