blob: 56e1828efb56e3f131ec047385c3c04394aab1fd [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Initialization of PPC64 specific backend library.
Mark Wielaard0c4a8682014-01-04 19:19:16 +01002 Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013, 2014 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
5
Mark Wielaardde2ed972012-06-05 17:15:16 +02006 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 * the GNU Lesser General Public License as published by the Free
10 Software Foundation; either version 3 of the License, or (at
11 your option) any later version
12
13 or
14
15 * the GNU General Public License as published by the Free
16 Software Foundation; either version 2 of the License, or (at
17 your option) any later version
18
19 or both in parallel, as here.
20
21 elfutils is distributed in the hope that it will be useful, but
Ulrich Drepper361df7d2006-04-04 21:38:57 +000022 WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 General Public License for more details.
25
Mark Wielaardde2ed972012-06-05 17:15:16 +020026 You should have received copies of the GNU General Public License and
27 the GNU Lesser General Public License along with this program. If
28 not, see <http://www.gnu.org/licenses/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
30#ifdef HAVE_CONFIG_H
31# include <config.h>
32#endif
33
Mark Wielaard159ac522013-12-18 11:05:54 +010034#include <string.h>
35
Roland McGrathcd60ea82005-11-16 01:57:40 +000036#define BACKEND ppc64_
37#define RELOC_PREFIX R_PPC64_
38#include "libebl_CPU.h"
39
40/* This defines the common reloc hooks based on ppc64_reloc.def. */
41#include "common-reloc.c"
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000042
43
44const char *
45ppc64_init (elf, machine, eh, ehlen)
46 Elf *elf __attribute__ ((unused));
47 GElf_Half machine __attribute__ ((unused));
48 Ebl *eh;
49 size_t ehlen;
50{
51 /* Check whether the Elf_BH object has a sufficent size. */
52 if (ehlen < sizeof (Ebl))
53 return NULL;
54
55 /* We handle it. */
56 eh->name = "PowerPC 64-bit";
Roland McGrathcd60ea82005-11-16 01:57:40 +000057 ppc64_init_reloc (eh);
Roland McGrathf47ba532005-11-19 07:40:29 +000058 HOOK (eh, reloc_simple_type);
59 HOOK (eh, dynamic_tag_name);
60 HOOK (eh, dynamic_tag_check);
Mark Wielaard0c4a8682014-01-04 19:19:16 +010061 HOOK (eh, machine_flag_check);
Roland McGrathf47ba532005-11-19 07:40:29 +000062 HOOK (eh, copy_reloc_p);
63 HOOK (eh, check_special_symbol);
Mark Wielaarda95c4ad2014-07-04 14:30:48 +020064 HOOK (eh, check_st_other_bits);
Roland McGrathf47ba532005-11-19 07:40:29 +000065 HOOK (eh, bss_plt_p);
66 HOOK (eh, return_value_location);
Roland McGrathc373d852006-10-10 00:25:21 +000067 HOOK (eh, register_info);
Roland McGrath1d8bb252008-08-07 08:39:41 +000068 HOOK (eh, syscall_abi);
Roland McGrathcb6d8652007-08-23 08:10:54 +000069 HOOK (eh, core_note);
70 HOOK (eh, auxv_info);
Jan Kratochviled9d2ca2013-08-27 22:49:36 +020071 HOOK (eh, abi_cfi);
Jan Kratochvil5cbf42a2013-12-15 18:56:17 +010072 /* gcc/config/ #define DWARF_FRAME_REGISTERS. */
73 eh->frame_nregs = (114 - 1) + 32;
74 HOOK (eh, set_initial_registers_tid);
75 HOOK (eh, dwarf_to_regno);
Mark Wielaard159ac522013-12-18 11:05:54 +010076 HOOK (eh, resolve_sym_value);
77
78 /* Find the function descriptor .opd table for resolve_sym_value. */
79 if (elf != NULL)
80 {
81 GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
82 if (ehdr != NULL && ehdr->e_type != ET_REL)
83 {
84 /* We could also try through DT_PPC64_OPD and DT_PPC64_OPDSZ. */
85 GElf_Shdr opd_shdr_mem, *opd_shdr;
86 Elf_Scn *scn = NULL;
87 while ((scn = elf_nextscn (elf, scn)) != NULL)
88 {
89 opd_shdr = gelf_getshdr (scn, &opd_shdr_mem);
90 if (opd_shdr != NULL
91 && (opd_shdr->sh_flags & SHF_ALLOC) != 0
92 && opd_shdr->sh_type == SHT_PROGBITS
Mark Wielaard5c1a45c2014-11-17 23:15:45 +010093 && opd_shdr->sh_size > 0)
Mark Wielaard159ac522013-12-18 11:05:54 +010094 {
Mark Wielaard5c1a45c2014-11-17 23:15:45 +010095 const char *name = elf_strptr (elf, ehdr->e_shstrndx,
96 opd_shdr->sh_name);
97 if (name != NULL && strcmp (name, ".opd") == 0)
98 {
99 eh->fd_addr = opd_shdr->sh_addr;
100 eh->fd_data = elf_getdata (scn, NULL);
101 break;
102 }
Mark Wielaard159ac522013-12-18 11:05:54 +0100103 }
104 }
105 }
106 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000107
108 return MODVERSION;
109}