Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine .sbss section with .bss. #288

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Combine .sbss section with .bss. #288

merged 1 commit into from
Nov 19, 2024

Conversation

nosuz
Copy link
Contributor

@nosuz nosuz commented Nov 16, 2024

The linker script doen't care the .sbss section and variables located in that section are not cleared by startup code. So, I would like to propose to include .sbss in .bss section.

Example code.

const std = @import("std");
const microzig = @import("microzig");

var a: bool = false;
pub fn main() void {
    while (true) {
        asm volatile ("nop");
        a = !a;
    }
}

I compiled it with -Doptimize=ReleaseSmall under examples/gigadevice/gd32 and this program makes following code.

0800001e <_start>:
 800001e:	1141                	addi	sp,sp,-16
 8000020:	c606                	sw	ra,12(sp)
 8000022:	20000537          	lui	a0,0x20000
 8000026:	00050513          	mv	a0,a0
 800002a:	200005b7          	lui	a1,0x20000
 800002e:	00058613          	mv	a2,a1
 8000032:	8e09                	sub	a2,a2,a0
 8000034:	4581                	li	a1,0
 8000036:	00000097          	auipc	ra,0x0
 800003a:	04c080e7          	jalr	76(ra) # 8000082 <memset>

The variable a is mapped on .sbss. However, the current linker script and start code consider only .bss section, and the variable a in .sbss is not cleared by startup code. Thus, I added a line to locate .sbss in .bss.

@ikskuh ikskuh merged commit 1bb11ec into ZigEmbeddedGroup:main Nov 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants