RFC: Objcopy: Section alignment

Jan Beulich jbeulich@suse.com
Tue Mar 26 13:08:20 GMT 2024


On 26.03.2024 13:44, Nick Clifton wrote:
> Hi Jan,
> 
>>>    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.
> 
> Agreed.  I think that I will leave file alignment alone for now.  If necessary
> that can be the subject of a future patch.
> 
>> ... by doing this adjustment, aren't you at risk of creating overlapping
>> sections? Should --set-section-alignment= perhaps be limited to
>> relocatable files?
> 
> Or better yet - not done at all and just left to the user to fix...
> 
> So here is a revised patch that does not change the VMAs or LMAs to match
> new section aligments, but instead issues an error message if they do not
> match.  It also updates the documentation to warn users about this behaviour
> and about the dangers of changing the VMAs of fully linked binaries.
> 
> Any further comments ?

Actually, there are: First, is the last doc hunk still applicable /
appropriately worded? "ensures" in particular I'm not sure about.

Perhaps related to that, the two new diagnostics look more like
errors than warnings to me. I think those ought to be just warnings
(by default at least), especially also with the FIXME for the LMA
related code. Which would in particular mean to not bail early from
setup_section(), and perhaps also to not set "status" to non-zero.

Further, while the new power_of_two() is merely split out code,
that code doesn't (already didn't before) deal with 0 properly. It
would spin indefinitely then afaict, rather than reporting "not a
power of two".

Finally, in the new --section-alignment related diagnostic, wouldn't
you better mention the option name, and not the internal variable's?

Jan


More information about the Binutils mailing list