[v2,3/4] readelf: Add support for AMDGPU code object V6

Message ID 20260507194615.943267-4-simon.marchi@efficios.com
State New
Headers
Series Add support for new AMDGPU architectures |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Simon Marchi May 7, 2026, 7:43 p.m. UTC
  From: Lancelot Six <lancelot.six@amd.com>

AMDGPU code object V6 adds the EF_AMDGPU_GENERIC_VERSION_V field.
Decode it when decoding the e_flags value for amdgpu.

The output for such generic GFX targets will look like:

$ readelf -h gpu.elf
  ELF Header:
    ...
    Flags:     0x1000151, gfx9-generic, xnack any, generic v1
                                                   ----------
    ...

... indicating that this ELF has the "generic code object v1" flag.

Change-Id: I0cb8014fc23150e16f43ab98adb3832ede253c88
Co-Authored-By: Simon Marchi <simon.marchi@efficios.com>
---
 binutils/readelf.c   | 14 ++++++++++++++
 include/elf/amdgpu.h |  6 ++++++
 2 files changed, 20 insertions(+)
  

Patch

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 8b565f085e5a..44fae500859c 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -5405,6 +5405,20 @@  decode_AMDGPU_machine_flags (char *out, unsigned int e_flags, Filedata *filedata
 	}
 
       e_flags &= ~EF_AMDGPU_FEATURE_SRAMECC_V4;
+
+      /* Extensions for HSA v6+.  */
+      if (abiversion >= ELFABIVERSION_AMDGPU_HSA_V6)
+	{
+	  unsigned int generic_v;
+
+	  generic_v = ((e_flags & EF_AMDGPU_GENERIC_VERSION_V)
+		       >> EF_AMDGPU_GENERIC_VERSION_V_SHIFT);
+
+	  if (generic_v > 0)
+	    out += sprintf (out, _(", generic v%u"), generic_v);
+
+	  e_flags &= ~EF_AMDGPU_GENERIC_VERSION_V;
+	}
     }
 
   if (e_flags != 0)
diff --git a/include/elf/amdgpu.h b/include/elf/amdgpu.h
index 747a15c417d1..c0bd74edfa01 100644
--- 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.  */
 
@@ -107,6 +108,11 @@ 
 #define EF_AMDGPU_FEATURE_SRAMECC_OFF_V4         0x800
 #define EF_AMDGPU_FEATURE_SRAMECC_ON_V4          0xc00
 
+/* Code object v6 machine flags.  */
+
+#define EF_AMDGPU_GENERIC_VERSION_V              0xff000000
+#define EF_AMDGPU_GENERIC_VERSION_V_SHIFT        24
+
 /* Notes. */
 
 #define NT_AMDGPU_METADATA                32