elf64-amdgcn.c 2.5 KB

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