mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yabin Cui <yabinc@google.com>
To: Nathan Chancellor <nathan@kernel.org>, Nicolas Schier <nsc@kernel.org>
Cc: Rong Xu <xur@google.com>, Han Shen <shenhan@google.com>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	linux-kbuild@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Yabin Cui <yabinc@google.com>
Subject: [PATCH] kbuild: modinst: Strip .llvm_bb_addr_map on INSTALL_MOD_STRIP=1
Date: Tue,  1 Dec 2026 23:02:28 +0000	[thread overview]
Message-ID: <20261201230228.579036-1-yabinc@google.com> (raw)

When CONFIG_PROPELLER_CLANG is enabled without
CLANG_PROPELLER_PROFILE_PREFIX, Clang and LLD emit non-SHF_ALLOC
.llvm_bb_addr_map metadata sections (along with .rela.llvm_bb_addr_map
relocation sections and, on arm64, associated $d mapping symbols in
.symtab) into loadable .ko modules.

These sections must remain in the unstripped build-tree .ko files so
offline tools such as llvm-propeller can generate profiles from them,
but they are unused at runtime and inflate installed modules when
INSTALL_MOD_STRIP=1 is passed to modules_install because --strip-debug
only removes standard debug sections. For example, across 405 stripped
arm64 modules in a 6.18 kernel build, leaving .llvm_bb_addr_map, its
relocations, and associated $d mapping symbols behind adds ~4.2 MB
(~5.7%) uncompressed.

Append --remove-section=.llvm_bb_addr_map to the default strip options
in scripts/Makefile.modinst when INSTALL_MOD_STRIP=1 and
CONFIG_PROPELLER_CLANG is enabled. Stripping inside cmd_strip runs
before cmd_sign and module compression, preserving appended module
signatures and compressed outputs while leaving custom
INSTALL_MOD_STRIP values unchanged.

Both llvm-strip and GNU strip support --remove-section=<name>, remove
all .llvm_bb_addr_map sections along with their .rela.llvm_bb_addr_map
relocations and associated symbol table entries, and exit cleanly
without warnings when .llvm_bb_addr_map is absent (for example, when
building with CLANG_PROPELLER_PROFILE_PREFIX).

Update the INSTALL_MOD_STRIP descriptions in scripts/Makefile.modinst,
Documentation/kbuild/kbuild.rst, and Documentation/kbuild/makefiles.rst
accordingly.

Verified with out-of-tree LLVM=1 builds and modules_install on x86_64
(both llvm-strip and GNU strip 2.47) and arm64 (non-LTO and ThinLTO)
with CONFIG_DEBUG_INFO=y and CONFIG_MODULE_SIG_ALL=y:
- Unstripped build-tree .ko files retain .debug_*, .llvm_bb_addr_map,
  and .rela.llvm_bb_addr_map.
- Installed .ko files with INSTALL_MOD_STRIP=1 and
  CONFIG_PROPELLER_CLANG=y strip all of those sections (and associated
  arm64 $d symbols) while keeping valid PKCS#7 appended signatures
  (unsigned prime_numbers.ko shrinks from 8384 to 7608 bytes on x86_64
  and from 9168 to 8376 bytes on arm64, matching CONFIG_PROPELLER_CLANG=n
  installed sizes).
- CONFIG_PROPELLER_CLANG=n passes only --strip-debug, and custom
  INSTALL_MOD_STRIP=--strip-unneeded overrides the defaults.

The patch, documentation updates, changelog, and build/strip
verification were prepared with assistance from Gemini based on the
problem description and proposed fix.

Fixes: d5dc95836147 ("kbuild: Add Propeller configuration for kernel build")
Signed-off-by: Yabin Cui <yabinc@google.com>
---
 Documentation/kbuild/kbuild.rst    | 6 ++++--
 Documentation/kbuild/makefiles.rst | 7 ++++---
 scripts/Makefile.modinst           | 8 ++++++--
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/Documentation/kbuild/kbuild.rst b/Documentation/kbuild/kbuild.rst
index e71a692a559a..6fd22b0af069 100644
--- a/Documentation/kbuild/kbuild.rst
+++ b/Documentation/kbuild/kbuild.rst
@@ -270,8 +270,10 @@ INSTALL_MOD_STRIP
 -----------------
 INSTALL_MOD_STRIP, if defined, will cause modules to be
 stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
-the default option --strip-debug will be used.  Otherwise,
-INSTALL_MOD_STRIP value will be used as the options to the strip command.
+the default option --strip-debug will be used (along with
+--remove-section=.llvm_bb_addr_map when CONFIG_PROPELLER_CLANG is
+enabled).  Otherwise, INSTALL_MOD_STRIP value will be used as the
+options to the strip command.
 
 INSTALL_HDR_PATH
 ----------------
diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst
index 535d30eef59a..69c8a8da6544 100644
--- a/Documentation/kbuild/makefiles.rst
+++ b/Documentation/kbuild/makefiles.rst
@@ -1686,9 +1686,10 @@ INSTALL_MOD_PATH, MODLIB
 INSTALL_MOD_STRIP
   If this variable is specified, it will cause modules to be stripped
   after they are installed.  If INSTALL_MOD_STRIP is "1", then the
-  default option --strip-debug will be used.  Otherwise, the
-  INSTALL_MOD_STRIP value will be used as the option(s) to the strip
-  command.
+  default option --strip-debug will be used (along with
+  --remove-section=.llvm_bb_addr_map when CONFIG_PROPELLER_CLANG is
+  enabled).  Otherwise, the INSTALL_MOD_STRIP value will be used as
+  the option(s) to the strip command.
 
 INSTALL_DTBS_PATH
   This variable specifies a prefix for relocations required by build
diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
index 9ba45e5b32b1..1cef4b4485cd 100644
--- a/scripts/Makefile.modinst
+++ b/scripts/Makefile.modinst
@@ -75,12 +75,16 @@ quiet_cmd_install = INSTALL $@
 #
 # INSTALL_MOD_STRIP, if defined, will cause modules to be stripped after they
 # are installed. If INSTALL_MOD_STRIP is '1', then the default option
-# --strip-debug will be used. Otherwise, INSTALL_MOD_STRIP value will be used
-# as the options to the strip command.
+# --strip-debug will be used (along with --remove-section=.llvm_bb_addr_map
+# when CONFIG_PROPELLER_CLANG is enabled). Otherwise, INSTALL_MOD_STRIP value
+# will be used as the options to the strip command.
 ifdef INSTALL_MOD_STRIP
 
 ifeq ($(INSTALL_MOD_STRIP),1)
 strip-option := --strip-debug
+ifdef CONFIG_PROPELLER_CLANG
+strip-option += --remove-section=.llvm_bb_addr_map
+endif
 else
 strip-option := $(INSTALL_MOD_STRIP)
 endif

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.56.1.911.g883d8bcb20-goog


                 reply	other threads:[~2026-12-01 23:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201230228.579036-1-yabinc@google.com \
    --to=yabinc@google.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=nsc@kernel.org \
    --cc=shenhan@google.com \
    --cc=xur@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®