[binutils-gdb] readelf: Add support for AMDGPU code object V6

Simon Marchi via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d49acf37a337408fdd5d008c633e7b31497565e3

commit d49acf37a337408fdd5d008c633e7b31497565e3
Author: Lancelot Six <[email protected]>
Date:   Fri Oct 31 17:54:11 2025 +0000

    readelf: Add support for AMDGPU code object V6
    
    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 <[email protected]>

Diff:
---
 binutils/readelf.c   | 14 ++++++++++++++
 include/elf/amdgpu.h |  6 ++++++
 2 files changed, 20 insertions(+)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 205adae1eea..bf27f9eec23 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -5406,6 +5406,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 f5b974ca124..645fef05b08 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.  */
 
@@ -108,6 +109,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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.