RISC-V: Make BSS section as the last section in vmlinux.lds.S
PATCH 1/1 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 using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.
--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/riscv/kernel/vmlinux.lds.S +2 -2
@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES
@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .; STABS_DEBUG
Signature · 1 line
2.17.1
Quoted 18 lines · Anup Patel
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.
Quoted 5 lines
Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 46 lines · Anup Patel
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/vmlinux.lds.S +2
-3@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .; STABS_DEBUG --
Quoted 2 lines
2.17.1
Hi All,
Any comment on this patch?
Regards,
Anup
Στις 2018-12-17 11:36, Anup Patel έγραψε:
Quoted 52 lines · Anup Patel
Quoted 46 lines
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/vmlinux.lds.S +2
-3@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .; STABS_DEBUG --Quoted 2 lines
2.17.1
Hi All,
Quoted 5 lines
Any comment on this patch?
Regards,
Anup
Just a note on coding style, you should be using a macro instead of 0x10 so that those who read the code can understand what it is and also a few comments since searching through the commit logs to understand why you used it isn't optimal.
Regards,
Nick
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 58 lines · Nick Kossifidis
Στις 2018-12-17 11:36, Anup Patel έγραψε:
Quoted 56 lines
Quoted 47 lines · Anup Patel
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/vmlinux.lds.S +2
-3@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .; STABS_DEBUG --Quoted 2 lines
2.17.1
Hi All,
Any comment on this patch?
Quoted 8 lines
Quoted 3 lines
Regards,
AnupJust a note on coding style, you should be using a macro instead of
0x10so that those who read the code can understand what it is and also a few comments since searching through the commit logs to understand why you used it isn't optimal.
RISC-V can support 32bit, 64bit and 128bit machine-word sizes.
The 0x10 number is the machine-word size in bytes for 128bit RISC-V CPU (i.e. maximum machine-word size).
I will add a macro MAX_BYTES_PER_LONG in vmlinux.lds.S and use it in-place of 0x10
Regards,
Anup
Quoted 45 lines · On Mon, 17 Dec 2018 01:36:45 PST (-0800), [email protected] wrote:
Quoted 44 lines · Anup Patel
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/vmlinux.lds.S +2
-2@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .;
Quoted 8 lines
Quoted 4 lines
arch/riscv/kernel/vmlinux.lds.S +0
-1STABS_DEBUG --2.17.1
Hi All,
Any comment on this patch?
Sorry, I haven't had a chance to look at it yet. Aside from the macro issue mentioned by Nick it seems OK.
Quoted 54 lines · Palmer Dabbelt
Quoted 52 lines · On Mon, 17 Dec 2018 01:36:45 PST (-0800), [email protected] wrote:
Quoted 46 lines · Anup Patel
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-Vvmlinux.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.Sand it reduces to 7991740 bytes with this patch applied using GCC 8.2.0. In summary, this patch reduces Linux-4.20-rc4 flat kernel Image size by 809 KB.Signed-off-by Anup Patel <[email protected]>--- arch/riscv/kernel/vmlinux.lds.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/riscv/kernel/vmlinux.lds.S +2
-3@@ -74,8 +74,6 @@ SECTIONS *(.sbss*) } - BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 0) - EXCEPTION_TABLE(0x10) NOTES@@ -83,6 +81,8 @@ SECTIONS *(.rel.dyn*) } + BSS_SECTION(0x10, 0x10, 0x10) + _end = .; STABS_DEBUG --Quoted 2 lines
2.17.1
Hi All,
Quoted 4 lines
Quoted 1 line
Any comment on this patch?
Sorry, I haven't had a chance to look at it yet. Aside from the macro issue mentioned by Nick it seems OK.
I have send v2 to address Nick's comment.
Regards,
Anup