[PATCH 1/1] Correct -Ue output for nm, objdump and readelf, like PR33360 does for strings.

Jan Beulich jbeulich@suse.com
Mon Sep 8 13:16:24 GMT 2025


On 05.09.2025 20:02, Andrew C Aitchison wrote:
> Signed-off-by: Andrew C Aitchison <github@aitchison.me.uk>
> ---
>  binutils/nm.c      | 4 ++--
>  binutils/objdump.c | 4 ++--
>  binutils/readelf.c | 4 ++--
>  3 files changed, 6 insertions(+), 6 deletions(-)

Much like the strings change this is okay to put in, while at the same time
I think we want to move to what you described in another reply, uniformly
using \unnnn and \Unnnnnnnn. I'm further wondering whether going just up to
4 input chars in the functions is actually sufficient. Aiui in all four
instances at least a sanity check is missing, guarding against us treating
a 5- or more char sequence as a 4-char one, breaking the stream of bytes.

Aiui this wants committing on your behalf?

Jan

> diff --git a/binutils/nm.c b/binutils/nm.c
> index dce9207f44f..6aa5143d6f2 100644
> --- a/binutils/nm.c
> +++ b/binutils/nm.c
> @@ -565,8 +565,8 @@ display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
>  
>  	case 4:
>  	  out += sprintf (out, "\\u%02x%02x%02x",
> -		  ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2),
> -		  ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2),
> +		  ((in[0] & 0x07) << 2) | ((in[1] & 0x30) >> 4),
> +		  ((in[1] & 0x0f) << 4) | ((in[2] & 0x3c) >> 2),
>  		  ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
>  	  break;
>  	default:
> diff --git a/binutils/objdump.c b/binutils/objdump.c
> index 0bea4d0761c..0af4889a564 100644
> --- a/binutils/objdump.c
> +++ b/binutils/objdump.c
> @@ -659,8 +659,8 @@ display_utf8 (const unsigned char * in, char * out, unsigned int * consumed)
>  
>  	case 4:
>  	  out += sprintf (out, "\\u%02x%02x%02x",
> -		  ((in[0] & 0x07) << 6) | ((in[1] & 0x3c) >> 2),
> -		  ((in[1] & 0x03) << 6) | ((in[2] & 0x3c) >> 2),
> +		  ((in[0] & 0x07) << 2) | ((in[1] & 0x30) >> 4),
> +		  ((in[1] & 0x0f) << 4) | ((in[2] & 0x3c) >> 2),
>  		  ((in[2] & 0x03) << 6) | ((in[3] & 0x3f)));
>  	  break;
>  	default:
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index 03c4520ff92..44eee71cedf 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -848,8 +848,8 @@ print_symbol_name (signed int width, const char * symbol)
>  		  if (width_remaining < 8)
>  		    break;
>  		  printf ("\\u%02x%02x%02x",
> -			  ((bytes[0] & 0x07) << 6) | ((bytes[1] & 0x3c) >> 2),
> -			  ((bytes[1] & 0x03) << 6) | ((bytes[2] & 0x3c) >> 2),
> +			  ((bytes[0] & 0x07) << 2) | ((bytes[1] & 0x30) >> 4),
> +			  ((bytes[1] & 0x0f) << 4) | ((bytes[2] & 0x3c) >> 2),
>  			  ((bytes[2] & 0x03) << 6) | (bytes[3] & 0x3f));
>  
>  		  break;



More information about the Binutils mailing list