From nobody Fri Dec 19 06:02:38 2025 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C8074D8CE for ; Mon, 13 Jan 2025 14:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778756; cv=none; b=H3K3mIGBMBQioX3pdpAzv8fDj3Ug+Dgfy0pPfs060zl7ghZCSvSqUX0Zv0BF9ji+RQYZsGoQ+BlchsOGaUSuzPgz9h+hHVfep7glOyYUFEwvWDu08pkskQe13LoSjHi2AYo0ZUwKQQ78oR0FiJsFYKo3nhPGHZ+rwDz1TP59cvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736778756; c=relaxed/simple; bh=grdeH3i3qZWvVei0BqLpq3JTPfxETbMSVvSfDMFCxHo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=mPgpYd8PGwYwU75bMprwq71fN4nilBSpihMza/I5ftCGUJVqmQs6NY4q1FGSTMLjVkUl7KjEuS9c0XTaKbtDE0OPs2JX9eq+JgYM4njRvn0Wqe7AvRUK7fnF4ZhJ9GgRuygif/pe0D2M2GvpvIL27BiS7OMJMCK6wb+zlV45AlI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=p/4371VP; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="p/4371VP" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso23428735e9.1 for ; Mon, 13 Jan 2025 06:32:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736778753; x=1737383553; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OzIqGGH3vBKieE2zzlwNtC18zjNLUz1ZncrxL4Bmag8=; b=p/4371VPLb5iCGBsOJnOU5Ld/fDlwACGSYNZWfP10PeH2dqWqmkzoJ3cieICNFajN9 3ar1cf53y0bKeqV9kmY207IPtGVX8N47mXAOLdhI4QEz5h4h/03ThT4DZgBo/nwkoEK2 97ViBy0fPHDLteMdYuPKmB9eVz3ADPdYTOOQXQMYwPqno5NiiJRo91w657x4XRavj4Ah XSTBNonYACHaIdqi6eHq6VwEpJnGzCaemDo4vcHb3iiRPEoMwK6MntTzM7FPbWInQxR8 2t5d/M9h7gjsxvfs8SyVSHQ9yg7KtHhI/31pSeKSoB4SVYF+Iu39otUbao07cSaZY9T6 jcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736778753; x=1737383553; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OzIqGGH3vBKieE2zzlwNtC18zjNLUz1ZncrxL4Bmag8=; b=A6p7e5+Y4rtouc2+vA4GGyhTtdkNhs/+roZ01nORkRKKKK3GqbcZlPQAkUThZzsKru OqSPjlBIw+RS5bUukiKAZt/AcE9276fzmnU5jN0BV6s0xoe7J9SRkW7Rl2QPEGIDfINq mML7F1l7DPeJuB2fk9mCybOx3SnTANerzvSADQ149haNNh2i85F0X/48bWnQv9s5cZJG 41t8zW/VLMb6ofgPK8CRsmeLu+tvezP1qyPk3aMtqBeMxXZJS1sus8lR52Jsg43VxT/q bHu7tA9SMmLxjaIlsFPmKb1pkPLwAOencqELXJAwgvDhDMk3W/c1CC3Dm/5poL+mnqoe j3+w== X-Gm-Message-State: AOJu0YzxcBw+NeNL2dm5UYfURzJEQ/lxeQU0kHtHXzGP7Vq4s+EK0lMd XVyzgXsaqdusgCx7QDA4Qu20JaKZf4/JB8pdyW4pm8Ok2FTFsc3zHDxzVcbqyLKuoyhzlQ== X-Google-Smtp-Source: AGHT+IFQeNAamqcGdcN8c7ytefb3W1Z5eHAuyFOJ2VehyPJ1eN/M3OxG5yO9oTpeEg8FqBs7yp+CS2pm X-Received: from wmsp9.prod.google.com ([2002:a05:600c:1d89:b0:436:6f3f:58de]) (user=ardb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:4510:b0:431:54d9:da57 with SMTP id 5b1f17b1804b1-436e26ffb2cmr209267185e9.30.1736778753695; Mon, 13 Jan 2025 06:32:33 -0800 (PST) Date: Mon, 13 Jan 2025 15:32:22 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=5275; i=ardb@kernel.org; h=from:subject; bh=wUg0mP/r/+W1sG3n3TuyOrD53kw2VZ0233ES5hgrKL4=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JIb1V+Ztpk/CP/SZ9zqc43/1juvV8Y8gnGft5h/z/Zkf1X 7qqw+fbUcrCIMbBICumyCIw+++7nacnStU6z5KFmcPKBDKEgYtTACZS5Mnwv1os/c2dXB+v0vZr OzhdA/IkdVh4I+Nn1TtnXxKJuX7MieF/QoNBWOUnw4zvy99c3N1fPbmT8/Ax++0LX7X+2dj0ZEI sCwA= X-Mailer: git-send-email 2.47.1.688.g23fc6f90ad-goog Message-ID: <20250113143222.1868692-2-ardb+git@google.com> Subject: [PATCH v2] kbuild: Strip runtime const RELA sections correctly From: Ard Biesheuvel To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Ard Biesheuvel , Linus Torvalds , Masahiro Yamada , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ard Biesheuvel Due to the fact that runtime const ELF sections are named without a leading period or double underscore, the RSTRIP logic that removes the static RELA sections from vmlinux fails to identify them. This results in a situation like below, where some sections that were supposed to get removed are left behind. [Nr] Name Type Address O= ff Size ES Flg Lk Inf Al [58] runtime_shift_d_hash_shift PROGBITS ffffffff83500f50 2= 900f50 000014 00 A 0 0 1 [59] .relaruntime_shift_d_hash_shift RELA 0000000000000000 5= 5b6f00 000078 18 I 70 58 8 [60] runtime_ptr_dentry_hashtable PROGBITS ffffffff83500f68 2= 900f68 000014 00 A 0 0 1 [61] .relaruntime_ptr_dentry_hashtable RELA 0000000000000000 5= 5b6f78 000078 18 I 70 60 8 [62] runtime_ptr_USER_PTR_MAX PROGBITS ffffffff83500f80 2= 900f80 000238 00 A 0 0 1 [63] .relaruntime_ptr_USER_PTR_MAX RELA 0000000000000000 5= 5b6ff0 000d50 18 I 70 62 8 So tweak the match expression to strip all sections starting with .rel. While at it, consolidate the logic used by RISC-V, s390 and x86 into a single shared Makefile library command. Cc: Linus Torvalds Cc: Masahiro Yamada Cc: linux-riscv@lists.infradead.org Cc: linux-s390@vger.kernel.org Link: https://lore.kernel.org/all/CAHk-=3Dwjk3ynjomNvFN8jf9A1k=3DqSc=3DJFF5= 91W00uXj-qqNUxPQ@mail.gmail.com/ Signed-off-by: Ard Biesheuvel --- v2: add missing include of scripts/Makefile.lib arch/riscv/Makefile.postlink | 10 ++-------- arch/s390/Makefile.postlink | 6 +----- arch/x86/Makefile.postlink | 6 +----- scripts/Makefile.lib | 3 +++ 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/arch/riscv/Makefile.postlink b/arch/riscv/Makefile.postlink index 829b9abc91f6..750d2784f69e 100644 --- a/arch/riscv/Makefile.postlink +++ b/arch/riscv/Makefile.postlink @@ -10,6 +10,7 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib =20 quiet_cmd_relocs_check =3D CHKREL $@ cmd_relocs_check =3D \ @@ -19,13 +20,6 @@ ifdef CONFIG_RELOCATABLE quiet_cmd_cp_vmlinux_relocs =3D CPREL vmlinux.relocs cmd_cp_vmlinux_relocs =3D cp vmlinux vmlinux.relocs =20 -quiet_cmd_relocs_strip =3D STRIPREL $@ -cmd_relocs_strip =3D $(OBJCOPY) --remove-section=3D'.rel.*' \ - --remove-section=3D'.rel__*' \ - --remove-section=3D'.rela.*' \ - --remove-section=3D'.rela__*' $@ -endif - # `@true` prevents complaint when there is nothing to be done =20 vmlinux: FORCE @@ -33,7 +27,7 @@ vmlinux: FORCE ifdef CONFIG_RELOCATABLE $(call if_changed,relocs_check) $(call if_changed,cp_vmlinux_relocs) - $(call if_changed,relocs_strip) + $(call if_changed,strip_relocs) endif =20 clean: diff --git a/arch/s390/Makefile.postlink b/arch/s390/Makefile.postlink index df82f5410769..1ae5478cd6ac 100644 --- a/arch/s390/Makefile.postlink +++ b/arch/s390/Makefile.postlink @@ -11,6 +11,7 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib =20 CMD_RELOCS=3Darch/s390/tools/relocs OUT_RELOCS =3D arch/s390/boot @@ -19,11 +20,6 @@ quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/relocs.S mkdir -p $(OUT_RELOCS); \ $(CMD_RELOCS) $@ > $(OUT_RELOCS)/relocs.S =20 -quiet_cmd_strip_relocs =3D RSTRIP $@ - cmd_strip_relocs =3D \ - $(OBJCOPY) --remove-section=3D'.rel.*' --remove-section=3D'.rel__*' \ - --remove-section=3D'.rela.*' --remove-section=3D'.rela__*' $@ - vmlinux: FORCE $(call cmd,relocs) $(call cmd,strip_relocs) diff --git a/arch/x86/Makefile.postlink b/arch/x86/Makefile.postlink index fef2e977cc7d..8b8a68162c94 100644 --- a/arch/x86/Makefile.postlink +++ b/arch/x86/Makefile.postlink @@ -11,6 +11,7 @@ __archpost: =20 -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.lib =20 CMD_RELOCS =3D arch/x86/tools/relocs OUT_RELOCS =3D arch/x86/boot/compressed @@ -20,11 +21,6 @@ quiet_cmd_relocs =3D RELOCS $(OUT_RELOCS)/$@.relocs $(CMD_RELOCS) $@ > $(OUT_RELOCS)/$@.relocs; \ $(CMD_RELOCS) --abs-relocs $@ =20 -quiet_cmd_strip_relocs =3D RSTRIP $@ - cmd_strip_relocs =3D \ - $(OBJCOPY) --remove-section=3D'.rel.*' --remove-section=3D'.rel__*' \ - --remove-section=3D'.rela.*' --remove-section=3D'.rela__*' $@ - # `@true` prevents complaint when there is nothing to be done =20 vmlinux: FORCE diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 7395200538da..f604f51d23ca 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -374,6 +374,9 @@ quiet_cmd_ar =3D AR $@ quiet_cmd_objcopy =3D OBJCOPY $@ cmd_objcopy =3D $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ =20 +quiet_cmd_strip_relocs =3D RSTRIP $@ +cmd_strip_relocs =3D $(OBJCOPY) --remove-section=3D'.rel*' $@ + # Gzip # ------------------------------------------------------------------------= --- =20 --=20 2.47.1.688.g23fc6f90ad-goog