From: Jan Beulich <jbeulich@suse.com>
To: Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org
Subject: Re: RFC: Objcopy: Section alignment
Date: Thu, 21 Mar 2024 17:59:56 +0100 [thread overview]
Message-ID: <494659da-1a66-48a9-976d-da19ab55a87e@suse.com> (raw)
In-Reply-To: <875xxf63e7.fsf@redhat.com>
On 21.03.2024 15:55, Nick Clifton wrote:
> It was recently pointed out to me that objcopy's --section-alignment
> option does not actually set the alignment of any sections. It just
> sets a field in the PE file format's optional header. This is rather
> confusing for the user.
Hmm. For one --file-alignment would then want similar treatment, but
afaict that might be more difficult to achieve (sections would need
moving around in the file). Plus I seem to vaguely recall that there
wants to be a certain correlation between section and file alignments
of individual sections, which you may break with such an adjustment.
> Plus it turns out that even if a section's alignment is set via the
> --set=section-alignment option, its LMA and VMA will not be changed to
> match the new alignment.
Perhaps do just this change in a first step? Albeit ...
> @@ -4267,6 +4289,30 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
> if (!bfd_set_section_alignment (osection, alignment))
> err = _("failed to set alignment");
>
> + /* If the VMA is not aligned and it was not set by the user
> + then adjust it. */
> + if (osection->vma & ((1 << alignment) - 1)
> + && change_section_address == 0
> + && find_section_list (bfd_section_name (isection), false,
> + SECTION_CONTEXT_ALTER_VMA
> + | SECTION_CONTEXT_SET_VMA) == NULL)
> + {
> + osection->vma += (1 << alignment);
> + osection->vma &= ~ ((1 << alignment) -1);
> + }
> +
> + /* If the LMA is not aligned and it was not set by the user
> + then adjust it. */
> + if (osection->lma & ((1 << alignment) - 1)
> + && change_section_address == 0
> + && find_section_list (bfd_section_name (isection), false,
> + SECTION_CONTEXT_ALTER_LMA
> + | SECTION_CONTEXT_SET_LMA) == NULL)
> + {
> + osection->lma += (1 << alignment);
> + osection->lma &= ~ ((1 << alignment) -1);
> + }
... by doing this adjustment, aren't you at risk of creating overlapping
sections? Should --set-section-alignment= perhaps be limited to
relocatable files?
Jan
next prev parent reply other threads:[~2024-03-21 16:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 14:55 Nick Clifton
2024-03-21 16:59 ` Jan Beulich [this message]
2024-03-26 12:44 ` Nick Clifton
2024-03-26 13:08 ` Jan Beulich
2024-03-28 13:08 ` Nick Clifton
2024-03-28 16:57 ` Jan Beulich
2024-04-02 8:45 ` Nick Clifton
2024-04-02 9:19 ` Jan Beulich
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=494659da-1a66-48a9-976d-da19ab55a87e@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@sourceware.org \
--cc=nickc@redhat.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).