[PATCH] gas: check section size against entry size

Jan Beulich jbeulich@suse.com
Mon Jul 14 09:11:36 GMT 2025


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.
---
Does the warning perhaps need hiding behind a (default-off) command line
option?

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.

As far as the linker is concerned, I find it difficult to establish a
sensible checking strategy: On one hand multiple sections with otherwise
similar attributes would better have matching entry size too. Otoh all
kinds of input sections may be merged into a single output one, and we
likely can't expect them to all match in this regard. Maybe the
granularity of such checking would want to be any single Input Section
Description?

--- a/gas/write.c
+++ b/gas/write.c
@@ -632,6 +632,10 @@ size_seg (bfd *abfd ATTRIBUTE_UNUSED, as
 #ifdef obj_frob_section
   obj_frob_section (sec);
 #endif
+
+  if (sec->entsize && (sec->size % sec->entsize))
+    as_warn (_("section `%s' size (%#" PRIx64 ") is not a multiple of its entry size %#x"),
+	     sec->name, (uint64_t) sec->size, sec->entsize);
 }
 
 #ifdef DEBUG2


More information about the Binutils mailing list