c828856b51
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@tinylab.org> Co-developed-by: Jisheng Zhang <jszhang@kernel.org> Signed-off-by: Jisheng Zhang <jszhang@kernel.org> Reviewed-by: Guo Ren <guoren@kernel.org> Tested-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Kefeng Wang <wangkefeng.wang@huawei.com> Tested-by: Nick Desaulniers <ndesaulniers@google.com> # build Link: https://lore.kernel.org/r/20230523165502.2592-5-jszhang@kernel.org Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
174 lines
3.1 KiB
ArmAsm
174 lines
3.1 KiB
ArmAsm
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
* Copyright (C) 2017 SiFive
|
|
*/
|
|
|
|
#define RO_EXCEPTION_TABLE_ALIGN 4
|
|
#define RUNTIME_DISCARD_EXIT
|
|
|
|
#ifdef CONFIG_XIP_KERNEL
|
|
#include "vmlinux-xip.lds.S"
|
|
#else
|
|
|
|
#include <asm/pgtable.h>
|
|
#define LOAD_OFFSET KERNEL_LINK_ADDR
|
|
|
|
#include <asm/vmlinux.lds.h>
|
|
#include <asm/page.h>
|
|
#include <asm/cache.h>
|
|
#include <asm/thread_info.h>
|
|
#include <asm/set_memory.h>
|
|
#include "image-vars.h"
|
|
|
|
#include <linux/sizes.h>
|
|
OUTPUT_ARCH(riscv)
|
|
ENTRY(_start)
|
|
|
|
jiffies = jiffies_64;
|
|
|
|
SECTIONS
|
|
{
|
|
/* Beginning of code and text segment */
|
|
. = LOAD_OFFSET;
|
|
_start = .;
|
|
HEAD_TEXT_SECTION
|
|
. = ALIGN(PAGE_SIZE);
|
|
|
|
.text : {
|
|
_text = .;
|
|
_stext = .;
|
|
TEXT_TEXT
|
|
SCHED_TEXT
|
|
LOCK_TEXT
|
|
KPROBES_TEXT
|
|
ENTRY_TEXT
|
|
IRQENTRY_TEXT
|
|
SOFTIRQENTRY_TEXT
|
|
_etext = .;
|
|
}
|
|
|
|
. = ALIGN(SECTION_ALIGN);
|
|
__init_begin = .;
|
|
__init_text_begin = .;
|
|
.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) ALIGN(SECTION_ALIGN) { \
|
|
_sinittext = .; \
|
|
INIT_TEXT \
|
|
_einittext = .; \
|
|
}
|
|
|
|
. = ALIGN(8);
|
|
__soc_early_init_table : {
|
|
__soc_early_init_table_start = .;
|
|
KEEP(*(__soc_early_init_table))
|
|
__soc_early_init_table_end = .;
|
|
}
|
|
__soc_builtin_dtb_table : {
|
|
__soc_builtin_dtb_table_start = .;
|
|
KEEP(*(__soc_builtin_dtb_table))
|
|
__soc_builtin_dtb_table_end = .;
|
|
}
|
|
/* we have to discard exit text and such at runtime, not link time */
|
|
.exit.text :
|
|
{
|
|
EXIT_TEXT
|
|
}
|
|
|
|
__init_text_end = .;
|
|
. = ALIGN(SECTION_ALIGN);
|
|
#ifdef CONFIG_EFI
|
|
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
|
|
__pecoff_text_end = .;
|
|
#endif
|
|
/* Start of init data section */
|
|
__init_data_begin = .;
|
|
INIT_DATA_SECTION(16)
|
|
|
|
.init.pi : {
|
|
KEEP(*(.init.pi*))
|
|
}
|
|
|
|
.init.bss : {
|
|
KEEP(*(.init.bss*)) /* from the EFI stub */
|
|
}
|
|
.exit.data :
|
|
{
|
|
EXIT_DATA
|
|
}
|
|
PERCPU_SECTION(L1_CACHE_BYTES)
|
|
|
|
.rel.dyn : {
|
|
*(.rel.dyn*)
|
|
}
|
|
|
|
.rela.dyn : ALIGN(8) {
|
|
__rela_dyn_start = .;
|
|
*(.rela .rela*)
|
|
__rela_dyn_end = .;
|
|
}
|
|
|
|
__init_data_end = .;
|
|
|
|
. = ALIGN(8);
|
|
.alternative : {
|
|
__alt_start = .;
|
|
KEEP(*(.alternative))
|
|
__alt_end = .;
|
|
}
|
|
__init_end = .;
|
|
|
|
/* Start of data section */
|
|
_sdata = .;
|
|
RO_DATA(SECTION_ALIGN)
|
|
.srodata : {
|
|
*(.srodata*)
|
|
}
|
|
|
|
. = ALIGN(SECTION_ALIGN);
|
|
_data = .;
|
|
|
|
RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_ALIGN)
|
|
.sdata : {
|
|
__global_pointer$ = . + 0x800;
|
|
*(.sdata*)
|
|
}
|
|
|
|
.got : { *(.got*) }
|
|
|
|
#ifdef CONFIG_RELOCATABLE
|
|
.data.rel : { *(.data.rel*) }
|
|
.plt : { *(.plt) }
|
|
.dynamic : { *(.dynamic) }
|
|
.dynsym : { *(.dynsym) }
|
|
.dynstr : { *(.dynstr) }
|
|
.hash : { *(.hash) }
|
|
.gnu.hash : { *(.gnu.hash) }
|
|
#endif
|
|
|
|
#ifdef CONFIG_EFI
|
|
.pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
|
|
__pecoff_data_raw_size = ABSOLUTE(. - __pecoff_text_end);
|
|
__pecoff_data_raw_end = ABSOLUTE(.);
|
|
#endif
|
|
|
|
/* End of data section */
|
|
_edata = .;
|
|
|
|
BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
|
|
|
|
#ifdef CONFIG_EFI
|
|
. = ALIGN(PECOFF_SECTION_ALIGNMENT);
|
|
__pecoff_data_virt_size = ABSOLUTE(. - __pecoff_text_end);
|
|
__pecoff_data_virt_end = ABSOLUTE(.);
|
|
#endif
|
|
_end = .;
|
|
|
|
STABS_DEBUG
|
|
DWARF_DEBUG
|
|
ELF_DETAILS
|
|
.riscv.attributes 0 : { *(.riscv.attributes) }
|
|
|
|
DISCARDS
|
|
}
|
|
#endif /* CONFIG_XIP_KERNEL */
|