From: Ard Biesheuvel <ardb+git@google.com>
To: linux-efi@vger.kernel.org
Cc: loongarch@lists.linux.dev, Ard Biesheuvel <ardb@kernel.org>,
Dmitry Antipov <dmantipov@yandex.ru>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>
Subject: [PATCH 2/3] efi/zboot: Eliminate unused code from the zboot executable
Date: Thu, 26 Nov 2026 16:50:20 +0100 [thread overview]
Message-ID: <20261126155017.2401147-7-ardb+git@google.com> (raw)
In-Reply-To: <20261126155017.2401147-5-ardb+git@google.com>
From: Ard Biesheuvel <ardb@kernel.org>
Wire up -ffunction-sections and --gc-sections so that unused functions
are dropped from the build. This saves some space, but more importantly,
will allow us to get rid of library routines that are never called
(64-bit shift on 32-bit, clz/ctz on RISC-V)
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/Makefile | 2 ++
drivers/firmware/efi/libstub/Makefile.zboot | 3 ++-
drivers/firmware/efi/libstub/zboot.lds | 4 ++--
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index ba6c9e763862..20b5b77956d1 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -34,6 +34,8 @@ cflags-$(CONFIG_LOONGARCH) += -fpie
cflags-$(CONFIG_EFI_PARAMS_FROM_FDT) += -I$(srctree)/scripts/dtc/libfdt
+cflags-$(CONFIG_EFI_ZBOOT) += -ffunction-sections
+
KBUILD_CFLAGS := $(subst $(CC_FLAGS_FTRACE),,$(cflags-y)) \
-Os -DDISABLE_BRANCH_PROFILING \
-include $(srctree)/include/linux/hidden.h \
diff --git a/drivers/firmware/efi/libstub/Makefile.zboot b/drivers/firmware/efi/libstub/Makefile.zboot
index 52baacf3e9d9..3b827e4b571d 100644
--- a/drivers/firmware/efi/libstub/Makefile.zboot
+++ b/drivers/firmware/efi/libstub/Makefile.zboot
@@ -50,7 +50,8 @@ endif
ZBOOT_DEPS := $(obj)/zboot-header.o $(objtree)/drivers/firmware/efi/libstub/lib.a
-LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds
+LDFLAGS_vmlinuz.efi.elf := -T $(srctree)/drivers/firmware/efi/libstub/zboot.lds \
+ --gc-sections
$(obj)/vmlinuz.efi.elf: $(obj)/vmlinuz.o $(ZBOOT_DEPS) FORCE
$(call if_changed,ld)
diff --git a/drivers/firmware/efi/libstub/zboot.lds b/drivers/firmware/efi/libstub/zboot.lds
index a785c0123749..f3d4342c8a08 100644
--- a/drivers/firmware/efi/libstub/zboot.lds
+++ b/drivers/firmware/efi/libstub/zboot.lds
@@ -16,7 +16,7 @@ SECTIONS
.rodata : ALIGN(8) {
__efistub__gzdata_start = .;
- *(.gzdata)
+ KEEP(*(.gzdata))
__efistub_payload_size = . - 4;
__efistub__gzdata_end = .;
*(.rodata* .init.rodata* .srodata*)
@@ -31,7 +31,7 @@ SECTIONS
.sbat : ALIGN(4096) {
_sbat = .;
- *(.sbat)
+ KEEP(*(.sbat))
_esbat = ALIGN(4096);
. = _esbat;
}
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-26 15:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 15:50 [PATCH 0/3] efi/libstub: Fix library dependencies Ard Biesheuvel
2026-11-26 15:50 ` [PATCH 1/3] efi/libstub: loongarch: Provide 64-bit integer shift helpers for 32-bit Ard Biesheuvel
2026-11-26 15:50 ` Ard Biesheuvel [this message]
2026-11-26 15:50 ` [PATCH 3/3] efi/libstub: Provide library helpers only where needed Ard Biesheuvel
2026-11-26 16:22 ` Dmitry Antipov
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=20261126155017.2401147-7-ardb+git@google.com \
--to=ardb+git@google.com \
--cc=ardb@kernel.org \
--cc=chenhuacai@kernel.org \
--cc=dmantipov@yandex.ru \
--cc=kernel@xen0n.name \
--cc=linux-efi@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
/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