x86: fix .bss with -fdata-sections
PATCH 1/1 x86: fix .bss with -fdata-sections
With LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with -fdata-sections, which also splits the .bss section. Use the common BSS_MAIN macro in the linker script to properly merge all the generated sections.
--- arch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/vmlinux.lds.S +1 -1
@@ -362,7 +362,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) - *(.bss) + *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); __bss_stop = .;
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Quoted 25 lines · Sami Tolvanen
With
LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with -fdata-sections, which also splits the .bss section. Use the commonBSS_MAINmacro in the linker script to properly merge all the generated sections.Signed-off-by Sami Tolvanen <[email protected]>--- arch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/vmlinux.lds.S +1
-2@@ -362,7 +362,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) - *(.bss) + *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); __bss_stop = .; --
Quoted 2 lines
2.21.0.392.gf8f6787159e-goog
Thanks for the patch! I checked as well that this issue doesn't exist for .text, .data, .sdata, .rodata, and .sbss; just .bss had this issue. Looks like this is "no functional change" when CONFIG_LD_DEAD_CODE_DATA_ELIMINATION is not set; it simply fixes the case where CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y.
Nicholas,
I don't understand the comment about RODATA_MAIN from commit 266ff2a8f51f ("kbuild: Fix asm-generic/vmlinux.lds.h for LD_DEAD_CODE_DATA_ELIMINATION"). It seems that there are no uses of RODATA_MAIN in the kernel. Can we remove its definition and that comment? (That's neither here nor there for this patch).
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 7 lines · Sami Tolvanen
With
LD_DEAD_CODE_DATA_ELIMINATION, we compile the kernel with -fdata-sections, which also splits the .bss section. Use the commonBSS_MAINmacro in the linker script to properly merge all the generated sections.Signed-off-by Sami Tolvanen <[email protected]>
Nice work tracking this down! :)
Nit/tweak/clarification for commit title:
x86/build: Fix truncated .bss with -fdata-sections
-Kees
Quoted 20 lines
--- arch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kernel/vmlinux.lds.S +1
-2@@ -362,7 +362,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) - *(.bss) + *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); __bss_stop = .; --2.21.0.392.gf8f6787159e-goog
Signature · 1 line
Kees Cook
tip-bot for Sami Tolvanen
merge bot[tip:x86/urgent] x86/build/lto: Fix truncated .bss with -fdata-sections
In reply to Sami Tolvanenx86/build/lto: Fix truncated .bss with -fdata-sections
Commit-ID: 6a03469a1edc94da52b65478f1e00837add869a3 Gitweb: https://git.kernel.org/tip/6a03469a1edc94da52b65478f1e00837add869a3 Author: Sami Tolvanen <[email protected]> AuthorDate: Mon, 15 Apr 2019 09:49:56 -0700 Committer: Ingo Molnar <[email protected]> CommitDate: Tue, 16 Apr 2019 08:20:55 +0200
x86/build/lto: Fix truncated .bss with -fdata-sections
With CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y, we compile the kernel with -fdata-sections, which also splits the .bss section.
The new section, with a new .bss.* name, which pattern gets missed by the main x86 linker script which only expects the '.bss' name. This results in the discarding of the second part and a too small, truncated .bss section and an unhappy, non-working kernel.
Use the common BSS_MAIN macro in the linker script to properly capture and merge all the generated BSS sections.
--- arch/x86/kernel/vmlinux.lds.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/vmlinux.lds.S +1 -1
@@ -362,7 +362,7 @@ SECTIONS .bss : AT(ADDR(.bss) - LOAD_OFFSET) { __bss_start = .; *(.bss..page_aligned) - *(.bss) + *(BSS_MAIN) BSS_DECRYPTED . = ALIGN(PAGE_SIZE); __bss_stop = .;