SHT_NOBITS
A section of this type occupies no space in the file but otherwise resembles SHT_PROGBITS. Although this section contains no bytes, the sh_offset member contains the conceptual file offset.
For sections of type SHT_NOBITS the sh_offset member is meaningful only for executable and shared objects where it has the file offset that the link editor would have assigned the section if the type had been SHT_PROGBITS.
As ``Sections'' in Chapter 4 describes, the .bss section has the type SHT_NOBITS. Although it occupies no space in the file, it contributes to the segment's memory image. Normally, these uninitialized data reside at the end of the segment, thereby making p_memsz larger than p_filesz in the associated program header element.
As ``Sections'' in Chapter 4 describes, in a relocatable object file the .bss section has the type SHT_NOBITS. In common with other SHT_NOBITS sections, although it occupies no space in the file, it contributes to the segment's memory image. Normally, this uninitialized data resides at the end of the segment, thereby making p_memsz larger than p_filesz in the associated program header element. Otherwise the link editor must change the section type to SHT_PROGBITS and will have to allocate space in the output file for the contents of the .bss sections.
Figure 4-16: Special Sections
Name Type Attributes
.bss SHT_NOBITS SHF_ALLOC+SHF_WRITE
PHDRS {
ph_text PT_LOAD FLAGS (0x5);
ph_data PT_LOAD FLAGS (0x6);
}
SECTIONS {
.text : { *(.text) } : ph_text
. = ALIGN (0x4000);
.bss : { *(.bss) } : ph_data
.nobits : { *(.nobits) } : ph_data
.data : { *(.data) } : ph_data
}
.text
.global _start
.type _start,@function
_start:
ret
.bss
.global bss
.type bss,@object
bss:
.quad 0
.quad 0
.section .nobits,"aw",@nobits
.global nobits
.type nobits,@object
nobits:
.quad 0
.data
.global data
.type data,@object
data:
.quad 0xdeadbeefdeadbeef
Just because it has to allocate space for those zeroes in the case of
a NOBITS section in the middle of a segment, doesn't mean that the
section can't still be SHT_NOBITS.
On Wed, Jul 25, 2018 at 11:35:27AM -0700, Cary Coutant wrote:
> Rather than tighten up the spec, I'd prefer to loosen it up -- the
> sh_offset member has no real meaning for SHT_NOBITS sections, and it
> should say that.
I agree with Cary. The "conceptual placement" idea is nonsense. The
net effect of that phrase encourages people to write validation tools
that check sh_offset for SHT_NOBITS sections, forcing linkers to
comply. There is no other utility that I can see.