.section directives with the same name but different fields

Alan Modra amodra@gmail.com
Thu Feb 6 08:33:00 GMT 2020


On Wed, Feb 05, 2020 at 11:38:37PM -0800, Fangrui Song wrote:
> ## Different sh_entsize
> 
> .section .foo,"aM",@progbits,4
> .section .foo,"aM",@progbits,8
> 
> GNU as emits a warning `Warning: ignoring changed section entity size for .foo`

I think this one probably should be an error rather than a warning.

> The output sh_entsize is 4. If the second .section defines an object, the object may get corrupted after merging
> (https://bugs.llvm.org/show_bug.cgi?id=43457 )
> For this case, we have several choices:
> 
> 1. (Status quo) Emit one section. Set sh_entsize to 4 and emit a warning.
> 2. Emit two sections, i.e. sh_entsize is a differentiator.

If you do, the linker won't do merging of values for those sections.

> 3. Emit one section. Set sh_entsize to 0. Should the assembler emit a warning?

And remove SHF_MERGE too I guess.  That's an option but I think it's
better just to error.

> 
> ## Different sh_flags
> 
> .section .foo,"aw"
> .section .foo,"a" # Warning: ignoring changed section attributes for .foo
> 
> Shall we emit two sections?

I don't think so.  User assembly often gets section attributes wrong
or leaves them off entirely for special sections known to the
assembler.  ie. the first .section .foo above is a built-in rather
than user input.

> 
> ## Different sh_type
> 
> .section .foo,"a",@progbits
> .section .foo,"a",@nobits   # Warning: ignoring changed section type for .foo
> 
> Shall we emit two sections?

Again we should continue to handle the case where .foo is a special
section of known type.  So I think a warning rather than creating two
sections is appropriate.

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list