From patchwork Sun Nov 4 21:33:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Santos X-Patchwork-Id: 992798 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=pobox.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RRQHwvOk"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=pobox.com header.i=@pobox.com header.b="hDjCrcKr"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42p8HQ5gC6zB6Ng for ; Mon, 5 Nov 2018 08:35:30 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Rc9ibyUWVo1Iac9aKYxykSDIMFaUsE3vAoDDAN74JSk=; b=RRQHwvOkL+PMlg bCPEqcYFTfoZJZ8dPD1SutTkSY41iWhcngHPYMi/xzij+G//YLIIly10SUQ8JRgzWOoNbHIcqSc3S nj1tkBWBWc5JDbD8QdPNXHPJDBESJKRAE7n/KMawXmhd5m0HzGtWP9a3M2QDHFyXRMypl+tj+HTq7 6bMfmjnQ9wVipZXLesk/TWFFDONzV0huXggYTrZS0LfGuSyxQhBtcHsJHjQudlKFa3wCewjsmMwOq mOcxyLo2p7VOd7pvWKu8j0S6ey+oHVCA5aw2GurSQ7D2qX0gBidb/cjE+W5pQHdCoks7Xw66cIVLj y4RnG4rj+TFcAS8URxPQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJQ3I-0000Op-9w; Sun, 04 Nov 2018 21:35:24 +0000 Received: from pb-smtp1.pobox.com ([64.147.108.70]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gJQ3E-0000Ne-SH for openwrt-devel@lists.openwrt.org; Sun, 04 Nov 2018 21:35:23 +0000 Received: from pb-smtp1.pobox.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id A44BE114887; Sun, 4 Nov 2018 16:35:08 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=sasl; bh=y70a kXVL/wZvjDERP/lVF4LJpkA=; b=hDjCrcKrsUpy80sqPmZS7juDO2EZBjMjTkZh 8vQjGJ8Ivzf9Z0O7VewrMWwjHK6zm3PXZq91xubyZ6OWHZwhwPyZn7uMC/TdHJud K/y66L5bJQxw+7O1MBrUFGoDlwwewK5xJYynpAD26CjVHYKDFQI5enRJuGF1859n DFyjeRo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:date:message-id:in-reply-to:references; q=dns; s=sasl; b= tpgxp1/KbiDVpSYwHjRHS4d3MRpQYxvpVz0g4fwZi72LNt2Q1gLE7k1aBly7xLXB LlySF6s5JrNVXqzJ+1SYl8499WCgD9dWnVU/gT4khxouhsKbNFnEASiwFIfimOZt Z2Ic7K3hXVYxQmwQfeXAK2zXTJQ/WM+aQL/LthzFcx4= Received: from pb-smtp1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp1.pobox.com (Postfix) with ESMTP id 9CD8A114886; Sun, 4 Nov 2018 16:35:08 -0500 (EST) Received: from love.attlocal.net (unknown [76.215.41.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pb-smtp1.pobox.com (Postfix) with ESMTPSA id B6236114884; Sun, 4 Nov 2018 16:35:06 -0500 (EST) From: Daniel Santos To: openwrt-devel@lists.openwrt.org, Felix Fietkau Date: Sun, 4 Nov 2018 15:33:48 -0600 Message-Id: <20181104213348.22891-2-daniel.santos@pobox.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181104213348.22891-1-daniel.santos@pobox.com> References: <20181027221547.25667-1-daniel.santos@pobox.com> <20181104213348.22891-1-daniel.santos@pobox.com> X-Pobox-Relay-ID: 802AD482-E079-11E8-AB69-063AD72159A7-06139138!pb-smtp1.pobox.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181104_133521_080102_0AACB188 X-CRM114-Status: GOOD ( 17.09 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [64.147.108.70 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain Subject: [OpenWrt-Devel] [PATCH v4 2/2] kernel: rework module stripping, add Kconfig option X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Darbyshire-Bryant , Philip Prindeville MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Add an option to the "Global build settings" menu to choose if and how kernel modules are stripped. Stripping is now performed upon install into staging, leaving modules in the kernel build tree untouched so that they are useful for remote debugging and such. The user will now be allowed to choose to 1.) leave modules unstripped, 2.) strip unneeded symbols and sections, or 3.) strip all -- the later of which exposes access to Felix's hack for removing non-essential module information. Thus, rather than having to go to the kernel_menuconfig to disable it when not desired, it can be disabled simply by selecting either "strip unneeded" or "strip none". The functionality of "strip all" and Felix's patch are logical mates. Although it is concievable that one may want to retain author, parameter descriptions, etc., but also do a strip-all, this can still be done by disabling Felix's patch via kernel_menuconfig. The kernel .config option MODULE_STRIPPED is renamed to MODULE_STRIP_ALL for disabiguation while the options to not strip or only strip-unneeded are not exported to the kernel .config as they are only relevent to the OpenWRT build. Signed-off-by: Daniel Santos --- config/Config-build.in | 29 ++++++++++++++++++++++ include/kernel.mk | 17 +++++++++++-- target/linux/generic/config-4.14 | 1 - target/linux/generic/config-4.9 | 1 - .../linux/generic/hack-4.14/204-module_strip.patch | 22 ++++++++-------- .../linux/generic/hack-4.9/204-module_strip.patch | 24 +++++++++--------- 6 files changed, 67 insertions(+), 27 deletions(-) diff --git a/config/Config-build.in b/config/Config-build.in index a082a5e0e2..72076d0648 100644 --- a/config/Config-build.in +++ b/config/Config-build.in @@ -151,6 +151,35 @@ menu "Global build settings" image. Note that this might make the kernel incompatible with any kernel modules that were not selected at the time the kernel image was created. + choice + prompt "Kernel module stripping" + default KERNEL_MODULE_STRIP_ALL + help + If and how modules should be stripped upon install. Modules + in the Linux build tree remain unchanged. + + config MODULE_STRIP_NONE + bool "strip none" + help + Will install modules exactly as they are built in the + tree, including any debug symbols if enabled in the + Kernel Hacking menuconfig menu. + + config MODULE_STRIP_UNNEEDED + bool "strip unneeded" + help + Strips all unneeded symbols from modules as they are + installed. + + config KERNEL_MODULE_STRIP_ALL + bool "strip all" + help + Further reduces size of kernel modules by stripping + all symbols, including relocations, and removing + customary strings such as author, version, parameter + descriptions, etc. + endchoice + config USE_MKLIBS bool "Strip unnecessary functions from libraries" help diff --git a/include/kernel.mk b/include/kernel.mk index 62a8e99e2d..251ac1c94c 100644 --- a/include/kernel.mk +++ b/include/kernel.mk @@ -122,6 +122,18 @@ ifdef CONFIG_USE_SPARSE KERNEL_MAKEOPTS += C=1 CHECK=$(STAGING_DIR_HOST)/bin/sparse endif +# Define command for copying kernel modules. +ifeq ($(CONFIG_MODULE_STRIP_NONE),y) + MODULE_COPY := $(CP) -L +else + MODULE_COPY = $(KERNEL_CROSS)objcopy + ifeq ($(CONFIG_MODULE_STRIP_UNNEEDED),y) + MODULE_COPY += --strip-unneeded + else # CONFIG_MODULE_STRIP_ALL + MODULE_COPY += --strip-all + endif +endif + PKG_EXTMOD_SUBDIRS ?= . define populate_module_symvers @@ -229,8 +241,9 @@ $(call KernelPackage/$(1)/config) if grep -q "$$$$$$$${mod##$(LINUX_DIR)/}" "$(LINUX_DIR)/modules.builtin"; then \ echo "NOTICE: module '$$$$$$$$mod' is built-in."; \ elif [ -e $$$$$$$$mod ]; then \ - mkdir -p $$(1)/$(MODULES_SUBDIR) ; \ - $(CP) -L $$$$$$$$mod $$(1)/$(MODULES_SUBDIR)/ ; \ + mkdir -p $$(1)/$(MODULES_SUBDIR); \ + mod_name=`basename $$$$$$$$mod`; \ + $(MODULE_COPY) $$$$$$$$mod $$(1)/$(MODULES_SUBDIR)/$$$$$$$$mod_name; \ else \ echo "ERROR: module '$$$$$$$$mod' is missing." >&2; \ exit 1; \ diff --git a/target/linux/generic/config-4.14 b/target/linux/generic/config-4.14 index 97207cf2eb..8a12b422cb 100644 --- a/target/linux/generic/config-4.14 +++ b/target/linux/generic/config-4.14 @@ -2674,7 +2674,6 @@ CONFIG_MODULES=y # CONFIG_MODULE_FORCE_UNLOAD is not set # CONFIG_MODULE_SIG is not set # CONFIG_MODULE_SRCVERSION_ALL is not set -CONFIG_MODULE_STRIPPED=y CONFIG_MODULE_UNLOAD=y # CONFIG_MODVERSIONS is not set # CONFIG_MOST is not set diff --git a/target/linux/generic/config-4.9 b/target/linux/generic/config-4.9 index 979028f04a..18cf72e75e 100644 --- a/target/linux/generic/config-4.9 +++ b/target/linux/generic/config-4.9 @@ -2502,7 +2502,6 @@ CONFIG_MODULES=y # CONFIG_MODULE_FORCE_UNLOAD is not set # CONFIG_MODULE_SIG is not set # CONFIG_MODULE_SRCVERSION_ALL is not set -CONFIG_MODULE_STRIPPED=y CONFIG_MODULE_UNLOAD=y # CONFIG_MODVERSIONS is not set # CONFIG_MOST is not set diff --git a/target/linux/generic/hack-4.14/204-module_strip.patch b/target/linux/generic/hack-4.14/204-module_strip.patch index db65062fcf..6ddc6a7312 100644 --- a/target/linux/generic/hack-4.14/204-module_strip.patch +++ b/target/linux/generic/hack-4.14/204-module_strip.patch @@ -34,7 +34,7 @@ Signed-off-by: Felix Fietkau +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description) -#ifdef MODULE -+#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED) ++#if defined(MODULE) && !defined(CONFIG_MODULE_STRIP_ALL) /* Creates an alias so file2alias.c can find device table. */ #define MODULE_DEVICE_TABLE(type, name) \ extern typeof(name) __mod_##type##__##name##_device_table \ @@ -44,7 +44,7 @@ Signed-off-by: Felix Fietkau #if defined(MODULE) || !defined(CONFIG_SYSFS) -#define MODULE_VERSION(_version) MODULE_INFO(version, _version) +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version) -+#elif defined(CONFIG_MODULE_STRIPPED) ++#elif defined(CONFIG_MODULE_STRIP_ALL) +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version) #else #define MODULE_VERSION(_version) \ @@ -68,7 +68,7 @@ Signed-off-by: Felix Fietkau +#define __MODULE_INFO_DISABLED(name) \ + struct __UNIQUE_ID(name) {} + -+#ifdef CONFIG_MODULE_STRIPPED ++#ifdef CONFIG_MODULE_STRIP_ALL +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name) +#else +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info) @@ -102,7 +102,7 @@ Signed-off-by: Felix Fietkau If unsure, or if you need to build out-of-tree modules, say N. -+config MODULE_STRIPPED ++config MODULE_STRIP_ALL + bool "Reduce module size" + depends on MODULES + help @@ -121,7 +121,7 @@ Signed-off-by: Felix Fietkau - const char *modmagic = get_modinfo(info, "vermagic"); int err; -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL + const char *modmagic = get_modinfo(info, "vermagic"); + if (flags & MODULE_INIT_IGNORE_VERMAGIC) @@ -141,7 +141,7 @@ Signed-off-by: Felix Fietkau symname = remove_dot(info.strtab + sym->st_name); handle_modversions(mod, &info, sym, symname); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL handle_moddevtable(mod, &info, sym, symname); +#endif } @@ -151,7 +151,7 @@ Signed-off-by: Felix Fietkau buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "\n"); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); buf_printf(b, "MODULE_INFO(name, KBUILD_MODNAME);\n"); +#endif @@ -162,7 +162,7 @@ Signed-off-by: Felix Fietkau static void add_intree_flag(struct buffer *b, int is_intree) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL if (is_intree) buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); +#endif @@ -173,7 +173,7 @@ Signed-off-by: Felix Fietkau static void add_staging_flag(struct buffer *b, const char *name) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL static const char *staging_dir = "drivers/staging"; if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) @@ -186,7 +186,7 @@ Signed-off-by: Felix Fietkau static void add_srcversion(struct buffer *b, struct module *mod) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL if (mod->srcversion[0]) { buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", @@ -200,7 +200,7 @@ Signed-off-by: Felix Fietkau add_staging_flag(&buf, mod->name); err |= add_versions(&buf, mod); add_depends(&buf, mod, modules); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL add_moddevtable(&buf, mod); +#endif add_srcversion(&buf, mod); diff --git a/target/linux/generic/hack-4.9/204-module_strip.patch b/target/linux/generic/hack-4.9/204-module_strip.patch index c6484a8f92..68707422a3 100644 --- a/target/linux/generic/hack-4.9/204-module_strip.patch +++ b/target/linux/generic/hack-4.9/204-module_strip.patch @@ -34,7 +34,7 @@ Signed-off-by: Felix Fietkau +#define MODULE_DESCRIPTION(_description) MODULE_INFO_STRIP(description, _description) -#ifdef MODULE -+#if defined(MODULE) && !defined(CONFIG_MODULE_STRIPPED) ++#if defined(MODULE) && !defined(CONFIG_MODULE_STRIP_ALL) /* Creates an alias so file2alias.c can find device table. */ #define MODULE_DEVICE_TABLE(type, name) \ extern const typeof(name) __mod_##type##__##name##_device_table \ @@ -44,7 +44,7 @@ Signed-off-by: Felix Fietkau #if defined(MODULE) || !defined(CONFIG_SYSFS) -#define MODULE_VERSION(_version) MODULE_INFO(version, _version) +#define MODULE_VERSION(_version) MODULE_INFO_STRIP(version, _version) -+#elif defined(CONFIG_MODULE_STRIPPED) ++#elif defined(CONFIG_MODULE_STRIP_ALL) +#define MODULE_VERSION(_version) __MODULE_INFO_DISABLED(version) #else #define MODULE_VERSION(_version) \ @@ -68,7 +68,7 @@ Signed-off-by: Felix Fietkau +#define __MODULE_INFO_DISABLED(name) \ + struct __UNIQUE_ID(name) {} + -+#ifdef CONFIG_MODULE_STRIPPED ++#ifdef CONFIG_MODULE_STRIP_ALL +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO_DISABLED(name) +#else +#define __MODULE_INFO_STRIP(tag, name, info) __MODULE_INFO(tag, name, info) @@ -102,7 +102,7 @@ Signed-off-by: Felix Fietkau If unsure, or if you need to build out-of-tree modules, say N. -+config MODULE_STRIPPED ++config MODULE_STRIP_ALL + bool "Reduce module size" + depends on MODULES + help @@ -121,7 +121,7 @@ Signed-off-by: Felix Fietkau - const char *modmagic = get_modinfo(info, "vermagic"); int err; -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL + const char *modmagic = get_modinfo(info, "vermagic"); + if (flags & MODULE_INIT_IGNORE_VERMAGIC) @@ -141,7 +141,7 @@ Signed-off-by: Felix Fietkau symname = remove_dot(info.strtab + sym->st_name); handle_modversions(mod, &info, sym, symname); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL handle_moddevtable(mod, &info, sym, symname); +#endif } @@ -151,7 +151,7 @@ Signed-off-by: Felix Fietkau buf_printf(b, "#include \n"); buf_printf(b, "#include \n"); buf_printf(b, "\n"); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL buf_printf(b, "MODULE_INFO(vermagic, VERMAGIC_STRING);\n"); +#endif buf_printf(b, "\n"); @@ -161,7 +161,7 @@ Signed-off-by: Felix Fietkau static void add_intree_flag(struct buffer *b, int is_intree) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL if (is_intree) buf_printf(b, "\nMODULE_INFO(intree, \"Y\");\n"); +#endif @@ -170,7 +170,7 @@ Signed-off-by: Felix Fietkau /* Cannot check for assembler */ static void add_retpoline(struct buffer *b) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL buf_printf(b, "\n#ifdef RETPOLINE\n"); buf_printf(b, "MODULE_INFO(retpoline, \"Y\");\n"); buf_printf(b, "#endif\n"); @@ -179,7 +179,7 @@ Signed-off-by: Felix Fietkau static void add_staging_flag(struct buffer *b, const char *name) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL static const char *staging_dir = "drivers/staging"; if (strncmp(staging_dir, name, strlen(staging_dir)) == 0) @@ -192,7 +192,7 @@ Signed-off-by: Felix Fietkau static void add_srcversion(struct buffer *b, struct module *mod) { -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL if (mod->srcversion[0]) { buf_printf(b, "\n"); buf_printf(b, "MODULE_INFO(srcversion, \"%s\");\n", @@ -206,7 +206,7 @@ Signed-off-by: Felix Fietkau add_staging_flag(&buf, mod->name); err |= add_versions(&buf, mod); add_depends(&buf, mod, modules); -+#ifndef CONFIG_MODULE_STRIPPED ++#ifndef CONFIG_MODULE_STRIP_ALL add_moddevtable(&buf, mod); +#endif add_srcversion(&buf, mod);