Skip to contentSkip to conversation

pc-bios/s390-ccw: build s390 bios with -fno-zero-initialized-in-bss

PATCH In review Christian Borntraeger 4 participants 11 messages Nov 20, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pc-bios/s390-ccw: build s390 bios with -fno-zero-initialized-in-bss

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

---
 pc-bios/s390-ccw/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/Makefile +1 -1
index 6d0c2ee..2687590 100644
@@ -12,7 +12,7 @@ $(call set-vpath, $(SRC_PATH)/pc-bios/s390-ccw)
 OBJECTS = start.o main.o bootmap.o sclp.o virtio.o virtio-scsi.o virtio-blkdev.o
 QEMU_CFLAGS := $(filter -W%, $(QEMU_CFLAGS))
 QEMU_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -msoft-float
-QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing
+QEMU_CFLAGS += -march=z900 -fPIE -fno-strict-aliasing -fno-zero-initialized-in-bss
 QEMU_CFLAGS += $(call cc-option, $(QEMU_CFLAGS), -fno-stack-protector)
 LDFLAGS += -Wl,-pie -nostdlib
 
Signature · 1 line
2.9.4
#1 lore raw
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Alex

#2 lore raw
Quoted 11 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

#3 lore raw
Quoted 8 lines · Christian Borntraeger
Quoted 6 lines · Alexander Graf
Quoted 5 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Alex

#4 lore raw
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Christian Borntraeger
Quoted 9 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Yes, I know but then we have to change the build process to use a linker script.(we rely on the default linker script right now).

#5 lore raw
Quoted 13 lines · Christian Borntraeger
Quoted 11 lines · Alexander Graf
Quoted 10 lines · Christian Borntraeger
Quoted 9 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Yes, I know but then we have to change the build process to use a linker script.(we rely on the default linker script right now).

I'm not sure how common generic linker scripts are, but in our default script we have existing markers for bss and end. You can look at the default linker script using gcc <c file> -Wl,-verbose. This simple source worked for me:

#include <stdio.h>

extern char __bss_start[];
extern char _end[];

int main(void)

{
    printf("BSS size: %lx\n", (long)_end - (long)__bss_start);
    return 0;
}

Alex

#6 lore raw
Quoted 18 lines · Alexander Graf
Quoted 17 lines · Christian Borntraeger
Quoted 15 lines · Alexander Graf
Quoted 13 lines · Christian Borntraeger
Quoted 10 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Yes, I know but then we have to change the build process to use a linker script.(we rely on the default linker script right now).

I'm not sure how common generic linker scripts are, but in our default script we have existing markers for bss and end. You can look at the default linker script using gcc <c file> -Wl,-verbose. This simple source worked for me:

Are we sure that the range between __bss_start and _end does not include other elements (besides bss)?

Quoted 18 lines

#include <stdio.h>

extern char __bss_start[];
extern char _end[];

int main(void)
{
    printf("BSS size: %lx\n", (long)_end - (long)__bss_start); return 0;
}

Alex

#7 lore raw
Quoted 16 lines · Christian Borntraeger
Quoted 14 lines · Alexander Graf
Quoted 13 lines · Christian Borntraeger
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Christian Borntraeger
Quoted 10 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Yes, I know but then we have to change the build process to use a linker script.(we rely on the default linker script right now).

I'm not sure how common generic linker scripts are, but in our default script we have existing markers for bss and end. You can look at the default linker script using gcc <c file> -Wl,-verbose. This simple source worked for me:

Are we sure that the range between __bss_start and _end does not include other elements (besides bss)?

It seems to be the intended semantic for the linker script I see as default, but I'm not an expert here :). Can you check with Uli?

Alex

#8 lore raw
Quoted 19 lines · Alexander Graf
Quoted 18 lines · Christian Borntraeger
Quoted 16 lines · Alexander Graf
Quoted 15 lines · Christian Borntraeger
Quoted 14 lines · Alexander Graf
Quoted 13 lines · Christian Borntraeger
Quoted 10 lines · Alexander Graf
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

Doesn't this bloat the firmware? Why don't we just manually clear bss in the firmware itself? It's what all other firmwares do :)

Yes the proper fix is to initialize bss in the bios itself.
I was trying to come up with something for 2.11, but since the patch does not solve the original issues, lets drop it.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Initializing bss is quite simple. You can probably even do it from C. Just set two variables before and after .bss in the linker script and memset(0) from start to end :).

Yes, I know but then we have to change the build process to use a linker script.(we rely on the default linker script right now).

I'm not sure how common generic linker scripts are, but in our default script we have existing markers for bss and end. You can look at the default linker script using gcc <c file> -Wl,-verbose. This simple source worked for me:

Are we sure that the range between __bss_start and _end does not include other elements (besides bss)?

It seems to be the intended semantic for the linker script I see as default, but I'm not an expert here :). Can you check with Uli?

I will.
But the "I am not sure" is exactly the reason why I prefer Thomas "band-aid" for 2.11. Doing the bss zeroing is certainly my preferred long term solution (and it was my first comment to Thomas' patch)

#10 lore raw
In reply to Christian Borntraeger
Quoted 8 lines · Christian Borntraeger

The QEMU ELF loader does not initialize the bss segment. This has triggered several bugs in the past, e.g. see commit 5d739a4787a5 ("s390-ccw.img: Fix sporadic errors with ccw boot image - initialize css").

Instead of fixing these things one-by-one we can build the BIOS with -fno-zero-initialized-in-bss. This will move the zero variables also into the data segment, which is then part of a LOAD section.

It fixes the problem only for variables that are explicitely intialized to 0 along with their declaration - it does not fix the problem for uninitialized variables.

Thomas