149d3bc91SRichard Lowe /* 249d3bc91SRichard Lowe 3*07dc1947SRichard Lowe Copyright (C) 2000,2002,2004 Silicon Graphics, Inc. All Rights Reserved. 4*07dc1947SRichard Lowe Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved. 5*07dc1947SRichard Lowe Portions Copyright 2008-2010 David Anderson. All rights reserved. 649d3bc91SRichard Lowe 749d3bc91SRichard Lowe This program is free software; you can redistribute it and/or modify it 849d3bc91SRichard Lowe under the terms of version 2.1 of the GNU Lesser General Public License 949d3bc91SRichard Lowe as published by the Free Software Foundation. 1049d3bc91SRichard Lowe 1149d3bc91SRichard Lowe This program is distributed in the hope that it would be useful, but 1249d3bc91SRichard Lowe WITHOUT ANY WARRANTY; without even the implied warranty of 1349d3bc91SRichard Lowe MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 1449d3bc91SRichard Lowe 1549d3bc91SRichard Lowe Further, this software is distributed without any warranty that it is 1649d3bc91SRichard Lowe free of the rightful claim of any third person regarding infringement 1749d3bc91SRichard Lowe or the like. Any license provided herein, whether implied or 1849d3bc91SRichard Lowe otherwise, applies only to this software file. Patent licenses, if 1949d3bc91SRichard Lowe any, provided herein do not apply to combinations of this program with 2049d3bc91SRichard Lowe other software, or any other product whatsoever. 2149d3bc91SRichard Lowe 2249d3bc91SRichard Lowe You should have received a copy of the GNU Lesser General Public 2349d3bc91SRichard Lowe License along with this program; if not, write the Free Software 24*07dc1947SRichard Lowe Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301, 2549d3bc91SRichard Lowe USA. 2649d3bc91SRichard Lowe 27*07dc1947SRichard Lowe Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, 2849d3bc91SRichard Lowe Mountain View, CA 94043, or: 2949d3bc91SRichard Lowe 3049d3bc91SRichard Lowe http://www.sgi.com 3149d3bc91SRichard Lowe 3249d3bc91SRichard Lowe For further information regarding this notice, see: 3349d3bc91SRichard Lowe 3449d3bc91SRichard Lowe http://oss.sgi.com/projects/GenInfo/NoticeExplan 3549d3bc91SRichard Lowe 3649d3bc91SRichard Lowe */ 3749d3bc91SRichard Lowe 3849d3bc91SRichard Lowe 3949d3bc91SRichard Lowe #ifdef HAVE_ELF_H 4049d3bc91SRichard Lowe #include <elf.h> 41*07dc1947SRichard Lowe #elif defined(HAVE_LIBELF_H) 42*07dc1947SRichard Lowe /* On one platform without elf.h this gets Elf32_Rel 43*07dc1947SRichard Lowe type defined (a required type). */ 44*07dc1947SRichard Lowe #include <libelf.h> 45*07dc1947SRichard Lowe #endif 46*07dc1947SRichard Lowe 47*07dc1947SRichard Lowe #if defined(sun) 48*07dc1947SRichard Lowe #include <sys/elf_SPARC.h> 49*07dc1947SRichard Lowe #include <sys/elf_386.h> 5049d3bc91SRichard Lowe #endif 5149d3bc91SRichard Lowe 5249d3bc91SRichard Lowe /* The target address is given: the place in the source integer 5349d3bc91SRichard Lowe is to be determined. 5449d3bc91SRichard Lowe */ 5549d3bc91SRichard Lowe #ifdef WORDS_BIGENDIAN 5649d3bc91SRichard Lowe #define WRITE_UNALIGNED(dbg,dest,source, srclength,len_out) \ 5749d3bc91SRichard Lowe { \ 5849d3bc91SRichard Lowe dbg->de_copy_word(dest, \ 5949d3bc91SRichard Lowe ((char *)source) +srclength-len_out, \ 6049d3bc91SRichard Lowe len_out) ; \ 6149d3bc91SRichard Lowe } 6249d3bc91SRichard Lowe 6349d3bc91SRichard Lowe 6449d3bc91SRichard Lowe #else /* LITTLE ENDIAN */ 6549d3bc91SRichard Lowe 6649d3bc91SRichard Lowe #define WRITE_UNALIGNED(dbg,dest,source, srclength,len_out) \ 6749d3bc91SRichard Lowe { \ 6849d3bc91SRichard Lowe dbg->de_copy_word( (dest) , \ 6949d3bc91SRichard Lowe ((char *)source) , \ 7049d3bc91SRichard Lowe len_out) ; \ 7149d3bc91SRichard Lowe } 7249d3bc91SRichard Lowe #endif 7349d3bc91SRichard Lowe 7449d3bc91SRichard Lowe 75*07dc1947SRichard Lowe #if defined(sparc) && defined(sun) 76*07dc1947SRichard Lowe #define REL32 Elf32_Rela 77*07dc1947SRichard Lowe #define REL64 Elf64_Rela 78*07dc1947SRichard Lowe #define REL_SEC_PREFIX ".rela" 79*07dc1947SRichard Lowe #else 80*07dc1947SRichard Lowe #define REL32 Elf32_Rel 81*07dc1947SRichard Lowe #define REL64 Elf64_Rel 82*07dc1947SRichard Lowe #define REL_SEC_PREFIX ".rel" 83*07dc1947SRichard Lowe #endif 8449d3bc91SRichard Lowe 8549d3bc91SRichard Lowe #include "dwarf.h" 86*07dc1947SRichard Lowe #include "libdwarf.h" 87*07dc1947SRichard Lowe 8849d3bc91SRichard Lowe #include "pro_opaque.h" 8949d3bc91SRichard Lowe #include "pro_error.h" 9049d3bc91SRichard Lowe #include "pro_util.h" 9149d3bc91SRichard Lowe #include "pro_encode_nm.h" 9249d3bc91SRichard Lowe #include "pro_alloc.h" 93