[PATCH 2/3] openssl: allow the user to choose the optimisation level

Rui Salvaterra rsalvaterra at gmail.com
Thu Oct 15 18:35:58 EDT 2020


Besides disabling slower/smaller code paths in OpenSSL itself, selecting
CONFIG_OPENSSL_OPTIMIZE_SPEED=y implied completely ignoring the target
optimisation level and always compiling at -O3. Create a new config option to
allow disabing this behaviour. No changes to the current defaults.

Library sizes (in bytes):

O3, 74kc, OPENSSL_OPTIMIZE_SPEED, OPENSSL_WITH_ASM
2010840 libcrypto.so.1.1
 443848 libssl.so.1.1

O2, 74kc, OPENSSL_OPTIMIZE_SPEED, OPENSSL_WITH_ASM
1865180 libcrypto.so.1.1
 428320 libssl.so.1.1

Os, 74kc, OPENSSL_OPTIMIZE_SPEED, OPENSSL_WITH_ASM
1716068 libcrypto.so.1.1
 398788 libssl.so.1.1

Signed-off-by: Rui Salvaterra <rsalvaterra at gmail.com>
---
 package/libs/openssl/Config.in | 7 +++++++
 package/libs/openssl/Makefile  | 7 +++++--
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/package/libs/openssl/Config.in b/package/libs/openssl/Config.in
index 8be6ee732a..fb46676314 100644
--- a/package/libs/openssl/Config.in
+++ b/package/libs/openssl/Config.in
@@ -13,6 +13,13 @@ config OPENSSL_OPTIMIZE_SPEED
 		increased by 20%-50% (mipsel & x86).
 		AES-GCM is supposed to be 3x faster on x86. YMMV.
 
+config OPENSSL_OVERRIDE_TARGET
+	default y
+	bool "Override target optimization level (force -O3)"
+	depends on OPENSSL_OPTIMIZE_SPEED
+	help
+		Force compiling at -O3 instead of the current target optimization level.
+
 config OPENSSL_WITH_ASM
 	bool
 	default y if !SMALL_FLASH || !arm
diff --git a/package/libs/openssl/Makefile b/package/libs/openssl/Makefile
index 9696748106..f3311567a7 100644
--- a/package/libs/openssl/Makefile
+++ b/package/libs/openssl/Makefile
@@ -38,6 +38,7 @@ PKG_CONFIG_DEPENDS:= \
 	CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK \
 	CONFIG_OPENSSL_NO_DEPRECATED \
 	CONFIG_OPENSSL_OPTIMIZE_SPEED \
+	CONFIG_OPENSSL_OVERRIDE_TARGET \
 	CONFIG_OPENSSL_PREFER_CHACHA_OVER_GCM \
 	CONFIG_OPENSSL_WITH_ARIA \
 	CONFIG_OPENSSL_WITH_ASM \
@@ -254,8 +255,10 @@ ifdef CONFIG_OPENSSL_NO_DEPRECATED
   OPENSSL_OPTIONS += no-deprecated
 endif
 
-ifeq ($(CONFIG_OPENSSL_OPTIMIZE_SPEED),y)
-  TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS)) -O3
+ifdef CONFIG_OPENSSL_OPTIMIZE_SPEED
+  ifdef CONFIG_OPENSSL_OVERRIDE_TARGET
+    TARGET_CFLAGS := $(filter-out -O%,$(TARGET_CFLAGS)) -O3
+  endif
 else
   OPENSSL_OPTIONS += -DOPENSSL_SMALL_FOOTPRINT
 endif
-- 
2.28.0




More information about the openwrt-devel mailing list