]> Git Repo - linux.git/commitdiff
Merge patch series "riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION"
authorPalmer Dabbelt <[email protected]>
Sun, 25 Jun 2023 23:24:06 +0000 (16:24 -0700)
committerPalmer Dabbelt <[email protected]>
Sat, 1 Jul 2023 14:38:19 +0000 (07:38 -0700)
Jisheng Zhang <[email protected]> says:

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

patch1 and patch2 are clean ups.
patch3 fixes a typo.
patch4 finally enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION for riscv.

* b4-shazam-merge:
  riscv: disable HAVE_LD_DEAD_CODE_DATA_ELIMINATION for LLD
  riscv: enable HAVE_LD_DEAD_CODE_DATA_ELIMINATION
  vmlinux.lds.h: use correct .init.data.* section name
  riscv: vmlinux-xip.lds.S: remove .alternative section
  riscv: move options to keep entries sorted
  riscv: Fix orphan section warnings caused by kernel/pi

Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Palmer Dabbelt <[email protected]>
1  2 
arch/riscv/Kconfig
include/asm-generic/vmlinux.lds.h

diff --combined arch/riscv/Kconfig
index 08f3a01fa1eaef7d151fd54ddb9c9fb3a83fb2d8,a8a9387eb2842b804f734e351fda9a954ce600a1..c8c22cf11602b123452dbbbf3240c097262c7725
@@@ -12,8 -12,6 +12,8 @@@ config 32BI
  
  config RISCV
        def_bool y
 +      select ACPI_GENERIC_GSI if ACPI
 +      select ACPI_REDUCED_HARDWARE_ONLY if ACPI
        select ARCH_DMA_DEFAULT_COHERENT
        select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION
        select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
@@@ -28,7 -26,6 +28,7 @@@
        select ARCH_HAS_GIGANTIC_PAGE
        select ARCH_HAS_KCOV
        select ARCH_HAS_MMIOWB
 +      select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
        select ARCH_HAS_PMEM_API
        select ARCH_HAS_PTE_SPECIAL
        select ARCH_HAS_SET_DIRECT_MAP if MMU
@@@ -45,7 -42,6 +45,7 @@@
        select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
        select ARCH_SUPPORTS_HUGETLBFS if MMU
        select ARCH_SUPPORTS_PAGE_TABLE_CHECK if MMU
 +      select ARCH_SUPPORTS_PER_VMA_LOCK if MMU
        select ARCH_USE_MEMTEST
        select ARCH_USE_QUEUED_RWLOCKS
        select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU
        select HAVE_CONTEXT_TRACKING_USER
        select HAVE_DEBUG_KMEMLEAK
        select HAVE_DMA_CONTIGUOUS if MMU
+       select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
+       select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
+       select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
+       select HAVE_FUNCTION_GRAPH_TRACER
+       select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
        select HAVE_EBPF_JIT if MMU
        select HAVE_FUNCTION_ARG_ACCESS_API
        select HAVE_FUNCTION_ERROR_INJECTION
        select HAVE_KPROBES if !XIP_KERNEL
        select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
        select HAVE_KRETPROBES if !XIP_KERNEL
-       select HAVE_RETHOOK if !XIP_KERNEL
+       # https://github.com/ClangBuiltLinux/linux/issues/1881
+       select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if !LD_IS_LLD
        select HAVE_MOVE_PMD
        select HAVE_MOVE_PUD
        select HAVE_PCI
        select HAVE_PERF_USER_STACK_DUMP
        select HAVE_POSIX_CPU_TIMERS_TASK_WORK
        select HAVE_REGS_AND_STACK_ACCESS_API
