don't over-align file positions of PE executable sections
authorJan Beulich <jbeulich@suse.com>
Thu, 19 May 2022 10:43:10 +0000 (12:43 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 19 May 2022 10:43:10 +0000 (12:43 +0200)
commitbc5baa9f13ffb3fd4c39f1a779062bfb3a980cea
treea1f48c77e0649e279fac9a94aded93f1b53c3d9a
parent5f3fc928df037b21ee401d7115951b988a3ea571
don't over-align file positions of PE executable sections

When a sufficiently small alignment was specified via --file-alignment,
individual section alignment shouldn't affect placement within the file.
This involves first of all clearing D_PAGED for images when section and
file alignment together don't permit paging of the image. The involved
comparison against COFF_PAGE_SIZE in turn helped point out (through a
compiler warning) that 'page_size' should be of unsigned type (as in
particular FileAlignment is). This yet in turn pointed out a dubious
error condition (which is being deleted).

For the D_PAGED case I think the enforced file alignment may still be
too high, but I'm wary of changing that logic without knowing of
possible corner cases.

Furthermore file positions in PE should be independent of the alignment
recorded in section headers anyway. Otherwise there are e.g. anomalies
following commit 6f8f6017a0c4 ("PR27567, Linking PE files adds alignment
section flags to executables") in that linking would use information a
subsequent processing step (e.g. stripping) wouldn't have available
anymore, and hence a binary could change in that 2nd step for no actual
reason. (Similarly stripping a binary linked with a linker pre-dating
that commit would change the binary again when stripping it a 2nd time.)
bfd/coffcode.h