determining output section type
Rasmus Villemoes
rasmus.villemoes@prevas.dk
Thu Nov 4 07:47:47 GMT 2021
On 04/11/2021 03.01, Alan Modra wrote:
> On Wed, Nov 03, 2021 at 01:40:52PM +0100, Rasmus Villemoes wrote:
>> Hi
>>
>> 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.
Hm, I wonder why that didn't work for me with an empty .data section and
moving the whole *(.data) to the beginning...
Ah, found it: I was using --gc-sections, and obviously an empty input
doesn't have any references to it. Wrapping the crtbegin.o(.data) in
KEEP() makes it work.
Thanks, I think I now have something that will work without modifying
the build system or the flags passed to ld.
Rasmus
More information about the Binutils
mailing list