+       select HAVE_RETHOOK if !XIP_KERNEL
        select HAVE_RSEQ
        select HAVE_STACKPROTECTOR
        select HAVE_SYSCALL_TRACEPOINTS
 +      select HOTPLUG_CORE_SYNC_DEAD if HOTPLUG_CPU
        select IRQ_DOMAIN
        select IRQ_FORCED_THREADING
        select KASAN_VMALLOC if KASAN
 +      select LOCK_MM_AND_FIND_VMA
        select MODULES_USE_ELF_RELA if MODULES
        select MODULE_SECTIONS if MODULES
        select OF
        select TRACE_IRQFLAGS_SUPPORT
        select UACCESS_MEMCPY if !MMU
        select ZONE_DMA32 if 64BIT
-       select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && MMU && (CLANG_SUPPORTS_DYNAMIC_FTRACE || GCC_SUPPORTS_DYNAMIC_FTRACE)
-       select HAVE_DYNAMIC_FTRACE_WITH_REGS if HAVE_DYNAMIC_FTRACE
-       select HAVE_FTRACE_MCOUNT_RECORD if !XIP_KERNEL
-       select HAVE_FUNCTION_GRAPH_TRACER
-       select HAVE_FUNCTION_TRACER if !XIP_KERNEL && !PREEMPTION
  
  config CLANG_SUPPORTS_DYNAMIC_FTRACE
        def_bool CC_IS_CLANG
@@@ -268,12 -264,6 +270,12 @@@ config RISCV_DMA_NONCOHEREN
  config AS_HAS_INSN
        def_bool $(as-instr,.insn r 51$(comma) 0$(comma) 0$(comma) t0$(comma) t0$(comma) zero)
  
 +config AS_HAS_OPTION_ARCH
 +      # https://reviews.llvm.org/D123515
 +      def_bool y
 +      depends on $(as-instr, .option arch$(comma) +m)
 +      depends on !$(as-instr, .option arch$(comma) -i)
 +
  source "arch/riscv/Kconfig.socs"
  source "arch/riscv/Kconfig.errata"
  
@@@ -472,44 -462,13 +474,44 @@@ config RISCV_ISA_SVPBM
  
           If you don't know what to do here, say Y.
  
 +config TOOLCHAIN_HAS_V
 +      bool
 +      default y
 +      depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64iv)
 +      depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32iv)
 +      depends on LLD_VERSION >= 140000 || LD_VERSION >= 23800
 +      depends on AS_HAS_OPTION_ARCH
 +
 +config RISCV_ISA_V
 +      bool "VECTOR extension support"
 +      depends on TOOLCHAIN_HAS_V
 +      depends on FPU
 +      select DYNAMIC_SIGFRAME
 +      default y
 +      help
 +        Say N here if you want to disable all vector related procedure
 +        in the kernel.
 +
 +        If you don't know what to do here, say Y.
 +
 +config RISCV_ISA_V_DEFAULT_ENABLE
 +      bool "Enable userspace Vector by default"
 +      depends on RISCV_ISA_V
 +      default y
 +      help
 +        Say Y here if you want to enable Vector in userspace by default.
 +        Otherwise, userspace has to make explicit prctl() call to enable
 +        Vector, or enable it via the sysctl interface.
 +
 +        If you don't know what to do here, say Y.
 +
  config TOOLCHAIN_HAS_ZBB
        bool
        default y
        depends on !64BIT || $(cc-option,-mabi=lp64 -march=rv64ima_zbb)
        depends on !32BIT || $(cc-option,-mabi=ilp32 -march=rv32ima_zbb)
        depends on LLD_VERSION >= 150000 || LD_VERSION >= 23900
 -      depends on AS_IS_GNU
 +      depends on AS_HAS_OPTION_ARCH
  
  config RISCV_ISA_ZBB
        bool "Zbb extension support for bit manipulation instructions"
