[PATCH] gas: check section size against entry size

Jan Beulich jbeulich@suse.com
Mon Jul 14 11:30:13 GMT 2025


On 14.07.2025 12:14, Alan Modra wrote:
> On Mon, Jul 14, 2025 at 11:11:36AM +0200, Jan Beulich wrote:
>> If a section has a non-zero entry size, its total size would generally
>> better be a multiple of the entry size. Warn if that's not the case.
> 
> Makes sense.
> 
>> Does the warning perhaps need hiding behind a (default-off) command line
>> option?
> 
> Not unless it triggers too much.  :-)

Good (the testsuite is fine; we'll see what people report). I wasn't really
fancying to add one.

>> For ELF, the spec doesn't mandate that only SHF_MERGE and SHF_STRINGS
>> sections may have a non-zero entry size. Should we permit other sections
>> to also have an entry size specified (e.g. via one of the presently
>> unused section letters 'E', 'z', or 'Z')? That way custom sections with
>> fixed element size could leverage e.g. the warning being added here.
> 
> I wouldn't be inclined to add such support until someone wants it
> enough to provide a patch.

That's going to be me then. I came to notice the lack of the warning while
experimenting with exactly the above, and specifically to have this kind
of warning generated (in the project I'm mainly working on). IOW the
question wasn't so much "whether to" but rather whether doing so might
conflict with anything I'm unaware of. Plus perhaps whether one of the
suggested letters would be preferable.

>> As far as the linker is concerned, I find it difficult to establish a
>> sensible checking strategy:
> 
> Maybe only for ld -r?

That may be a little too little. Plus would it buy use much to limit things
like this? Arbitrary input sections can be folded into a single output one
there as well, can't they?

Jan


More information about the Binutils mailing list