lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93960845-2af5-ac2b-c562-d8c89ad961a4@huawei.com>
Date:   Wed, 24 May 2023 19:04:23 +0800
From:   Kefeng Wang <wangkefeng.wang@...wei.com>
To:     Jisheng Zhang <jszhang@...nel.org>,
        Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>,
        Arnd Bergmann <arnd@...db.de>
CC:     <linux-riscv@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
        <linux-arch@...r.kernel.org>, Zhangjin Wu <falcon@...ylab.org>,
        Guo Ren <guoren@...nel.org>, Bin Meng <bmeng@...ylab.org>
Subject: Re: [PATCH v2 4/4] riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION



On 2023/5/24 0:55, Jisheng Zhang wrote:
> From: Zhangjin Wu <falcon@...ylab.org>
> 
> Select CONFIG_HAVE_LD_DEAD_CODE_DATA_ELIMINATION for RISC-V, allowing
> the user to enable dead code elimination. In order for this to work,
> ensure that we keep the alternative table by annotating them with KEEP.
> 
> This boots well on qemu with both rv32_defconfig & rv64 defconfig, but
> it only shrinks their builds by ~1%, a smaller config is thereforce
> customized to test this feature:
> 
>            | rv32                   | rv64
>    --------|------------------------|---------------------
>     No DCE | 4460684                | 4893488
>        DCE | 3986716                | 4376400
>     Shrink |  473968 (~10.6%)       |  517088 (~10.5%)
> 
> The config used above only reserves necessary options to boot on qemu
> with serial console, more like the size-critical embedded scenes:
> 
>    - rv64 config: https://pastebin.com/crz82T0s
>    - rv32 config: rv64 config + 32-bit.config
> 
> Here is Jisheng's original commit-msg:
> When trying to run linux with various opensource riscv core on
> resource limited FPGA platforms, for example, those FPGAs with less
> than 16MB SDRAM, I want to save mem as much as possible. One of the
> major technologies is kernel size optimizations, I found that riscv
> does not currently support HAVE_LD_DEAD_CODE_DATA_ELIMINATION, which
> passes -fdata-sections, -ffunction-sections to CFLAGS and passes the
> --gc-sections flag to the linker.
> 
> This not only benefits my case on FPGA but also benefits defconfigs.
> Here are some notable improvements from enabling this with defconfigs:
> 
> nommu_k210_defconfig:
>     text    data     bss     dec     hex
> 1112009  410288   59837 1582134  182436     before
>   962838  376656   51285 1390779  1538bb     after
> 
> rv32_defconfig:
>     text    data     bss     dec     hex
> 8804455 2816544  290577 11911576 b5c198     before
> 8692295 2779872  288977 11761144 b375f8     after
> 
> defconfig:
>     text    data     bss     dec     hex
> 9438267 3391332  485333 13314932 cb2b74     before
> 9285914 3350052  483349 13119315 c82f53     after
> 
> Signed-off-by: Zhangjin Wu <falcon@...ylab.org>
> Co-developed-by: Jisheng Zhang <jszhang@...nel.org>
> Signed-off-by: Jisheng Zhang <jszhang@...nel.org>
> Reviewed-by: Guo Ren <guoren@...nel.org>
> Tested-by: Bin Meng <bmeng@...ylab.org>

Reviewed-by: Kefeng Wang <wangkefeng.wang@...wei.com>

> ---
>   arch/riscv/Kconfig              | 1 +
>   arch/riscv/kernel/vmlinux.lds.S | 6 +++---
>   2 files changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index 8f55aa4aae34..62e84fee2cfd 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -115,6 +115,7 @@ config RISCV
>   	select HAVE_KPROBES if !XIP_KERNEL
>   	select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
>   	select HAVE_KRETPROBES if !XIP_KERNEL
> +	select HAVE_LD_DEAD_CODE_DATA_ELIMINATION
>   	select HAVE_MOVE_PMD
>   	select HAVE_MOVE_PUD
>   	select HAVE_PCI
> diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
> index e5f9f4677bbf..492dd4b8f3d6 100644
> --- a/arch/riscv/kernel/vmlinux.lds.S
> +++ b/arch/riscv/kernel/vmlinux.lds.S
> @@ -85,11 +85,11 @@ SECTIONS
>   	INIT_DATA_SECTION(16)
>   
>   	.init.pi : {
> -		*(.init.pi*)
> +		KEEP(*(.init.pi*))
>   	}
>   
>   	.init.bss : {
> -		*(.init.bss)	/* from the EFI stub */
> +		KEEP(*(.init.bss*))	/* from the EFI stub */
>   	}
>   	.exit.data :
>   	{
> @@ -112,7 +112,7 @@ SECTIONS
>   	. = ALIGN(8);
>   	.alternative : {
>   		__alt_start = .;
> -		*(.alternative)
> +		KEEP(*(.alternative))
>   		__alt_end = .;
>   	}
>   	__init_end = .;

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