This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Padding between .text and .data
> > > . = ALIGN(256) + (. & (256 - 1));
>
> It looks as though this inserts either exactly zero bytes if the
> section happens to already be aligned, or exactly 256 bytes if the
> section is unaligned, with this latter case being far more likely. If
> the .text and .data sections must be in different pages for the MMU's
> sake, I understand the ALIGN(256) requirement. What's the reason for
> the additional (. & (256 - 1)) bytes placed at the beginning of the
> next page?
I misread; this is the *other* optimization. Sorry.
The idea here is that you want data in the file and data in memory to
both be similarly aligned; such that if you break memory up into
sector-sized blocks, the data in each block corresponds to a block of
data on disk.
Thus, even though the data segment might start, say, 100k beyond the
end of code when in memory, the gap is always *exactly* some multiple
of disk blocks, and there's no bytes wasted on the disk.
Example:
.text 00000000 - 00000123
.data 10000124 - 10001234
Note that there's a huge gap between the two in the memory map, but on
disk you can put .data's first byte immediately after .text's last
byte, and still have a block-to-block alignment between disk and
memory (i.e. you can read block 0x100-0x1ff and store it at 00000100
if you needed .text, or 10000100 if you needed .data)