RFC: generating a header using the linker (ASCII, ASCIZ commands)

Nick Clifton nickc@redhat.com
Mon Feb 13 10:09:09 GMT 2023


Hi Ulf,

> My very first mailing to the list. 

Well then welcome to the binutils community.


> One of the problems was that we wanted to generate a header,
> and for various reasons, it was desirable to have the linker generate the header

 From the sound of what you have written below it would be
easier to use the assembler to create the header and then just
include it as another object file when you perform your link.
That together with a customised linker script should allow you
to achieve what you want without having to add new code to the
linker.


> The text area should be aligned with a flash erase sector.

This should be possible using a linker script.  You can use the MEMORY
directive to specify the flash memory region(s) and the various section
alignment and assignment directives to put the text section where you
want.


>      I could not see a way to align easily to the flash boundaries and add fill-

Perhaps you could provide an example of what you want to achieve ?
I am pretty sure that it can be done using linker script directives.


> 2: How generate the CRC? It would be good to have such an application in binutils.
> 
>     I ported the ielfutils from
> 
>      IAR has a windows command line program which is open source (ielfutils) so
>      I ported that to Linux

Well if you already have a tool, then that is fine.

It is true that the binutils does not have a tool specifically for the creation
of CRCs, but then that does seem to be a bit of a niche application.

In theory you might be able to use the objcopy command to extract the text section
which you could then pass to a tool to generate the CRC.

Also - could you use the build-id mechanism instead ?  That would create a
special section containing a CRC-like value which your run-time system could
access.


> 3. You  want strings in the header. Not just BYTEs, SHORTs and LONGs etc.
> 
>      It is of course possible to emulate strings using the above functions but not so nice.

Agreed.  Having a couple of string directives supported in the linker
syntax would be nice.


> Depending on the size of the string, I can get warnings: 
> "warning: unsupported relocation type 1051152 at ffad8"

Hmmm, this looks like memory corruption of some kind.

I looked over the code you provided and it looks good, but that
was just a visual check.  I would have to have an actual reproducer
in order to investigate further.


> +     for (bfd_vma i = 0 ; i < size ; i++) {
> +        new_stmt = new_stat (lang_data_statement, stat_ptr);
> +        new_stmt->exp = exp_intop(s[i]);
> +        new_stmt->type = BYTE;
> +     }

FYI - this loop (and the one below) could be simplified to:

   for (bfd_vma i = 0; i < size; i++)
     lang_add_data (BYTYE, exp_intop(s[i]);





More information about the Binutils mailing list