xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/elf64-tilegx.c (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* TILE-Gx-specific support for 64-bit ELF.
2*e992f068Schristos    Copyright (C) 2011-2022 Free Software Foundation, Inc.
375fd0b74Schristos 
475fd0b74Schristos    This file is part of BFD, the Binary File Descriptor library.
575fd0b74Schristos 
675fd0b74Schristos    This program is free software; you can redistribute it and/or modify
775fd0b74Schristos    it under the terms of the GNU General Public License as published by
875fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos    (at your option) any later version.
1075fd0b74Schristos 
1175fd0b74Schristos    This program is distributed in the hope that it will be useful,
1275fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1475fd0b74Schristos    GNU General Public License for more details.
1575fd0b74Schristos 
1675fd0b74Schristos    You should have received a copy of the GNU General Public License
1775fd0b74Schristos    along with this program; if not, write to the Free Software
1875fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1975fd0b74Schristos    MA 02110-1301, USA.  */
2075fd0b74Schristos 
2175fd0b74Schristos #include "sysdep.h"
2275fd0b74Schristos #include "bfd.h"
2375fd0b74Schristos #include "libbfd.h"
2475fd0b74Schristos #include "elf-bfd.h"
2575fd0b74Schristos #include "elfxx-tilegx.h"
2675fd0b74Schristos #include "elf64-tilegx.h"
2775fd0b74Schristos 
2875fd0b74Schristos 
2975fd0b74Schristos /* Support for core dump NOTE sections.  */
3075fd0b74Schristos 
31*e992f068Schristos static bool
tilegx_elf_grok_prstatus(bfd * abfd,Elf_Internal_Note * note)3275fd0b74Schristos tilegx_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3375fd0b74Schristos {
3475fd0b74Schristos   int offset;
3575fd0b74Schristos   size_t size;
3675fd0b74Schristos 
3775fd0b74Schristos   if (note->descsz != TILEGX_PRSTATUS_SIZEOF)
38*e992f068Schristos     return false;
3975fd0b74Schristos 
4075fd0b74Schristos   /* pr_cursig */
4175fd0b74Schristos   elf_tdata (abfd)->core->signal =
4275fd0b74Schristos     bfd_get_16 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_CURSIG);
4375fd0b74Schristos 
4475fd0b74Schristos   /* pr_pid */
4575fd0b74Schristos   elf_tdata (abfd)->core->pid =
4675fd0b74Schristos     bfd_get_32 (abfd, note->descdata + TILEGX_PRSTATUS_OFFSET_PR_PID);
4775fd0b74Schristos 
4875fd0b74Schristos   /* pr_reg */
4975fd0b74Schristos   offset = TILEGX_PRSTATUS_OFFSET_PR_REG;
5075fd0b74Schristos   size   = TILEGX_GREGSET_T_SIZE;
5175fd0b74Schristos 
5275fd0b74Schristos   /* Make a ".reg/999" section.  */
5375fd0b74Schristos   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
5475fd0b74Schristos 					  size, note->descpos + offset);
5575fd0b74Schristos }
5675fd0b74Schristos 
57*e992f068Schristos static bool
tilegx_elf_grok_psinfo(bfd * abfd,Elf_Internal_Note * note)5875fd0b74Schristos tilegx_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
5975fd0b74Schristos {
6075fd0b74Schristos   if (note->descsz != TILEGX_PRPSINFO_SIZEOF)
61*e992f068Schristos     return false;
6275fd0b74Schristos 
6375fd0b74Schristos   elf_tdata (abfd)->core->program
6475fd0b74Schristos     = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_FNAME, 16);
6575fd0b74Schristos   elf_tdata (abfd)->core->command
6675fd0b74Schristos     = _bfd_elfcore_strndup (abfd, note->descdata + TILEGX_PRPSINFO_OFFSET_PR_PSARGS, ELF_PR_PSARGS_SIZE);
6775fd0b74Schristos 
6875fd0b74Schristos 
6975fd0b74Schristos   /* Note that for some reason, a spurious space is tacked
7075fd0b74Schristos      onto the end of the args in some (at least one anyway)
7175fd0b74Schristos      implementations, so strip it off if it exists.  */
7275fd0b74Schristos   {
7375fd0b74Schristos     char *command = elf_tdata (abfd)->core->command;
7475fd0b74Schristos     int n = strlen (command);
7575fd0b74Schristos 
7675fd0b74Schristos     if (0 < n && command[n - 1] == ' ')
7775fd0b74Schristos       command[n - 1] = '\0';
7875fd0b74Schristos   }
7975fd0b74Schristos 
80*e992f068Schristos   return true;
8175fd0b74Schristos }
8275fd0b74Schristos 
8375fd0b74Schristos 
8475fd0b74Schristos #define ELF_ARCH		bfd_arch_tilegx
8575fd0b74Schristos #define ELF_TARGET_ID		TILEGX_ELF_DATA
8675fd0b74Schristos #define ELF_MACHINE_CODE	EM_TILEGX
8775fd0b74Schristos #define ELF_MAXPAGESIZE		0x10000
8875fd0b74Schristos #define ELF_COMMONPAGESIZE	0x10000
8975fd0b74Schristos 
9075fd0b74Schristos 
9175fd0b74Schristos #define TARGET_BIG_SYM		tilegx_elf64_be_vec
9275fd0b74Schristos #define TARGET_BIG_NAME		"elf64-tilegx-be"
9375fd0b74Schristos #define TARGET_LITTLE_SYM	tilegx_elf64_le_vec
9475fd0b74Schristos #define TARGET_LITTLE_NAME	"elf64-tilegx-le"
9575fd0b74Schristos 
9675fd0b74Schristos #define elf_backend_reloc_type_class	     tilegx_reloc_type_class
9775fd0b74Schristos 
9875fd0b74Schristos #define bfd_elf64_bfd_reloc_name_lookup	     tilegx_reloc_name_lookup
9975fd0b74Schristos #define bfd_elf64_bfd_link_hash_table_create tilegx_elf_link_hash_table_create
10075fd0b74Schristos #define bfd_elf64_bfd_reloc_type_lookup	     tilegx_reloc_type_lookup
10175fd0b74Schristos #define bfd_elf64_bfd_merge_private_bfd_data \
10275fd0b74Schristos   _bfd_tilegx_elf_merge_private_bfd_data
10375fd0b74Schristos 
10475fd0b74Schristos #define elf_backend_copy_indirect_symbol     tilegx_elf_copy_indirect_symbol
10575fd0b74Schristos #define elf_backend_create_dynamic_sections  tilegx_elf_create_dynamic_sections
10675fd0b74Schristos #define elf_backend_check_relocs	     tilegx_elf_check_relocs
10775fd0b74Schristos #define elf_backend_adjust_dynamic_symbol    tilegx_elf_adjust_dynamic_symbol
10875fd0b74Schristos #define elf_backend_omit_section_dynsym	     tilegx_elf_omit_section_dynsym
10975fd0b74Schristos #define elf_backend_size_dynamic_sections    tilegx_elf_size_dynamic_sections
11075fd0b74Schristos #define elf_backend_relocate_section	     tilegx_elf_relocate_section
11175fd0b74Schristos #define elf_backend_finish_dynamic_symbol    tilegx_elf_finish_dynamic_symbol
11275fd0b74Schristos #define elf_backend_finish_dynamic_sections  tilegx_elf_finish_dynamic_sections
11375fd0b74Schristos #define elf_backend_gc_mark_hook	     tilegx_elf_gc_mark_hook
11475fd0b74Schristos #define elf_backend_plt_sym_val		     tilegx_elf_plt_sym_val
11575fd0b74Schristos #define elf_info_to_howto_rel		     NULL
11675fd0b74Schristos #define elf_info_to_howto		     tilegx_info_to_howto_rela
11775fd0b74Schristos #define elf_backend_grok_prstatus	     tilegx_elf_grok_prstatus
11875fd0b74Schristos #define elf_backend_grok_psinfo		     tilegx_elf_grok_psinfo
11975fd0b74Schristos #define elf_backend_additional_program_headers tilegx_additional_program_headers
12075fd0b74Schristos 
12175fd0b74Schristos #define elf_backend_init_index_section	_bfd_elf_init_1_index_section
12275fd0b74Schristos 
12375fd0b74Schristos #define elf_backend_can_gc_sections 1
12475fd0b74Schristos #define elf_backend_can_refcount 1
12575fd0b74Schristos #define elf_backend_want_got_plt 1
12675fd0b74Schristos #define elf_backend_plt_readonly 1
12775fd0b74Schristos /* Align PLT mod 64 byte L2 line size. */
12875fd0b74Schristos #define elf_backend_plt_alignment 6
12975fd0b74Schristos #define elf_backend_want_plt_sym 1
13075fd0b74Schristos #define elf_backend_got_header_size 8
131ede78133Schristos #define elf_backend_want_dynrelro 1
13275fd0b74Schristos #define elf_backend_rela_normal 1
13375fd0b74Schristos #define elf_backend_default_execstack 0
13475fd0b74Schristos 
13575fd0b74Schristos #include "elf64-target.h"
136