1*7fd79137SRobert Mustacchi /* 2*7fd79137SRobert Mustacchi 3*7fd79137SRobert Mustacchi Copyright (C) 2000,2004 Silicon Graphics, Inc. All Rights Reserved. 4*7fd79137SRobert Mustacchi Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved. 5*7fd79137SRobert Mustacchi 6*7fd79137SRobert Mustacchi This program is free software; you can redistribute it and/or modify it 7*7fd79137SRobert Mustacchi under the terms of version 2.1 of the GNU Lesser General Public License 8*7fd79137SRobert Mustacchi as published by the Free Software Foundation. 9*7fd79137SRobert Mustacchi 10*7fd79137SRobert Mustacchi This program is distributed in the hope that it would be useful, but 11*7fd79137SRobert Mustacchi WITHOUT ANY WARRANTY; without even the implied warranty of 12*7fd79137SRobert Mustacchi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13*7fd79137SRobert Mustacchi 14*7fd79137SRobert Mustacchi Further, this software is distributed without any warranty that it is 15*7fd79137SRobert Mustacchi free of the rightful claim of any third person regarding infringement 16*7fd79137SRobert Mustacchi or the like. Any license provided herein, whether implied or 17*7fd79137SRobert Mustacchi otherwise, applies only to this software file. Patent licenses, if 18*7fd79137SRobert Mustacchi any, provided herein do not apply to combinations of this program with 19*7fd79137SRobert Mustacchi other software, or any other product whatsoever. 20*7fd79137SRobert Mustacchi 21*7fd79137SRobert Mustacchi You should have received a copy of the GNU Lesser General Public 22*7fd79137SRobert Mustacchi License along with this program; if not, write the Free Software 23*7fd79137SRobert Mustacchi Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301, 24*7fd79137SRobert Mustacchi USA. 25*7fd79137SRobert Mustacchi 26*7fd79137SRobert Mustacchi Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane, 27*7fd79137SRobert Mustacchi Mountain View, CA 94043, or: 28*7fd79137SRobert Mustacchi 29*7fd79137SRobert Mustacchi http://www.sgi.com 30*7fd79137SRobert Mustacchi 31*7fd79137SRobert Mustacchi For further information regarding this notice, see: 32*7fd79137SRobert Mustacchi 33*7fd79137SRobert Mustacchi http://oss.sgi.com/projects/GenInfo/NoticeExplan 34*7fd79137SRobert Mustacchi 35*7fd79137SRobert Mustacchi */ 36*7fd79137SRobert Mustacchi 37*7fd79137SRobert Mustacchi 38*7fd79137SRobert Mustacchi 39*7fd79137SRobert Mustacchi 40*7fd79137SRobert Mustacchi #define IS_64BIT(dbg) ((dbg)->de_flags & DW_DLC_SIZE_64 ? 1 : 0) 41*7fd79137SRobert Mustacchi #define ISA_IA64(dbg) ((dbg)->de_flags & DW_DLC_ISA_IA64 ? 1 : 0) 42*7fd79137SRobert Mustacchi 43*7fd79137SRobert Mustacchi /* definition of sizes of types, given target machine */ 44*7fd79137SRobert Mustacchi #define sizeof_sbyte(dbg) sizeof(Dwarf_Sbyte) 45*7fd79137SRobert Mustacchi #define sizeof_ubyte(dbg) sizeof(Dwarf_Ubyte) 46*7fd79137SRobert Mustacchi #define sizeof_uhalf(dbg) sizeof(Dwarf_Half) 47*7fd79137SRobert Mustacchi /* certain sizes not defined here, but set in dbg record. 48*7fd79137SRobert Mustacchi See pro_init.c 49*7fd79137SRobert Mustacchi */ 50*7fd79137SRobert Mustacchi 51*7fd79137SRobert Mustacchi /* Computes amount of padding necessary to align n to a k-boundary. */ 52*7fd79137SRobert Mustacchi /* Important: Assumes n, k both GREATER than zero. */ 53*7fd79137SRobert Mustacchi #define PADDING(n, k) ( (k)-1 - ((n)-1)%(k) ) 54*7fd79137SRobert Mustacchi 55*7fd79137SRobert Mustacchi /* The following defines are only important for users of the 56*7fd79137SRobert Mustacchi ** producer part of libdwarf, and such should have these 57*7fd79137SRobert Mustacchi ** defined correctly (as necessary) 58*7fd79137SRobert Mustacchi ** by the #include <elf.h> done in pro_incl.h 59*7fd79137SRobert Mustacchi ** before the #include "pro_util.h". 60*7fd79137SRobert Mustacchi ** For others producer macros do not matter so 0 is a usable value, and 61*7fd79137SRobert Mustacchi ** zero values let compilation succeed on more non-MIPS architectures. 62*7fd79137SRobert Mustacchi ** A better approach would be welcome. 63*7fd79137SRobert Mustacchi */ 64*7fd79137SRobert Mustacchi /* R_MIPS* are #define so #ifndef works */ 65*7fd79137SRobert Mustacchi /* R_IA_64* are not necessarily #define (might be enum) so #ifndef 66*7fd79137SRobert Mustacchi is useless, we use the configure script generating 67*7fd79137SRobert Mustacchi HAVE_R_IA_64_DIR32LSB and HAVE_R_IA64_DIR32LSB. 68*7fd79137SRobert Mustacchi */ 69*7fd79137SRobert Mustacchi #ifndef R_MIPS_64 70*7fd79137SRobert Mustacchi #define R_MIPS_64 0 71*7fd79137SRobert Mustacchi #endif 72*7fd79137SRobert Mustacchi #ifndef R_MIPS_32 73*7fd79137SRobert Mustacchi #define R_MIPS_32 0 74*7fd79137SRobert Mustacchi #endif 75*7fd79137SRobert Mustacchi #ifndef R_MIPS_SCN_DISP 76*7fd79137SRobert Mustacchi #define R_MIPS_SCN_DISP 0 77*7fd79137SRobert Mustacchi #endif 78*7fd79137SRobert Mustacchi 79*7fd79137SRobert Mustacchi /* R_IA_64_DIR32LSB came before the now-standard R_IA64_DIR32LSB 80*7fd79137SRobert Mustacchi (etc) was defined. This now deals with either form, 81*7fd79137SRobert Mustacchi preferring the new form if available. */ 82*7fd79137SRobert Mustacchi #ifdef HAVE_R_IA64_DIR32LSB 83*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR32LSB R_IA64_DIR32LSB 84*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR64LSB R_IA64_DIR64LSB 85*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL64LSB R_IA64_SEGREL64LSB 86*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL32LSB R_IA64_SEGREL32LSB 87*7fd79137SRobert Mustacchi #endif 88*7fd79137SRobert Mustacchi #if defined(HAVE_R_IA_64_DIR32LSB) && !defined(HAVE_R_IA64_DIR32LSB) 89*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR32LSB R_IA_64_DIR32LSB 90*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR64LSB R_IA_64_DIR64LSB 91*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL64LSB R_IA_64_SEGREL64LSB 92*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL32LSB R_IA_64_SEGREL32LSB 93*7fd79137SRobert Mustacchi #endif 94*7fd79137SRobert Mustacchi #if !defined(HAVE_R_IA_64_DIR32LSB) && !defined(HAVE_R_IA64_DIR32LSB) 95*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR32LSB 0 96*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_DIR64LSB 0 97*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL64LSB 0 98*7fd79137SRobert Mustacchi #define DWARF_PRO_R_IA64_SEGREL32LSB 0 99*7fd79137SRobert Mustacchi #endif 100*7fd79137SRobert Mustacchi 101*7fd79137SRobert Mustacchi /* 102*7fd79137SRobert Mustacchi * The default "I don't know" value can't be zero. 103*7fd79137SRobert Mustacchi * Because that's the sentinel value that means "no relocation". 104*7fd79137SRobert Mustacchi * In order to use this library in 'symbolic relocation mode we 105*7fd79137SRobert Mustacchi * don't care if this value is the right relocation value, 106*7fd79137SRobert Mustacchi * only that it's non-NULL. So at the end, we define it 107*7fd79137SRobert Mustacchi * to something sensible. 108*7fd79137SRobert Mustacchi */ 109*7fd79137SRobert Mustacchi 110*7fd79137SRobert Mustacchi 111*7fd79137SRobert Mustacchi 112*7fd79137SRobert Mustacchi #if defined(sun) 113*7fd79137SRobert Mustacchi #if defined(sparc) 114*7fd79137SRobert Mustacchi #define Get_REL64_isa(dbg) (R_SPARC_UA64) 115*7fd79137SRobert Mustacchi #define Get_REL32_isa(dbg) (R_SPARC_UA32) 116*7fd79137SRobert Mustacchi #define Get_REL_SEGREL_isa(dbg) (R_SPARC_NONE) /* I don't know! */ 117*7fd79137SRobert Mustacchi #else /* i386 */ 118*7fd79137SRobert Mustacchi #define Get_REL64_isa(dbg) (R_386_32) /* Any non-zero value is ok */ 119*7fd79137SRobert Mustacchi #define Get_REL32_isa(dbg) (R_386_32) 120*7fd79137SRobert Mustacchi #define Get_REL_SEGREL_isa(dbg) (R_386_NONE) /* I don't know! */ 121*7fd79137SRobert Mustacchi #endif /* sparc || i386 */ 122*7fd79137SRobert Mustacchi #else /* !sun */ 123*7fd79137SRobert Mustacchi #ifdef HAVE_SYS_IA64_ELF_H 124*7fd79137SRobert Mustacchi #define Get_REL64_isa(dbg) (ISA_IA64(dbg) ? \ 125*7fd79137SRobert Mustacchi DWARF_PRO_R_IA64_DIR64LSB : R_MIPS_64) 126*7fd79137SRobert Mustacchi #define Get_REL32_isa(dbg) (ISA_IA64(dbg) ? \ 127*7fd79137SRobert Mustacchi DWARF_PRO_R_IA64_DIR32LSB : R_MIPS_32) 128*7fd79137SRobert Mustacchi 129*7fd79137SRobert Mustacchi 130*7fd79137SRobert Mustacchi /* ia64 uses 32bit dwarf offsets for sections */ 131*7fd79137SRobert Mustacchi #define Get_REL_SEGREL_isa(dbg) (ISA_IA64(dbg) ? \ 132*7fd79137SRobert Mustacchi DWARF_PRO_R_IA64_SEGREL32LSB : R_MIPS_SCN_DISP) 133*7fd79137SRobert Mustacchi #else /* HAVE_SYS_IA64_ELF_H */ 134*7fd79137SRobert Mustacchi 135*7fd79137SRobert Mustacchi #if !defined(linux) && !defined(__BEOS__) 136*7fd79137SRobert Mustacchi #define Get_REL64_isa(dbg) (R_MIPS_64) 137*7fd79137SRobert Mustacchi #define Get_REL32_isa(dbg) (R_MIPS_32) 138*7fd79137SRobert Mustacchi #define Get_REL_SEGREL_isa(dbg) (R_MIPS_SCN_DISP) 139*7fd79137SRobert Mustacchi #else 140*7fd79137SRobert Mustacchi #define Get_REL64_isa(dbg) (1) 141*7fd79137SRobert Mustacchi #define Get_REL32_isa(dbg) (1) /* these are used on linux */ 142*7fd79137SRobert Mustacchi #define Get_REL_SEGREL_isa(dbg) (1) /* non zero values, see comments above */ 143*7fd79137SRobert Mustacchi #endif 144*7fd79137SRobert Mustacchi 145*7fd79137SRobert Mustacchi #endif /* HAVE_SYS_IA64_ELF_H */ 146*7fd79137SRobert Mustacchi #endif /* !sun */ 147*7fd79137SRobert Mustacchi 148*7fd79137SRobert Mustacchi 149