[PATCH 1/3] Make UTF-8 output simpler and easier to read.

Andrew C Aitchison werdna@aitchison.me.uk
Tue Sep 23 07:23:00 GMT 2025


On Tue, 23 Sep 2025, Jan Beulich wrote:

> On 13.09.2025 17:12, Andrew C Aitchison wrote:
>> ---
>>  binutils/nm.c      | 19 +++++++++----------
>>  binutils/objdump.c | 19 +++++++++----------
>>  binutils/readelf.c | 19 +++++++++----------
>>  binutils/strings.c | 23 +++++++++++------------
>>  4 files changed, 38 insertions(+), 42 deletions(-)
>
> Largely okay; a number of cosmetics, though:

Yes.
I am used to projects which object to 8 character tab spacing, and 
prefer to avoid tabs altogether.
I have not found any description (for human or computer) of the 
binutils style, and I see no response from binutils to the suggestion
from gdb to having an optional clang-format config:
   https://sourceware.org/pipermail/binutils/2025-September/143986.html
In the absence of a house style I don't know what to change my editor
to do and seem to have failed to stop it from upsetting your preferences.


>> --- a/binutils/nm.c
>> +++ b/binutils/nm.c
>> @@ -553,22 +553,21 @@ display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
>>        switch (nchars)
>>  	{
>>  	case 2:
>> -	  out += sprintf (out, "\\u%02x%02x",
>> -		  ((in[0] & 0x1c) >> 2),
>> -		  ((in[0] & 0x03) << 6) | (in[1] & 0x3f));
>> +	  out += sprintf (out, "\\u%04x",
>> +		  ((in[0] & 0x1f) << 6) | (in[1] & 0x3f));
>>  	  break;
>>
>>  	case 3:
>> -	  out += sprintf (out, "\\u%02x%02x",
>> -		  ((in[0] & 0x0f) << 4) | ((in[1] & 0x3c) >> 2),
>> -		  ((in[1] & 0x03) << 6) | ((in[2] & 0x3f)));
>> +	  out += sprintf (out, "\\u%04x",
>> +		  ((in[0] & 0x0f) << 12) | ((in[1] & 0x3f) << 6) | ((in[2] & 0x3f)) );
>
> Here any below, please avoid the extra blank before the final parenthesis.

This is the second time I have been asked me to change something which 
I find makes the code more readable - that space makes it easier for me to 
see whether the parentheses are balanced.
(The first was that Alan asked that there be no trailing operators
- I find they make it easier to know how this line connects with the next 
one.)

It is all subjective preference, but the project doesn't seem to
make its preferences clear for me to follow.

>> --- a/binutils/readelf.c
>> +++ b/binutils/readelf.c
>> @@ -833,24 +833,23 @@ print_symbol_name (signed int width, const char * symbol)
>>  		case 2:
>>  		  if (width_remaining < 6)
>>  		    break;
>> -		  printf ("\\u%02x%02x",
>> -			  (bytes[0] & 0x1c) >> 2,
>> -			  ((bytes[0] & 0x03) << 6) | (bytes[1] & 0x3f));
>> +		  printf ("\\u%04x",
>> +				  ((bytes[0] & 0x1f) << 6) | (bytes[1] & 0x3f));
>
> There looks to be an indentation issue here (and again further down).
>
>>  		  break;
>>  		case 3:
>>  		  if (width_remaining < 6)
>>  		    break;
>> -		  printf ("\\u%02x%02x",
>> -			  ((bytes[0] & 0x0f) << 4) | ((bytes[1] & 0x3c) >> 2),
>> -			  ((bytes[1] & 0x03) << 6) | (bytes[2] & 0x3f));
>> +		  printf ("\\u%04x",
>> +				  ((bytes[0] & 0x0f) << 12) | ((bytes[1] & 0x3f) << 6) | ((bytes[2] & 0x3f)) );
>
> This line also has grown too long.
>
>> --- a/binutils/strings.c
>> +++ b/binutils/strings.c
>> @@ -739,27 +739,26 @@ display_utf8_char (const unsigned char * buffer)
>>      case unicode_escape:
>>      case unicode_highlight:
>>        if (unicode_display == unicode_highlight && isatty (1))
>> -	printf ("\x1B[31;47m"); /* Red.  */
>> +        printf ("\x1B[31;47m"); /* Red.  */
>
> Why is the tab being replaced by 8 blanks here? In fact, why is this line
> being touched at all?

Editor. Or me failing to undo the damage of my editor.
As I tried to say in my other reply, what is the point of git-format-patch
if I have to hand-edit the patches.

>>        switch (utf8_len)
>> -	{
>> +        {
>>  	case 2:
>> -	  printf ("\\u%02x%02x",
>> -		  ((buffer[0] & 0x1c) >> 2),
>> -		  ((buffer[0] & 0x03) << 6) | (buffer[1] & 0x3f));
>> +	  printf ("\\u%04x",
>> +	    ((buffer[0] & 0x1f) << 6) | (buffer[1] & 0x3f));
>
> Indentation of the continuation line looks to previously have been correct,
> but now it's not. (Again, same below.)

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew@aitchison.me.uk


More information about the Binutils mailing list