Inclusion of Custom NOLOAD Section in pei-x86-64 Output Binary
Jan Beulich
jbeulich@suse.com
Fri Jun 13 14:12:40 GMT 2025
On 27.05.2025 11:30, Niteesh G. S. wrote:
> GNU binutils version 2.43.1
> Target Format: pei-x86-64
>
> I'm encountering an issue with the GNU linker when defining a custom
> uninitialized data section in my linker script. Specifically, I have the
> following section defined:
>
> .boot.bss (NOLOAD) : {
> *(.boot.bss)
> }
>
> My expectation is that this section, marked with the NOLOAD attribute,
> would not be included in the loadable segments of the output binary.
> However, upon inspecting the generated binary, I observe that .boot.bss is
> being included in the loadable segments, contrary to the intended
> behavior.
>
> objdump -h kernel.pe
> ------------------------------------------------------------------------------------------
> kernel/kernel.pe: file format pei-x86-64
>
> Sections:
> Idx Name Size VMA LMA File off
> Algn
> 0 .boot.text 00000048 0000000000100000 0000000000100000 00000400
> 2**2
> CONTENTS, ALLOC, LOAD, READONLY, CODE
> 1 .boot.bss 00002000 0000000000101000 0000000000101000 00000600
> 2**2
> CONTENTS, ALLOC, LOAD, DATA
> -------------------------------------------------------------------------------------------
>
> Is this the intended behaviour? How can I create a custom BSS section in
> non-elf targets?
About three years ago I had to look into this. My conclusion was that NOLOAD
is simply ignored for PE/COFF. See e.g. the comment resulting from that
analysis in
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=dedb0aa42c6d1ee31805dfc61630db2c41117330
Jan
More information about the Binutils
mailing list