/*
Copyright (C) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
Portions Copyright 2007-2010 Sun Microsystems, Inc. All rights reserved.
Portions Copyright 2008-2010 Arxan Technologies, Inc. All Rights Reserved.
Portions Copyright 2009-2010 David Anderson. All rights reserved.
Portions Copyright 2009-2010 Novell Inc. All rights reserved.
under the terms of version 2.1 of the GNU Lesser General Public License
as published by the Free Software Foundation.
This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write the Free Software
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
USA.
Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
Mountain View, CA 94043, or:
For further information regarding this notice, see:
*/
#include "config.h"
#include "dwarf_incl.h"
#include "dwarf_elf_access.h"
#ifdef HAVE_ELF_H
#include <elf.h>
#endif
#ifdef HAVE_LIBELF_H
#include <libelf.h>
#else
#ifdef HAVE_LIBELF_LIBELF_H
#endif
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define FALSE 0
#ifndef EM_MIPS
/* This is the standard elf value EM_MIPS. */
#endif
#ifdef HAVE_ELF64_GETEHDR
#endif
#ifdef HAVE_ELF64_GETSHDR
#endif
#ifdef WORDS_BIGENDIAN
{ \
len_out) ; \
}
#else /* LITTLE ENDIAN */
{ \
((char *)source) , \
len_out) ; \
}
#endif
typedef struct {
int is_64bit;
int libdwarf_owns_elf;
#ifdef HAVE_ELF64_GETEHDR
#endif
/* Elf symtab and its strtab. Initialized at first
call to do relocations, the actual data is in the Dwarf_Debug
struct, not allocated locally here. */
struct Dwarf_Elf_Rela {
/*Dwarf_ufixed64 r_info; */
};
static int dwarf_elf_object_access_load_section(void* obj_in,
int* error);
/*
dwarf_elf_object_access_internals_init()
*/
static int
int* error)
{
char *ehdr_ident = 0;
return DW_DLV_ERROR;
}
}
}
#ifdef HAVE_ELF64_GETEHDR
return DW_DLV_ERROR;
}
#else
return DW_DLV_ERROR;
#endif
}
else {
return DW_DLV_ERROR;
}
}
/* The following length_size is Not Too Significant. Only used
one calculation, and an approximate one at that. */
Other platforms make length 4 always. */
/* 4 here supports 32bit-offset dwarf2, as emitted by cygnus
tools, and the dwarfv2.1 64bit extension setting.
This is not the same as the size-of-an-offset, which
is 4 in 32bit dwarf and 8 in 64bit dwarf. */
}
return DW_DLV_OK;
}
/*
dwarf_elf_object_access_get_byte_order
*/
static
{
return obj->endianness;
}
/*
dwarf_elf_object_access_get_section_count()
*/
static
{
return obj->section_count;
}
/*
dwarf_elf_object_access_get_section()
*/
static
int
void* obj_in,
int* error)
{
#ifdef HAVE_ELF64_GETSHDR
#endif
*error = DW_DLE_MDE;
return DW_DLV_ERROR;
}
#ifdef HAVE_ELF64_GETSHDR
return DW_DLV_ERROR;
}
return DW_DLV_ERROR;
}
return DW_DLV_OK;
#else
return DW_DLV_ERROR;
#endif /* HAVE_ELF64_GETSHDR */
}
return DW_DLV_ERROR;
}
return DW_DLV_ERROR;
}
return DW_DLV_OK;
}
/*
dwarf_elf_object_access_get_length_size
*/
static
{
return obj->length_size;
}
/*
dwarf_elf_object_access_get_pointer_size
*/
static
{
return obj->pointer_size;
}
return DW_DLV_OK; \
}
static int
{
/* dbg-> de_debug_str,syms); */
/* de_elf_symtab,syms); */
/* de_elf_strtab,syms); */
return DW_DLV_ERROR;
}
static void
int endianness,
{
/*
relap->r_info = relp->r_info;
*/
}
static void
int endianness,
{
#ifdef HAVE_ELF64_RELA
/*
relap->r_info = relp->r_info;
*/
/* This is really wierd. Treat this very specially.
The Elf64 LE MIPS object used for
testing (that has rela) wants the
values as sym ssym type3 type2 type, treating
each value as independent value. But libelf xlate
treats it as something else so we fudge here.
It is unclear
how to precisely characterize where these relocations
were used.
SGI MIPS on IRIX never used .rela relocations.
The BE 64bit elf MIPS test object with rela uses traditional
elf relocation layouts, not this special case. */
/* We ignore the special TYPE2 and TYPE3, they should be
value R_MIPS_NONE in rela. */
} else
{
}
#endif
}
static void
int endianness,
int machine,
unsigned int num_relocations,
struct Dwarf_Elf_Rela *relap)
{
unsigned int i = 0;
int endianness,
int machine,
struct Dwarf_Elf_Rela *relap);
/* Handle 32/64 bit issue
*/
if (is_64bit) {
} else {
}
for (i=0; i < num_relocations; i++) {
}
}
static int
int endianness,
int machine,
struct Dwarf_Elf_Rela **relas,
unsigned int *nrelas,
int *error)
{
unsigned int relocation_size = 0;
if (is_64bit) {
#ifdef HAVE_ELF64_RELA
relocation_size = sizeof(Elf64_Rela);
#else
return DW_DLV_ERROR;
#endif
} else {
relocation_size = sizeof(Elf32_Rela);
}
if (relocation_section == NULL) {
return(DW_DLV_ERROR);
}
if ((relocation_section_size != 0)) {
return DW_DLV_ERROR;
}
if (!*relas) {
*error = DW_DLE_MAF;
return(DW_DLV_ERROR);
}
}
return(DW_DLV_OK);
}
static Dwarf_Bool
{
Dwarf_Bool r = 0;
switch (machine) {
case EM_MIPS:
break;
#endif
#if defined(EM_SPARC32PLUS) && defined (R_SPARC_UA32)
case EM_SPARC32PLUS:
r = (type == R_SPARC_UA32);
break;
#endif
#if defined(EM_SPARCV9) && defined (R_SPARC_UA32)
case EM_SPARCV9:
r = (type == R_SPARC_UA32);
break;
#endif
#if defined(EM_SPARC) && defined (R_SPARC_UA32)
case EM_SPARC:
r = (type == R_SPARC_UA32);
break;
#endif
case EM_386:
break;
#endif
#if defined(EM_IA_64) && defined (R_IA64_SECREL32LSB)
case EM_IA_64:
r = (type == R_IA64_SECREL32LSB);
break;
#endif
#if defined(EM_PPC64) && defined (R_PPC64_ADDR32)
case EM_PPC64:
r = (type == R_PPC64_ADDR32);
break;
#endif
#if defined(EM_PPC) && defined (R_PPC_ADDR32)
case EM_PPC:
r = (type == R_PPC_ADDR32);
break;
#endif
case EM_S390:
break;
#endif
#if defined(EM_X86_64) && defined (R_X86_64_32)
case EM_X86_64:
r = (type == R_X86_64_32);
break;
#endif
}
return r;
}
static Dwarf_Bool
{
Dwarf_Bool r = 0;
switch (machine) {
case EM_MIPS:
break;
#endif
#if defined(EM_SPARC32PLUS) && defined (R_SPARC_UA64)
case EM_SPARC32PLUS:
r = (type == R_SPARC_UA64);
break;
#endif
#if defined(EM_SPARCV9) && defined (R_SPARC_UA64)
case EM_SPARCV9:
r = (type == R_SPARC_UA64);
break;
#endif
#if defined(EM_SPARC) && defined (R_SPARC_UA64)
case EM_SPARC:
r = (type == R_SPARC_UA64);
break;
#endif
#if defined(EM_IA_64) && defined (R_IA64_SECREL32LSB)
case EM_IA_64:
r = (type == R_IA64_DIR64LSB);
break;
#endif
#if defined(EM_PPC64) && defined (R_PPC64_ADDR64)
case EM_PPC64:
r = (type == R_PPC64_ADDR64);
break;
#endif
case EM_S390:
break;
#endif
#if defined(EM_X86_64) && defined (R_X86_64_64)
case EM_X86_64:
r = (type == R_X86_64_64);
break;
#endif
}
return r;
}
static void
{
unsigned int type = 0;
unsigned int sym_idx = 0;
#ifdef HAVE_ELF64_SYM
#else
#endif
/* Dwarf_Elf_Rela dereferencing */
if (is_64bit) {
#ifdef HAVE_ELF64_SYM
#endif
} else {
/* Convert Elf32_Sym struct to Elf64_Sym struct. We point at
* an Elf64_Sym local variable (sym_buf) to allow us to use the
* same pointer (sym) for both 32-bit and 64-bit instances.
*/
}
/* Determine relocation size */
reloc_size = 4;
reloc_size = 8;
} else {
return;
}
{
/* Assuming we do not need to do a READ_UNALIGNED here
at target_section + offset and add its value to
outval. Some ABIs say no read (for example MIPS),
but if some do then which ones? */
}
}
static int
int *error)
{
unsigned int i;
for (i = 0; i < nrelas; i++) {
&(relas)[i],
}
}
return DW_DLV_OK;
}
static int
struct Dwarf_Section_s *relocatablesec,
int *error)
{
unsigned int nrelas = 0;
return ret;
}
/* Some systems read Elf in read-only memory via mmap or the like.
So the only safe thing is to copy the current data into
malloc space and refer to the malloc space instead of the
space returned by the elf library */
if(!mspace) {
return DW_DLV_ERROR;
}
dbg,
return ret;
}
/*
Find the section data in dbg and find all the relevant
sections. Then do relocations.
*/
static int
int* error)
{
if (section_index == 0) {
return DW_DLV_NO_ENTRY;
}
/* The section to relocate must already be loaded into memory. */
return res;
}
/* Sun and possibly others do not always set sh_link in .debug_* sections.
So we cannot do full consistency checks. */
if(relocatablesec->dss_reloc_index == 0 ) {
/* Something is wrong. */
return DW_DLV_ERROR;
}
/* Now load the relocations themselves. */
return res;
}
/* Now get the symtab. */
}
/* Something is wrong. */
return DW_DLV_ERROR;
}
/* Something is wrong. */
return DW_DLV_ERROR;
}
/* Now load the symtab */
return res;
}
}
/* Now load the strtab */
return res;
}
}
/* We have all the data we need in memory. */
return res;
}
/*
dwarf_elf_object_access_load_section
*/
static int
int* error)
{
if (section_index == 0) {
return DW_DLV_NO_ENTRY;
}
{
*error = DW_DLE_MDE;
return DW_DLV_ERROR;
}
/*
When using libelf as a producer, section data may be stored
in multiple buffers. In libdwarf however, we only use libelf
as a consumer (there is a dwarf producer API, but it doesn't
use libelf). Because of this, this single call to elf_getdata
will retrieve the entire section in a single contiguous
buffer. */
*error = DW_DLE_MDE;
return DW_DLV_ERROR;
}
}
return DW_DLV_OK;
}
/* dwarf_elf_access method table. */
{
};
/*
Interface for the ELF object file implementation.
*/
int
int libdwarf_owns_elf,
int *err)
{
int res = 0;
if(!internals) {
/* Impossible case, we hope. Give up. */
return DW_DLV_ERROR;
}
return DW_DLV_ERROR;
}
if(!intfc) {
/* Impossible case, we hope. Give up. */
return DW_DLV_ERROR;
}
/* Initialize the interface struct */
return DW_DLV_OK;
}
/*
Clean up the Dwarf_Obj_Access_Interface returned by elf_access_init.
*/
void
{
if(!obj) {
return;
}
if(internals->libdwarf_owns_elf){
}
}
}
/*
This function returns the Elf * pointer
associated with a Dwarf_Debug.
This function only makes sense if ELF is implied.
*/
int
Dwarf_Error * error)
{
return (DW_DLV_ERROR);
}
if(obj) {
return (DW_DLV_ERROR);
}
return DW_DLV_OK;
}
return DW_DLV_ERROR;
}