From 05bca8b0ee12c795e730acc92058d72f423ffacb Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Fri, 28 Aug 2020 17:25:25 -0500 Subject: [PATCH] when BUILD_LINUXKM, suppress building the library; rename $KROOT/$KARCH to $KERNEL_ROOT/$KERNEL_ARCH; remove SIMD enablement from linuxkm CFLAGS; add linuxkm support for -DKERNEL_OPT=x. --- Makefile.am | 2 +- configure.ac | 21 ++++++++++++--------- linuxkm/Makefile | 28 +++++++++++++++++++--------- m4/ax_linuxkm.m4 | 18 +++++++++--------- src/include.am | 2 ++ 5 files changed, 43 insertions(+), 28 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7ac5a4d6c..d8225d167 100644 --- a/Makefile.am +++ b/Makefile.am @@ -198,7 +198,7 @@ endif include scripts/include.am if BUILD_LINUXKM -export KROOT KARCH AM_CFLAGS CFLAGS AM_CCASFLAGS CCASFLAGS src_libwolfssl_la_OBJECTS ENABLED_CRYPT_TESTS +export KERNEL_ROOT KERNEL_ARCH KERNEL_OPT AM_CFLAGS CFLAGS AM_CCASFLAGS CCASFLAGS src_libwolfssl_la_OBJECTS ENABLED_CRYPT_TESTS SUBDIRS = linuxkm endif diff --git a/configure.ac b/configure.ac index e93ffd99a..a62b04e12 100644 --- a/configure.ac +++ b/configure.ac @@ -3361,20 +3361,22 @@ then AC_PATH_DEFAULT_KERNEL_SOURCE AC_ARG_WITH([linux-source], [AS_HELP_STRING([--with-linux-source=PATH],[PATH to root of Linux kernel build tree])], - [KROOT=$withval], - [KROOT=$DEFAULT_KROOT]) - AC_SUBST([KROOT]) + [KERNEL_ROOT=$withval], + [KERNEL_ROOT=$DEFAULT_KERNEL_ROOT]) + AC_SUBST([KERNEL_ROOT]) AC_DEFAULT_KERNEL_ARCH AC_ARG_WITH([linux-arch], [AS_HELP_STRING([--with-linux-arch=arch],[built arch (SRCARCH) of Linux kernel build tree])], - [KARCH=$withval], - [KARCH=$DEFAULT_KARCH]) - AC_SUBST([KARCH]) + [KERNEL_ARCH=$withval], + [KERNEL_ARCH=$DEFAULT_KERNEL_ARCH]) + AC_SUBST([KERNEL_ARCH]) - if test -z "${KROOT}"; then + if test -z "${KERNEL_ROOT}"; then AC_MSG_ERROR([Linux kernel source root not found -- supply with --with-linux-source=PATH.]) fi + + ENABLED_NO_LIBRARY=yes fi @@ -5498,6 +5500,7 @@ AM_CONDITIONAL([BUILD_DES3],[test "x$ENABLED_DES3" = "xyes" || test "x$ENABLED_U AM_CONDITIONAL([BUILD_PKCS7],[test "x$ENABLED_PKCS7" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"]) AM_CONDITIONAL([BUILD_HASHFLAGS],[test "x$ENABLED_HASHFLAGS" = "xyes"]) AM_CONDITIONAL([BUILD_LINUXKM],[test "x$ENABLED_LINUXKM" = "xyes"]) +AM_CONDITIONAL([BUILD_NO_LIBRARY],[test "x$ENABLED_NO_LIBRARY" = "xyes"]) CREATE_HEX_VERSION @@ -5761,8 +5764,8 @@ echo " * Secure Remote Password $ENABLED_SRP" echo " * Small Stack: $ENABLED_SMALL_STACK" echo " * Linux Kernel Module: $ENABLED_LINUXKM" test "$ENABLED_LINUXKM" = "yes" && \ -echo " * Linux Kernel Build Root: $KROOT" && \ -echo " * Linux Kernel Build Arch: $KARCH" +echo " * Linux Kernel Build Root: $KERNEL_ROOT" && \ +echo " * Linux Kernel Build Arch: $KERNEL_ARCH" echo " * valgrind unit tests: $ENABLED_VALGRIND" echo " * LIBZ: $ENABLED_LIBZ" echo " * Examples: $ENABLED_EXAMPLES" diff --git a/linuxkm/Makefile b/linuxkm/Makefile index 43b5c5c2f..5d1bb02a5 100644 --- a/linuxkm/Makefile +++ b/linuxkm/Makefile @@ -1,18 +1,22 @@ +# libwolfssl Linux kernel module Makefile (wraps Kbuild makefile) + +SHELL=/bin/bash + all: libwolfssl.ko .PHONY: libwolfssl.ko ifndef MODULE_TOP -MODULE_TOP=$(CURDIR) + MODULE_TOP=$(CURDIR) endif ifndef SRC_TOP -SRC_TOP=$(shell dirname $(MODULE_TOP)) + SRC_TOP=$(shell dirname $(MODULE_TOP)) endif WOLFSSL_CFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CFLAGS) $(CFLAGS) -Wno-declaration-after-statement -Wno-redundant-decls -ifeq "$(KARCH)" "x86" -WOLFSSL_CFLAGS+=-msse -mmmx -msse2 -mavx -mavx2 +ifdef KERNEL_OPT + WOLFSSL_CFLAGS += $(KERNEL_OPT) endif WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) $(CCASFLAGS) @@ -20,24 +24,30 @@ WOLFSSL_ASFLAGS=-DHAVE_CONFIG_H -I$(SRC_TOP) -DBUILDING_WOLFSSL $(AM_CCASFLAGS) WOLFSSL_OBJ_FILES=$(patsubst %.lo, %.o, $(patsubst src/src_libwolfssl_la-%, src/%, $(patsubst src/libwolfssl_la-%, src/%, $(patsubst wolfcrypt/src/src_libwolfssl_la-%, wolfcrypt/src/%, $(src_libwolfssl_la_OBJECTS))))) ifeq "$(ENABLED_CRYPT_TESTS)" "yes" -WOLFSSL_OBJ_FILES+=wolfcrypt/test/test.o + WOLFSSL_OBJ_FILES+=wolfcrypt/test/test.o else -WOLFSSL_CFLAGS+=-DNO_CRYPT_TEST + WOLFSSL_CFLAGS+=-DNO_CRYPT_TEST endif export WOLFSSL_CFLAGS WOLFSSL_ASFLAGS WOLFSSL_OBJ_FILES libwolfssl.ko: - @if test -z "$(KROOT)"; then echo '$$KROOT is unset' >&2; exit 1; fi + @if test -z "$(KERNEL_ROOT)"; then echo '$$KERNEL_ROOT is unset' >&2; exit 1; fi @if test -z "$(AM_CFLAGS)$(CFLAGS)"; then echo '$$AM_CFLAGS and $$CFLAGS are both unset.' >&2; exit 1; fi @if test -z "$(src_libwolfssl_la_OBJECTS)"; then echo '$$src_libwolfssl_la_OBJECTS is unset.' >&2; exit 1; fi @mkdir -p linuxkm src wolfcrypt/src wolfcrypt/test @if test ! -h $(SRC_TOP)/Kbuild; then ln -s $(MODULE_TOP)/Kbuild $(SRC_TOP)/Kbuild; fi - +make -C $(KROOT) M=$(MODULE_TOP) src=$(SRC_TOP) + +make -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) + @echo Linux kernel module build succeeded. + @echo Module is libwolfssl.ko in $(MODULE_TOP). + +.PHONY: install +install: + @echo Module is libwolfssl.ko in $(MODULE_TOP) .PHONY: clean clean: - +make -C $(KROOT) M=$(MODULE_TOP) src=$(SRC_TOP) clean + +make -C $(KERNEL_ROOT) M=$(MODULE_TOP) src=$(SRC_TOP) clean .PHONY: dist dist: diff --git a/m4/ax_linuxkm.m4 b/m4/ax_linuxkm.m4 index 0605c3d49..a74f4c423 100644 --- a/m4/ax_linuxkm.m4 +++ b/m4/ax_linuxkm.m4 @@ -2,11 +2,11 @@ AC_DEFUN([AC_PATH_DEFAULT_KERNEL_SOURCE], [ AC_MSG_CHECKING([for default kernel build root]) if test -d /lib/modules/`uname -r`/build/.config; then - DEFAULT_KROOT=/lib/modules/`uname -r`/build - AC_MSG_RESULT([$DEFAULT_KROOT]) + DEFAULT_KERNEL_ROOT=/lib/modules/`uname -r`/build + AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT]) elif test -r /usr/src/linux/.config; then - DEFAULT_KROOT=/usr/src/linux - AC_MSG_RESULT([$DEFAULT_KROOT]) + DEFAULT_KERNEL_ROOT=/usr/src/linux + AC_MSG_RESULT([$DEFAULT_KERNEL_ROOT]) else AC_MSG_RESULT([no default configured kernel found]) fi @@ -16,13 +16,13 @@ AC_DEFUN([AC_DEFAULT_KERNEL_ARCH], [ AC_REQUIRE([AC_PROG_AWK]) AC_MSG_CHECKING([for default kernel arch]) -if test -f ${KROOT}/.config; then +if test -f ${KERNEL_ROOT}/.config; then # "# Linux/x86 5.8.1-gentoo Kernel Configuration" - DEFAULT_KARCH=`$AWK '/^# Linux/\ -{split($[]2,arch_fields,"/"); print arch_fields[[2]]; exit(0);}' ${KROOT}/.config` + DEFAULT_KERNEL_ARCH=`$AWK '/^# Linux/\ +{split($[]2,arch_fields,"/"); print arch_fields[[2]]; exit(0);}' ${KERNEL_ROOT}/.config` fi -if test -n "$DEFAULT_KARCH"; then - AC_MSG_RESULT([$DEFAULT_KARCH]) +if test -n "$DEFAULT_KERNEL_ARCH"; then + AC_MSG_RESULT([$DEFAULT_KERNEL_ARCH]) else AC_MSG_RESULT([no default configured kernel arch found]) fi diff --git a/src/include.am b/src/include.am index 506671dca..5948c50fa 100644 --- a/src/include.am +++ b/src/include.am @@ -2,7 +2,9 @@ # included from Top Level Makefile.am # All paths should be given relative to the root +if !BUILD_NO_LIBRARY lib_LTLIBRARIES+= src/libwolfssl.la +endif src_libwolfssl_la_SOURCES = src_libwolfssl_la_LDFLAGS = ${AM_LDFLAGS} -no-undefined -version-info ${WOLFSSL_LIBRARY_VERSION} src_libwolfssl_la_LIBADD = $(LIBM) $(LIB_ADD) $(LIB_STATIC_ADD)