determining output section type
Alan Modra
amodra@gmail.com
Thu Nov 4 02:01:12 GMT 2021
On Wed, Nov 03, 2021 at 01:40:52PM +0100, Rasmus Villemoes wrote:
> Hi
>
> I've observed that there has been some change between 2.34 and 2.35 (and
> from some 'git grep'/'git blame' I suspect commit 8c803a2dd7d3
> (elf_backend_section_flags and _bfd_elf_init_private_section_data))
> which ends up breaking module loading on our old vxworks platform.
Yes, that probably is the commit that broke things for you. The
output section type is now being taken from the type of the first
input section present. With your script you'd get SHT_PREINIT_ARRAY
if you happened to be linking any .preinit_array sections.
> The issue is that the .data section now ends up having type INIT_ARRAY
> rather than PROGBITS, and the ELF loader on target doesn't know anything
> about that section type, so it ignores it. We use a custom linker
> script, part of which reads
>
> .data 0 :
> {
> PROVIDE(__start_data = .);
>
> _ctors = .;
> KEEP (*(.preinit_array))
> KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*)))
> KEEP (*(.init_array))
> LONG(0)
>
> ...
> *(.data)
> *(.data.*) *(.gnu.linkonce.d*) *(.data1)
> PROVIDE(__stop_data = .);
> }
>
> If I rearrange this to put the *(.data) stanza at the beginning, the
> .data section in the output file does get type PROGBITS, but only if any
> of the input .data sections are non-empty. I could arrange for that in
> the toolchain I build since that includes linking in a crtbegin.o that I
> control, but it seems a little wasteful and fragile.
>
> Is there some way in the linker script (or otherwise) to force .data to
> have type PROGBITS? I'd rather not need a post-processing step editing
> the ELF file, even if it could be done with objcopy or similar.
No, I think you have already found the only way to get SHT_PROGBITS in
this case. Incidentally, it isn't necessary that the input .data
section is non-empty, just that one is present.
I used
.data :
{
empty.o*(.data)
...
.init_array and the like
...
*(.data)
...
}
That makes the output section SHT_PROGBITS even though empty.o has a
zero size .data and I placed empty.o last on the ld command line.
This works with 2.35 and current mainline.
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list