Skip to content

Commit 22e6a2e

Browse files
avpatelpalmer-dabbelt
authored andcommitted
RISC-V: Make BSS section as the last section in vmlinux.lds.S
The objcopy only emits loadable sections when creating flat kernel Image. To have minimal possible size of flat kernel Image, we should have all non-loadable sections after loadable sections. Currently, execption table section (loadable section) is after BSS section (non-loadable section) in the RISC-V vmlinux.lds.S. This is not optimal for having minimal flat kernel Image size hence this patch makes BSS section as the last section in RISC-V vmlinux.lds.S. In addition, we make BSS section aligned to 16byte instead of PAGE aligned which further reduces flat kernel Image size by few KBs. The flat kernel Image size of Linux-4.20-rc4 using GCC 8.2.0 is 8819980 bytes with current RISC-V vmlinux.lds.S and it reduces to 7991740 bytes with this patch applied. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB. Signed-off-by: Anup Patel <anup@brainfault.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent bfeffd1 commit 22e6a2e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/riscv/kernel/vmlinux.lds.S

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <asm/cache.h>
1919
#include <asm/thread_info.h>
2020

21+
#define MAX_BYTES_PER_LONG 0x10
22+
2123
OUTPUT_ARCH(riscv)
2224
ENTRY(_start)
2325

@@ -74,15 +76,17 @@ SECTIONS
7476
*(.sbss*)
7577
}
7678

77-
BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0)
78-
7979
EXCEPTION_TABLE(0x10)
8080
NOTES
8181

8282
.rel.dyn : {
8383
*(.rel.dyn*)
8484
}
8585

86+
BSS_SECTION(MAX_BYTES_PER_LONG,
87+
MAX_BYTES_PER_LONG,
88+
MAX_BYTES_PER_LONG)
89+
8690
_end = .;
8791

8892
STABS_DEBUG

0 commit comments

Comments
 (0)