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.
Unified · Split
| @@ -18,6 +18,8 @@ · 17 unmodified lines | |||
| 18 | #include <asm/cache.h> | 18 | #include <asm/cache.h> |
| 19 | #include <asm/thread_info.h> | 19 | #include <asm/thread_info.h> |
| 20 | 20 | ||
| 21 | #define MAX_BYTES_PER_LONG 0x10 | ||
| 22 | |||
| 21 | OUTPUT_ARCH(riscv) | 23 | OUTPUT_ARCH(riscv) |
| 22 | ENTRY(_start) | 24 | ENTRY(_start) |
| 23 | 25 | ||
| @@ -74,8 +76,6 @@ SECTIONS · 50 unmodified lines | |||
| 74 | *(.sbss*) | 76 | *(.sbss*) |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) | ||
| 78 | |||
| 79 | EXCEPTION_TABLE(0x10) | 79 | EXCEPTION_TABLE(0x10) |
| 80 | NOTES | 80 | NOTES |
| 81 | 81 | ||
| @@ -83,6 +83,10 @@ SECTIONS · 1 unmodified line | |||
| 83 | *(.rel.dyn*) | 83 | *(.rel.dyn*) |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | BSS_SECTION(MAX_BYTES_PER_LONG, | ||
| 87 | MAX_BYTES_PER_LONG, | ||
| 88 | MAX_BYTES_PER_LONG) | ||
| 89 | |||
| 86 | _end = .; | 90 | _end = .; |
| 87 | 91 | ||
| 88 | STABS_DEBUG | 92 | STABS_DEBUG |