diff --git a/tools/build/Makefile b/tools/build/Makefile index ee9d9692df3b..28257a2ea2e5 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile @@ -1,345 +1,347 @@ # $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 .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.pwcache.c+= -I${.CURDIR}/../../contrib/libc-pwcache SRCS+= pwcache.c .endif _WITH_STRSVIS!= grep -c strsvis ${HOST_INCLUDE_ROOT}/vis.h 2>/dev/null || true .if ${_WITH_STRSVIS} == 0 .PATH: ${.CURDIR}/../../contrib/libc-vis INCS+= vis.h SRCS+= vis.c unvis.c CFLAGS.vis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 CFLAGS.unvis.c+= -I${.CURDIR}/../../contrib/libc-vis -DHAVE_VIS=0 -DHAVE_SVIS=0 .endif _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 .endif _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 ${HOST_INCLUDE_ROOT}/strings.h || true .if ${_WITH_EXPLICIT_BZERO} == 0 # .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(${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 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 .if ${.MAKE.OS} != "FreeBSD" .PATH: ${.CURDIR}/cross-build # 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 +# Stub implementations of fflagstostr/strtofflags +SRCS+= fflags.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 sh sleep stat tee touch tr true uname uniq unxz \ wc which xz # 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} @export PATH=$${PATH}:/usr/local/bin; source_path=`which ${_tool}`; \ if [ ! -e "$${source_path}" ] ; then \ echo "Cannot find host tool '${_tool}' in PATH ($$PATH)." >&2; 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 [ -e ${DESTDIR}/${_dir} ] && [ ! -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 diff --git a/tools/build/cross-build/capsicum_stubs.c b/tools/build/cross-build/capsicum_stubs.c index b042796c069f..227ef3496b09 100644 --- a/tools/build/cross-build/capsicum_stubs.c +++ b/tools/build/cross-build/capsicum_stubs.c @@ -1,67 +1,68 @@ /*- * 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) +cap_ioctls_limit(int fd __unused, const cap_ioctl_t *cmds __unused, + size_t ncmds __unused) { return 0; /* Just pretend that it succeeded */ } int -cap_fcntls_limit(int fd, uint32_t fcntlrights) +cap_fcntls_limit(int fd __unused, uint32_t fcntlrights __unused) { return 0; /* Just pretend that it succeeded */ } int -cap_rights_limit(int fd, const cap_rights_t *rights) +cap_rights_limit(int fd __unused, const cap_rights_t *rights __unused) { return 0; /* Just pretend that it succeeded */ } int cap_enter(void) { errno = ENOSYS; return -1; } diff --git a/tools/build/cross-build/fake_sysctl.c b/tools/build/cross-build/fake_sysctl.c index 7b9524e1626b..289fb83652f6 100644 --- a/tools/build/cross-build/fake_sysctl.c +++ b/tools/build/cross-build/fake_sysctl.c @@ -1,58 +1,60 @@ /*- * 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 #include int -__freebsd_sysctlbyname( - const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) +__freebsd_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, + const 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); } diff --git a/tools/build/cross-build/include/common/unistd.h b/tools/build/cross-build/fflags.c similarity index 77% copy from tools/build/cross-build/include/common/unistd.h copy to tools/build/cross-build/fflags.c index f438b8936105..f1d23c3637b6 100644 --- a/tools/build/cross-build/include/common/unistd.h +++ b/tools/build/cross-build/fflags.c @@ -1,57 +1,62 @@ /*- * 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. * + * This work was supported by Innovate UK project 105694, "Digital Security by + * Design (DSbD) Technology Platform Prototype". + * * 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 -#include_next -#include -static inline int -check_utility_compat(const char *utility) +#include +#include + +char * +fflagstostr(u_long flags __unused) { + return strdup(""); +} + +int +strtofflags(char **stringp __unused, u_long *setp, u_long *clrp) +{ + /* On linux just ignore the file flags for now */ /* - * The check_utility_compat() function returns zero if utility should - * implement strict IEEE Std 1003.1-2001 (“POSIX.1”) behavior, and - * nonzero otherwise. - * - * During bootstrapping from another host system always returning 1 - * is probably the best. + * XXX: this will prevent makefs from setting noschg on libc, etc. + * so we should really find a way to support flags in disk images. */ - return (1); + if (setp) + *setp = 0; + if (clrp) + *clrp = 0; + return (0); /* success */ } - -/* Just needs to be declared, doesn't actually have to be implemented */ -void closefrom(int lowfd); diff --git a/tools/build/cross-build/include/common/grp.h b/tools/build/cross-build/include/common/grp.h index add44b9f8695..08a8bc540569 100644 --- a/tools/build/cross-build/include/common/grp.h +++ b/tools/build/cross-build/include/common/grp.h @@ -1,61 +1,61 @@ /*- * 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 #include_next #define group_from_gid __nbcompat_group_from_gid int pwcache_groupdb(int (*a_setgroupent)(int), void (*a_endgrent)(void), struct group *(*a_getgrnam)(const char *), struct group *(*a_getgrgid)(gid_t)); int gid_from_group(const char *name, gid_t *gid); int gid_from_group(const char *name, gid_t *gid); const char *group_from_gid(gid_t gid, int noname); #ifdef __linux__ static inline int -setgroupent(int stayopen) +setgroupent(int stayopen __unused) { setgrent(); return (1); } #endif diff --git a/tools/build/cross-build/include/common/pwd.h b/tools/build/cross-build/include/common/pwd.h index 243da3a1332f..e167fe47701f 100644 --- a/tools/build/cross-build/include/common/pwd.h +++ b/tools/build/cross-build/include/common/pwd.h @@ -1,60 +1,60 @@ /*- * 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 #include_next #define user_from_uid __nbcompat_user_from_uid int pwcache_userdb(int (*a_setpassent)(int), void (*a_endpwent)(void), struct passwd *(*a_getpwnam)(const char *), struct passwd *(*a_getpwuid)(uid_t)); int uid_from_user(const char *name, uid_t *uid); int uid_from_user(const char *name, uid_t *uid); const char *user_from_uid(uid_t uid, int noname); #ifdef __linux__ static inline int -setpassent(int stayopen) +setpassent(int stayopen __unused) { setpwent(); return (1); } #endif diff --git a/tools/build/cross-build/include/common/sys/cdefs.h b/tools/build/cross-build/include/common/sys/cdefs.h index c86369ab778a..c129542b6180 100644 --- a/tools/build/cross-build/include/common/sys/cdefs.h +++ b/tools/build/cross-build/include/common/sys/cdefs.h @@ -1,281 +1,257 @@ /*- * 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 /* musl libc does not provide a sys/cdefs.h header */ #if __has_include_next() #include_next #else /* No sys/cdefs.h header exists so we have to provide some basic macros */ #ifdef __cplusplus #define __BEGIN_DECLS extern "C" { #define __END_DECLS } #else #define __BEGIN_DECLS #define __END_DECLS #endif #endif #ifndef __FBSDID #define __FBSDID(id) #endif #ifndef __IDSTRING #define __IDSTRING(name, string) #endif -#ifndef rounddown -#define rounddown(x, y) (((x) / (y)) * (y)) -#define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */ -#define roundup(x, y) ((((x) + ((y)-1)) / (y)) * (y)) /* to any y */ -#define roundup2(x, y) \ - (((x) + ((y)-1)) & (~((y)-1))) /* if y is powers of two */ -#define powerof2(x) ((((x)-1) & (x)) == 0) -#endif - #ifndef __pure #define __pure __attribute__((__pure__)) #endif #ifndef __packed #define __packed __attribute__((__packed__)) #endif #ifndef __dead2 #define __dead2 __attribute__((__noreturn__)) #endif #ifndef __pure2 #define __pure2 __attribute__((__const__)) #endif #ifndef __used #define __used __attribute__((__used__)) #endif #ifndef __aligned #define __aligned(x) __attribute__((__aligned__(x))) #endif #ifndef __section #define __section(x) __attribute__((__section__(x))) #endif #ifndef __alloc_size #define __alloc_size(...) __attribute__((__alloc_size__(__VA_ARGS__))) #endif #ifndef __alloc_size2 #define __alloc_size2(n, x) __attribute__((__alloc_size__(n, x))) #endif #ifndef __alloc_align #define __alloc_align(x) __attribute__((__alloc_align__(x))) #endif #ifndef __result_use_check #define __result_use_check __attribute__((__warn_unused_result__)) #endif #ifndef __printflike #define __printflike(fmtarg, firstvararg) \ __attribute__((__format__(__printf__, fmtarg, firstvararg))) #endif #ifndef __printf0like #define __printf0like(fmtarg, firstvararg) \ __attribute__((__format__(__printf0__, fmtarg, firstvararg))) #endif #ifndef __predict_true #define __predict_true(exp) __builtin_expect((exp), 1) #endif #ifndef __predict_false #define __predict_false(exp) __builtin_expect((exp), 0) #endif #ifndef __weak_reference #ifdef __ELF__ #define __weak_reference(sym, alias) \ __asm__(".weak " #alias); \ __asm__(".equ " #alias ", " #sym) #else #define __weak_reference(sym, alias) \ static int alias() __attribute__((weakref(#sym))); #endif #endif /* Some files built as part of the bootstrap libegacy use these macros, but * since we aren't actually building libc.so, we can defined them to be empty */ #ifndef __sym_compat #define __sym_compat(sym, impl, verid) /* not needed for bootstrapping */ #endif #ifndef __sym_default #define __sym_default(sym, impl, verid) /* not needed for bootstrapping */ #endif #ifndef __sym_default #define __warn_references(sym, msg) /* not needed for bootstrapping */ #endif #ifndef __malloc_like #define __malloc_like __attribute__((__malloc__)) #endif -#ifndef nitems -// https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 -#define nitems(x) \ - ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) -#endif - #ifndef __min_size #if !defined(__cplusplus) #define __min_size(x) static(x) #else #define __min_size(x) (x) #endif #endif #ifndef __unused #define __unused __attribute__((unused)) #endif #define __format_arg(fmtarg) __attribute__((__format_arg__(fmtarg))) #ifndef __exported #define __exported __attribute__((__visibility__("default"))) #endif #ifndef __hidden #define __hidden __attribute__((__visibility__("hidden"))) #endif #ifndef __unreachable #define __unreachable() __builtin_unreachable() #endif #ifndef __clang__ /* GCC doesn't like the printf0 format specifier. Clang treats it the same as * printf so add the compatibility macro here. */ #define __printf0__ __printf__ #endif -/* - * These should probably be in sys/types.h but mtree expects them to exist - * without including - */ -typedef unsigned char u_char; -typedef unsigned short u_short; -typedef unsigned int u_int; -typedef unsigned long u_long; - /* On MacOS __CONCAT is defined as x ## y, which won't expand macros */ #undef __CONCAT #define __CONCAT1(x, y) x##y #define __CONCAT(x, y) __CONCAT1(x, y) #ifndef __STRING #define __STRING(x) #x /* stringify without expanding x */ #endif #ifndef __XSTRING #define __XSTRING(x) __STRING(x) /* expand x, then stringify */ #endif #ifndef __has_feature #define __has_feature(...) 0 #endif #ifndef __has_builtin #define __has_builtin(...) 0 #endif /* * Nullability qualifiers: currently only supported by Clang. */ #if !(defined(__clang__) && __has_feature(nullability)) #define _Nonnull #define _Nullable #define _Null_unspecified #define __NULLABILITY_PRAGMA_PUSH #define __NULLABILITY_PRAGMA_POP #else #define __NULLABILITY_PRAGMA_PUSH \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wnullability-completeness\"") #define __NULLABILITY_PRAGMA_POP _Pragma("clang diagnostic pop") #endif #ifndef __offsetof #define __offsetof(type, field) __builtin_offsetof(type, field) #endif #define __rangeof(type, start, end) \ (__offsetof(type, end) - __offsetof(type, start)) #ifndef __containerof #define __containerof(x, s, m) \ ({ \ const volatile __typeof(((s *)0)->m) *__x = (x); \ __DEQUALIFY( \ s *, (const volatile char *)__x - __offsetof(s, m)); \ }) #endif #ifndef __RCSID #define __RCSID(x) #endif #ifndef __FBSDID #define __FBSDID(x) #endif #ifndef __RCSID #define __RCSID(x) #endif #ifndef __RCSID_SOURCE #define __RCSID_SOURCE(x) #endif #ifndef __SCCSID #define __SCCSID(x) #endif #ifndef __COPYRIGHT #define __COPYRIGHT(x) #endif #ifndef __DECONST #define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var)) #endif #ifndef __DEVOLATILE #define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var)) #endif #ifndef __DEQUALIFY #define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var)) #endif /* Expose all declarations when using FreeBSD headers */ #define __POSIX_VISIBLE 200809 #define __XSI_VISIBLE 700 #define __BSD_VISIBLE 1 #define __ISO_C_VISIBLE 2011 #define __EXT1_VISIBLE 1 diff --git a/tools/build/cross-build/include/common/sys/param.h b/tools/build/cross-build/include/common/sys/param.h index a197fe3ea9ff..f672b1067d46 100644 --- a/tools/build/cross-build/include/common/sys/param.h +++ b/tools/build/cross-build/include/common/sys/param.h @@ -1,65 +1,91 @@ /*- * 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. * + * This work was supported by Innovate UK project 105694, "Digital Security by + * Design (DSbD) Technology Platform Prototype". + * * 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 #include_next #ifndef BLKDEV_IOSIZE #define BLKDEV_IOSIZE PAGE_SIZE /* default block device I/O size */ #endif #ifndef DFLTPHYS #define DFLTPHYS (64 * 1024) /* default max raw I/O transfer size */ #endif #ifndef MAXPHYS #define MAXPHYS (128 * 1024) /* max raw I/O transfer size */ #endif #ifndef MAXDUMPPGS #define MAXDUMPPGS (DFLTPHYS / PAGE_SIZE) #endif #ifndef MCLSHIFT #define MCLSHIFT 11 /* convert bytes to mbuf clusters */ #endif #ifndef MCLBYTES #define MCLBYTES (1 << MCLSHIFT) /* size of an mbuf cluster */ #endif #ifndef __PAST_END #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) #endif + +#ifndef nitems +// https://stackoverflow.com/questions/1598773/is-there-a-standard-function-in-c-that-would-return-the-length-of-an-array/1598827#1598827 +#define nitems(x) \ + ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x]))))) +#endif + +#ifndef rounddown +#define rounddown(x, y) (((x) / (y)) * (y)) +#endif +#ifndef rounddown2 +#define rounddown2(x, y) ((x) & (~((y)-1))) /* if y is power of two */ +#endif +#ifndef roundup +#define roundup(x, y) ((((x) + ((y)-1)) / (y)) * (y)) /* to any y */ +#endif +#ifndef roundup2 +#define roundup2(x, y) \ + (((x) + ((y)-1)) & (~((y)-1))) /* if y is powers of two */ +#endif +#ifndef powerof2 +#define powerof2(x) ((((x)-1) & (x)) == 0) +#endif diff --git a/tools/build/cross-build/include/common/unistd.h b/tools/build/cross-build/include/common/unistd.h index f438b8936105..593dd700f140 100644 --- a/tools/build/cross-build/include/common/unistd.h +++ b/tools/build/cross-build/include/common/unistd.h @@ -1,57 +1,57 @@ /*- * 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 #include_next #include static inline int -check_utility_compat(const char *utility) +check_utility_compat(const char *utility __unused) { /* * The check_utility_compat() function returns zero if utility should * implement strict IEEE Std 1003.1-2001 (“POSIX.1”) behavior, and * nonzero otherwise. * * During bootstrapping from another host system always returning 1 * is probably the best. */ return (1); } /* Just needs to be declared, doesn't actually have to be implemented */ void closefrom(int lowfd); diff --git a/tools/build/cross-build/include/linux/limits.h b/tools/build/cross-build/include/linux/limits.h index 98523fe0d7a3..833b49b49348 100644 --- a/tools/build/cross-build/include/linux/limits.h +++ b/tools/build/cross-build/include/linux/limits.h @@ -1,114 +1,110 @@ /*- * 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$ */ #if __has_include_next() #include_next #endif -#ifdef __STRICT_ANSI__ -#warning __STRICT_ANSI__ defined -#endif - #if __has_include() #include #endif #if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L #if !defined(_GNU_SOURCE) #warning "Attempting to use limits.h with -std=c89/without _GNU_SOURCE, many macros will be missing" #endif #else /* Not C89 */ /* Not C89 -> check that all macros that we expect are defined */ #ifndef IOV_MAX #error IOV_MAX should be defined #endif #endif /* C89 */ #ifndef MAXBSIZE #define MAXBSIZE 65536 /* must be power of 2 */ #endif #ifndef OFF_MAX #define OFF_MAX UINT64_MAX #endif #ifndef QUAD_MAX #define QUAD_MAX INT64_MAX #endif #ifndef GID_MAX #define GID_MAX ((gid_t)-1) #endif #ifndef UID_MAX #define UID_MAX ((uid_t)-1) #endif #ifdef __GLIBC__ #ifndef _LIBC_LIMITS_H_ #error "DIDN't include correct limits?" #endif #ifndef __USE_XOPEN #warning __USE_XOPEN should be defined (did you forget to set _GNU_SOURCE?) #endif #include #include /* For IOV_MAX */ /* Sanity checks for glibc */ #ifndef _GNU_SOURCE #error _GNU_SOURCE not defined #endif #ifndef __USE_POSIX #warning __USE_POSIX not defined #endif #if defined __GNUC__ && !defined _GCC_LIMITS_H_ #error "GCC limits not included" #endif #ifndef __OFF_T_MATCHES_OFF64_T #error "Expected 64-bit off_t" #endif #ifndef _POSIX_PATH_MAX #define _POSIX_PATH_MAX PATH_MAX #endif #endif diff --git a/tools/build/cross-build/include/linux/sys/sysctl.h b/tools/build/cross-build/include/linux/sys/sysctl.h deleted file mode 100644 index d24a85b4a266..000000000000 --- a/tools/build/cross-build/include/linux/sys/sysctl.h +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * 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 -/* The Linux sysctl struct has a member called __unused */ -#undef __unused -#include_next -#define __unused __attribute__((unused)) diff --git a/tools/build/cross-build/include/linux/unistd.h b/tools/build/cross-build/include/linux/unistd.h index 0a6b6296a9de..9d1bd1bf4025 100644 --- a/tools/build/cross-build/include/linux/unistd.h +++ b/tools/build/cross-build/include/linux/unistd.h @@ -1,105 +1,87 @@ /*- * 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 #ifndef __USE_POSIX2 /* Ensure that unistd.h pulls in getopt */ #define __USE_POSIX2 #endif #include_next #include #include #include #include #include #ifndef required_argument #error "something went wrong including getopt" #endif __BEGIN_DECLS #ifdef __GLIBC__ static inline int issetugid(void) { return (0); } #endif -static inline char * -fflagstostr(u_long flags) -{ - return strdup(""); -} - -static inline int -strtofflags(char **stringp, u_long *setp, u_long *clrp) -{ - /* On linux just ignore the file flags for now */ - /* - * XXXAR: this will prevent makefs from setting noschg on libc, etc - * so we should really build the version from libc - */ - if (setp) - *setp = 0; - if (clrp) - *clrp = 0; - return (0); /* success */ -} +char *fflagstostr(unsigned long flags); +int strtofflags(char **stringp, u_long *setp, u_long *clrp); /* * getentropy() was added in glibc 2.25. Declare it for !glibc and older * versions. */ #if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 25) static inline int getentropy(void *buf, size_t buflen) { return (syscall(__NR_getrandom, buf, buflen, 0)); } #endif /* Used by elftoolchain: */ extern char *program_invocation_name; extern char *program_invocation_short_name; void *setmode(const char *); mode_t getmode(const void *, mode_t); __END_DECLS diff --git a/tools/build/mk/Makefile.boot b/tools/build/mk/Makefile.boot index ada14e6112f4..4adc04b0ea9a 100644 --- a/tools/build/mk/Makefile.boot +++ b/tools/build/mk/Makefile.boot @@ -1,100 +1,105 @@ # $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+= -I${SRCTOP}/tools/build/cross-build/include/common +# This is needed for code that compiles for pre-C11 C standards +CWARNFLAGS+= -Wno-typedef-redefinition +# bsd.sys.mk explicitly turns on -Wsystem-headers, but that's extremely +# noisy when building on Linux. +CWARNFLAGS+= -Wno-system-headers # 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 +CFLAGS+= -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 # GCC doesn't allow silencing warn_unused_result calls with (void) casts. CFLAGS.gcc+=-Wno-unused-result