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