[PATCH v1 4/7] ld.texi: Add ASCII to info file

Ulf Samuelsson binutils@emagii.com
Fri Jul 5 15:38:31 GMT 2024


Den 2024-07-02 kl. 10:12, skrev Jan Beulich:
> First: Please don't drop the mailing list from Cc. Second: Please don't
> top-post.
>
> On 02.07.2024 00:21, Ulf Samuelsson wrote:
>> I submitted the code in this patch series more than a year ago, and it got accepted.
>> Then a lot was reverted since I had not assigned the copyright to FSF.
>> For unknown reasons, my ASCIZ patches remained, but the ASCII stuff was reverted.
>> The reason for the naming is to be similar to how I remember naming in some assemblers where ASCIZ is zero terminated and ASCII is not zero terminated.
>>
>> If the string is too long, so it does not fit, it is really an error.
>> Adding a zero when truncating is a little less intrusive and may reduce runtime errors.
>> ASCII tells people what it is meant to be doing. ASCIIZ will make a lot of people wonder what the difference is between ASCIZ and ASCIIZ. It will also be misleading, because it does not add a zero if the string fits.
> Then did I read the code wrong? I was left with the impression that you'll
> truncate at size-1, to ensure zero termination. Plus as you say in this
> doc, size being 0 results in ASCIZ behavior, i.e. zero-terminates too.

              "          111111"
              "0123456789012345"

   ASCII (16) "This is a string"

   results in 'size' == 16. Since the string is 16 characters, 'len' 
will be 16 as well.

   This loop will be run 16 times, and i will be 16 at the exit of

   for (i = 0; i < len; i++)
     lang_add_data (BYTE, exp_intop (string[i]));

   Since i == 16, and size == 16, the following loop will not be run 
even once.

   while (i++ < size)
     lang_add_data (BYTE, exp_intop ('\0'));

   so no '\0' will be added.

===============================

   ASCII (16) "This is a string."

   size = 16, len = 17.  len > size, solen is set to 16-1 = 15.

   copy the first 15 characters in the first loop, add a single '\0' in 
the second loop.

===============================

   ASCII (16) "This is string"

   size = 16, len = 14

   copy the first 14 characters in the first loop, add a '\0' twice in 
the second loop.


>
>> I would prefer the syntax ”ASCII <size>, string” but I never got it to work. Adding parantheses made it work.
>> ”ASCII (<size>, string)” seems downright ugly and also very different from the ASCIZ directive.
> In which case I have to question that original ASCIZ directive's syntax.
> Imo it should have used parentheses, too, matching other statements with
> "operands". Together with requiring quotation, overloading ASCIZ then
> wouldn't have been a problem now.
>
> Jan

-- 
Best Regards
Ulf Samuelsson



More information about the Binutils mailing list