binutils/readelf: handle AMDGPU relocation types
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 16 Mar 2022 13:01:54 +0000 (09:01 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Wed, 16 Mar 2022 13:01:54 +0000 (09:01 -0400)
Make readelf recognize AMDGPU relocation types, as documented here:

  https://llvm.org/docs/AMDGPUUsage.html#amdgpu-relocation-records

The user-visible change looks like:

    -000000000004  000400000001 unrecognized: 1       0000000000000000 SCRATCH_RSRC_DWORD0
    -00000000000c  000500000001 unrecognized: 1       0000000000000000 SCRATCH_RSRC_DWORD1
    -000000000014  000600000007 unrecognized: 7       0000000000000000 global_var0
    -00000000001c  000700000008 unrecognized: 8       0000000000000000 global_var1
    -000000000024  000800000009 unrecognized: 9       0000000000000000 global_var2
    -00000000002c  00090000000a unrecognized: a       0000000000000000 global_var3
    -000000000034  000a0000000b unrecognized: b       0000000000000000 global_var4
    +000000000004  000400000001 R_AMDGPU_ABS32_LO 0000000000000000 SCRATCH_RSRC_DWORD0
    +00000000000c  000500000001 R_AMDGPU_ABS32_LO 0000000000000000 SCRATCH_RSRC_DWORD1
    +000000000014  000600000007 R_AMDGPU_GOTPCREL 0000000000000000 global_var0
    +00000000001c  000700000008 R_AMDGPU_GOTPCREL 0000000000000000 global_var1
    +000000000024  000800000009 R_AMDGPU_GOTPCREL 0000000000000000 global_var2
    +00000000002c  00090000000a R_AMDGPU_REL32_LO 0000000000000000 global_var3
    +000000000034  000a0000000b R_AMDGPU_REL32_HI 0000000000000000 global_var4

binutils/ChangeLog:

* readelf.c (dump_relocations): Handle EM_AMDGPU.

include/ChangeLog:

* elf/amdgpu.h: Add relocation values.

Change-Id: I2ed4589f4cd37ea11ad2e0cb38d4b682271e1334

binutils/ChangeLog
binutils/readelf.c
include/ChangeLog
include/elf/amdgpu.h

index eb8c1975837357d04c15f4a24e37ece4f74597c2..6d49d8c71258d786dae3d14878dd07e8efe421d9 100644 (file)
@@ -1,3 +1,7 @@
+2022-03-16  Simon Marchi  <simon.marchi@efficios.com>
+
+       * readelf.c (dump_relocations): Handle EM_AMDGPU.
+
 2022-03-16  Simon Marchi  <simon.marchi@efficios.com>
 
        * Makefile.am (readelf_CFLAGS): New.
index ff07112eb8437eefb7a5dfbc4bee016c3dd4cf2f..a2dbaa4722e3f4e583729a01dd6c3c4ec170a6c7 100644 (file)
@@ -1930,6 +1930,9 @@ dump_relocations (Filedata *          filedata,
          rtype = elf_loongarch_reloc_type (type);
          break;
 
+       case EM_AMDGPU:
+         rtype = elf_amdgpu_reloc_type (type);
+         break;
        }
 
       if (rtype == NULL)
index 64aeb12839860804d987459b3eaaf48981bd7774..82194629c97d361d12b3e9650ff7f70775383e76 100644 (file)
@@ -1,3 +1,7 @@
+2022-03-16  Simon Marchi  <simon.marchi@efficios.com>
+
+       * elf/amdgpu.h: Add relocation values.
+
 2022-03-16  Simon Marchi  <simon.marchi@efficios.com>
 
        * elf/amdgcn.h (NT_AMDGPU_METADATA): New.
index e3c90dc74e85df935c757c3aaa64f1a22167b17a..140e8996ad2514b984477e482bb081d7a0241b64 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef _ELF_AMDGPU_H
 #define _ELF_AMDGPU_H
 
+#include "elf/reloc-macros.h"
+
 /* e_ident[EI_ABIVERSION] values, when e_ident[EI_OSABI] is
    ELFOSABI_AMDGPU_HSA.  */
 
 
 #define NT_AMDGPU_METADATA                32
 
+/* Relocations.  */
+
+START_RELOC_NUMBERS (elf_amdgpu_reloc_type)
+ RELOC_NUMBER (R_AMDGPU_NONE,           0)
+ RELOC_NUMBER (R_AMDGPU_ABS32_LO,       1)
+ RELOC_NUMBER (R_AMDGPU_ABS32_HI,       2)
+ RELOC_NUMBER (R_AMDGPU_ABS64,          3)
+ RELOC_NUMBER (R_AMDGPU_REL32,          4)
+ RELOC_NUMBER (R_AMDGPU_REL64,          5)
+ RELOC_NUMBER (R_AMDGPU_ABS32,          6)
+ RELOC_NUMBER (R_AMDGPU_GOTPCREL,       7)
+ RELOC_NUMBER (R_AMDGPU_GOTPCREL32_LO,  8)
+ RELOC_NUMBER (R_AMDGPU_GOTPCREL32_HI,  9)
+ RELOC_NUMBER (R_AMDGPU_REL32_LO,      10)
+ RELOC_NUMBER (R_AMDGPU_REL32_HI,      11)
+ RELOC_NUMBER (R_AMDGPU_RELATIVE64,    13)
+ RELOC_NUMBER (R_AMDGPU_REL16,         16)
+END_RELOC_NUMBERS (R_AMDGPU_max)
+
 #endif /* _ELF_AMDGPU_H */