[v4,0/6] ASCIZ Command for output section

Message ID 20230213162009.15515-1-binutils@emagii.com
Headers
Series ASCIZ Command for output section |

Message

Frager, Neal via Binutils Feb. 13, 2023, 4:20 p.m. UTC
  Introduce an ASCIZ command for an output section
When generating a header for an embedded system
there is often a need to add text information.

There are arguments for generating the header in the linker
instead of compiling the header as part of the program.
The lack of support for strings makes this process a bit unwieldy.

The ASCIZ command allows you to specify a zero-terminated string as a parameter.

Example:

    ASCIZ "This is a string"

The string contains 16 characters, but a NUL character is added to the end,
so the areas reserved is 16+1 = 17 characters.

The string may contain '\n', '\r', '\t' and octals, but not hex characters.

Ideally, there should be a command which reserves a fixed size area.

I:E:

    ASCII 20, "This is a string"

but I have failed to get make this work in 'ld',
so this patch series is limited to ASCIZ.

[PATCH v4 1/6] Document the ASCIZ command
[PATCH v4 2/6] Add ASCIZ to NEWS
[PATCH v4 3/6] Add ASCIZ to testsuite
[PATCH v4 4/6] ldlex.l: Add ASCIZ token
[PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command
[PATCH v4 6/6] Parse ASCIZ command
  

Comments

Ulf Samuelsson Feb. 13, 2023, 4:24 p.m. UTC | #1
Looks like I reached the mail limit PATCH V4 6/6 changed V3 like this:

-        int value = c;
+        int value = c - '0';

Best Regards
Ulf Samuelsson

Den 2023-02-13 kl. 17:20, skrev Ulf Samuelsson via Binutils:
> Introduce an ASCIZ command for an output section
> When generating a header for an embedded system
> there is often a need to add text information.
>
> There are arguments for generating the header in the linker
> instead of compiling the header as part of the program.
> The lack of support for strings makes this process a bit unwieldy.
>
> The ASCIZ command allows you to specify a zero-terminated string as a parameter.
>
> Example:
>
>      ASCIZ "This is a string"
>
> The string contains 16 characters, but a NUL character is added to the end,
> so the areas reserved is 16+1 = 17 characters.
>
> The string may contain '\n', '\r', '\t' and octals, but not hex characters.
>
> Ideally, there should be a command which reserves a fixed size area.
>
> I:E:
>
>      ASCII 20, "This is a string"
>
> but I have failed to get make this work in 'ld',
> so this patch series is limited to ASCIZ.
>
> [PATCH v4 1/6] Document the ASCIZ command
> [PATCH v4 2/6] Add ASCIZ to NEWS
> [PATCH v4 3/6] Add ASCIZ to testsuite
> [PATCH v4 4/6] ldlex.l: Add ASCIZ token
> [PATCH v4 5/6] ldgram.y: Add 'ASCIZ <string>' command
> [PATCH v4 6/6] Parse ASCIZ command
>
  
Nick Clifton Feb. 14, 2023, 10:16 a.m. UTC | #2
Hi Ulf,

> Introduce an ASCIZ command for an output section
> When generating a header for an embedded system
> there is often a need to add text information.

Thanks for contributing this patch series.  I have applied
the patches with a few minor tweaks - mostly to the new
test case so that it did not cause new failures on targets
which pad code to an alignment greater than 4 bytes.

Cheers
   Nick
  
Ulf Samuelsson Feb. 14, 2023, 4:07 p.m. UTC | #3
Thank You.

I will start to try to implement the "ASCII" command as well.

ASCII <length> , <string>

I had some problems with getting syntax errors on this so I think
I will send in a preliminary patchset and see if anyone can spot an 
obvious error.


One question:
    The lang_add_string contains an error message if the string does not 
fit into the allocated area.
    This will never get triggered by the ASCIZ command, since that will 
allocate the size of the string.
    If you specify a size to the ASCII command and then provide a longer 
string it will trigger.

    There are no translations for the string at the moment.

    Will the linker output the English string, or what?

    What is the procedure to get a translation?
    I can provide a Swedish translation at the least.

Best Regards
Ulf Samuelsson

Den 2023-02-14 kl. 11:16, skrev Nick Clifton:
> Hi Ulf,
>
>> Introduce an ASCIZ command for an output section
>> When generating a header for an embedded system
>> there is often a need to add text information.
>
> Thanks for contributing this patch series.  I have applied
> the patches with a few minor tweaks - mostly to the new
> test case so that it did not cause new failures on targets
> which pad code to an alignment greater than 4 bytes.
>
> Cheers
>   Nick
>
>
  
Nick Clifton Feb. 14, 2023, 4:20 p.m. UTC | #4
Hi Ulf,

> One question:
>     The lang_add_string contains an error message if the string does not fit into the allocated area.
>     This will never get triggered by the ASCIZ command, since that will allocate the size of the string.
>     If you specify a size to the ASCII command and then provide a longer string it will trigger.

Ah - you know that I mentioned that I had tidied up the code
a little bit ?  Well the other area I tidied was the lang_add_string
function.  I simplified it, removed the redundant size checking code
and string padding code, and changed the stacked if-statements into
a simpler switch-statement...

So currently there are no messages that need translation,


>   There are no translations for the string at the moment. 
>    Will the linker output the English string, or what?

If a translation for a specific string is not available then it will
just be displayed as-is.  So in this case the English version will be
used.


>     What is the procedure to get a translation?

The hard way:

   Create a new ld/po/ld.pot file and send it to the Translation Project
   with a request for new translations:
     https://translationproject.org/html/maintainers.html

The easy way:

   Wait for the next official release of the binutils.  As part of
   the process for creating a release I take care of asking the Translation
   Project to update the translation files.

   Note - this does not mean that new translations will be created
   for all supported languages.  The translation project runs on a
   volunteer basis and it is up the the volunteers to find time to
   create new translations and/or update old translations.


>     I can provide a Swedish translation at the least.

If you would like to volunteer some time to the Translation Project
I am sure that they would love to hear from you.

Cheers
   Nick