First, ELF executables in xv6 does not have a bss segment.
Although they have a .bss section in its binary containers (ELF), it is included in the first segment in the ELF executable. It might be important to tell the meaning of segments from the meaning of sections in ELF specification correctly. In typical cases, segments should be handled by OS kernels, on the other hand, sections should be handled by language systems.
In addition to this, xv6 kernel provides zeroed-pages to prepare user VMs.
Thus, xv6 kernel handle .bss section properly.
Would you please pay attention to the fact that exec function copies contents of the segment with ph.filesz NOT ph.memsz. This is a key trick to make .bss section zeroed because ph.filesz is lesser than
ph.memsz if .bss section exists. So exec() function can keep pages in .bss section zero.
Hi,
First, ELF executables in xv6 does not have a bss segment. Although they have a .bss section in its binary containers (ELF), it is included in the first segment in the ELF executable. It might be important to tell the meaning of segments from the meaning of sections in ELF specification correctly. In typical cases, segments should be handled by OS kernels, on the other hand, sections should be handled by language systems.
In addition to this, xv6 kernel provides zeroed-pages to prepare user VMs. Thus, xv6 kernel handle .bss section properly.
Would you please pay attention to the fact that exec function copies contents of the segment with ph.filesz NOT ph.memsz. This is a key trick to make .bss section zeroed because ph.filesz is lesser than ph.memsz if .bss section exists. So exec() function can keep pages in .bss section zero.
Thanks, Regards,