Skip to contentSkip to conversation

efi_loader: Fix -fdata-section fallout with bss

PATCH New Alexander Graf 2 participants 6 messages Aug 20, 2018 – Aug 21, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover efi_loader: Fix -fdata-section fallout with bss

While trying to fix efi_loader problems that could only be resolved by enabling individual function and data sections (commit 7e21fbca26d18 "efi_loader: Rename sections to allow for implicit data") some cases where .bss was included in the linker scripts slipped through.

This lead to random breakage when .bss contents were accessed, because the respective regions were not initialized properly.

With this patch set, all those should be resolved now.

Alex

Alexander Graf (3):
x86: Include bss subsections in linker script
x86: Enable -fdata-sections always
riscv: Include bss subsections in linker script

 arch/riscv/cpu/ax25/u-boot.lds  | 2 +-
 arch/x86/config.mk              | 4 +---
 arch/x86/cpu/u-boot-64.lds      | 2 +-
 arch/x86/cpu/u-boot.lds         | 2 +-
 arch/x86/lib/elf_ia32_efi.lds   | 2 +-
 arch/x86/lib/elf_x86_64_efi.lds | 2 +-
 6 files changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.12.3
#1 lore raw

PATCH 1/3 x86: Include bss subsections in linker script

When we build with -fdata-sections we may end up with bss subsections. Our linker script explicitly lists only a single consecutive bss section though.

Adapt the statement to also include subsections.

This fixes booting efi-x86_app_defconfig.

---
 arch/x86/cpu/u-boot-64.lds      | 2 +-
 arch/x86/cpu/u-boot.lds         | 2 +-
 arch/x86/lib/elf_ia32_efi.lds   | 2 +-
 arch/x86/lib/elf_x86_64_efi.lds | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/cpu/u-boot-64.lds +1 -1
index 862aa2d35e..98c7f8e9c5 100644
@@ -95,7 +95,7 @@ SECTIONS
 
 	.bss __rel_dyn_start (OVERLAY) : {
 		__bss_start = .;
-		*(.bss)
+		*(.bss*)
 		*(COM*)
 		. = ALIGN(4);
 		__bss_end = .;
arch/x86/cpu/u-boot.lds +1 -1
index a1cc19ce4c..a283c290ee 100644
@@ -94,7 +94,7 @@ SECTIONS
 
 	.bss __rel_dyn_start (OVERLAY) : {
 		__bss_start = .;
-		*(.bss)
+		*(.bss*)
 		*(COM*)
 		. = ALIGN(4);
 		__bss_end = .;
arch/x86/lib/elf_ia32_efi.lds +1 -1
index 983fabbc4d..aad61e7f81 100644
@@ -46,7 +46,7 @@ SECTIONS
 		*(.sbss)
 		*(.scommon)
 		*(.dynbss)
-		*(.bss)
+		*(.bss*)
 		*(COMMON)
 
 		/* U-Boot lists and device tree */
arch/x86/lib/elf_x86_64_efi.lds +1 -1
index 7cad70a2e4..b436429b33 100644
@@ -44,7 +44,7 @@ SECTIONS
 		*(.sbss)
 		*(.scommon)
 		*(.dynbss)
-		*(.bss)
+		*(.bss*)
 		*(COMMON)
 		*(.rel.local)
 
Signature · 1 line
2.12.3
#2 lore raw

PATCH 1/3 x86: Include bss subsections in linker script

Quoted 7 lines · Alexander Graf

When we build with -fdata-sections we may end up with bss subsections. Our linker script explicitly lists only a single consecutive bss section though.

Adapt the statement to also include subsections.

This fixes booting efi-x86_app_defconfig.

Quoted 8 lines
---
 arch/x86/cpu/u-boot-64.lds      | 2 +-
 arch/x86/cpu/u-boot.lds         | 2 +-
 arch/x86/lib/elf_ia32_efi.lds   | 2 +-
 arch/x86/lib/elf_x86_64_efi.lds | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
#3 lore raw

PATCH 2/3 x86: Enable -fdata-sections always

In reply to Alexander Graf

We left -fdata-sections disabled for x86_64 before because we encountered random bugs that were at that time inexplicable.

Turns out this really was just side effects of missing .bss* statements in the linker scripts. With those fixed, we can enable data sections for all targets.

---
 arch/x86/config.mk | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/config.mk +1 -3
index 586e11a0dd..5b04febd68 100644
@@ -23,13 +23,11 @@ endif
 
 ifeq ($(IS_32BIT),y)
 PLATFORM_CPPFLAGS += -march=i386 -m32
-# TODO: These break on x86_64; need to debug further
-PLATFORM_RELFLAGS += -fdata-sections
 else
 PLATFORM_CPPFLAGS += $(if $(CONFIG_SPL_BUILD),,-fpic) -fno-common -m64
 endif
 
-PLATFORM_RELFLAGS += -ffunction-sections -fvisibility=hidden
+PLATFORM_RELFLAGS += -fdata-sections -ffunction-sections -fvisibility=hidden
 
 PLATFORM_LDFLAGS += -Bsymbolic -Bsymbolic-functions
 PLATFORM_LDFLAGS += -m $(if $(IS_32BIT),elf_i386,elf_x86_64)
Signature · 1 line
2.12.3
#4 lore raw

PATCH 2/3 x86: Enable -fdata-sections always

Quoted 12 lines · Alexander Graf

We left -fdata-sections disabled for x86_64 before because we encountered random bugs that were at that time inexplicable.

Turns out this really was just side effects of missing .bss* statements in the linker scripts. With those fixed, we can enable data sections for all targets.

---
 arch/x86/config.mk | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
#5 lore raw

PATCH 3/3 riscv: Include bss subsections in linker script

In reply to Alexander Graf

When we build with -fdata-sections we may end up with bss subsections. Our linker script explicitly lists only a single consecutive bss section though.

Adapt the statement to also include subsections.

---
 arch/riscv/cpu/ax25/u-boot.lds | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/cpu/ax25/u-boot.lds +1 -1
index 3cc89746b1..c50b9642f1 100644
@@ -82,7 +82,7 @@ SECTIONS
 
 	.bss : {
         __bss_start = .;
-        *(.bss)
+        *(.bss*)
 		. = ALIGN(4);
 		__bss_end = .;
 	}
Signature · 1 line
2.12.3