From: LIU Hao <lh_mouse@126.com>
To: Richard Campbell <richard.u.campbell@gmail.com>, cygwin@cygwin.com
Subject: Re: Alignment of .text sections in object files
Date: Tue, 24 May 2022 12:33:09 +0800 [thread overview]
Message-ID: <6cc7c523-abcf-a2cc-fe1b-0387651f45ff@126.com> (raw)
In-Reply-To: <CALwydEsLmkC2FpSeXdc4Jkb_X48DjZ=KH6e+QB0nyFUwb79RAg@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 2197 bytes --]
在 2022-05-23 23:21, Richard Campbell 写道:
> On Mon, May 23, 2022 at 8:03 AM LIU Hao <lh_mouse@126.com> wrote:
>>
>> So my question is, is
>> it really necessary for .text sections in object files to be aligned to 16-byte boundaries? And
>> could you please kindly elaborate it a little?
>
> I believe the relevant requirement is found in the "Optional Header
> Windows-Specific Fields (Image Only)" part of the
> https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
> specification.
>
> This header "contain[s] additional information that is required by the
> linker and loader in Windows," and in particular has a
> "SectionAlignment" field: "The alignment (in bytes) of sections when
> they are loaded into memory. It must be greater than or equal to
> FileAlignment. The default is the page size for the architecture."
>
> Turning to FileAlignment: "The alignment factor (in bytes) that is
> used to align the raw data of sections in the image file. The value
> should be a power of 2 between 512 and 64 K, inclusive. The default is
> 512. If the SectionAlignment is less than the architecture's page
> size, then FileAlignment must match SectionAlignment."
>
> ...I'd expect you to see the alignment set to 0x200, which is the
> default and the minimum for FileAlignment, so a 16 byte boundary seems
> odd to me. There's a little more information here:
> https://docs.microsoft.com/en-us/archive/msdn-magazine/2002/february/inside-windows-win32-portable-executable-file-format-in-detail
>
> Best regards,
>
> -Richard Campbell
[please keep CC'ing me as I am not subscribed to this list]
The FileAlignment is a totally different thing. Typically the linker (GNU LD for example) is
responsible for combining all .text sections from object files to create a final .text section for
the executable output, whose offset (in the output file) is specified by FileAlignment, which cannot
be below 512.
However we were talking about something before linking: the alignment of .text sections in
individual object files. They have a default alignment of 16 bytes, shown in objdump as `2**4`.
--
Best regards,
LIU Hao
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
prev parent reply other threads:[~2022-05-24 4:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-23 13:01 LIU Hao
[not found] ` <CALwydEsLmkC2FpSeXdc4Jkb_X48DjZ=KH6e+QB0nyFUwb79RAg@mail.gmail.com>
2022-05-24 4:33 ` LIU Hao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6cc7c523-abcf-a2cc-fe1b-0387651f45ff@126.com \
--to=lh_mouse@126.com \
--cc=cygwin@cygwin.com \
--cc=richard.u.campbell@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).