1883529b6Schristos /* TILE-Gx-specific support for 64-bit ELF.
2*cb63e24eSchristos Copyright (C) 2011-2024 Free Software Foundation, Inc.
3883529b6Schristos
4883529b6Schristos This file is part of BFD, the Binary File Descriptor library.
5883529b6Schristos
6883529b6Schristos This program is free software; you can redistribute it and/or modify
7883529b6Schristos it under the terms of the GNU General Public License as published by
8883529b6Schristos the Free Software Foundation; either version 3 of the License, or
9883529b6Schristos (at your option) any later version.
10883529b6Schristos
11883529b6Schristos This program is distributed in the hope that it will be useful,
12883529b6Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of
13883529b6Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14883529b6Schristos GNU General Public License for more details.
15883529b6Schristos
16883529b6Schristos You should have received a copy of the GNU General Public License
17883529b6Schristos along with this program; if not, write to the Free Software
18883529b6Schristos Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19883529b6Schristos MA 02110-1301, USA. */
20883529b6Schristos
21883529b6Schristos #include "sysdep.h"
22883529b6Schristos #include "bfd.h"
23883529b6Schristos #include "libbfd.h"
24883529b6Schristos #include "elf-bfd.h"
25883529b6Schristos #include "elfxx-tilegx.h"
26883529b6Schristos #include "elf64-tilegx.h"
27883529b6Schristos
28883529b6Schristos
29883529b6Schristos /* Support for core dump NOTE sections. */
30883529b6Schristos
314f645668Schristos static bool
tilegx_elf_grok_prstatus(bfd * abfd,Elf_Internal_Note * note)32883529b6Schristos tilegx_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
33883529b6Schristos {
34883529b6Schristos int offset;
35883529b6Schristos size_t size;
36883529b6Schristos
37883529b6Schristos if (note->descsz != TILEGX_PRSTATUS_SIZEOF)
384f645668Schristos return false;
39883529b6Schristos
40883529b6Schristos /* pr_cursig */
419573673dSchristos elf_tdata (abfd)->core->signal =
42883529b6Schristos bfd_get_16 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_CURSIG);
43883529b6Schristos
44883529b6Schristos /* pr_pid */
459573673dSchristos elf_tdata (abfd)->core->pid =
46883529b6Schristos bfd_get_32 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_PID);
47883529b6Schristos
48883529b6Schristos /* pr_reg */
49883529b6Schristos offset = TILEGX_PRSTATUS_OFFSET_PR_REG;
50883529b6Schristos size = TILEGX_GREGSET_T_SIZE;
51883529b6Schristos
52883529b6Schristos /* Make a ".reg/999" section. */
53883529b6Schristos return _bfd_elfcore_make_pseudosection (abfd, ".reg",
54883529b6Schristos size, note->descpos + offset);
55883529b6Schristos }
56883529b6Schristos
574f645668Schristos static bool
tilegx_elf_grok_psinfo(bfd * abfd,Elf_Internal_Note * note)58883529b6Schristos tilegx_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
59883529b6Schristos {
60883529b6Schristos if (note->descsz != TILEGX_PRPSINFO_SIZEOF)
614f645668Schristos return false;
62883529b6Schristos
639573673dSchristos elf_tdata (abfd)->core->program
64883529b6Schristos = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_FNAME, 16);
659573673dSchristos elf_tdata (abfd)->core->command
66883529b6Schristos = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_PSARGS, ELF_PR_PSARGS_SIZE);
67883529b6Schristos
68883529b6Schristos
69883529b6Schristos /* Note that for some reason, a spurious space is tacked
70883529b6Schristos onto the end of the args in some (at least one anyway)
71883529b6Schristos implementations, so strip it off if it exists. */
72883529b6Schristos {
739573673dSchristos char *command = elf_tdata (abfd)->core->command;
74883529b6Schristos int n = strlen (command);
75883529b6Schristos
76883529b6Schristos if (0 < n && command[n - 1] == ' ')
77883529b6Schristos command[n - 1] = '\0';
78883529b6Schristos }
79883529b6Schristos
804f645668Schristos return true;
81883529b6Schristos }
82883529b6Schristos
83883529b6Schristos
84883529b6Schristos #define ELF_ARCH bfd_arch_tilegx
85883529b6Schristos #define ELF_TARGET_ID TILEGX_ELF_DATA
86883529b6Schristos #define ELF_MACHINE_CODE EM_TILEGX
87883529b6Schristos #define ELF_MAXPAGESIZE 0x10000
88883529b6Schristos #define ELF_COMMONPAGESIZE 0x10000
89883529b6Schristos
90883529b6Schristos
919573673dSchristos #define TARGET_BIG_SYM tilegx_elf64_be_vec
92883529b6Schristos #define TARGET_BIG_NAME "elf64-tilegx-be"
939573673dSchristos #define TARGET_LITTLE_SYM tilegx_elf64_le_vec
94883529b6Schristos #define TARGET_LITTLE_NAME "elf64-tilegx-le"
95883529b6Schristos
96883529b6Schristos #define elf_backend_reloc_type_class tilegx_reloc_type_class
97883529b6Schristos
98883529b6Schristos #define bfd_elf64_bfd_reloc_name_lookup tilegx_reloc_name_lookup
99883529b6Schristos #define bfd_elf64_bfd_link_hash_table_create tilegx_elf_link_hash_table_create
100883529b6Schristos #define bfd_elf64_bfd_reloc_type_lookup tilegx_reloc_type_lookup
101883529b6Schristos #define bfd_elf64_bfd_merge_private_bfd_data \
102883529b6Schristos _bfd_tilegx_elf_merge_private_bfd_data
103883529b6Schristos
104883529b6Schristos #define elf_backend_copy_indirect_symbol tilegx_elf_copy_indirect_symbol
105883529b6Schristos #define elf_backend_create_dynamic_sections tilegx_elf_create_dynamic_sections
106883529b6Schristos #define elf_backend_check_relocs tilegx_elf_check_relocs
107883529b6Schristos #define elf_backend_adjust_dynamic_symbol tilegx_elf_adjust_dynamic_symbol
108883529b6Schristos #define elf_backend_omit_section_dynsym tilegx_elf_omit_section_dynsym
109883529b6Schristos #define elf_backend_size_dynamic_sections tilegx_elf_size_dynamic_sections
110883529b6Schristos #define elf_backend_relocate_section tilegx_elf_relocate_section
111883529b6Schristos #define elf_backend_finish_dynamic_symbol tilegx_elf_finish_dynamic_symbol
112883529b6Schristos #define elf_backend_finish_dynamic_sections tilegx_elf_finish_dynamic_sections
113883529b6Schristos #define elf_backend_gc_mark_hook tilegx_elf_gc_mark_hook
114883529b6Schristos #define elf_backend_plt_sym_val tilegx_elf_plt_sym_val
115883529b6Schristos #define elf_info_to_howto_rel NULL
116883529b6Schristos #define elf_info_to_howto tilegx_info_to_howto_rela
117883529b6Schristos #define elf_backend_grok_prstatus tilegx_elf_grok_prstatus
118883529b6Schristos #define elf_backend_grok_psinfo tilegx_elf_grok_psinfo
119883529b6Schristos #define elf_backend_additional_program_headers tilegx_additional_program_headers
120883529b6Schristos
121883529b6Schristos #define elf_backend_init_index_section _bfd_elf_init_1_index_section
122883529b6Schristos
123883529b6Schristos #define elf_backend_can_gc_sections 1
124883529b6Schristos #define elf_backend_can_refcount 1
125883529b6Schristos #define elf_backend_want_got_plt 1
126883529b6Schristos #define elf_backend_plt_readonly 1
127883529b6Schristos /* Align PLT mod 64 byte L2 line size. */
128883529b6Schristos #define elf_backend_plt_alignment 6
129883529b6Schristos #define elf_backend_want_plt_sym 1
130883529b6Schristos #define elf_backend_got_header_size 8
131fc4f4269Schristos #define elf_backend_want_dynrelro 1
132883529b6Schristos #define elf_backend_rela_normal 1
133883529b6Schristos #define elf_backend_default_execstack 0
134883529b6Schristos
135883529b6Schristos #include "elf64-target.h"
136