public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: binutils@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 7/7] binutils/readelf: handle AMDGPU relocation types
Date: Tue, 15 Mar 2022 15:43:03 -0400	[thread overview]
Message-ID: <20220315194303.3716792-8-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20220315194303.3716792-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

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/readelf.c   |  3 +++
 include/elf/amdgpu.h | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/binutils/readelf.c b/binutils/readelf.c
index ff07112eb843..a2dbaa4722e3 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -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)
diff --git a/include/elf/amdgpu.h b/include/elf/amdgpu.h
index e3c90dc74e85..140e8996ad25 100644
--- a/include/elf/amdgpu.h
+++ b/include/elf/amdgpu.h
@@ -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.  */
 
@@ -91,4 +93,23 @@
 
 #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 */
-- 
2.35.1


  parent reply	other threads:[~2022-03-15 19:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 19:42 [PATCH 0/7] Add AMDGCN support to readelf Simon Marchi
2022-03-15 19:42 ` [PATCH 1/7] bfd: add AMDGCN architecture Simon Marchi
2022-03-15 19:42 ` [PATCH 2/7] opcodes: handle bfd_amdgcn_arch in configure script Simon Marchi
2022-03-15 19:42 ` [PATCH 3/7] binutils/readelf: handle AMDGPU OS ABIs Simon Marchi
2022-03-15 19:43 ` [PATCH 4/7] binutils/readelf: decode AMDGPU-specific e_flags Simon Marchi
2022-03-15 19:43 ` [PATCH 5/7] binutils/readelf: handle NT_AMDGPU_METADATA note name Simon Marchi
2022-03-15 19:43 ` [PATCH 6/7] binutils/readelf: build against msgpack, dump NT_AMDGPU_METADATA note contents Simon Marchi
2022-03-15 19:43 ` Simon Marchi [this message]
2022-03-16  0:08 ` [PATCH 0/7] Add AMDGCN support to readelf Alan Modra
2022-03-16 13:02   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220315194303.3716792-8-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=binutils@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).