From f88dbe36c858bfe2414c212a19a830724f3b8bb7 Mon Sep 17 00:00:00 2001 From: Jacob Weinstock Date: Fri, 6 Oct 2023 19:50:10 -0600 Subject: [PATCH] Update kernel to 5.15 Signed-off-by: Jacob Weinstock --- .github/workflows/kernel-ci.yaml | 2 +- .github/workflows/kernel-push.yaml | 2 +- kernel/Dockerfile | 65 +- kernel/Dockerfile.bcc | 62 +- kernel/Dockerfile.kconfig | 15 +- kernel/Dockerfile.kconfigx | 71 ++ kernel/Dockerfile.perf | 5 +- kernel/Dockerfile.zfs | 7 +- kernel/Makefile | 23 +- kernel/Makefile.old | 310 --------- kernel/README.md | 380 ++++++++++- kernel/bcc.patches/100-musl-compat.patch | 788 ----------------------- kernel/bcc.patches/cdefs.h | 628 ------------------ kernel/bcc.patches/decl.patch | 23 - kernel/bcc.patches/error.h | 29 - kernel/bcc.patches/intl.patch | 11 - kernel/bcc.patches/temp_failure.patch | 17 - kernel/config-5.15.x-aarch64 | 2 +- kernel/config-5.15.x-x86_64 | 2 +- rules.mk | 6 + 20 files changed, 488 insertions(+), 1960 deletions(-) create mode 100644 kernel/Dockerfile.kconfigx delete mode 100644 kernel/Makefile.old delete mode 100644 kernel/bcc.patches/100-musl-compat.patch delete mode 100644 kernel/bcc.patches/cdefs.h delete mode 100644 kernel/bcc.patches/decl.patch delete mode 100644 kernel/bcc.patches/error.h delete mode 100644 kernel/bcc.patches/intl.patch delete mode 100644 kernel/bcc.patches/temp_failure.patch diff --git a/.github/workflows/kernel-ci.yaml b/.github/workflows/kernel-ci.yaml index 4c03ab3..e39b2a2 100644 --- a/.github/workflows/kernel-ci.yaml +++ b/.github/workflows/kernel-ci.yaml @@ -21,7 +21,7 @@ jobs: - run: echo "REGISTRY=$(ip addr show dev bond0 | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }' | head -n 1)" >> $GITHUB_ENV - - run: make -C kernel devbuild ORG=${REGISTRY}:5000 + - run: make -C kernel devbuild ORG=${REGISTRY}:5000 IMAGE=hook-kernel # TODO: add artifacts for the built images #- uses: actions/upload-artifact@v3 diff --git a/.github/workflows/kernel-push.yaml b/.github/workflows/kernel-push.yaml index df2b05a..4075079 100644 --- a/.github/workflows/kernel-push.yaml +++ b/.github/workflows/kernel-push.yaml @@ -21,4 +21,4 @@ jobs: username: ${{ secrets.QUAY_USERNAME }} password: ${{ secrets.QUAY_PASSWORD }} - - run: make -C kernel build + - run: make -C kernel ORG=quay.io/tinkerbell IMAGE=hook-kernel build diff --git a/kernel/Dockerfile b/kernel/Dockerfile index 1ad02e8..609f0a6 100644 --- a/kernel/Dockerfile +++ b/kernel/Dockerfile @@ -1,4 +1,6 @@ -FROM linuxkit/alpine:e2391e0b164c57db9f6c4ae110ee84f766edc430 AS kernel-build +ARG BUILD_IMAGE +FROM ${BUILD_IMAGE} AS kernel-build +ARG BUILD_IMAGE RUN apk add \ argp-standalone \ automake \ @@ -16,10 +18,12 @@ RUN apk add \ installkernel \ kmod \ elfutils-dev \ + libunwind-dev \ linux-headers \ mpc1-dev \ mpfr-dev \ ncurses-dev \ + openssl \ openssl-dev \ patch \ rsync \ @@ -30,23 +34,18 @@ RUN apk add \ xz-dev \ zlib-dev -# libunwind-dev pkg is missing for s390x for now. Only install on other arch -RUN [ $(uname -m) != s390x ] && apk add libunwind-dev || true - ARG KERNEL_VERSION ARG KERNEL_SERIES ARG EXTRA ARG DEBUG -ENV WIREGUARD_VERSION=1.0.20200506 -ENV WIREGUARD_SHA256="98a99f2b825a82d57a7213e666f1ee4f7cc02bddb09bf4908b4b09447a8f121e" -ENV WIREGUARD_URL=https://git.zx2c4.com/wireguard-linux-compat/snapshot/wireguard-linux-compat-${WIREGUARD_VERSION}.tar.xz - # We copy the entire directory. This copies some unneeded files, but # allows us to check for the existence /patches-${KERNEL_SERIES} to # build kernels without patches. COPY / / +RUN mkdir -p /out/src + # Download and verify kernel # PGP keys: 589DA6B1 (greg@kroah.com) & 6092693E (autosigner@kernel.org) & 00411886 (torvalds@linux-foundation.org) RUN KERNEL_MAJOR=$(echo ${KERNEL_VERSION} | cut -d . -f 1) && \ @@ -60,19 +59,17 @@ RUN KERNEL_MAJOR=$(echo ${KERNEL_VERSION} | cut -d . -f 1) && \ KERNEL_SHA256=$(grep linux-${KERNEL_VERSION}.tar.xz sha256sums.asc | cut -d ' ' -f 1) && \ [ -f linux-${KERNEL_VERSION}.tar.xz ] || curl -fsSLO ${KERNEL_SOURCE} && \ echo "${KERNEL_SHA256} linux-${KERNEL_VERSION}.tar.xz" | sha256sum -c - && \ - xz -T 0 -d linux-${KERNEL_VERSION}.tar.xz && \ + xz -d linux-${KERNEL_VERSION}.tar.xz && \ curl -fsSLO ${KERNEL_PGP2_SIGN} && \ gpg2 --verify linux-${KERNEL_VERSION}.tar.sign linux-${KERNEL_VERSION}.tar && \ - cat linux-${KERNEL_VERSION}.tar | tar --absolute-names -x && mv /linux-${KERNEL_VERSION} /linux - - -RUN mkdir -p /out/src + cat linux-${KERNEL_VERSION}.tar | tar --absolute-names -x && mv /linux-${KERNEL_VERSION} /linux && \ + printf "KERNEL_SOURCE=${KERNEL_SOURCE}\n" > /out/kernel-source-info WORKDIR /tmp # Download Intel ucode, create a CPIO archive for it, and keep it in the build context # so the firmware can also be referenced with CONFIG_EXTRA_FIRMWARE ENV UCODE_REPO=https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files -ENV UCODE_COMMIT=microcode-20191115 +ENV UCODE_COMMIT=microcode-20210608 RUN set -e && \ if [ $(uname -m) == x86_64 ]; then \ git clone ${UCODE_REPO} ucode && \ @@ -105,13 +102,10 @@ RUN set -e && \ done; \ fi - - # Save kernel source -RUN tar cJf /out/src/linux.tar.xz /linux +RUN XZ_DEFAULTS="-T0" tar cJf /out/src/linux.tar.xz /linux # Kernel config -# The s390x defconfig moved with 5.2.x RUN case $(uname -m) in \ x86_64) \ KERNEL_DEF_CONF=/linux/arch/x86/configs/x86_64_defconfig; \ @@ -119,13 +113,6 @@ RUN case $(uname -m) in \ aarch64) \ KERNEL_DEF_CONF=/linux/arch/arm64/configs/defconfig; \ ;; \ - s390x) \ - if [ -f /linux/arch/s390/defconfig ]; then \ - KERNEL_DEF_CONF=/linux/arch/s390/defconfig; \ - else \ - KERNEL_DEF_CONF=/linux/arch/s390/configs/defconfig; \ - fi; \ - ;; \ esac && \ cp /config-${KERNEL_SERIES}-$(uname -m) ${KERNEL_DEF_CONF}; \ if [ -n "${EXTRA}" ] && [ -f "/config-${KERNEL_SERIES}-$(uname -m)${EXTRA}" ]; then \ @@ -142,41 +129,20 @@ RUN case $(uname -m) in \ # Kernel -RUN case $(uname -m) in \ - s390x) \ - KCFLAGS="-fno-pie -fPIC"; \ - ;; \ - *) \ - KCFLAGS="-fno-pie"; \ - ;; \ - esac && \ - make -j "$(getconf _NPROCESSORS_ONLN)" KCFLAGS="$KCFLAGS" && \ +RUN make -j "$(getconf _NPROCESSORS_ONLN)" KCFLAGS="-fno-pie" && \ case $(uname -m) in \ x86_64) \ cp arch/x86_64/boot/bzImage /out/kernel; \ ;; \ aarch64) \ - cp arch/arm64/boot/Image /out/kernel; \ - ;; \ - s390x) \ - cp arch/s390/boot/bzImage /out/kernel; \ + cp arch/arm64/boot/Image.gz /out/kernel; \ ;; \ esac && \ cp System.map /out && \ ([ -n "${DEBUG}" ] && cp vmlinux /out || true) -# WireGuard (skip kernels which have it in tree) -RUN if [ ! -d /linux/drivers/net/wireguard ]; then \ - curl -fsSL -o /wireguard.tar.xz "${WIREGUARD_URL}" && \ - echo "${WIREGUARD_SHA256} /wireguard.tar.xz" | sha256sum -c - && \ - cp /wireguard.tar.xz /out/src/ && \ - tar -C / --one-top-level=wireguard --strip-components=2 -xJf /wireguard.tar.xz "wireguard-linux-compat-${WIREGUARD_VERSION}/src" && \ - make -j "$(getconf _NPROCESSORS_ONLN)" M="/wireguard" modules; \ - fi - # Modules and Device Tree binaries RUN make INSTALL_MOD_PATH=/tmp/kernel-modules modules_install && \ - make INSTALL_MOD_PATH=/tmp/kernel-modules M="/wireguard" modules_install && \ ( DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdepth 1)) && \ cd /tmp/kernel-modules/lib/modules/$DVER && \ rm build source && \ @@ -208,8 +174,7 @@ RUN DVER=$(basename $(find /tmp/kernel-modules/lib/modules/ -mindepth 1 -maxdept tar cf - -T - | (cd $dir; tar xf -) && \ ( cd /tmp && tar cf /out/kernel-dev.tar usr/src ) -RUN printf "KERNEL_SOURCE=${KERNEL_SOURCE}\n" > /out/kernel-source-info - +RUN printf "${BUILD_IMAGE}" > /out/kernel-builder FROM scratch ENTRYPOINT [] diff --git a/kernel/Dockerfile.bcc b/kernel/Dockerfile.bcc index 1b32c21..755f586 100644 --- a/kernel/Dockerfile.bcc +++ b/kernel/Dockerfile.bcc @@ -1,7 +1,9 @@ ARG IMAGE +ARG BUILD_IMAGE + FROM ${IMAGE} as ksrc -FROM linuxkit/alpine:e2391e0b164c57db9f6c4ae110ee84f766edc430 AS build +FROM ${BUILD_IMAGE} AS build RUN apk update && apk upgrade -a && \ apk add --no-cache \ argp-standalone \ @@ -14,8 +16,8 @@ RUN apk update && apk upgrade -a && \ clang-static \ cmake \ curl \ + elfutils-dev \ flex-dev \ - fts-dev \ gettext-dev \ git \ iperf3 \ @@ -26,39 +28,22 @@ RUN apk update && apk upgrade -a && \ llvm-static \ luajit-dev \ m4 \ - python \ + musl-fts-dev \ + python3 \ zlib-dev \ && true -RUN ln -s /usr/lib/cmake/llvm5/ /usr/lib/cmake/llvm && \ - ln -s /usr/include/llvm5/llvm-c/ /usr/include/llvm-c && \ - ln -s /usr/include/llvm5/llvm/ /usr/include/llvm +RUN ln -s /usr/lib/cmake/llvm10/ /usr/lib/cmake/llvm && \ + ln -s /usr/include/llvm10/llvm-c/ /usr/include/llvm-c && \ + ln -s /usr/include/llvm10/llvm/ /usr/include/llvm WORKDIR /build -COPY ./bcc.patches/ ./ -RUN mv error.h /usr/include/ && \ - mv cdefs.h /usr/include/sys/ - -ENV ELFUTILS_VERSION=0.165 -ENV ELFUTILS_SHA256="a7fc9277192caaa5f30b47e8c0518dbcfd8c4a19c6493a63d511d804290ce972" -RUN curl -sSL -O https://fedorahosted.org/releases/e/l/elfutils/0.165/elfutils-$ELFUTILS_VERSION.tar.bz2 && \ - echo "${ELFUTILS_SHA256} /build/elfutils-$ELFUTILS_VERSION.tar.bz2" | sha256sum -c - && \ - tar xjf elfutils-$ELFUTILS_VERSION.tar.bz2 && \ - cd elfutils-$ELFUTILS_VERSION && \ - patch -p1 < ../100-musl-compat.patch && \ - patch -p0 < ../decl.patch && \ - patch -p0 < ../intl.patch - -ENV BCC_COMMIT=0fa419a64e71984d42f107c210d3d3f0cc82d59a +ENV BCC_COMMIT=14278bf1a52dd76ff66eed02cc9db7c7ec240da6 RUN git clone https://github.com/iovisor/bcc.git && \ cd bcc && \ - git checkout $BCC_COMMIT - -ENV LJSYSCALL_COMMIT=e587f8c55aad3955dddab3a4fa6c1968037b5c6e -RUN git clone https://github.com/justincormack/ljsyscall.git && \ - cd ljsyscall && \ - git checkout $LJSYSCALL_COMMIT + git checkout $BCC_COMMIT && \ + sed -i 's///' examples/cpp/KModRetExample.cc COPY --from=ksrc /kernel-headers.tar /build COPY --from=ksrc /kernel-dev.tar /build @@ -67,24 +52,15 @@ RUN tar xf /build/kernel-headers.tar && \ tar xf /build/kernel-dev.tar && \ tar xf /build/kernel.tar -RUN cd elfutils-$ELFUTILS_VERSION && \ - aclocal && \ - automake && \ - ./configure --prefix=/usr CFLAGS="-Wno-strict-aliasing -Wno-error" && \ - make -C libelf && make -C libelf install - RUN mkdir -p bcc/build && cd bcc/build && \ cmake .. -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \ -DCMAKE_C_FLAGS="-I/build/usr/include" \ + -DPYTHON_CMD=python3 \ -DCMAKE_CXX_FLAGS="-I/build/usr/include" \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DLUAJIT_INCLUDE_DIR=/usr/include/luajit-2.1 && \ + -DCMAKE_INSTALL_PREFIX=/usr && \ make && \ make install -RUN mkdir -p /usr/local/share/lua/5.1/ && \ - cd ljsyscall && \ - cp -a *.lua syscall /usr/local/share/lua/5.1/ RUN mkdir -p /out/usr/ && \ cp -a /build/usr/src /out/usr/ && \ cp -a /build/usr/include /out/usr @@ -93,22 +69,20 @@ RUN mkdir -p /out/usr/lib && \ cp -a /usr/lib/libstdc* /out/usr/lib/ && \ cp -a /usr/lib/libintl* /out/usr/lib/ && \ cp -a /usr/lib64/* /out/usr/lib/ -RUN mkdir -p /out/usr/lib/python2.7 && \ - cp -a /usr/lib/python2.7/site-packages /out/usr/lib/python2.7/ +RUN mkdir -p /out/usr/lib/python3.8 && \ + cp -a /usr/lib/python3.8/site-packages /out/usr/lib/python3.8/ RUN mkdir -p /out/usr/share && \ cp -a /usr/share/bcc /out/usr/share/ RUN mkdir -p /out/usr/bin && \ cp -a /usr/bin/bcc-lua /out/usr/bin/ -RUN mkdir -p /out/usr/local/share/ && \ - cp -a /usr/local/share/lua /out/usr/local/share/ -FROM linuxkit/alpine:e2391e0b164c57db9f6c4ae110ee84f766edc430 as mirror +FROM ${BUILD_IMAGE} as mirror RUN mkdir -p /out/etc/apk && cp -r /etc/apk/* /out/etc/apk/ RUN apk update && apk upgrade -a && \ apk add --no-cache --initdb -p /out \ busybox \ luajit \ - python \ + python3 \ zlib \ && true diff --git a/kernel/Dockerfile.kconfig b/kernel/Dockerfile.kconfig index 22ad9fc..3d916d4 100644 --- a/kernel/Dockerfile.kconfig +++ b/kernel/Dockerfile.kconfig @@ -1,4 +1,8 @@ -FROM linuxkit/alpine:e2391e0b164c57db9f6c4ae110ee84f766edc430 AS kernel-build +ARG BUILD_IMAGE +FROM ${BUILD_IMAGE} AS kernel-build + +ARG KERNEL_VERSIONS + RUN apk add \ argp-standalone \ bison \ @@ -14,8 +18,6 @@ RUN apk add \ patch \ xz -ARG KERNEL_VERSIONS - COPY / / # Unpack kernels (download if not present) @@ -43,13 +45,6 @@ RUN set -e && \ fi && \ [ ! -f /config-${SERIES}-x86_64 ] || mv /config-${SERIES}-x86_64 arch/x86/configs/x86_64_defconfig && \ [ ! -f /config-${SERIES}-aarch64 ] || mv /config-${SERIES}-aarch64 arch/arm64/configs/defconfig ; \ - if [ -f /config-${SERIES}-s390x ]; then \ - if [ -f /linux/arch/s390/defconfig ]; then \ - mv /config-${SERIES}-s390x arch/s390/defconfig; \ - else \ - mv /config-${SERIES}-s390x arch/s390/configs/defconfig; \ - fi; \ - fi; \ done ENTRYPOINT ["/bin/sh"] diff --git a/kernel/Dockerfile.kconfigx b/kernel/Dockerfile.kconfigx new file mode 100644 index 0000000..94da3b9 --- /dev/null +++ b/kernel/Dockerfile.kconfigx @@ -0,0 +1,71 @@ +# syntax=docker/dockerfile:1.3-labs + +ARG BUILD_IMAGE + +FROM ${BUILD_IMAGE} AS kernel-build +ARG KERNEL_VERSIONS +ARG TARGETARCH + +RUN apk add \ + argp-standalone \ + bison \ + build-base \ + curl \ + diffutils \ + flex \ + gmp-dev \ + libarchive-tools \ + mpc1-dev \ + mpfr-dev \ + ncurses-dev \ + patch \ + xz + +COPY / / + +# Unpack kernels (download if not present) +RUN <..- -# - linuxkit/kernel:.. -# The is the git tree hash of the current directory. The build -# will only rebuild the kernel image if the git tree hash changed. -# -# For some kernels we also build a separate package containing the perf utility -# which is specific to a given kernel. perf packages are tagged the same way -# kernel packages. - -# This option is for running docker manifest command -export DOCKER_CLI_EXPERIMENTAL := enabled - -# set ORG in the env or make call -# having it in the makefile is dangerous as its too easy to overwrite previous pushes/tags -ifeq ($(strip $(ORG)),) -# ^ guards against ORG being defined but empty string which makes `ORG ?=` not work - ORG := quay.io/tinkerbell -endif -# makes sure there's no trailing / so we can just add them in the recipes which looks nicer -ORG := $(shell echo "${ORG}" | sed 's|/*$$||') - -IMAGE:=hook-kernel -IMAGE_BCC:=hook-kernel-bcc -IMAGE_PERF:=hook-kernel-perf -IMAGE_ZFS:=hook-zfs-kmod - -# You can specify an extra options for the Makefile. This will: -# - append a config$(EXTRA) to the kernel config for your kernel/arch -# - append $(EXTRA) to the CONFIG_LOCALVERSION of your kernel -EXTRA?= - -# You can enable debug options for the Makefile. This will: -# - append a config-dbg to the kernel config for your kernel/arch -# - append -dbg to the CONFIG_LOCALVERSION of your kernel -DEBUG?= - -ifeq ($(HASH),) -HASH_COMMIT?=HEAD # Setting this is only really useful with the show-tag target -HASH?=$(shell git ls-tree --full-tree $(HASH_COMMIT) -- $(CURDIR) | awk '{print $$3}') - -ifneq ($(HASH_COMMIT),HEAD) # Others can't be dirty by definition -DIRTY=$(shell git update-index -q --refresh && git diff-index --quiet HEAD -- $(CURDIR) || echo "-dirty") -endif -endif - -KERNEL_PLATFORMS:=linux/amd64,linux/arm64 -PERF_PLATFORMS:=linux/amd64 -BCC_PLATFORMS:=linux/amd64 - -ARCH := $(shell uname -m) - -TAG=$(HASH)$(DIRTY) - -REPO?=https://github.com/linuxkit/linuxkit -ifneq ($(REPO),) -REPO_LABEL=--label org.opencontainers.image.source=$(REPO) -endif -ifeq ($(DIRTY),) -REPO_COMMIT=$(shell git rev-parse HEAD) -COMMIT_LABEL=--label org.opencontainers.image.revision=$(REPO_COMMIT) -endif -LABELS=$(REPO_LABEL) $(COMMIT_LABEL) - -ifeq ($(DOCKER_CONTENT_TRUST),) -ifndef NOTRUST -export DOCKER_CONTENT_TRUST=1 -endif -endif - -KERNEL_VERSIONS= - -.PHONY: build devbuild -# Targets: -# devbuild: Builds all kernels only for the local arch -# build: Builds all kernels -devbuild: -build: - -# A template for defining kernel build -# Arguments: -# $1: Full kernel version, e.g., 4.9.22 -# $2: Kernel "series", e.g., 4.9.x -# $3: Build a specific kernel like -rt: Preempt-RT (used as suffix for image) -# This defines targets like: -# build_4.9.x and push_4.9.x and adds them as dependencies -# to the global targets -# Set $3 to "-rt", to build Preempt-RT kernels. This defines targets like -# build_4.14.x-rt and adds "-rt" to the hub image name. -# Set $4 to "-dbg", to build debug kernels. This defines targets like -# build_4.9.x-dbg and adds "-dbg" to the hub image name. -# Set $3 to "-rt" and $4 to "-dbg" to build debug Preempt-RT kernel. -define kernel - -ifeq ($(4),) -KERNEL_VERSIONS+=$(1) -endif - -devbuild_$(2)$(3)$(4): Dockerfile Makefile $(wildcard patches-$(2)/*) $(wildcard config-$(2)*) config-dbg - docker buildx build \ - --load \ - --build-arg KERNEL_VERSION=$(1) \ - --build-arg KERNEL_SERIES=$(2) \ - --build-arg EXTRA=$(3) \ - --build-arg DEBUG=$(4) \ - $(LABELS) \ - --no-cache -t $(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) . - - -build_$(2)$(3)$(4): Dockerfile Makefile $(wildcard patches-$(2)/*) $(wildcard config-$(2)*) config-dbg - @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi - docker pull $(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) || \ - docker buildx build \ - --platform $(KERNEL_PLATFORMS) \ - --push \ - --build-arg KERNEL_VERSION=$(1) \ - --build-arg KERNEL_SERIES=$(2) \ - --build-arg EXTRA=$(3) \ - --build-arg DEBUG=$(4) \ - $(LABELS) \ - --no-cache -t $(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) . - -forcebuild_$(2)$(3)$(4): Dockerfile Makefile $(wildcard patches-$(2)/*) $(wildcard config-$(2)*) config-dbg - docker buildx build \ - --platform $(KERNEL_PLATFORMS) \ - --push \ - --build-arg KERNEL_VERSION=$(1) \ - --build-arg KERNEL_SERIES=$(2) \ - --build-arg EXTRA=$(3) \ - --build-arg DEBUG=$(4) \ - $(LABELS) \ - -t $(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) . - -show-tag_$(2)$(3)$(4): - @echo $(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) - -devbuild: devbuild_$(2)$(3)$(4) -build: build_$(2)$(3)$(4) -forcebuild: forcebuild_$(2)$(3)$(4) -show-tags: show-tag_$(2)$(3)$(4) - -# 'docker build' with the FROM image supplied as --build-arg -# *and* with DOCKER_CONTENT_TRUST=1 currently does not work -# (https://github.com/moby/moby/issues/34199). So, we pull the image -# with DCT as part of the dependency on build_$(2)$(3)$(4) and then build -# with DOCKER_CONTENT_TRUST explicitly set to 0 - -# Only build perf on x86 and latest LTS and stable kernels -ifeq ($(ARCH),x86_64) -ifeq ($(2), $(filter $(2),5.10.x)) -devbuild_perf_$(2)$(3)$(4): devbuild_$(2)$(3)$(4) - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.perf \ - --load \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) \ - --no-cache --network=none \ - -t $(ORG)/$(IMAGE_PERF):$(1)$(3)$(4)-$(TAG) . - -build_perf_$(2)$(3)$(4): build_$(2)$(3)$(4) - @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi - docker pull $(ORG)/$(IMAGE_PERF):$(1)$(3)$(4)-$(TAG) || \ - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.perf \ - --platform $(PERF_PLATFORMS) \ - --push \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) \ - --no-cache --network=none \ - -t $(ORG)/$(IMAGE_PERF):$(1)$(3)$(4)-$(TAG) . - -forcebuild_perf_$(2)$(3)$(4): build_$(2)$(3)$(4) - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.perf \ - --platform $(PERF_PLATFORMS) \ - --push \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) \ - --no-cache --network=none \ - -t $(ORG)/$(IMAGE_PERF):$(1)$(3)$(4)-$(TAG) . - -#devbuild: devbuild_perf_$(2)$(3)$(4) -#build: build_perf_$(2)$(3)$(4) -#forcebuild: forcebuild_perf_$(2)$(3)$(4) -endif -endif - -# Only build BCC on x86 and only on latest LTS and latest stable kernels. -ifeq ($(ARCH),x86_64) -ifeq ($(2), $(filter $(2),5.6.x 5.4.x)) -devbuild_bcc_$(2)$(3)$(4): devbuild_$(2)$(3)$(4) - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.bcc \ - --load \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) --no-cache \ - -t $(ORG)/$(IMAGE_BCC):$(1)$(3)$(4)-$(TAG) . - -build_bcc_$(2)$(3)$(4): build_$(2)$(3)$(4) - @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi - docker pull $(ORG)/$(IMAGE_BCC):$(1)$(3)$(4)-$(TAG) || \ - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.bcc \ - --platform $(BCC_PLATFORMS) \ - --push \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) --no-cache \ - -t $(ORG)/$(IMAGE_BCC):$(1)$(3)$(4)-$(TAG) . - -forcebuild_bcc_$(2)$(3)$(4): build_$(2)$(3)$(4) - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.bcc \ - --platform $(BCC_PLATFORMS) \ - --push \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) --no-cache \ - -t $(ORG)/$(IMAGE_BCC):$(1)$(3)$(4)-$(TAG) . - -#devbuild: devbuild_bcc_$(2)$(3)$(4) -#build: build_bcc_$(2)$(3)$(4) -#forcebuild: forcebuild_bcc_$(2)$(3)$(4) -endif -endif - -ifeq ($(4),) -# ZFS does not compile against -dbg kernels because CONFIG_DEBUG_LOCK_ALLOC -# is incompatible with CDDL, apparently (this is ./configure check) -build_zfs_$(2)$(3): build_$(2)$(3) - @if [ x"$(DIRTY)" != x ]; then echo "Your repository is not clean. Will not push image"; exit 1; fi - docker pull $(ORG)/$(IMAGE_ZFS):$(1)$(3)-$(TAG) || \ - DOCKER_CONTENT_TRUST=0 docker buildx build \ - -f Dockerfile.zfs \ - --platform $(KERNEL_PLATFORMS) \ - --push \ - --build-arg IMAGE=$(ORG)/$(IMAGE):$(1)$(3)$(4)-$(TAG) \ - $(LABELS) --no-cache \ - -t $(ORG)/$(IMAGE_ZFS):$(1)$(3)$(4)-$(TAG) . - -endif - -endef - -# -# Build Targets -# Debug targets only for latest stable and LTS stable -# -ifeq ($(ARCH),x86_64) -$(eval $(call kernel,5.10.85,5.10.x,$(EXTRA),$(DEBUG))) -#$(eval $(call kernel,5.4.28,5.4.x,-rt,)) - -else ifeq ($(ARCH),aarch64) -$(eval $(call kernel,5.10.85,5.10.x,$(EXTRA),$(DEBUG))) -#$(eval $(call kernel,5.4.28,5.4.x,-rt,)) - -endif - -# Target for kernel config -kconfig: -ifeq (${KCONFIG_TAG},) - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/amd64,linux/arm64 \ - --push \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig . -else - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/amd64,linux/arm64 \ - -o type=local,dest=out/kconfig \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig:${KCONFIG_TAG} . -endif - -kconfig_amd64: -ifeq (${KCONFIG_TAG},) - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/amd64 \ - --load \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig . -else - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/arm64 \ - -o type=local,dest=out/kconfig \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig:${KCONFIG_TAG} . -endif - -kconfig_arm64: -ifeq (${KCONFIG_TAG},) - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/arm64 \ - --load \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig . -else - docker buildx build --no-cache -f Dockerfile.kconfig \ - --platform linux/arm64 \ - -o type=local,dest=out/kconfig \ - --build-arg KERNEL_VERSIONS="$(KERNEL_VERSIONS)" \ - -t $(ORG)/kconfig:${KCONFIG_TAG} . -endif - - -.PHONY: clean -clean: - rm out/ diff --git a/kernel/README.md b/kernel/README.md index 7577e3b..54b5438 100644 --- a/kernel/README.md +++ b/kernel/README.md @@ -1,65 +1,393 @@ -# Kernels +# Linux kernels -This kernel folder is used to build a kernel image for hook and is based upon the kernel builder from [linuxkit](https://github.com/linuxkit/linuxkit). +LinuxKit kernel images are distributed as hub images which contain the +kernel, kernel modules, kernel config file, and optionally, kernel +headers to compile kernel modules against. The repository containing +the official LinuxKit kernels is at +[linuxkit/kernels](https://hub.docker.com/r/linuxkit/kernel/). -## Compile the kernel +The LinuxKit kernels are based on the latest stable releases and are +updated frequently to include bug and security fixes. For some +kernels we do carry additional patches, which are mostly back-ported +fixes from newer kernels. The full kernel source with patches can be +found on [github](https://github.com/linuxkit/linux). Each kernel +image is tagged with the full kernel version (e.g., +`linuxkit/kernel:4.9.33`) and with the full kernel version plus the +hash of the files it was created from (git tree hash of the `./kernel` +directory). For selected kernels (mostly the LTS kernels and latest +stable kernels) we also compile/push kernels with additional debugging +enabled. The hub images for these kernels have the `-dbg` suffix in +the tag. For some kernels, we also provide matching packages +containing the `perf` utility for debugging and performance tracing. +The perf package is called `kernel-perf` and is tagged the same way as +the kernel packages. -The Makefile will build the multiarchitecture `5.10.x` kernel images based upon the configurations in config_5.10.x_arch. +In addition to the official images, there are also some +[scripts](../contrib/foreign-kernels) which repackage kernels packages +from some Linux distributions into LinuxKit kernel packages. These are +mostly provided for testing purposes. +Note now linuxkit also embraces Preempt-RT Linux kernel to support more +use cases for the promising IoT scenarios. All -rt patches are grabbed from +https://www.kernel.org/pub/linux/kernel/projects/rt/. But so far we just +enable it over 4.14.x. + + +## Loading kernel modules + +Most kernel modules are autoloaded with `mdev` but if you need to `modprobe` a module manually you can use the `modprobe` package in the `onboot` section like this: ``` -make build_5.10.x + - name: modprobe + image: linuxkit/modprobe: + command: ["modprobe", "-a", "iscsi_tcp", "dm_multipath"] ``` -**Note** Use `-j ` with the make command to dramatically speed up build time. +## Compiling external kernel modules + +This section describes how to build external (out-of-tree) kernel +modules. You need the following to build external modules. All of +these are to be built for a specific version of the kernel. For +the examples, we will assume 5.10.104; replace with your desired +version. + +* source available to your modules - you need to get those on your own +* kernel development headers - available in the `linuxkit/kernel` image as `kernel-dev.tar`, e.g. `linuxkit/kernel:5.10.104` +* OS with sources and compiler - this **must** be the exact same version as that used to compile the kernel + +As described above, the `linuxkit/kernel` images include `kernel-dev.tar` which contains +the headers and other files required to compile kernel modules against +the specific version of the kernel. Currently, the headers are not +included in the initial RAM disk, but it is possible to compile custom +modules offline and then include the modules in the initial RAM disk. + +The source is available as the same name as the `linuxkit/kernel` image, with the addition of `-builder` on the tag. +For example: + +* `linuxkit/kernel:5.10.92` has builder `linuxkit/kernel:5.10.92-builder` +* `linuxkit/kernel:5.15.15` has builder `linuxkit/kernel:5.15.15-builder` + +With the above in hand, you can create a multi-stage `Dockerfile` build to compile your modules. +There is an [example](../test/cases/020_kernel/113_kmod_5.10.x), but +basically one can use a multi-stage build to compile the kernel +modules: + +```dockerfile +FROM linuxkit/kernel:5.10.104 AS ksrc +FROM linuxkit/kernel:5.10.104-builder AS build + +RUN apk add build-base -To build a kernel for local testing for just a single architecture, usue the devbuild targets: +COPY --from=ksrc /kernel-dev.tar / +RUN tar xf kernel-dev.tar +# copy module source code and compile ``` -make devbuild_5.10.x + +To use the kernel module, we recommend adding a final stage to the +Dockerfile above, which copies the kernel module from the `build` +stage and performs a `insmod` as the entry point. You can add this +package to the `onboot` section in your YAML +file. [test.yml](../test/cases/020_kernel/113_kmod_5.10.x/test.yml) +contains an example for the configuration. + +### Builder Backups + +As described above, the OS builder is referenced via `-builder`, e.g. +`linuxkit/kernel:5.15.15-builder`. + +As a fallback, in case the `-builder` image is not available or you cannot access it from your development environment, +you have 3 total places to determine the correct version of the OS image with sources and compiler: + +* `-builder` tag added to the kernel version, e.g. `linuxkit/kernel:5.10.104-builder` +* labels on the kernel image, e.g. `docker inspect linuxkit/kernel:5.10.104 | jq -r '.[].Config.Labels["org.mobyproject.linuxkit.kernel.buildimage"]'` +* `/kernel-builder` file in the kernel image + +You **should** use `-builder` tag as the `AS build` in your `Dockerfile`, but you **can** use +the direct source, extracted from the labels or `/kernel-builder` file in the kernel image, in the `AS build`. + +For example, in the case of `5.10.104`, the label and `/kernel-builder` file show `linuxkit/alpine:2be490394653b7967c250e86fd42cef88de428ba`, +so you can use either `linuxkit/alpine:2be490394653b7967c250e86fd42cef88de428ba` or +`linuxkit/kernel:5.10.104-builder` to build the modules. + +Thus, the following are equivalent: + +```dockerfile +FROM linuxkit/kernel:5.10.104 AS ksrc +FROM linuxkit/kernel:5.10.104-builder AS build ``` -## Modify the kernel +```dockerfile +FROM linuxkit/kernel:5.10.104 AS ksrc +FROM linuxkit/alpine:2be490394653b7967c250e86fd42cef88de428ba AS build +``` -The Makefile can build a docker environment to configure a new kernel, it can generate a docker image and push it to the tinkerbell repository or build a local image. +## Modifying the kernel config -**NOTE** This builder makes use of the docker `buildx` functionality that can be enabled with `docker buildx create --use` +Each series of kernels has a config file dedicated to it +in [../kernel/](../kernel), +e.g. +[config-5.10.x-x86_64](../kernel/config-5.10.x-x86_64), +which is applied during the kernel build process. + +If you need to modify the kernel config, `make kconfig` in +the [kernel](../kernel) directory will create a local +`linuxkit/kconfig` Docker image, which contains the patched sources +for all support kernels and architectures in +`/linux-4..`. The kernel source also has the kernel config +copied to the default kernel config. + +Running the image like: + +```sh +docker run --rm -ti -v $(pwd):/src linuxkit/kconfig +``` + +will give you a interactive shell where you can modify the kernel +configuration you want, either by editing the config file, or via +`make menuconfig` etc. Once you are done, save the file as `.config` +and copy it back to the source tree, +e.g. `/src/kernel-config-4.9.x-x86_64`. + +You can also configure other architectures other than the native +one. For example to configure the arm64 kernel on x86_64, use: + +``` +make ARCH=arm64 defconfig +make ARCH=arm64 oldconfig # or menuconfig +``` + +**Note**: We try to keep the differences between kernel versions and +architectures to a minimum, so if you make changes to one +configuration also try to apply it to the others. The script [kconfig-split.py](../scripts/kconfig-split.py) can be used to compare kernel config files. For example: + +```sh +../scripts/kconfig-split.py config-4.9.x-aarch64 config-4.9.x-x86_64 +``` + +creates a file with the common and the x86_64 and arm64 specific +config options for the 4.9.x kernel series. + +## Building and using custom kernels + +To build and test locally modified kernels, e.g., to try a different +kernel config or new patches, the existing kernel build system in +the [`kernel`](../kernel/) directory can be re-used. For example, +assuming the current 4.9 kernel is 4.9.33, you can build a local +kernel with: + +```sh +make build_4.9.x +``` + +This will create a local kernel image called +`linuxkit/kernel:4.9.33--dirty` assuming you haven't committed +you local changes. You can then use this in your YAML file as: + +``` +kernel: + image: linuxkit/kernel:4.9.33--dirty +``` -Making a **multi-arch** image and pushing to the quay.io repository: +If you have committed your local changes, the `-dirty` will not be +appended. Then you can also override the Hub organisation to use the +image elsewhere with (and also disable image signing): +```sh +make ORG= ``` -make kconfig + +The image will be uploaded to Hub and can be use in a YAML file as +`/kernel:4.9.33` or as `/kernel:4.9.33-`. + +The kernel build system has some provision to allow local +customisation to the build. + +If you want to override/add some kernel config options, you can add a +file called `config-4.9.x-x86_64-foo` and then invoke the build with `make +EXTRA=-foo build_4.9.x-foo` and this will build an image with the +additional kernel config options enabled. + +If you want additional patches being applied, just copy them to the +`patches-4.X.x` and the build process will pick them up. + + +## Working with Linux kernel patches for LinuxKit + +We may apply patches to the Linux kernel used in LinuxKit, primarily to +cherry-pick some upstream patches or to add some additional +functionality, not yet accepted upstream. + +Patches are located in `kernel/patches-` and should follow these rules: +- Patches *must* be in `git am` format, i.e. they should contain a + complete and sensible commit message. +- Patches *must* contain a Developer's Certificate of Origin. +- Patch files *must* have a numeric prefix to ensure the ordering in + which they are applied. +- If patches are cherry-picked, they *must* be cherry-picked with `-x` + to contain the original commit ID. +- If patches are from a different git tree (other than the stable + tree), or from a mailing list posting they should contain an + `Origin:` line with a link to the source. + +This document outlines the recommended procedure to handle +patches. The general process is to apply them to a branch of the +[Linux stable tree](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/) +and then export them with `git format-patch`. + +If you want to add or remove patches currently used, please also ping +@rneugeba on the PR so that we can update our internal Linux tree to +ensure that patches are carried forward if we update the kernel in the +future. + + +### Preparation + +Patches are applied to point releases of the linux stable tree. You +need an up-to-date copy of that tree: + +```sh +git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git ``` -Making a **local** image (multi-arch isn't supported locally, so generate the kernel config for your local architecture [amd64/arm64]) +Add it as a remote to a clone of the [LinuxKit clone](https://github.com/linuxkit/linux). + +We use the following variables: +- `KITSRC`: Base directory of LinuxKit repository +- `LINUXSRC`: Base directory of Linux stable kernel repository +e.g.: +```sh +KITSRC=~/src/linuxkit/linuxkit +LINUXSRC=~/src/linuxkit/linux ``` -make kconfig_amd64 + +to refer to the location of the LinuxKit and Linux kernel trees. + + +### Updating the patches to a new kernel version + +There are different ways to do this, but we recommend applying the +patches to the current version and then rebase to the new version. We +define the following variables to refer to the current base tag and +the new tag you want to rebase the patches to: + +```sh +CURTAG=v4.9.14 +NEWTAG=v4.9.15 ``` -We can now run this image: +If you don't already have a branch, it's best to import the current +patch set and then rebase: +```sh +cd $LINUXSRC +git checkout -b ${NEWTAG}-linuxkit ${CURTAG} +git am ${KITSRC}/kernel/patches/*.patch +git rebase ${NEWTAG}-linuxkit ${NEWTAG} ``` -docker run --rm -ti -v $(pwd):/src:z quay.io/tinkerbell/kconfig + +The `git am` should not have any conflicts and if the rebase has +conflicts resolve them, then `git add ` and `git rebase +--continue`. + +If you already have linux tree with a `${CURTAG}-linuxkit` branch, you +can rebase by creating a new branch from the current branch and then +rebase: + +```sh +cd $LINUXSRC +git checkout ${CURTAG}-linuxkit +git branch ${NEWTAG}-linuxkit ${CURTAG}-linuxkit +git rebase --onto ${NEWTAG} ${NEWTAG} ${NEWTAG}-linuxkit ``` -If modifying the config for a different architecture, it is best to specify the platform to -avoid any surprises when attempting to build the kernel later. +Again, resolve any conflicts as described above. + + +### Adding/Removing patches +If you want to add or remove patches make sure you have an up-to-date +branch with the currently applied patches (see above). Then either any +normal means (`git cherry-pick -x`, `git am`, or `git commit`, etc) to +add new patches. For cherry-picked patches also please add a `Origin:` +line after the DCO lines with a reference the git tree the patch was +cherry-picked from. + +If the patch is not cherry-picked try to include as much information +in the commit message as possible as to where the patch originated +from. The canonical form would be to add a `Origin:` line after the +DCO lines, e.g.: + +``` +Origin: https://patchwork.ozlabs.org/patch/622404/ ``` -docker run --rm -ti -v $(pwd):/src:z --platform=linux/arm64 quay.io/tinkerbell/kconfig + +### Export patches to LinuxKit + +To export patches to LinuxKit, you should use `git format-patch` from +the Linux tree, e.g., something along these lines: + +```sh +cd $LINUXSRC +rm $KITSRC/kernel/patches-4.9.x/* +git format-patch -o $KITSRC/kernel/patches-4.9.x v4.9.15..HEAD ``` -We can now navigate to the source code and run the UI for configuring the kernel: +Then, create a PR for LinuxKit. + + +## Using `perf` + +The `kernel-perf` package contains a statically linked `perf` binary +under `/usr/bin` which is matched with the kernel of the same tag. +The simplest way to use the `perf` utility is to add the package to +the `init` section in the YAML file. This adds the binary to the root +filesystem. + +To use the binary, you can either bind mount it into the `getty` or +`ssh` service container or you can access the root filesystem from the +`getty` container via `nsenter`: +```sh +nsenter -m/proc/1/ns/mnt ash ``` -cd linux-5-10 -make menuconfig + +Alternatively, you can add the `kernel-perf` package as stage in a +multi-stage build to add it to a custom package. + + +## ZFS + +The kernel build Makefile has support for building the ZFS kernel +modules. Note, the modules are currently not distributed as standard +LinuxKit packages and if you wish to use them you have to compile them +yourself: + +```sh +cd kernel +make ORG= push_zfs_4.9.x # or different kernel version ``` -Copy the new configuration: +will build and push a `zfs-kmod-4.9.` image to Docker Hub +under the `ORG` specified. This package contains the all the standard +kernel modules from the kernel specified plus the `spl` and `zfs` +kernel modules, with `depmod` run over them, so they can be +`modprobe`ed. To use the modules do something like this in your YAML +file: ``` -cp .config /src/config-5.10.x-x86_64 +kernel: + image: linuxkit/kernel:4.9. + cmdline: "console=tty0 console=ttyS0 console=ttyAMA0" +init: + - /zfs-kmod:4.9. + ... ``` -We can now build our new kernel ! +Then, you also need to make sure the Alpine `zfs` utilities are +available in the container where your want to run `zfs` commands. The +Alpine `zfs` utilities are available in `linuxkit/alpine` and the +version of the kernel module should match the version of the +tools. The container where you run the `zfs` tools might also need +`CAP_SYS_MODULE` to be able to load the kernel modules. diff --git a/kernel/bcc.patches/100-musl-compat.patch b/kernel/bcc.patches/100-musl-compat.patch deleted file mode 100644 index 25e1504..0000000 --- a/kernel/bcc.patches/100-musl-compat.patch +++ /dev/null @@ -1,788 +0,0 @@ ---- a/lib/system.h -+++ b/lib/system.h -@@ -68,6 +68,16 @@ extern int crc32_file (int fd, uint32_t - - #define gettext_noop(Str) Str - -+#ifndef TEMP_FAILURE_RETRY -+#define TEMP_FAILURE_RETRY(expression) \ -+ (__extension__ \ -+ ({ long int __result; \ -+ do __result = (long int) (expression); \ -+ while (__result == -1L && errno == EINTR); \ -+ __result; })) -+#endif -+ -+#define error(status, errno, ...) err(status, __VA_ARGS__) - - static inline ssize_t __attribute__ ((unused)) - pwrite_retry (int fd, const void *buf, size_t len, off_t off) ---- a/lib/color.c -+++ b/lib/color.c -@@ -32,7 +32,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/lib/xmalloc.c -+++ b/lib/xmalloc.c -@@ -30,7 +30,7 @@ - # include - #endif - --#include -+#include - #include - #include - #include ---- a/src/addr2line.c -+++ b/src/addr2line.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/ar.c -+++ b/src/ar.c -@@ -22,7 +22,7 @@ - - #include - #include --#include -+#include - #include - #include - #include ---- a/src/arlib2.c -+++ b/src/arlib2.c -@@ -20,7 +20,7 @@ - # include - #endif - --#include -+#include - #include - #include - #include ---- a/src/arlib.c -+++ b/src/arlib.c -@@ -21,7 +21,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/src/elfcmp.c -+++ b/src/elfcmp.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/elflint.c -+++ b/src/elflint.c -@@ -24,7 +24,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/findtextrel.c -+++ b/src/findtextrel.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/i386_ld.c -+++ b/src/i386_ld.c -@@ -20,7 +20,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/src/ld.c -+++ b/src/ld.c -@@ -21,7 +21,7 @@ - - #include - #include --#include -+#include - #include - #include - #include ---- a/src/ldgeneric.c -+++ b/src/ldgeneric.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/ldlex.c -+++ b/src/ldlex.c -@@ -1106,7 +1106,7 @@ char *ldtext; - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/ldscript.c -+++ b/src/ldscript.c -@@ -95,7 +95,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include -@@ -106,7 +106,7 @@ - #include - #include - --/* The error handler. */ -+/* The err.handler. */ - static void yyerror (const char *s); - - /* Some helper functions we need to construct the data structures ---- a/src/nm.c -+++ b/src/nm.c -@@ -26,7 +26,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/objdump.c -+++ b/src/objdump.c -@@ -21,7 +21,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/src/ranlib.c -+++ b/src/ranlib.c -@@ -24,7 +24,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/readelf.c -+++ b/src/readelf.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/size.c -+++ b/src/size.c -@@ -21,7 +21,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/src/stack.c -+++ b/src/stack.c -@@ -18,7 +18,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/strings.c -+++ b/src/strings.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/strip.c -+++ b/src/strip.c -@@ -24,7 +24,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/src/unstrip.c -+++ b/src/unstrip.c -@@ -31,7 +31,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/tests/addrscopes.c -+++ b/tests/addrscopes.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - - ---- a/tests/allregs.c -+++ b/tests/allregs.c -@@ -21,7 +21,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/tests/backtrace.c -+++ b/tests/backtrace.c -@@ -24,7 +24,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #ifdef __linux__ ---- a/tests/backtrace-data.c -+++ b/tests/backtrace-data.c -@@ -27,7 +27,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #if defined(__x86_64__) && defined(__linux__) ---- a/tests/buildid.c -+++ b/tests/buildid.c -@@ -23,7 +23,7 @@ - #include ELFUTILS_HEADER(elf) - #include ELFUTILS_HEADER(dwelf) - #include --#include -+#include - #include - #include - #include ---- a/tests/debugaltlink.c -+++ b/tests/debugaltlink.c -@@ -23,7 +23,7 @@ - #include ELFUTILS_HEADER(dw) - #include ELFUTILS_HEADER(dwelf) - #include --#include -+#include - #include - #include - #include ---- a/tests/debuglink.c -+++ b/tests/debuglink.c -@@ -21,7 +21,7 @@ - #include - #include ELFUTILS_HEADER(dwelf) - #include --#include -+#include - #include - #include - #include ---- a/tests/dwfl-addr-sect.c -+++ b/tests/dwfl-addr-sect.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ELFUTILS_HEADER(dwfl) ---- a/tests/dwfl-bug-addr-overflow.c -+++ b/tests/dwfl-bug-addr-overflow.c -@@ -20,7 +20,7 @@ - #include - #include - #include --#include -+#include - #include - #include ELFUTILS_HEADER(dwfl) - ---- a/tests/dwfl-bug-fd-leak.c -+++ b/tests/dwfl-bug-fd-leak.c -@@ -24,7 +24,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/tests/dwfl-bug-getmodules.c -+++ b/tests/dwfl-bug-getmodules.c -@@ -18,7 +18,7 @@ - #include - #include ELFUTILS_HEADER(dwfl) - --#include -+#include - - static const Dwfl_Callbacks callbacks = - { ---- a/tests/dwfllines.c -+++ b/tests/dwfllines.c -@@ -27,7 +27,7 @@ - #include - #include - #include --#include -+#include - - int - main (int argc, char *argv[]) ---- a/tests/dwflmodtest.c -+++ b/tests/dwflmodtest.c -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ELFUTILS_HEADER(dwfl) ---- a/tests/dwfl-report-elf-align.c -+++ b/tests/dwfl-report-elf-align.c -@@ -20,7 +20,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/tests/dwflsyms.c -+++ b/tests/dwflsyms.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - - static const char * ---- a/tests/early-offscn.c -+++ b/tests/early-offscn.c -@@ -19,7 +19,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/tests/ecp.c -+++ b/tests/ecp.c -@@ -20,7 +20,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/tests/find-prologues.c -+++ b/tests/find-prologues.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - ---- a/tests/funcretval.c -+++ b/tests/funcretval.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - ---- a/tests/funcscopes.c -+++ b/tests/funcscopes.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - ---- a/tests/line2addr.c -+++ b/tests/line2addr.c -@@ -26,7 +26,7 @@ - #include - #include - #include --#include -+#include - - - static void ---- a/tests/low_high_pc.c -+++ b/tests/low_high_pc.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - ---- a/tests/md5-sha1-test.c -+++ b/tests/md5-sha1-test.c -@@ -19,7 +19,7 @@ - #endif - - #include --#include -+#include - - #include "md5.h" - #include "sha1.h" ---- a/tests/rdwrmmap.c -+++ b/tests/rdwrmmap.c -@@ -19,7 +19,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/tests/saridx.c -+++ b/tests/saridx.c -@@ -17,7 +17,7 @@ - - #include - --#include -+#include - #include - #include - #include ---- a/tests/sectiondump.c -+++ b/tests/sectiondump.c -@@ -18,7 +18,7 @@ - #include - - #include --#include -+#include - #include - #include - #include ---- a/tests/varlocs.c -+++ b/tests/varlocs.c -@@ -25,7 +25,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/libelf/libelf.h -+++ b/libelf/libelf.h -@@ -29,6 +29,7 @@ - #ifndef _LIBELF_H - #define _LIBELF_H 1 - -+#include - #include - #include - ---- a/libasm/asm_end.c -+++ b/libasm/asm_end.c -@@ -32,7 +32,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/libasm/asm_newscn.c -+++ b/libasm/asm_newscn.c -@@ -32,7 +32,7 @@ - #endif - - #include --#include -+#include - #include - #include - #include ---- a/libcpu/i386_gendis.c -+++ b/libcpu/i386_gendis.c -@@ -31,7 +31,7 @@ - # include - #endif - --#include -+#include - #include - #include - #include ---- a/libcpu/i386_lex.c -+++ b/libcpu/i386_lex.c -@@ -578,7 +578,7 @@ char *i386_text; - #endif - - #include --#include -+#include - #include - - #include ---- a/libcpu/i386_lex.l -+++ b/libcpu/i386_lex.l -@@ -31,7 +31,7 @@ - #endif - - #include --#include -+#include - #include - - #include ---- a/libcpu/i386_parse.c -+++ b/libcpu/i386_parse.c -@@ -107,7 +107,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/libdw/libdw_alloc.c -+++ b/libdw/libdw_alloc.c -@@ -31,7 +31,7 @@ - # include - #endif - --#include -+#include - #include - #include - #include -@@ -74,5 +74,5 @@ __attribute ((noreturn, visibility ("hid - __libdw_oom (void) - { - while (1) -- error (EXIT_FAILURE, ENOMEM, "libdw"); -+ err (EXIT_FAILURE, "libdw: out of memory"); - } ---- a/libebl/eblopenbackend.c -+++ b/libebl/eblopenbackend.c -@@ -32,7 +32,7 @@ - - #include - #include --#include -+#include - #include - #include - #include ---- a/src/ldlex.l -+++ b/src/ldlex.l -@@ -23,7 +23,7 @@ - #include - #include - #include --#include -+#include - #include - #include - #include ---- a/libebl/eblwstrtab.c -+++ b/libebl/eblwstrtab.c -@@ -305,7 +305,7 @@ copystrings (struct Ebl_WStrent *nodep, - - /* Process the current node. */ - nodep->offset = *offsetp; -- *freep = wmempcpy (*freep, nodep->string, nodep->len); -+ *freep = wmemcpy (*freep, nodep->string, nodep->len) + nodep->len; - *offsetp += nodep->len * sizeof (wchar_t); - - for (subs = nodep->next; subs != NULL; subs = subs->next) ---- a/libdwfl/dwfl_error.c -+++ b/libdwfl/dwfl_error.c -@@ -140,6 +140,7 @@ __libdwfl_seterrno (Dwfl_Error error) - const char * - dwfl_errmsg (int error) - { -+ static __thread char s[64] = ""; - if (error == 0 || error == -1) - { - int last_error = global_error; -@@ -154,7 +155,8 @@ dwfl_errmsg (int error) - switch (error &~ 0xffff) - { - case OTHER_ERROR (ERRNO): -- return strerror_r (error & 0xffff, "bad", 0); -+ strerror_r (error & 0xffff, s, sizeof(s)); -+ return s; - case OTHER_ERROR (LIBELF): - return elf_errmsg (error & 0xffff); - case OTHER_ERROR (LIBDW): ---- a/libdwfl/libdwfl.h -+++ b/libdwfl/libdwfl.h -@@ -31,6 +31,27 @@ - - #include "libdw.h" - #include -+#include -+#include -+#include -+ -+#ifndef TEMP_FAILURE_RETRY -+#define TEMP_FAILURE_RETRY(expression) \ -+ (__extension__ \ -+ ({ long int __result; \ -+ do __result = (long int) (expression); \ -+ while (__result == -1L && errno == EINTR); \ -+ __result; })) -+#endif -+ -+#ifndef strndupa -+#define strndupa(s, n) \ -+ (__extension__ ({const char *__in = (s); \ -+ size_t __len = strnlen (__in, (n)) + 1; \ -+ char *__out = (char *) alloca (__len); \ -+ __out[__len-1] = '\0'; \ -+ (char *) memcpy (__out, __in, __len-1);})) -+#endif - - /* Handle for a session using the library. */ - typedef struct Dwfl Dwfl; ---- a/libdwfl/find-debuginfo.c -+++ b/libdwfl/find-debuginfo.c -@@ -372,7 +372,7 @@ dwfl_standard_find_debuginfo (Dwfl_Modul - /* If FILE_NAME is a symlink, the debug file might be associated - with the symlink target name instead. */ - -- char *canon = canonicalize_file_name (file_name); -+ char *canon = realpath (file_name, NULL); - if (canon != NULL && strcmp (file_name, canon)) - fd = find_debuginfo_in_path (mod, canon, - debuglink_file, debuglink_crc, ---- a/libdwfl/dwfl_build_id_find_elf.c -+++ b/libdwfl/dwfl_build_id_find_elf.c -@@ -94,7 +94,7 @@ __libdwfl_open_by_build_id (Dwfl_Module - { - if (*file_name != NULL) - free (*file_name); -- *file_name = canonicalize_file_name (name); -+ *file_name = realpath (name, NULL); - if (*file_name == NULL) - { - *file_name = name; ---- a/libelf/elf_getarsym.c -+++ b/libelf/elf_getarsym.c -@@ -297,7 +297,7 @@ elf_getarsym (Elf *elf, size_t *ptr) - arsym[cnt].as_off = (*u32)[cnt]; - - arsym[cnt].as_hash = _dl_elf_hash (str_data); -- str_data = rawmemchr (str_data, '\0') + 1; -+ str_data = memchr (str_data, '\0', SIZE_MAX) + 1; - } - - /* At the end a special entry. */ diff --git a/kernel/bcc.patches/cdefs.h b/kernel/bcc.patches/cdefs.h deleted file mode 100644 index 8ec9770..0000000 --- a/kernel/bcc.patches/cdefs.h +++ /dev/null @@ -1,628 +0,0 @@ -/* $NetBSD: cdefs.h,v 1.129 2016/12/27 21:52:01 christos Exp $ */ - -/* * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Berkeley Software Design, Inc. - * - * 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. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. - * - * @(#)cdefs.h 8.8 (Berkeley) 1/9/95 - */ - -#ifndef _SYS_CDEFS_H_ -#define _SYS_CDEFS_H_ - -#ifdef _KERNEL_OPT -#include "opt_diagnostic.h" -#endif - -/* - * Macro to test if we're using a GNU C compiler of a specific vintage - * or later, for e.g. features that appeared in a particular version - * of GNU C. Usage: - * - * #if __GNUC_PREREQ__(major, minor) - * ...cool feature... - * #else - * ...delete feature... - * #endif - */ -#ifdef __GNUC__ -#define __GNUC_PREREQ__(x, y) \ - ((__GNUC__ == (x) && __GNUC_MINOR__ >= (y)) || \ - (__GNUC__ > (x))) -#else -#define __GNUC_PREREQ__(x, y) 0 -#endif - -#ifdef __GNUC__ -#define __strict_weak_alias(alias,sym) \ - __unused static __typeof__(alias) *__weak_alias_##alias = &sym; \ - __weak_alias(alias,sym) -#else -#define __strict_weak_alias(alias,sym) __weak_alias(alias,sym) -#endif - -/* - * Optional marker for size-optimised MD calling convention. - */ -#ifndef __compactcall -#define __compactcall -#endif - -/* - * The __CONCAT macro is used to concatenate parts of symbol names, e.g. - * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo. - * The __CONCAT macro is a bit tricky -- make sure you don't put spaces - * in between its arguments. __CONCAT can also concatenate double-quoted - * strings produced by the __STRING macro, but this only works with ANSI C. - */ - -#define ___STRING(x) __STRING(x) -#define ___CONCAT(x,y) __CONCAT(x,y) - -#if __STDC__ || defined(__cplusplus) -#define __P(protos) protos /* full-blown ANSI C */ -#define __CONCAT(x,y) x ## y -#define __STRING(x) #x - -#define __const const /* define reserved names to standard */ -#define __signed signed -#define __volatile volatile -#if defined(__cplusplus) || defined(__PCC__) -#define __inline inline /* convert to C++/C99 keyword */ -#else -#if !defined(__GNUC__) && !defined(__lint__) -#define __inline /* delete GCC keyword */ -#endif /* !__GNUC__ && !__lint__ */ -#endif /* !__cplusplus */ - -#else /* !(__STDC__ || __cplusplus) */ -#define __P(protos) () /* traditional C preprocessor */ -#define __CONCAT(x,y) x/**/y -#define __STRING(x) "x" - -#ifndef __GNUC__ -#define __const /* delete pseudo-ANSI C keywords */ -#define __inline -#define __signed -#define __volatile -#endif /* !__GNUC__ */ - -/* - * In non-ANSI C environments, new programs will want ANSI-only C keywords - * deleted from the program and old programs will want them left alone. - * Programs using the ANSI C keywords const, inline etc. as normal - * identifiers should define -DNO_ANSI_KEYWORDS. - */ -#ifndef NO_ANSI_KEYWORDS -#define const __const /* convert ANSI C keywords */ -#define inline __inline -#define signed __signed -#define volatile __volatile -#endif /* !NO_ANSI_KEYWORDS */ -#endif /* !(__STDC__ || __cplusplus) */ - -/* - * Used for internal auditing of the NetBSD source tree. - */ -#ifdef __AUDIT__ -#define __aconst __const -#else -#define __aconst -#endif - -/* - * Compile Time Assertion. - */ -#ifdef __COUNTER__ -#define __CTASSERT(x) __CTASSERT0(x, __ctassert, __COUNTER__) -#else -#define __CTASSERT(x) __CTASSERT99(x, __INCLUDE_LEVEL__, __LINE__) -#define __CTASSERT99(x, a, b) __CTASSERT0(x, __CONCAT(__ctassert,a), \ - __CONCAT(_,b)) -#endif -#define __CTASSERT0(x, y, z) __CTASSERT1(x, y, z) -#define __CTASSERT1(x, y, z) typedef char y ## z[/*CONSTCOND*/(x) ? 1 : -1] __unused - -/* - * The following macro is used to remove const cast-away warnings - * from gcc -Wcast-qual; it should be used with caution because it - * can hide valid errors; in particular most valid uses are in - * situations where the API requires it, not to cast away string - * constants. We don't use *intptr_t on purpose here and we are - * explicit about unsigned long so that we don't have additional - * dependencies. - */ -#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) - -/* - * The following macro is used to remove the volatile cast-away warnings - * from gcc -Wcast-qual; as above it should be used with caution - * because it can hide valid errors or warnings. Valid uses include - * making it possible to pass a volatile pointer to memset(). - * For the same reasons as above, we use unsigned long and not intptr_t. - */ -#define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) - -/* - * GCC2 provides __extension__ to suppress warnings for various GNU C - * language extensions under "-ansi -pedantic". - */ -#if !__GNUC_PREREQ__(2, 0) -#define __extension__ /* delete __extension__ if non-gcc or gcc1 */ -#endif - -/* - * GCC1 and some versions of GCC2 declare dead (non-returning) and - * pure (no side effects) functions using "volatile" and "const"; - * unfortunately, these then cause warnings under "-ansi -pedantic". - * GCC2 uses a new, peculiar __attribute__((attrs)) style. All of - * these work for GNU C++ (modulo a slight glitch in the C++ grammar - * in the distribution version of 2.5.5). - * - * GCC defines a pure function as depending only on its arguments and - * global variables. Typical examples are strlen and sqrt. - * - * GCC defines a const function as depending only on its arguments. - * Therefore calling a const function again with identical arguments - * will always produce the same result. - * - * Rounding modes for floating point operations are considered global - * variables and prevent sqrt from being a const function. - * - * Calls to const functions can be optimised away and moved around - * without limitations. - */ -#if !__GNUC_PREREQ__(2, 0) && !defined(__lint__) -#define __attribute__(x) -#endif - -#if __GNUC_PREREQ__(2, 5) -#define __dead __attribute__((__noreturn__)) -#elif defined(__GNUC__) -#define __dead __volatile -#else -#define __dead -#endif - -#if __GNUC_PREREQ__(2, 96) -#define __pure __attribute__((__pure__)) -#elif defined(__GNUC__) -#define __pure __const -#else -#define __pure -#endif - -#if __GNUC_PREREQ__(2, 5) -#define __constfunc __attribute__((__const__)) -#else -#define __constfunc -#endif - -#if __GNUC_PREREQ__(3, 0) -#define __noinline __attribute__((__noinline__)) -#else -#define __noinline /* nothing */ -#endif - -#if __GNUC_PREREQ__(3, 0) -#define __always_inline __attribute__((__always_inline__)) -#else -#define __always_inline /* nothing */ -#endif - -#if __GNUC_PREREQ__(4, 1) -#define __returns_twice __attribute__((__returns_twice__)) -#else -#define __returns_twice /* nothing */ -#endif - -#if __GNUC_PREREQ__(4, 5) -#define __noclone __attribute__((__noclone__)) -#else -#define __noclone /* nothing */ -#endif - -/* - * __unused: Note that item or function might be unused. - */ -#if __GNUC_PREREQ__(2, 7) || defined(__lint__) -#define __unused __attribute__((__unused__)) -#else -#define __unused /* delete */ -#endif - -/* - * __used: Note that item is needed, even if it appears to be unused. - */ -#if __GNUC_PREREQ__(3, 1) -#define __used __attribute__((__used__)) -#else -#define __used __unused -#endif - -/* - * __diagused: Note that item is used in diagnostic code, but may be - * unused in non-diagnostic code. - */ -#if (defined(_KERNEL) && defined(DIAGNOSTIC)) \ - || (!defined(_KERNEL) && !defined(NDEBUG)) -#define __diagused /* empty */ -#else -#define __diagused __unused -#endif - -/* - * __debugused: Note that item is used in debug code, but may be - * unused in non-debug code. - */ -#if defined(DEBUG) -#define __debugused /* empty */ -#else -#define __debugused __unused -#endif - -#if __GNUC_PREREQ__(3, 1) -#define __noprofile __attribute__((__no_instrument_function__)) -#else -#define __noprofile /* nothing */ -#endif - -#if __GNUC_PREREQ__(4, 6) || defined(__clang__) -#define __unreachable() __builtin_unreachable() -#else -#define __unreachable() do {} while (/*CONSTCOND*/0) -#endif - -#if defined(__cplusplus) -#define __BEGIN_EXTERN_C extern "C" { -#define __END_EXTERN_C } -#define __static_cast(x,y) static_cast(y) -#else -#define __BEGIN_EXTERN_C -#define __END_EXTERN_C -#define __static_cast(x,y) (x)y -#endif - -#if __GNUC_PREREQ__(4, 0) -# define __dso_public __attribute__((__visibility__("default"))) -# define __dso_hidden __attribute__((__visibility__("hidden"))) -# define __BEGIN_PUBLIC_DECLS \ - _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C -# define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") -# define __BEGIN_HIDDEN_DECLS \ - _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C -# define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop") -#else -# define __dso_public -# define __dso_hidden -# define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C -# define __END_PUBLIC_DECLS __END_EXTERN_C -# define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C -# define __END_HIDDEN_DECLS __END_EXTERN_C -#endif -#if __GNUC_PREREQ__(4, 2) -# define __dso_protected __attribute__((__visibility__("protected"))) -#else -# define __dso_protected -#endif - -#define __BEGIN_DECLS __BEGIN_PUBLIC_DECLS -#define __END_DECLS __END_PUBLIC_DECLS - -/* - * Non-static C99 inline functions are optional bodies. They don't - * create global symbols if not used, but can be replaced if desirable. - * This differs from the behavior of GCC before version 4.3. The nearest - * equivalent for older GCC is `extern inline'. For newer GCC, use the - * gnu_inline attribute additionally to get the old behavior. - * - * For C99 compilers other than GCC, the C99 behavior is expected. - */ -#if defined(__GNUC__) && defined(__GNUC_STDC_INLINE__) -#define __c99inline extern __attribute__((__gnu_inline__)) __inline -#elif defined(__GNUC__) -#define __c99inline extern __inline -#elif defined(__STDC_VERSION__) -#define __c99inline __inline -#endif - -#if defined(__lint__) -#define __packed __packed -#define __aligned(x) /* delete */ -#define __section(x) /* delete */ -#elif __GNUC_PREREQ__(2, 7) || defined(__PCC__) -#define __packed __attribute__((__packed__)) -#define __aligned(x) __attribute__((__aligned__(x))) -#define __section(x) __attribute__((__section__(x))) -#elif defined(_MSC_VER) -#define __packed /* ignore */ -#else -#define __packed error: no __packed for this compiler -#define __aligned(x) error: no __aligned for this compiler -#define __section(x) error: no __section for this compiler -#endif - -/* - * C99 defines the restrict type qualifier keyword, which was made available - * in GCC 2.92. - */ -#if defined(__lint__) -#define __restrict /* delete __restrict when not supported */ -#elif __STDC_VERSION__ >= 199901L -#define __restrict restrict -#elif __GNUC_PREREQ__(2, 92) -#define __restrict __restrict__ -#else -#define __restrict /* delete __restrict when not supported */ -#endif - -/* - * C99 defines __func__ predefined identifier, which was made available - * in GCC 2.95. - */ -#if !(__STDC_VERSION__ >= 199901L) -#if __GNUC_PREREQ__(2, 6) -#define __func__ __PRETTY_FUNCTION__ -#elif __GNUC_PREREQ__(2, 4) -#define __func__ __FUNCTION__ -#else -#define __func__ "" -#endif -#endif /* !(__STDC_VERSION__ >= 199901L) */ - -#if defined(_KERNEL) -#if defined(NO_KERNEL_RCSIDS) -#undef __KERNEL_RCSID -#define __KERNEL_RCSID(_n, _s) /* nothing */ -#endif /* NO_KERNEL_RCSIDS */ -#endif /* _KERNEL */ - -#if !defined(_STANDALONE) && !defined(_KERNEL) -#if defined(__GNUC__) || defined(__PCC__) -#define __RENAME(x) ___RENAME(x) -#elif defined(__lint__) -#define __RENAME(x) __symbolrename(x) -#else -#error "No function renaming possible" -#endif /* __GNUC__ */ -#else /* _STANDALONE || _KERNEL */ -#define __RENAME(x) no renaming in kernel/standalone environment -#endif - -/* - * A barrier to stop the optimizer from moving code or assume live - * register values. This is gcc specific, the version is more or less - * arbitrary, might work with older compilers. - */ -#if __GNUC_PREREQ__(2, 95) -#define __insn_barrier() __asm __volatile("":::"memory") -#else -#define __insn_barrier() /* */ -#endif - -/* - * GNU C version 2.96 adds explicit branch prediction so that - * the CPU back-end can hint the processor and also so that - * code blocks can be reordered such that the predicted path - * sees a more linear flow, thus improving cache behavior, etc. - * - * The following two macros provide us with a way to use this - * compiler feature. Use __predict_true() if you expect the expression - * to evaluate to true, and __predict_false() if you expect the - * expression to evaluate to false. - * - * A few notes about usage: - * - * * Generally, __predict_false() error condition checks (unless - * you have some _strong_ reason to do otherwise, in which case - * document it), and/or __predict_true() `no-error' condition - * checks, assuming you want to optimize for the no-error case. - * - * * Other than that, if you don't know the likelihood of a test - * succeeding from empirical or other `hard' evidence, don't - * make predictions. - * - * * These are meant to be used in places that are run `a lot'. - * It is wasteful to make predictions in code that is run - * seldomly (e.g. at subsystem initialization time) as the - * basic block reordering that this affects can often generate - * larger code. - */ -#if __GNUC_PREREQ__(2, 96) -#define __predict_true(exp) __builtin_expect((exp) != 0, 1) -#define __predict_false(exp) __builtin_expect((exp) != 0, 0) -#else -#define __predict_true(exp) (exp) -#define __predict_false(exp) (exp) -#endif - -/* - * Compiler-dependent macros to declare that functions take printf-like - * or scanf-like arguments. They are null except for versions of gcc - * that are known to support the features properly (old versions of gcc-2 - * didn't permit keeping the keywords out of the application namespace). - */ -#if __GNUC_PREREQ__(2, 7) -#define __printflike(fmtarg, firstvararg) \ - __attribute__((__format__ (__printf__, fmtarg, firstvararg))) -#ifndef __syslog_attribute__ -#define __syslog__ __printf__ -#endif -#define __sysloglike(fmtarg, firstvararg) \ - __attribute__((__format__ (__syslog__, fmtarg, firstvararg))) -#define __scanflike(fmtarg, firstvararg) \ - __attribute__((__format__ (__scanf__, fmtarg, firstvararg))) -#define __format_arg(fmtarg) __attribute__((__format_arg__ (fmtarg))) -#else -#define __printflike(fmtarg, firstvararg) /* nothing */ -#define __scanflike(fmtarg, firstvararg) /* nothing */ -#define __sysloglike(fmtarg, firstvararg) /* nothing */ -#define __format_arg(fmtarg) /* nothing */ -#endif - -/* - * Macros for manipulating "link sets". Link sets are arrays of pointers - * to objects, which are gathered up by the linker. - * - * Object format-specific code has provided us with the following macros: - * - * __link_set_add_text(set, sym) - * Add a reference to the .text symbol `sym' to `set'. - * - * __link_set_add_rodata(set, sym) - * Add a reference to the .rodata symbol `sym' to `set'. - * - * __link_set_add_data(set, sym) - * Add a reference to the .data symbol `sym' to `set'. - * - * __link_set_add_bss(set, sym) - * Add a reference to the .bss symbol `sym' to `set'. - * - * __link_set_decl(set, ptype) - * Provide an extern declaration of the set `set', which - * contains an array of pointers to type `ptype'. This - * macro must be used by any code which wishes to reference - * the elements of a link set. - * - * __link_set_start(set) - * This points to the first slot in the link set. - * - * __link_set_end(set) - * This points to the (non-existent) slot after the last - * entry in the link set. - * - * __link_set_count(set) - * Count the number of entries in link set `set'. - * - * In addition, we provide the following macros for accessing link sets: - * - * __link_set_foreach(pvar, set) - * Iterate over the link set `set'. Because a link set is - * an array of pointers, pvar must be declared as "type **pvar", - * and the actual entry accessed as "*pvar". - * - * __link_set_entry(set, idx) - * Access the link set entry at index `idx' from set `set'. - */ -#define __link_set_foreach(pvar, set) \ - for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++) - -#define __link_set_entry(set, idx) (__link_set_start(set)[idx]) - -/* - * Return the natural alignment in bytes for the given type - */ -#if __GNUC_PREREQ__(4, 1) -#define __alignof(__t) __alignof__(__t) -#else -#define __alignof(__t) (sizeof(struct { char __x; __t __y; }) - sizeof(__t)) -#endif - -/* - * Return the number of elements in a statically-allocated array, - * __x. - */ -#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) - -#ifndef __ASSEMBLER__ -/* __BIT(n): nth bit, where __BIT(0) == 0x1. */ -#define __BIT(__n) \ - (((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \ - ((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1)))) - -/* __BITS(m, n): bits m through n, m < n. */ -#define __BITS(__m, __n) \ - ((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1)) -#endif /* !__ASSEMBLER__ */ - -/* find least significant bit that is set */ -#define __LOWEST_SET_BIT(__mask) ((((__mask) - 1) & (__mask)) ^ (__mask)) - -#define __PRIuBIT PRIuMAX -#define __PRIuBITS __PRIuBIT - -#define __PRIxBIT PRIxMAX -#define __PRIxBITS __PRIxBIT - -#define __SHIFTOUT(__x, __mask) (((__x) & (__mask)) / __LOWEST_SET_BIT(__mask)) -#define __SHIFTIN(__x, __mask) ((__x) * __LOWEST_SET_BIT(__mask)) -#define __SHIFTOUT_MASK(__mask) __SHIFTOUT((__mask), (__mask)) - -/* - * Only to be used in other headers that are included from both c or c++ - * NOT to be used in code. - */ -#ifdef __cplusplus -#define __CAST(__dt, __st) static_cast<__dt>(__st) -#else -#define __CAST(__dt, __st) ((__dt)(__st)) -#endif - -#define __CASTV(__dt, __st) __CAST(__dt, __CAST(void *, __st)) -#define __CASTCV(__dt, __st) __CAST(__dt, __CAST(const void *, __st)) - -#define __USE(a) ((void)(a)) - -#define __type_mask(t) (/*LINTED*/sizeof(t) < sizeof(intmax_t) ? \ - (~((1ULL << (sizeof(t) * NBBY)) - 1)) : 0ULL) - -#ifndef __ASSEMBLER__ -static __inline long long __zeroll(void) { return 0; } -static __inline unsigned long long __zeroull(void) { return 0; } -#else -#define __zeroll() (0LL) -#define __zeroull() (0ULL) -#endif - -#define __negative_p(x) (!((x) > 0) && ((x) != 0)) - -#define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) -#define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) -#define __type_min_u(t) ((t)0ULL) -#define __type_max_u(t) ((t)~0ULL) -#define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) -#define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) -#define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) - - -#define __type_fit_u(t, a) (/*LINTED*/!__negative_p(a) && \ - (uintmax_t)((a) + __zeroull()) <= (uintmax_t)__type_max_u(t)) - -#define __type_fit_s(t, a) (/*LINTED*/__negative_p(a) ? \ - ((intmax_t)((a) + __zeroll()) >= (intmax_t)__type_min_s(t)) : \ - ((intmax_t)((a) + __zeroll()) >= (intmax_t)0 && \ - (intmax_t)((a) + __zeroll()) <= (intmax_t)__type_max_s(t))) - -/* - * return true if value 'a' fits in type 't' - */ -#define __type_fit(t, a) (__type_is_signed(t) ? \ - __type_fit_s(t, a) : __type_fit_u(t, a)) - -#endif /* !_SYS_CDEFS_H_ */ diff --git a/kernel/bcc.patches/decl.patch b/kernel/bcc.patches/decl.patch deleted file mode 100644 index 4f69bfa..0000000 --- a/kernel/bcc.patches/decl.patch +++ /dev/null @@ -1,23 +0,0 @@ ---- libelf/elf.h-orig -+++ libelf/elf.h -@@ -21,7 +21,9 @@ - - #include - --__BEGIN_DECLS -+#ifdef __cplusplus -+extern "C" { -+#endif - - /* Standard ELF types. */ - -@@ -3553,6 +3555,8 @@ - #define R_TILEGX_NUM 130 - - --__END_DECLS -+#ifdef __cplusplus -+} -+#endif - - #endif /* elf.h */ diff --git a/kernel/bcc.patches/error.h b/kernel/bcc.patches/error.h deleted file mode 100644 index 6b71c7e..0000000 --- a/kernel/bcc.patches/error.h +++ /dev/null @@ -1,29 +0,0 @@ -# include -# include -# include -# include -static void error_at_line(int status, int errnum, const char *filename, - unsigned int linenum, const char *format, ...) -{ - va_list ap; - - fflush(stdout); - - if (filename != NULL) - fprintf(stderr, "%s:%u: ", filename, linenum); - - va_start(ap, format); - vfprintf(stderr, format, ap); - va_end(ap); - - if (errnum != 0) - fprintf(stderr, ": %s", strerror(errnum)); - - fprintf(stderr, "\n"); - - if (status != 0) - exit(status); -} - -#define error(status, errnum, format...) \ - error_at_line(status, errnum, NULL, 0, format) diff --git a/kernel/bcc.patches/intl.patch b/kernel/bcc.patches/intl.patch deleted file mode 100644 index 6c19193..0000000 --- a/kernel/bcc.patches/intl.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- libelf/Makefile.am-orig -+++ libelf/Makefile.am -@@ -95,7 +95,7 @@ - libelf_pic_a_SOURCES = - am_libelf_pic_a_OBJECTS = $(libelf_a_SOURCES:.c=.os) - --libelf_so_LDLIBS = -lz -+libelf_so_LDLIBS = -lz -lintl - if USE_LOCKS - libelf_so_LDLIBS += -lpthread - endif diff --git a/kernel/bcc.patches/temp_failure.patch b/kernel/bcc.patches/temp_failure.patch deleted file mode 100644 index 2997f45..0000000 --- a/kernel/bcc.patches/temp_failure.patch +++ /dev/null @@ -1,17 +0,0 @@ ---- lib/system.h-orig -+++ lib/system.h -@@ -70,6 +70,14 @@ - - #define gettext_noop(Str) Str - -+#ifndef TEMP_FAILURE_RETRY -+# define TEMP_FAILURE_RETRY(expression) \ -+ (__extension__ \ -+ ({ long int __result; \ -+ do __result = (long int) (expression); \ -+ while (__result == -1L && errno == EINTR); \ -+ __result; })) -+#endif - - #define pwrite_retry(fd, buf, len, off) \ - TEMP_FAILURE_RETRY (pwrite (fd, buf, len, off)) diff --git a/kernel/config-5.15.x-aarch64 b/kernel/config-5.15.x-aarch64 index 35e31cd..527045d 100644 --- a/kernel/config-5.15.x-aarch64 +++ b/kernel/config-5.15.x-aarch64 @@ -5295,4 +5295,4 @@ CONFIG_RUNTIME_TESTING_MENU=y CONFIG_ARCH_USE_MEMTEST=y # CONFIG_MEMTEST is not set # end of Kernel Testing and Coverage -# end of Kernel hacking \ No newline at end of file +# end of Kernel hacking diff --git a/kernel/config-5.15.x-x86_64 b/kernel/config-5.15.x-x86_64 index c321fb2..43539b7 100644 --- a/kernel/config-5.15.x-x86_64 +++ b/kernel/config-5.15.x-x86_64 @@ -4918,4 +4918,4 @@ CONFIG_ARCH_USE_MEMTEST=y # CONFIG_MEMTEST is not set # CONFIG_HYPERV_TESTING is not set # end of Kernel Testing and Coverage -# end of Kernel hacking \ No newline at end of file +# end of Kernel hacking diff --git a/rules.mk b/rules.mk index cbeaa5a..014ec28 100644 --- a/rules.mk +++ b/rules.mk @@ -104,3 +104,9 @@ dist dbg-dist: tar -xf $$f -C $$d/ initrd.img && mv $$d/initrd.img $$d/initramfs-$$arch tar -cf- -C $$d initramfs-$$arch vmlinuz-$$arch | pigz > $$d/hook_$$arch.tar.gz done + +build_5.15.x: + $(MAKE) -C kernel ORG=$(ORG) IMAGE=hook-kernel build_5.15.x + +build_5.10.x: + $(MAKE) -C kernel ORG=$(ORG) IMAGE=hook-kernel build_5.10.x