xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/elf64-amdgcn.c (revision c42dbd0ed2e61fe6eda8590caa852ccf34719964)
1*c42dbd0eSchristos /* AMDGCN ELF support for BFD.
2*c42dbd0eSchristos 
3*c42dbd0eSchristos    Copyright (C) 2019-2022 Free Software Foundation, Inc.
4*c42dbd0eSchristos 
5*c42dbd0eSchristos    This file is part of BFD, the Binary File Descriptor library.
6*c42dbd0eSchristos 
7*c42dbd0eSchristos    This program is free software; you can redistribute it and/or modify
8*c42dbd0eSchristos    it under the terms of the GNU General Public License as published by
9*c42dbd0eSchristos    the Free Software Foundation; either version 3 of the License, or
10*c42dbd0eSchristos    (at your option) any later version.
11*c42dbd0eSchristos 
12*c42dbd0eSchristos    This program is distributed in the hope that it will be useful,
13*c42dbd0eSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c42dbd0eSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c42dbd0eSchristos    GNU General Public License for more details.
16*c42dbd0eSchristos 
17*c42dbd0eSchristos    You should have received a copy of the GNU General Public License
18*c42dbd0eSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19*c42dbd0eSchristos 
20*c42dbd0eSchristos /* This file handles ELF files that are of the AMDGCN architecture.  The
21*c42dbd0eSchristos    format is documented here:
22*c42dbd0eSchristos 
23*c42dbd0eSchristos      https://llvm.org/docs/AMDGPUUsage.html#elf-code-object */
24*c42dbd0eSchristos 
25*c42dbd0eSchristos #include "sysdep.h"
26*c42dbd0eSchristos #include "bfd.h"
27*c42dbd0eSchristos #include "libbfd.h"
28*c42dbd0eSchristos #include "elf-bfd.h"
29*c42dbd0eSchristos #include "elf/amdgpu.h"
30*c42dbd0eSchristos 
31*c42dbd0eSchristos #include <string.h>
32*c42dbd0eSchristos 
33*c42dbd0eSchristos static bool
elf64_amdgcn_object_p(bfd * abfd)34*c42dbd0eSchristos elf64_amdgcn_object_p (bfd *abfd)
35*c42dbd0eSchristos {
36*c42dbd0eSchristos   Elf_Internal_Ehdr *hdr = elf_elfheader (abfd);
37*c42dbd0eSchristos   unsigned int mach;
38*c42dbd0eSchristos   unsigned char osabi;
39*c42dbd0eSchristos   unsigned char osabi_version;
40*c42dbd0eSchristos 
41*c42dbd0eSchristos   BFD_ASSERT (hdr->e_machine == EM_AMDGPU);
42*c42dbd0eSchristos 
43*c42dbd0eSchristos   osabi = hdr->e_ident[EI_OSABI];
44*c42dbd0eSchristos   osabi_version = hdr->e_ident[EI_ABIVERSION];
45*c42dbd0eSchristos 
46*c42dbd0eSchristos   /* Objects with OS ABI HSA version 2 encoded the GPU model differently (in a
47*c42dbd0eSchristos      note), but they are deprecated, so we don't need to support them.  Reject
48*c42dbd0eSchristos      them specifically.
49*c42dbd0eSchristos 
50*c42dbd0eSchristos      At the time of writing, all AMDGCN objects encode the specific GPU
51*c42dbd0eSchristos      model in the EF_AMDGPU_MACH field of e_flags.  */
52*c42dbd0eSchristos   if (osabi == ELFOSABI_AMDGPU_HSA
53*c42dbd0eSchristos       && osabi_version < ELFABIVERSION_AMDGPU_HSA_V3)
54*c42dbd0eSchristos     return false;
55*c42dbd0eSchristos 
56*c42dbd0eSchristos   mach = elf_elfheader (abfd)->e_flags & EF_AMDGPU_MACH;
57*c42dbd0eSchristos 
58*c42dbd0eSchristos   /* Avoid matching non-AMDGCN AMDGPU objects (e.g. r600).  */
59*c42dbd0eSchristos   if (mach < EF_AMDGPU_MACH_AMDGCN_MIN)
60*c42dbd0eSchristos     return false;
61*c42dbd0eSchristos 
62*c42dbd0eSchristos   bfd_default_set_arch_mach (abfd, bfd_arch_amdgcn, mach);
63*c42dbd0eSchristos   return true;
64*c42dbd0eSchristos }
65*c42dbd0eSchristos 
66*c42dbd0eSchristos 
67*c42dbd0eSchristos #define TARGET_LITTLE_SYM	amdgcn_elf64_le_vec
68*c42dbd0eSchristos #define TARGET_LITTLE_NAME	"elf64-amdgcn"
69*c42dbd0eSchristos #define ELF_ARCH		bfd_arch_amdgcn
70*c42dbd0eSchristos #define ELF_TARGET_ID		AMDGCN_ELF_DATA
71*c42dbd0eSchristos #define ELF_MACHINE_CODE	EM_AMDGPU
72*c42dbd0eSchristos #define ELF_MAXPAGESIZE		0x10000 /* 64KB */
73*c42dbd0eSchristos #define ELF_COMMONPAGESIZE	0x1000  /* 4KB */
74*c42dbd0eSchristos 
75*c42dbd0eSchristos #define bfd_elf64_bfd_reloc_type_lookup bfd_default_reloc_type_lookup
76*c42dbd0eSchristos #define bfd_elf64_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
77*c42dbd0eSchristos 
78*c42dbd0eSchristos #define elf_backend_object_p elf64_amdgcn_object_p
79*c42dbd0eSchristos 
80*c42dbd0eSchristos #include "elf64-target.h"
81