2020-08-31 20:53:58 -05:00
|
|
|
# Linux kernel-native Makefile ("Kbuild") for libwolfssl.ko
|
|
|
|
|
#
|
2025-01-21 09:55:03 -07:00
|
|
|
# Copyright (C) 2006-2025 wolfSSL Inc.
|
2020-08-31 20:53:58 -05:00
|
|
|
#
|
|
|
|
|
# This file is part of wolfSSL.
|
|
|
|
|
#
|
|
|
|
|
# wolfSSL is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2025-07-10 16:01:52 -06:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2020-08-31 20:53:58 -05:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# wolfSSL is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
2020-08-18 14:17:44 -05:00
|
|
|
|
2025-02-23 15:33:46 -06:00
|
|
|
.ONESHELL:
|
2024-07-16 14:24:37 -05:00
|
|
|
SHELL=bash
|
2020-08-18 14:17:44 -05:00
|
|
|
|
2025-04-10 17:23:17 +00:00
|
|
|
ifeq "$(KERNEL_ARCH)" "x86"
|
|
|
|
|
KERNEL_ARCH_X86 := yes
|
|
|
|
|
else ifeq "$(KERNEL_ARCH)" "x86_64"
|
|
|
|
|
KERNEL_ARCH_X86 := yes
|
|
|
|
|
else
|
|
|
|
|
KERNEL_ARCH_X86 := no
|
|
|
|
|
endif
|
|
|
|
|
|
2020-08-18 14:17:44 -05:00
|
|
|
ifeq "$(WOLFSSL_OBJ_FILES)" ""
|
2020-08-31 20:53:58 -05:00
|
|
|
$(error $$WOLFSSL_OBJ_FILES is unset.)
|
2020-08-18 14:17:44 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifeq "$(WOLFSSL_CFLAGS)" ""
|
2020-08-31 20:53:58 -05:00
|
|
|
$(error $$WOLFSSL_CFLAGS is unset.)
|
2020-08-18 14:17:44 -05:00
|
|
|
endif
|
|
|
|
|
|
2022-01-07 22:39:38 -06:00
|
|
|
WOLFSSL_CFLAGS += -ffreestanding -Wframe-larger-than=$(MAX_STACK_FRAME_SIZE) -isystem $(shell $(CC) -print-file-name=include)
|
2021-08-19 11:15:52 -05:00
|
|
|
|
2025-04-10 17:23:17 +00:00
|
|
|
ifeq "$(KERNEL_ARCH)" "aarch64"
|
2024-01-31 11:49:46 -06:00
|
|
|
WOLFSSL_CFLAGS += -mno-outline-atomics
|
|
|
|
|
else ifeq "$(KERNEL_ARCH)" "arm64"
|
|
|
|
|
WOLFSSL_CFLAGS += -mno-outline-atomics
|
2021-08-19 11:15:52 -05:00
|
|
|
endif
|
2020-08-31 18:37:04 -05:00
|
|
|
|
2020-08-28 10:32:30 -05:00
|
|
|
obj-m := libwolfssl.o
|
|
|
|
|
|
2021-08-19 11:15:52 -05:00
|
|
|
WOLFSSL_OBJ_TARGETS := $(patsubst %, $(obj)/%, $(WOLFSSL_OBJ_FILES))
|
|
|
|
|
|
|
|
|
|
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
|
|
|
|
|
WOLFCRYPT_PIE_FILES := $(patsubst %, $(obj)/%, $(WOLFCRYPT_PIE_FILES))
|
|
|
|
|
endif
|
2020-08-28 10:32:30 -05:00
|
|
|
|
|
|
|
|
$(obj)/linuxkm/module_exports.o: $(WOLFSSL_OBJ_TARGETS)
|
|
|
|
|
|
2024-07-16 14:24:37 -05:00
|
|
|
ifndef KERNEL_THREAD_STACK_SIZE
|
|
|
|
|
ifdef CROSS_COMPILE
|
|
|
|
|
KERNEL_THREAD_STACK_SIZE=16384
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
|
2020-08-22 01:10:28 -05:00
|
|
|
# this mechanism only works in kernel 5.x+ (fallback to hardcoded value)
|
2024-07-16 14:24:37 -05:00
|
|
|
ifndef KERNEL_THREAD_STACK_SIZE
|
|
|
|
|
hostprogs := linuxkm/get_thread_size
|
|
|
|
|
always-y := $(hostprogs)
|
|
|
|
|
endif
|
2024-01-31 11:49:46 -06:00
|
|
|
|
|
|
|
|
HOST_EXTRACFLAGS += $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(KBUILD_CFLAGS) -static -fno-omit-frame-pointer
|
|
|
|
|
|
2022-07-19 10:20:04 -05:00
|
|
|
# "-mindirect-branch=keep -mfunction-return=keep" to avoid "undefined reference
|
|
|
|
|
# to `__x86_return_thunk'" on CONFIG_RETHUNK kernels (5.19.0-rc7)
|
2025-04-10 17:23:17 +00:00
|
|
|
ifeq "$(KERNEL_ARCH_X86)" "yes"
|
2024-01-31 11:49:46 -06:00
|
|
|
HOST_EXTRACFLAGS += -mindirect-branch=keep -mfunction-return=keep
|
2024-01-26 14:04:02 -06:00
|
|
|
endif
|
|
|
|
|
|
2020-08-22 01:10:28 -05:00
|
|
|
# this rule is needed to get build to succeed in 4.x (get_thread_size still doesn't get built)
|
|
|
|
|
$(obj)/linuxkm/get_thread_size: $(src)/linuxkm/get_thread_size.c
|
|
|
|
|
|
2024-07-16 14:24:37 -05:00
|
|
|
ifndef KERNEL_THREAD_STACK_SIZE
|
|
|
|
|
$(WOLFSSL_OBJ_TARGETS): | $(obj)/linuxkm/get_thread_size
|
|
|
|
|
KERNEL_THREAD_STACK_SIZE=$(shell test -x $(obj)/linuxkm/get_thread_size && $(obj)/linuxkm/get_thread_size || echo 16384)
|
|
|
|
|
endif
|
2020-08-22 00:32:32 -05:00
|
|
|
MAX_STACK_FRAME_SIZE=$(shell echo $$(( $(KERNEL_THREAD_STACK_SIZE) / 4)))
|
|
|
|
|
|
2020-08-28 10:32:30 -05:00
|
|
|
libwolfssl-y := $(WOLFSSL_OBJ_FILES) linuxkm/module_hooks.o linuxkm/module_exports.o
|
2020-08-18 14:17:44 -05:00
|
|
|
|
2020-09-01 14:40:53 -05:00
|
|
|
WOLFSSL_CFLAGS_NO_VECTOR_INSNS := $(CFLAGS_SIMD_DISABLE) $(CFLAGS_FPU_DISABLE)
|
|
|
|
|
ifeq "$(ENABLED_ASM)" "yes"
|
|
|
|
|
WOLFSSL_CFLAGS_YES_VECTOR_INSNS := $(CFLAGS_SIMD_ENABLE) $(CFLAGS_FPU_DISABLE) $(CFLAGS_AUTO_VECTORIZE_DISABLE)
|
2020-08-31 20:53:58 -05:00
|
|
|
else
|
2020-09-01 14:40:53 -05:00
|
|
|
WOLFSSL_CFLAGS_YES_VECTOR_INSNS := $(WOLFSSL_CFLAGS_NO_VECTOR_INSNS)
|
2020-08-31 18:37:04 -05:00
|
|
|
endif
|
|
|
|
|
|
2021-08-19 11:15:52 -05:00
|
|
|
ccflags-y := $(WOLFSSL_CFLAGS) $(WOLFSSL_CFLAGS_NO_VECTOR_INSNS)
|
2020-08-31 18:37:04 -05:00
|
|
|
|
|
|
|
|
$(obj)/libwolfssl.mod.o: ccflags-y :=
|
2024-12-10 13:02:07 -06:00
|
|
|
$(obj)/wolfcrypt/test/test.o: ccflags-y += -DNO_MAIN_DRIVER -DWOLFSSL_NO_OPTIONS_H
|
2020-08-22 00:32:32 -05:00
|
|
|
|
2020-08-31 18:37:04 -05:00
|
|
|
$(obj)/wolfcrypt/src/aes.o: ccflags-y = $(WOLFSSL_CFLAGS) $(WOLFSSL_CFLAGS_YES_VECTOR_INSNS)
|
2020-08-18 14:17:44 -05:00
|
|
|
|
2021-08-19 11:15:52 -05:00
|
|
|
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
|
2025-07-22 16:45:06 -05:00
|
|
|
# note, we need -fno-stack-protector to avoid references to
|
|
|
|
|
# "__stack_chk_fail" from the wolfCrypt container.
|
|
|
|
|
PIE_FLAGS := -fPIE -fno-stack-protector -fno-toplevel-reorder
|
2021-08-19 11:15:52 -05:00
|
|
|
PIE_SUPPORT_FLAGS := -DUSE_WOLFSSL_LINUXKM_PIE_REDIRECT_TABLE
|
2025-07-23 17:30:14 -05:00
|
|
|
# the kernel sanitizers generate external references to
|
|
|
|
|
# __ubsan_handle_out_of_bounds(), __ubsan_handle_shift_out_of_bounds(), etc.
|
|
|
|
|
KASAN_SANITIZE := n
|
|
|
|
|
UBSAN_SANITIZE := n
|
2025-04-10 17:23:17 +00:00
|
|
|
ifeq "$(KERNEL_ARCH_X86)" "yes"
|
linuxkm/x86_vector_register_glue.c:
* refactor the save_vector_registers_x86() algorithm to depend directly on preempt_count(), and use local_bh_enable() and preempt_disable() directly, to mitigate glitchiness around irq_fpu_usable() and crypto_simd_usable();
* eliminate the WC_FPU_ALREADY_FLAG kludge.
* improve the error and warning messages, and add some additional checks and messages for unexpected states; add VRG_PR_ERR_X and VRG_PR_WARN_X for pr_*_once() semantics on regular builds, but unlimited messages when WOLFSSL_LINUXKM_VERBOSE_DEBUG.
linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c:
* move the spinlock-based implementation of wc_LockMutex() from linuxkm_wc_port.h to module_hooks.c, due to numerous stuboorn direct external symbol references;
* extensively refactor the kernel header #include strategy, keeping many more superfluous headers out of __PIE__ objects, and fixing unavoidable static header functions with grafted __always_inline attributes;
* add version exceptions for RHEL 9.5.
linuxkm/Kbuild:
* on x86 with CONFIG_MITIGATION_{RETPOLINE,RETHUNK}, use inline rethunks rather than none;
* refactor check for "Error: section(s) missed by containerization." using `readelf --sections --syms`, for 100% coverage, more informative error output, and suppression of false positives on printk-related cruft;
configure.ac and linuxkm/lkcapi_sha_glue.c: use LINUXKM_LKCAPI_[DONT_]REGISTER_{SHA,HMAC}_ALL to represent --enable-linuxkm-lkcapi-register=[-]all-{sha,hmac}, which allows alg families (notably SHA1) to be masked out piecemeal;
linuxkm/lkcapi_rsa_glue.c: in linuxkm_test_pkcs1pad_driver(), mitigate unused args when LINUXKM_AKCIPHER_NO_SIGNVERIFY.
2025-07-16 13:09:03 -05:00
|
|
|
PIE_FLAGS += -mcmodel=small
|
|
|
|
|
ifeq "$(CONFIG_MITIGATION_RETPOLINE)" "y"
|
|
|
|
|
PIE_FLAGS += -mfunction-return=thunk-inline
|
|
|
|
|
else
|
|
|
|
|
PIE_FLAGS += -mfunction-return=keep
|
|
|
|
|
endif
|
|
|
|
|
ifeq "$(CONFIG_MITIGATION_RETHUNK)" "y"
|
|
|
|
|
PIE_FLAGS += -mindirect-branch=thunk-inline
|
|
|
|
|
else
|
|
|
|
|
PIE_FLAGS += -mindirect-branch=keep
|
|
|
|
|
endif
|
2021-08-19 11:15:52 -05:00
|
|
|
endif
|
|
|
|
|
ifeq "$(KERNEL_ARCH)" "mips"
|
|
|
|
|
PIE_FLAGS += -mabicalls
|
|
|
|
|
endif
|
|
|
|
|
$(WOLFCRYPT_PIE_FILES): ccflags-y += $(PIE_SUPPORT_FLAGS) $(PIE_FLAGS)
|
|
|
|
|
$(WOLFCRYPT_PIE_FILES): ccflags-remove-y += -pg
|
2025-07-21 19:34:00 -05:00
|
|
|
# using inline retpolines leads to "unannotated intra-function call"
|
|
|
|
|
# warnings from objtool without this:
|
2021-08-19 11:15:52 -05:00
|
|
|
$(WOLFCRYPT_PIE_FILES): OBJECT_FILES_NON_STANDARD := y
|
|
|
|
|
$(obj)/linuxkm/module_hooks.o: ccflags-y += $(PIE_SUPPORT_FLAGS)
|
|
|
|
|
endif
|
|
|
|
|
|
2025-07-23 14:31:52 -05:00
|
|
|
ifdef KERNEL_EXTRA_CFLAGS_REMOVE
|
|
|
|
|
ccflags-remove-y += KERNEL_EXTRA_CFLAGS_REMOVE
|
|
|
|
|
endif
|
|
|
|
|
|
2024-12-10 13:02:07 -06:00
|
|
|
$(obj)/wolfcrypt/benchmark/benchmark.o: ccflags-y = $(WOLFSSL_CFLAGS) $(CFLAGS_FPU_ENABLE) $(CFLAGS_SIMD_ENABLE) $(PIE_SUPPORT_FLAGS) -DNO_MAIN_FUNCTION -DWOLFSSL_NO_OPTIONS_H
|
wolfssl/wolfcrypt/types.h:
* fix overallocation in WC_DECLARE_ARRAY() macro in the !WOLFSSL_SMALL_STACK path.
* rename WC_INIT_ARRAY() to WC_ALLOC_ARRAY() for clarity (it doesn't initialize any memory).
* rename WC_DECLARE_ARRAY_DYNAMIC_DEC(), WC_DECLARE_ARRAY_DYNAMIC_EXE(), and WC_FREE_ARRAY_DYNAMIC() to WC_DECLARE_HEAP_ARRAY(), WC_ALLOC_HEAP_ARRAY(), and WC_FREE_HEAP_ARRAY(), respectively, also for clarity, and refactor out the duplicate definitions.
* add WC_ALLOC_VAR(), and move the XMALLOC() in smallstack WC_DECLARE_VAR() into it. smallstack WC_DECLARE_VAR() now initializes the pointer to NULL, like smallstack WC_DECLARE_ARRAY(), assuring all pointers are valid upon shortcircuit to cleanup for a failed allocation (see WC_ALLOC_DO_ON_FAILURE below).
* add a new hook "WC_ALLOC_DO_ON_FAILURE" in WC_ALLOC_VAR(), WC_ALLOC_ARRAY(), and WC_DECLARE_ARRAY_DYNAMIC_EXE(), which is invoked when an allocation fails. by default the hook is defined to WC_DO_NOTHING.
* add basic safety to WC_*_HEAP_ARRAY() by recording/detecting allocation state via idx##VAR_NAME.
* add macros WC_ARRAY_OK() and WC_HEAP_ARRAY_OK() to test if allocation succeeded.
* add macros WC_CALLOC_ARRAY() and WC_CALLOC_HEAP_ARRAY() which zero the objects.
* add macro WC_CALLOC_VAR() which zeros the object.
ED448: smallstack refactor of ge448_scalarmult_base().
src/tls.c tests/api.c wolfcrypt/test/test.c: update WC_DECLARE_VAR()s with now-required matching WC_ALLOC_VAR()s.
wolfcrypt/benchmark/benchmark.c:
* no functional changes in default error-free behavior.
* add definition of WC_ALLOC_DO_ON_FAILURE() that prints error message, sets ret, and does goto exit.
* add BENCH_NTIMES and BENCH_AGREETIMES overrideeable macros, to allow fast sanitizer runs and slow high-precision runs.
* smallstack refactor of all declarations of stack arrays of the form foo[BENCH_MAX_PENDING], using WC_DECLARE_ARRAY() (35 in all).
* additional smallstack refactors, using WC_DECLARE_VAR(), for bench_aesxts(), bench_ed448KeyGen(), bench_eccsi*(), and bench_sakke*().
* fixes for various unhandled error conditions around malloc failures.
wolfcrypt/test/test.c: opportunistically constify several (42) static constants, moving them to the readonly data segment.
linuxkm/Makefile: if ENABLED_LINUXKM_BENCHMARKS, add wolfcrypt/benchmark/benchmark.o to WOLFSSL_OBJ_FILES.
linuxkm/Kbuild: enable FPU for benchmark.o, and remove enablement for module_hooks.o.
linuxkm/module_hooks.c: remove inline include of benchmark.c.
2024-02-16 02:32:18 -06:00
|
|
|
$(obj)/wolfcrypt/benchmark/benchmark.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_ENABLE_SIMD_DISABLE)
|
2023-05-17 01:44:36 -05:00
|
|
|
|
2020-09-08 23:11:03 -05:00
|
|
|
asflags-y := $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPUSIMD_DISABLE)
|
|
|
|
|
|
2021-10-18 15:00:47 -05:00
|
|
|
# vectorized implementations that are kernel-safe are listed here.
|
2024-08-14 14:39:45 -05:00
|
|
|
# these are known kernel-compatible, but need the vector instructions enabled in the assembler,
|
|
|
|
|
# and most of them still irritate objtool.
|
2020-09-08 23:11:03 -05:00
|
|
|
$(obj)/wolfcrypt/src/aes_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
2020-08-31 18:37:04 -05:00
|
|
|
$(obj)/wolfcrypt/src/aes_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2021-10-18 15:00:47 -05:00
|
|
|
$(obj)/wolfcrypt/src/aes_gcm_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
2020-08-31 18:37:04 -05:00
|
|
|
$(obj)/wolfcrypt/src/aes_gcm_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2023-09-28 09:25:37 +10:00
|
|
|
$(obj)/wolfcrypt/src/aes_xts_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/aes_xts_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2021-10-18 15:00:47 -05:00
|
|
|
$(obj)/wolfcrypt/src/sp_x86_64_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
2021-09-15 23:05:32 -05:00
|
|
|
$(obj)/wolfcrypt/src/sp_x86_64_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2024-04-19 01:35:45 -05:00
|
|
|
$(obj)/wolfcrypt/src/sha256_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/sha256_asm.o: OBJECT_FILES_NON_STANDARD := y
|
|
|
|
|
$(obj)/wolfcrypt/src/sha512_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/sha512_asm.o: OBJECT_FILES_NON_STANDARD := y
|
|
|
|
|
$(obj)/wolfcrypt/src/sha3_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/sha3_asm.o: OBJECT_FILES_NON_STANDARD := y
|
|
|
|
|
$(obj)/wolfcrypt/src/chacha_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/chacha_asm.o: OBJECT_FILES_NON_STANDARD := y
|
|
|
|
|
$(obj)/wolfcrypt/src/poly1305_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
|
|
|
|
$(obj)/wolfcrypt/src/poly1305_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2025-03-06 14:19:00 +10:00
|
|
|
$(obj)/wolfcrypt/src/wc_mlkem_asm.o: asflags-y = $(WOLFSSL_ASFLAGS) $(ASFLAGS_FPU_DISABLE_SIMD_ENABLE)
|
2025-05-30 13:39:33 -05:00
|
|
|
$(obj)/wolfcrypt/src/wc_mlkem_asm.o: OBJECT_FILES_NON_STANDARD := y
|
2020-08-28 10:32:30 -05:00
|
|
|
|
2024-12-16 11:43:26 -06:00
|
|
|
ifndef READELF
|
|
|
|
|
READELF := readelf
|
|
|
|
|
endif
|
|
|
|
|
|
2021-08-19 11:15:52 -05:00
|
|
|
ifeq "$(ENABLED_LINUXKM_PIE)" "yes"
|
|
|
|
|
|
2025-07-09 16:29:04 -05:00
|
|
|
LDFLAGS_libwolfssl.o += -T $(src)/wolfcrypt.lds
|
|
|
|
|
|
2021-08-19 11:15:52 -05:00
|
|
|
rename-pie-text-and-data-sections: $(WOLFSSL_OBJ_TARGETS)
|
|
|
|
|
|
|
|
|
|
ifndef NM
|
|
|
|
|
NM := nm
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
ifndef OBJCOPY
|
|
|
|
|
OBJCOPY := objcopy
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
.PHONY: rename-pie-text-and-data-sections
|
|
|
|
|
rename-pie-text-and-data-sections:
|
|
|
|
|
ifneq "$(quiet)" "silent_"
|
|
|
|
|
@echo -n ' Checking wolfCrypt for unresolved symbols and forbidden relocations... '
|
|
|
|
|
endif
|
2025-02-23 15:33:46 -06:00
|
|
|
@cd "$(obj)" || exit $$?
|
|
|
|
|
$(LD) -relocatable -o wolfcrypt_test_link.o $(WOLFCRYPT_PIE_FILES) || exit $$?
|
|
|
|
|
undefined=$$($(NM) --undefined-only wolfcrypt_test_link.o) || exit $$?
|
|
|
|
|
GOT_relocs=$$($(READELF) --relocs --wide wolfcrypt_test_link.o | egrep '^[^ ]+ +[^ ]+ +[^ ]*GOT[^ ]* ') || [ $$? = 1 ] || exit 2
|
|
|
|
|
rm wolfcrypt_test_link.o
|
|
|
|
|
if [ -n "$$undefined" ]; then
|
|
|
|
|
echo "wolfCrypt container has unresolved symbols:" 1>&2
|
|
|
|
|
echo "$$undefined" 1>&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if [ -n "$$GOT_relocs" ]; then
|
|
|
|
|
echo "wolfCrypt container has GOT relocations (non-local function address used as operand?):" 1>&2
|
|
|
|
|
echo "$$GOT_relocs" 1>&2
|
|
|
|
|
exit 1
|
2021-08-19 11:15:52 -05:00
|
|
|
fi
|
|
|
|
|
ifneq "$(quiet)" "silent_"
|
2025-02-23 15:33:46 -06:00
|
|
|
echo 'OK.'
|
2021-08-19 11:15:52 -05:00
|
|
|
endif
|
2025-02-23 15:33:46 -06:00
|
|
|
cd "$(obj)" || exit $$?
|
|
|
|
|
for file in $(WOLFCRYPT_PIE_FILES); do
|
2025-07-09 16:29:04 -05:00
|
|
|
$(OBJCOPY) --rename-section .text=.text.wolfcrypt \
|
|
|
|
|
--rename-section .text.unlikely=.text.wolfcrypt \
|
|
|
|
|
--rename-section .rodata=.rodata.wolfcrypt \
|
|
|
|
|
--rename-section .rodata.str1.1=.rodata.wolfcrypt \
|
|
|
|
|
--rename-section .rodata.str1.8=.rodata.wolfcrypt \
|
2025-07-16 16:46:12 -05:00
|
|
|
--rename-section .rodata.cst16=.rodata.wolfcrypt \
|
2025-07-09 16:29:04 -05:00
|
|
|
--rename-section .data=.data.wolfcrypt \
|
linuxkm/x86_vector_register_glue.c:
* refactor the save_vector_registers_x86() algorithm to depend directly on preempt_count(), and use local_bh_enable() and preempt_disable() directly, to mitigate glitchiness around irq_fpu_usable() and crypto_simd_usable();
* eliminate the WC_FPU_ALREADY_FLAG kludge.
* improve the error and warning messages, and add some additional checks and messages for unexpected states; add VRG_PR_ERR_X and VRG_PR_WARN_X for pr_*_once() semantics on regular builds, but unlimited messages when WOLFSSL_LINUXKM_VERBOSE_DEBUG.
linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c:
* move the spinlock-based implementation of wc_LockMutex() from linuxkm_wc_port.h to module_hooks.c, due to numerous stuboorn direct external symbol references;
* extensively refactor the kernel header #include strategy, keeping many more superfluous headers out of __PIE__ objects, and fixing unavoidable static header functions with grafted __always_inline attributes;
* add version exceptions for RHEL 9.5.
linuxkm/Kbuild:
* on x86 with CONFIG_MITIGATION_{RETPOLINE,RETHUNK}, use inline rethunks rather than none;
* refactor check for "Error: section(s) missed by containerization." using `readelf --sections --syms`, for 100% coverage, more informative error output, and suppression of false positives on printk-related cruft;
configure.ac and linuxkm/lkcapi_sha_glue.c: use LINUXKM_LKCAPI_[DONT_]REGISTER_{SHA,HMAC}_ALL to represent --enable-linuxkm-lkcapi-register=[-]all-{sha,hmac}, which allows alg families (notably SHA1) to be masked out piecemeal;
linuxkm/lkcapi_rsa_glue.c: in linuxkm_test_pkcs1pad_driver(), mitigate unused args when LINUXKM_AKCIPHER_NO_SIGNVERIFY.
2025-07-16 13:09:03 -05:00
|
|
|
--rename-section .data.rel.local=.data.wolfcrypt \
|
2025-07-09 16:29:04 -05:00
|
|
|
--rename-section .bss=.bss.wolfcrypt "$$file" || exit $$?
|
2021-08-19 11:15:52 -05:00
|
|
|
done
|
2025-07-10 00:57:51 -05:00
|
|
|
[ "$(KERNEL_ARCH_X86)" != "yes" ] || \
|
linuxkm/x86_vector_register_glue.c:
* refactor the save_vector_registers_x86() algorithm to depend directly on preempt_count(), and use local_bh_enable() and preempt_disable() directly, to mitigate glitchiness around irq_fpu_usable() and crypto_simd_usable();
* eliminate the WC_FPU_ALREADY_FLAG kludge.
* improve the error and warning messages, and add some additional checks and messages for unexpected states; add VRG_PR_ERR_X and VRG_PR_WARN_X for pr_*_once() semantics on regular builds, but unlimited messages when WOLFSSL_LINUXKM_VERBOSE_DEBUG.
linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c:
* move the spinlock-based implementation of wc_LockMutex() from linuxkm_wc_port.h to module_hooks.c, due to numerous stuboorn direct external symbol references;
* extensively refactor the kernel header #include strategy, keeping many more superfluous headers out of __PIE__ objects, and fixing unavoidable static header functions with grafted __always_inline attributes;
* add version exceptions for RHEL 9.5.
linuxkm/Kbuild:
* on x86 with CONFIG_MITIGATION_{RETPOLINE,RETHUNK}, use inline rethunks rather than none;
* refactor check for "Error: section(s) missed by containerization." using `readelf --sections --syms`, for 100% coverage, more informative error output, and suppression of false positives on printk-related cruft;
configure.ac and linuxkm/lkcapi_sha_glue.c: use LINUXKM_LKCAPI_[DONT_]REGISTER_{SHA,HMAC}_ALL to represent --enable-linuxkm-lkcapi-register=[-]all-{sha,hmac}, which allows alg families (notably SHA1) to be masked out piecemeal;
linuxkm/lkcapi_rsa_glue.c: in linuxkm_test_pkcs1pad_driver(), mitigate unused args when LINUXKM_AKCIPHER_NO_SIGNVERIFY.
2025-07-16 13:09:03 -05:00
|
|
|
{ $(READELF) --sections --syms --wide $(WOLFCRYPT_PIE_FILES) | \
|
|
|
|
|
$(AWK) -v obj="$(obj)" ' \
|
|
|
|
|
/^File:/ { \
|
|
|
|
|
phase = 0; \
|
|
|
|
|
delete wolfcrypt_data_sections; \
|
|
|
|
|
delete wolfcrypt_text_sections; \
|
|
|
|
|
delete other_sections; \
|
|
|
|
|
if (substr($$2, 1, length(obj)) == obj) { \
|
|
|
|
|
curfile = substr($$2, length(obj) + 2); \
|
|
|
|
|
} else { \
|
|
|
|
|
curfile=$$2; \
|
|
|
|
|
} \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
/^Section Headers:/ { \
|
|
|
|
|
phase = 1; \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
/^Symbol table / { \
|
|
|
|
|
phase = 2; \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
{ \
|
|
|
|
|
if (phase == 1) { \
|
|
|
|
|
if (match($$0, "^ *\\[ *([0-9]+)\\] +([^ ]+) ", a)) {\
|
|
|
|
|
switch (a[2]) { \
|
|
|
|
|
case ".text.wolfcrypt": \
|
|
|
|
|
{ \
|
|
|
|
|
wolfcrypt_text_sections[a[1]] = a[2]; \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
case /^\.(data|rodata|bss)\.wolfcrypt$$/: \
|
|
|
|
|
{ \
|
|
|
|
|
wolfcrypt_data_sections[a[1]] = a[2]; \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
default: \
|
|
|
|
|
{ \
|
|
|
|
|
other_sections[a[1]] = a[2]; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
else if (phase == 2) { \
|
|
|
|
|
if ($$4 == "FUNC") { \
|
|
|
|
|
if (! ($$7 in wolfcrypt_text_sections)) { \
|
|
|
|
|
print curfile ": " $$4 " " $$8 " " other_sections[$$7] >"/dev/stderr"; \
|
|
|
|
|
++warnings; \
|
|
|
|
|
} \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
else if ($$4 == "OBJECT") { \
|
|
|
|
|
if (! ($$7 in wolfcrypt_data_sections)) { \
|
|
|
|
|
if ((other_sections[$$7] == ".printk_index") || \
|
|
|
|
|
(($$8 ~ /^_entry\.[0-9]+$$|^kernel_read_file_str$$/) && \
|
|
|
|
|
(other_sections[$$7] == ".data.rel.ro.local"))) \
|
|
|
|
|
next; \
|
|
|
|
|
print curfile ": " $$4 " " $$8 " " other_sections[$$7] >"/dev/stderr"; \
|
|
|
|
|
++warnings; \
|
|
|
|
|
} \
|
|
|
|
|
next; \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
END { \
|
|
|
|
|
if (warnings) { \
|
|
|
|
|
exit(1); \
|
|
|
|
|
} else { \
|
|
|
|
|
exit(0); \
|
|
|
|
|
}}'; } || \
|
|
|
|
|
{ echo 'Error: symbol(s) missed by containerization.' >&2; exit 1; }
|
2021-08-19 11:15:52 -05:00
|
|
|
ifneq "$(quiet)" "silent_"
|
2025-02-23 15:33:46 -06:00
|
|
|
echo ' wolfCrypt .{text,data,rodata} sections containerized to .{text,data,rodata}.wolfcrypt'
|
2021-08-19 11:15:52 -05:00
|
|
|
endif
|
|
|
|
|
|
2024-05-30 11:21:42 -05:00
|
|
|
$(obj)/linuxkm/module_exports.c: rename-pie-text-and-data-sections
|
2021-08-19 11:15:52 -05:00
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
2020-08-28 10:32:30 -05:00
|
|
|
# auto-generate the exported symbol list, leveraging the WOLFSSL_API visibility tags.
|
|
|
|
|
# exclude symbols that don't match wc_* or wolf*.
|
2025-07-31 10:37:39 -05:00
|
|
|
$(obj)/linuxkm/module_exports.c: $(src)/module_exports.c.template $(WOLFSSL_OBJ_TARGETS) $(obj)/linuxkm/module_hooks.o
|
2025-02-23 15:33:46 -06:00
|
|
|
@cp $< $@ || exit $$?
|
|
|
|
|
if [[ "$${VERSION}" -gt 6 || ("$${VERSION}" -eq 6 && "$${PATCHLEVEL}" -ge 13) ]]; then
|
|
|
|
|
# use ASCII octal escape to avoid syntax disruption in the awk script.
|
|
|
|
|
ns='\042WOLFSSL\042'
|
|
|
|
|
else
|
|
|
|
|
ns='WOLFSSL'
|
|
|
|
|
fi
|
2025-07-31 10:37:39 -05:00
|
|
|
$(READELF) --symbols --wide $(filter %.o,$^) |
|
2025-02-23 15:33:46 -06:00
|
|
|
$(AWK) '/^ *[0-9]+: / {
|
|
|
|
|
if ($$8 !~ /^(wc_|wolf|WOLF|TLSX_)/){next;}
|
|
|
|
|
if (($$4 == "FUNC") && ($$5 == "GLOBAL") && ($$6 == "DEFAULT")) {
|
|
|
|
|
print "EXPORT_SYMBOL_NS_GPL(" $$8 ", '"$$ns"');";
|
|
|
|
|
}
|
|
|
|
|
}' >> $@ || exit $$?
|
|
|
|
|
echo -e "#ifndef NO_CRYPT_TEST\nEXPORT_SYMBOL_NS_GPL(wolfcrypt_test, $${ns});\n#endif" >> $@
|
2020-08-28 10:32:30 -05:00
|
|
|
|
2024-05-30 11:21:42 -05:00
|
|
|
clean-files := linuxkm src wolfcrypt
|