[PATCH 3/3] readelf: Add support for AMDGPU code object V6

Simon Marchi simon.marchi@polymtl.ca
Thu May 7 19:25:46 GMT 2026


On 11/7/25 8:42 AM, Jan Beulich wrote:
> On 31.10.2025 18:54, Luis Machado wrote:
>> --- a/binutils/readelf.c
>> +++ b/binutils/readelf.c
>> @@ -5357,6 +5357,20 @@ decode_AMDGPU_machine_flags (char *out, unsigned int e_flags, Filedata *filedata
>>  	}
>>  
>>        e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V4;
>> +
>> +
> 
> Nit: No double blank lines please.

Fixed.

>> +      /* Extensions for HSA v6+.  */
>> +      if (abiversion >= ELFABIVERSION_AMDGPU_HSA_V6)
>> +	{
>> +	  int generic_v;
> 
> unsigned? I.e. the values held can't be negative, can they?

Fixed.

>> +	  generic_v = ((e_flags & EF_AMDGPU_GENERIC_VERSION_V)
>> +		       >> EF_AMDGPU_GENERIC_VERSION_V_SHIFT);
>> +
>> +	  if (generic_v > 0)
>> +	    out += sprintf (out, _(", generic_v%d"), generic_v);
> 
> Seeing that it's gfx9-generic in the example output, why not generic-v%u?

Note that the generic object version is unrelated to the '9' in
gfx9-generic.

  Generic processor (see AMDGPU Generic Processors) code objects are
  versioned (see AMDGPU ELF Header e_flags for Code Object V6 and After)
  between 1 and 255. The version of non-generic code objects is always
  set to 0.

Ref: https://llvm.org/docs/AMDGPUUsage.html#generic-processor-versioning

Do you mean just to use hypens consistently, instead of an underscore?
"llvm-readelf prints it like this already" might be an argument to do it
this way, but I don't really mind, I can change it to "generic-v%u" if
you prefer.  It could even be a space ("generic v%u"), just like there
is a space in the "xnack any" flag.

> 
>> +	  e_flags &= ~EF_AMDGPU_GENERIC_VERSION_V;
>> +	}
>>      }
>>  
>>    if (e_flags != 0)
>> --- a/include/elf/amdgpu.h
>> +++ b/include/elf/amdgpu.h
>> @@ -29,6 +29,7 @@
>>  #define ELFABIVERSION_AMDGPU_HSA_V3 1
>>  #define ELFABIVERSION_AMDGPU_HSA_V4 2
>>  #define ELFABIVERSION_AMDGPU_HSA_V5 3
>> +#define ELFABIVERSION_AMDGPU_HSA_V6 4
>>  
>>  /* Processor selection mask for EF_AMDGPU_MACH_* values.  */
>>  
>> @@ -91,7 +92,7 @@
>>  #define EF_AMDGPU_FEATURE_XNACK_V3   0x100
>>  #define EF_AMDGPU_FEATURE_SRAMECC_V3 0x200
>>  
>> -/* Code object v4 (and later) machine flags.  */
>> +/* Code object v4 (and v5) machine flags.  */
> 
> This looks to contradict the comment in readelf.c saying "Extensions for
> HSA v6+." If the flags below here aren't valid from v6 onwards, doesn't
> readelf.c need more changes?

It looks like all those flags are still valid in v6 (v6 is a superset,
all those flags plus the new EF_AMDGPU_GENERIC_VERSION_V):

https://llvm.org/docs/AMDGPUUsage.html#amdgpu-elf-header-e-flags-table-v6-onwards

So I think we can keep the comment as is.

Simon


More information about the Binutils mailing list