From: "liuyuntao (F)" <liuyuntao12@huawei.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>, <arnd@arndb.de>,
<geert@linux-m68k.org>, <linux@armlinux.org.uk>, <afd@ti.com>,
<akpm@linux-foundation.org>, <kirill.shutemov@linux.intel.com>,
<geert+renesas@glider.be>, <corbet@lwn.net>, <rppt@kernel.org>,
<robh@kernel.org>, <tglx@linutronix.de>,
<linus.walleij@linaro.org>, <maskray@google.com>
Subject: Re: [PATCH-next v3] arm32: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
Date: Fri, 15 Mar 2024 18:23:47 +0800 [thread overview]
Message-ID: <d7a1996f-f558-4cea-b8ca-eb071d02c6d4@huawei.com> (raw)
In-Reply-To: <CAMj1kXH+FaddHV5--kqB_wVgw_M682MvchPB1BoCuDuA6vVyvg@mail.gmail.com>
On 2024/3/15 16:06, Ard Biesheuvel wrote:
> On Fri, 15 Mar 2024 at 07:37, Yuntao Liu <liuyuntao12@huawei.com> wrote:
>>
>> The current arm32 architecture does not yet support the
>> HAVE_LD_DEAD_CODE_DATA_ELIMINATION feature. arm32 is widely used in
>> embedded scenarios, and enabling this feature would be beneficial for
>> reducing the size of the kernel image.
>>
>> In order to make this work, we keep the necessary tables by annotating
>> them with KEEP, also it requires further changes to linker script to KEEP
>> some tables and wildcard compiler generated sections into the right place.
>> When using ld.lld for linking, the KEEP keyword is not recognized within
>> the OVERLAY command, Ard proposed a concise method to solve this problem.
>>
>> It boots normally with defconfig, vexpress_defconfig and tinyconfig.
>> The size comparison of zImage is as follows:
>> defconfig vexpress_defconfig tinyconfig
>> 5137712 5138024 424192 no dce
>> 5032560 4997824 298384 dce
>> 2.0% 2.7% 29.7% shrink
>>
>> When using smaller config file, there is a significant reduction in the
>> size of the zImage.
>>
>> We also tested this patch on a commercially available single-board
>> computer, and the comparison is as follows:
>> a15eb_config
>> 2161384 no dce
>> 2092240 dce
>> 3.2% shrink
>>
>> The zImage size has been reduced by approximately 3.2%, which is 70KB on
>> 2.1M.
>>
>> Signed-off-by: Yuntao Liu <liuyuntao12@huawei.com>
>> Tested-by: Arnd Bergmann <arnd@arndb.de>
>> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
>> ---
>> v3:
>> - A better way to KEEP .vectors section for ld.lld linking.
>>
>> v2:
>> - Support config XIP_KERNEL.
>> - Support LLVM compilation.
>> - https://lore.kernel.org/all/20240307151231.654025-1-liuyuntao12@huawei.com/
>>
>> v1: https://lore.kernel.org/all/20240220081527.23408-1-liuyuntao12@huawei.com/
>> ---
>> arch/arm/Kconfig | 1 +
>> arch/arm/boot/compressed/vmlinux.lds.S | 6 +++++-
>> arch/arm/include/asm/vmlinux.lds.h | 2 +-
>> arch/arm/kernel/entry-armv.S | 3 +++
>> arch/arm/kernel/vmlinux-xip.lds.S | 4 ++--
>> arch/arm/kernel/vmlinux.lds.S | 6 +++---
>> 6 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
>> index b14aed3a17ab..45f25f6e7a62 100644
>> --- a/arch/arm/Kconfig
>> +++ b/arch/arm/Kconfig
>> @@ -114,6 +114,7 @@ config ARM
>> select HAVE_KERNEL_XZ
>> select HAVE_KPROBES if !XIP_KERNEL && !CPU_ENDIAN_BE32 && !CPU_V7M
>> select HAVE_KRETPROBES if HAVE_KPROBES
>> + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
>> select HAVE_MOD_ARCH_SPECIFIC
>> select HAVE_NMI
>> select HAVE_OPTPROBES if !THUMB2_KERNEL
>> diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S
>> index 3fcb3e62dc56..affd30714f01 100644
>> --- a/arch/arm/boot/compressed/vmlinux.lds.S
>> +++ b/arch/arm/boot/compressed/vmlinux.lds.S
>> @@ -89,7 +89,11 @@ SECTIONS
>> * The EFI stub always executes from RAM, and runs strictly before the
>> * decompressor, so we can make an exception for its r/w data, and keep it
>> */
>> +#ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
>> + *(.data.* .bss.*)
>> +#else
>> *(.data.efistub .bss.efistub)
>> +#endif
>> __pecoff_data_end = .;
>>
>
> This is still not right.
>
> Can you just add -fno-data-sections to cflags-$(CONFIG_ARM) in
> drivers/firmware/efi/libstub/Makefile?
>
I rebuild kernel in such way:
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -28,6 +28,7 @@ cflags-$(CONFIG_ARM) += -DEFI_HAVE_STRLEN
-DEFI_HAVE_STRNLEN \
-DEFI_HAVE_MEMCHR -DEFI_HAVE_STRRCHR \
-DEFI_HAVE_STRCMP -fno-builtin -fpic \
$(call cc-option,-mno-single-pic-base)
+cflags-$(CONFIG_ARM) += -fno-data-sections
cflags-$(CONFIG_RISCV) += -fpic -DNO_ALTERNATIVE -mno-relax
cflags-$(CONFIG_LOONGARCH) += -fpi
but I am still encountering this error:
arm-linux-gnueabi-ld: warning: orphan section `.data.efi_loglevel' from
`drivers/firmware/efi/libstub/printk.stub.o' being placed in section
`.data.efi_loglevel'
arm-linux-gnueabi-ld: warning: orphan section `.data.screen_info_guid'
from `drivers/firmware/efi/libstub/screen_info.stub.o' being placed in
section `.data.screen_info_guid'
arm-linux-gnueabi-ld: warning: orphan section `.data.cpu_state_guid'
from `drivers/firmware/efi/libstub/arm32-stub.stub.o' being placed in
section `.data.cpu_state_guid'
arm-linux-gnueabi-ld: warning: orphan section `.data.efi_nokaslr' from
`drivers/firmware/efi/libstub/efi-stub-helper.stub.o' being placed in
section `.data.efi_nokaslr'
arm-linux-gnueabi-ld: error: zImage file size is incorrect
I am puzzled because I could not find any option named
-fno-data-sections for GCC.
next prev parent reply other threads:[~2024-03-15 10:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 6:31 Yuntao Liu
2024-03-15 8:06 ` Ard Biesheuvel
2024-03-15 10:23 ` liuyuntao (F) [this message]
2024-03-15 10:46 ` Ard Biesheuvel
2024-03-15 11:48 ` liuyuntao (F)
2024-03-15 11:51 ` Arnd Bergmann
2024-03-15 12:10 ` liuyuntao (F)
2024-03-15 12:13 ` Ard Biesheuvel
2024-03-15 12:21 ` liuyuntao (F)
2024-03-15 12:46 ` Ard Biesheuvel
2024-03-15 12:51 ` liuyuntao (F)
2024-03-15 12:58 ` Ard Biesheuvel
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=d7a1996f-f558-4cea-b8ca-eb071d02c6d4@huawei.com \
--to=liuyuntao12@huawei.com \
--cc=afd@ti.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=corbet@lwn.net \
--cc=geert+renesas@glider.be \
--cc=geert@linux-m68k.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=maskray@google.com \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=tglx@linutronix.de \
/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®