Skip to contentSkip to conversation

x86: fix .bss with -fdata-sections

PATCH In review Sami Tolvanen 4 participants 4 messages Apr 15, 2019 – Apr 16, 2019 x86

lore
Share & tools
lore
#0 lore raw

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
index bad8c51fee6e..a5127b2c195f 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
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 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 -2
index bad8c51fee6e..a5127b2c195f 100644
@@ -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
Reviewed-by on v1 1/1
#2 lore raw
In reply to Sami Tolvanen
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 common BSS_MAIN macro in the linker script to properly merge all the generated sections.

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
index bad8c51fee6e..a5127b2c195f 100644
@@ -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
#3 lore raw

[tip:x86/urgent] x86/build/lto: Fix truncated .bss with -fdata-sections

In reply to Sami Tolvanen
x86/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.

Cc Borislav Petkov <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Nick Desaulniers <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
[ Extended the changelog. ]
---
 arch/x86/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/vmlinux.lds.S +1 -1
index bad8c51fee6e..a5127b2c195f 100644
@@ -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 = .;