Blame backends/ppc64_init.c

Packit Service 97d2fb
/* Initialization of PPC64 specific backend library.
Packit Service 97d2fb
   Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013, 2014 Red Hat, Inc.
Packit Service 97d2fb
   This file is part of elfutils.
Packit Service 97d2fb
   Written by Ulrich Drepper <drepper@redhat.com>, 2004.
Packit Service 97d2fb
Packit Service 97d2fb
   This file is free software; you can redistribute it and/or modify
Packit Service 97d2fb
   it under the terms of either
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU Lesser General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 3 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or
Packit Service 97d2fb
Packit Service 97d2fb
     * the GNU General Public License as published by the Free
Packit Service 97d2fb
       Software Foundation; either version 2 of the License, or (at
Packit Service 97d2fb
       your option) any later version
Packit Service 97d2fb
Packit Service 97d2fb
   or both in parallel, as here.
Packit Service 97d2fb
Packit Service 97d2fb
   elfutils is distributed in the hope that it will be useful, but
Packit Service 97d2fb
   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 97d2fb
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 97d2fb
   General Public License for more details.
Packit Service 97d2fb
Packit Service 97d2fb
   You should have received copies of the GNU General Public License and
Packit Service 97d2fb
   the GNU Lesser General Public License along with this program.  If
Packit Service 97d2fb
   not, see <http://www.gnu.org/licenses/>.  */
Packit Service 97d2fb
Packit Service 97d2fb
#ifdef HAVE_CONFIG_H
Packit Service 97d2fb
# include <config.h>
Packit Service 97d2fb
#endif
Packit Service 97d2fb
Packit Service 97d2fb
#include <string.h>
Packit Service 97d2fb
Packit Service 97d2fb
#define BACKEND		ppc64_
Packit Service 97d2fb
#define RELOC_PREFIX	R_PPC64_
Packit Service 97d2fb
#include "libebl_CPU.h"
Packit Service 97d2fb
Packit Service 97d2fb
/* This defines the common reloc hooks based on ppc64_reloc.def.  */
Packit Service 97d2fb
#include "common-reloc.c"
Packit Service 97d2fb
Packit Service 97d2fb
Packit Service 97d2fb
Ebl *
Packit Service 97d2fb
ppc64_init (Elf *elf __attribute__ ((unused)),
Packit Service 97d2fb
	    GElf_Half machine __attribute__ ((unused)),
Packit Service 97d2fb
	    Ebl *eh)
Packit Service 97d2fb
{
Packit Service 97d2fb
  /* We handle it.  */
Packit Service 97d2fb
  ppc64_init_reloc (eh);
Packit Service 97d2fb
  HOOK (eh, reloc_simple_type);
Packit Service 97d2fb
  HOOK (eh, dynamic_tag_name);
Packit Service 97d2fb
  HOOK (eh, dynamic_tag_check);
Packit Service 97d2fb
  HOOK (eh, machine_flag_check);
Packit Service 97d2fb
  HOOK (eh, copy_reloc_p);
Packit Service 97d2fb
  HOOK (eh, check_special_symbol);
Packit Service 97d2fb
  HOOK (eh, check_st_other_bits);
Packit Service 97d2fb
  HOOK (eh, bss_plt_p);
Packit Service 97d2fb
  HOOK (eh, return_value_location);
Packit Service 97d2fb
  HOOK (eh, register_info);
Packit Service 97d2fb
  HOOK (eh, core_note);
Packit Service 97d2fb
  HOOK (eh, auxv_info);
Packit Service 97d2fb
  HOOK (eh, check_object_attribute);
Packit Service 97d2fb
  HOOK (eh, abi_cfi);
Packit Service 97d2fb
  /* gcc/config/ #define DWARF_FRAME_REGISTERS.  */
Packit Service 97d2fb
  eh->frame_nregs = (114 - 1) + 32;
Packit Service 97d2fb
  HOOK (eh, set_initial_registers_tid);
Packit Service 97d2fb
  HOOK (eh, dwarf_to_regno);
Packit Service 97d2fb
  HOOK (eh, unwind);
Packit Service 97d2fb
  HOOK (eh, resolve_sym_value);
Packit Service 97d2fb
Packit Service 97d2fb
  /* Find the function descriptor .opd table for resolve_sym_value.  */
Packit Service 97d2fb
  if (elf != NULL)
Packit Service 97d2fb
    {
Packit Service 97d2fb
      GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (elf, &ehdr_mem);
Packit Service 97d2fb
      size_t shstrndx;
Packit Service 97d2fb
      if (ehdr != NULL && ehdr->e_type != ET_REL
Packit Service 97d2fb
	  && elf_getshdrstrndx (elf, &shstrndx) == 0)
Packit Service 97d2fb
	{
Packit Service 97d2fb
	  /* We could also try through DT_PPC64_OPD and DT_PPC64_OPDSZ. */
Packit Service 97d2fb
	  GElf_Shdr opd_shdr_mem, *opd_shdr;
Packit Service 97d2fb
	  Elf_Scn *scn = NULL;
Packit Service 97d2fb
	  while ((scn = elf_nextscn (elf, scn)) != NULL)
Packit Service 97d2fb
	    {
Packit Service 97d2fb
	      opd_shdr = gelf_getshdr (scn, &opd_shdr_mem);
Packit Service 97d2fb
	      if (opd_shdr != NULL
Packit Service 97d2fb
		  && (opd_shdr->sh_flags & SHF_ALLOC) != 0
Packit Service 97d2fb
		  && opd_shdr->sh_type == SHT_PROGBITS
Packit Service 97d2fb
		  && opd_shdr->sh_size > 0)
Packit Service 97d2fb
		{
Packit Service 97d2fb
		  const char *name = elf_strptr (elf, shstrndx,
Packit Service 97d2fb
						 opd_shdr->sh_name);
Packit Service 97d2fb
		  if (name != NULL && strcmp (name, ".opd") == 0)
Packit Service 97d2fb
		    {
Packit Service 97d2fb
		      eh->fd_addr = opd_shdr->sh_addr;
Packit Service 97d2fb
		      eh->fd_data = elf_getdata (scn, NULL);
Packit Service 97d2fb
		      break;
Packit Service 97d2fb
		    }
Packit Service 97d2fb
		}
Packit Service 97d2fb
	    }
Packit Service 97d2fb
	}
Packit Service 97d2fb
    }
Packit Service 97d2fb
Packit Service 97d2fb
  return eh;
Packit Service 97d2fb
}