Skip to content

Commit

Permalink
userlib: Add a fallback dummy section if .bss is empty
Browse files Browse the repository at this point in the history
Binaries without uninitialized global variable may generate a `.bss`
LOAD segment with no valid content (`p_filesz` = 0, `p_memsz` = 0). The
problem with such a segment is that ELF parser may fail with unaligned
segment address error. To avoid this, add a dummy `.bss` to force non-zero
memory allocation, ensuring a meaningful PT_LOAD.

Signed-off-by: Vijay Dhanraj <[email protected]>
  • Loading branch information
vijaydhanraj committed Dec 10, 2024
1 parent ee99ff7 commit 4a6fef6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion user/lib/module.lds
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,19 @@ SECTIONS
} :rodata
_erodata = .;
. = ALIGN(4096);
.bss : {
.bss (NOLOAD) : {
_bss = .;
*(.bss) *(.bss.[0-9a-zA-Z_]*)
. = ALIGN(16);
_ebss = .;
} :bss

/* Fallback dummy section if `.bss` is empty */
. = ALIGN(4096);
.bss_dummy (NOLOAD) : {
LONG(0);
} :bss

. = ALIGN(4096);
heap_start = .;
}
Expand Down

0 comments on commit 4a6fef6

Please sign in to comment.