@@@ -594,25 -553,6 +596,25 @@@ config FP
  
          If you don't know what to do here, say Y.
  
 +config IRQ_STACKS
 +      bool "Independent irq & softirq stacks" if EXPERT
 +      default y
 +      select HAVE_IRQ_EXIT_ON_IRQ_STACK
 +      select HAVE_SOFTIRQ_ON_OWN_STACK
 +      help
 +        Add independent irq & softirq stacks for percpu to prevent kernel stack
 +        overflows. We may save some memory footprint by disabling IRQ_STACKS.
 +
 +config THREAD_SIZE_ORDER
 +      int "Kernel stack size (in power-of-two numbers of page size)" if VMAP_STACK && EXPERT
 +      range 0 4
 +      default 1 if 32BIT && !KASAN
 +      default 3 if 64BIT && KASAN
 +      default 2
 +      help
 +        Specify the Pages of thread stack size (from 4KB to 64KB), which also
 +        affects irq stack size, which is equal to thread stack size.
 +
  endmenu # "Platform type"
  
  menu "Kernel features"
@@@ -769,7 -709,6 +771,7 @@@ config EF
        depends on OF && !XIP_KERNEL
        depends on MMU
        default y
 +      select ARCH_SUPPORTS_ACPI if 64BIT
        select EFI_GENERIC_STUB
        select EFI_PARAMS_FROM_FDT
        select EFI_RUNTIME_WRAPPERS
@@@ -862,11 -801,8 +864,11 @@@ menu "Power management options
  
  source "kernel/power/Kconfig"
  
 +# Hibernation is only possible on systems where the SBI implementation has
 +# marked its reserved memory as not accessible from, or does not run
 +# from the same memory as, Linux
  config ARCH_HIBERNATION_POSSIBLE
 -      def_bool y
 +      def_bool NONPORTABLE
  
  config ARCH_HIBERNATION_HEADER
        def_bool HIBERNATION
@@@ -882,5 -818,3 +884,5 @@@ source "drivers/cpufreq/Kconfig
  endmenu # "CPU Power Management"
  
  source "arch/riscv/kvm/Kconfig"
 +
 +source "drivers/acpi/Kconfig"
index da9e5629ea43d2739152e4b07baaa94a3b252fd2,371026ca72214cbcaf1e209c06da9856d7a2e1b2..e8f276fb1b11b5cb2de3dd8be7843c9a089e0807
  /* init and exit section handling */
  #define INIT_DATA                                                     \
        KEEP(*(SORT(___kentry+*)))                                      \
-       *(.init.data init.data.*)                                       \
+       *(.init.data .init.data.*)                                      \
        MEM_DISCARD(init.data*)                                         \
        KERNEL_CTORS()                                                  \
        MCOUNT_REC()                                                    \
  
  #ifdef CONFIG_UNWINDER_ORC
  #define ORC_UNWIND_TABLE                                              \
 +      .orc_header : AT(ADDR(.orc_header) - LOAD_OFFSET) {             \
 +              BOUNDED_SECTION_BY(.orc_header, _orc_header)            \
 +      }                                                               \
        . = ALIGN(4);                                                   \
        .orc_unwind_ip : AT(ADDR(.orc_unwind_ip) - LOAD_OFFSET) {       \
                BOUNDED_SECTION_BY(.orc_unwind_ip, _orc_unwind_ip)      \
  /*
   * Discard .note.GNU-stack, which is emitted as PROGBITS by the compiler.
   * Otherwise, the type of .notes section would become PROGBITS instead of NOTES.
 + *
 + * Also, discard .note.gnu.property, otherwise it forces the notes section to
 + * be 8-byte aligned which causes alignment mismatches with the kernel's custom
 + * 4-byte aligned notes.
   */
  #define NOTES                                                         \
 -      /DISCARD/ : { *(.note.GNU-stack) }                              \
 +      /DISCARD/ : {                                                   \
 +              *(.note.GNU-stack)                                      \
 +              *(.note.gnu.property)                                   \
 +      }                                                               \
        .notes : AT(ADDR(.notes) - LOAD_OFFSET) {                       \
                BOUNDED_SECTION_BY(.note.*, _notes)                     \
        } NOTES_HEADERS                                                 \
This page took 0.072108 seconds and 4 git commands to generate.