Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/bfd/elf64-amdgcn.c
Line
Count
Source
1
/* AMDGCN ELF support for BFD.
2
3
   Copyright (C) 2019-2025 Free Software Foundation, Inc.
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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/>.  */
19
20
/* This file handles ELF files that are of the AMDGCN architecture.  The
21
   format is documented here:
22
23
     https://llvm.org/docs/AMDGPUUsage.html#elf-code-object */
24
25
#include "sysdep.h"
26
#include "bfd.h"
27
#include "libbfd.h"
28
#include "elf-bfd.h"
29
#include "elf/amdgpu.h"
30
31
#include <string.h>
32
33
static bool
34
elf64_amdgcn_object_p (bfd *abfd)
35
1.26k
{
36
1.26k
  Elf_Internal_Ehdr *hdr = elf_elfheader (abfd);
37
1.26k
  unsigned int mach;
38
1.26k
  unsigned char osabi;
39
1.26k
  unsigned char osabi_version;
40
41
1.26k
  BFD_ASSERT (hdr->e_machine == EM_AMDGPU);
42
43
1.26k
  osabi = hdr->e_ident[EI_OSABI];
44
1.26k
  osabi_version = hdr->e_ident[EI_ABIVERSION];
45
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.
49
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
1.26k
  if (osabi == ELFOSABI_AMDGPU_HSA
53
1.26k
      && osabi_version < ELFABIVERSION_AMDGPU_HSA_V3)
54
3
    return false;
55
56
1.25k
  mach = elf_elfheader (abfd)->e_flags & EF_AMDGPU_MACH;
57
58
  /* Avoid matching non-AMDGCN AMDGPU objects (e.g. r600).  */
59
1.25k
  if (mach < EF_AMDGPU_MACH_AMDGCN_MIN)
60
682
    return false;
61
62
575
  bfd_default_set_arch_mach (abfd, bfd_arch_amdgcn, mach);
63
575
  return true;
64
1.25k
}
65
66
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 */
74
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
77
78
#define elf_backend_object_p elf64_amdgcn_object_p
79
80
#include "elf64-target.h"