xref: /titanic_44/usr/src/tools/ctf/dwarf/common/pro_util.h (revision 07dc1947c362e187fb955d283b692f8769dd5def)
149d3bc91SRichard Lowe /*
249d3bc91SRichard Lowe 
3*07dc1947SRichard Lowe   Copyright (C) 2000,2004 Silicon Graphics, Inc.  All Rights Reserved.
4*07dc1947SRichard Lowe   Portions Copyright 2002-2010 Sun Microsystems, Inc. All rights reserved.
549d3bc91SRichard Lowe 
649d3bc91SRichard Lowe   This program is free software; you can redistribute it and/or modify it
749d3bc91SRichard Lowe   under the terms of version 2.1 of the GNU Lesser General Public License
849d3bc91SRichard Lowe   as published by the Free Software Foundation.
949d3bc91SRichard Lowe 
1049d3bc91SRichard Lowe   This program is distributed in the hope that it would be useful, but
1149d3bc91SRichard Lowe   WITHOUT ANY WARRANTY; without even the implied warranty of
1249d3bc91SRichard Lowe   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1349d3bc91SRichard Lowe 
1449d3bc91SRichard Lowe   Further, this software is distributed without any warranty that it is
1549d3bc91SRichard Lowe   free of the rightful claim of any third person regarding infringement
1649d3bc91SRichard Lowe   or the like.  Any license provided herein, whether implied or
1749d3bc91SRichard Lowe   otherwise, applies only to this software file.  Patent licenses, if
1849d3bc91SRichard Lowe   any, provided herein do not apply to combinations of this program with
1949d3bc91SRichard Lowe   other software, or any other product whatsoever.
2049d3bc91SRichard Lowe 
2149d3bc91SRichard Lowe   You should have received a copy of the GNU Lesser General Public
2249d3bc91SRichard Lowe   License along with this program; if not, write the Free Software
23*07dc1947SRichard Lowe   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston MA 02110-1301,
2449d3bc91SRichard Lowe   USA.
2549d3bc91SRichard Lowe 
26*07dc1947SRichard Lowe   Contact information:  Silicon Graphics, Inc., 1500 Crittenden Lane,
2749d3bc91SRichard Lowe   Mountain View, CA 94043, or:
2849d3bc91SRichard Lowe 
2949d3bc91SRichard Lowe   http://www.sgi.com
3049d3bc91SRichard Lowe 
3149d3bc91SRichard Lowe   For further information regarding this notice, see:
3249d3bc91SRichard Lowe 
3349d3bc91SRichard Lowe   http://oss.sgi.com/projects/GenInfo/NoticeExplan
3449d3bc91SRichard Lowe 
3549d3bc91SRichard Lowe */
3649d3bc91SRichard Lowe 
3749d3bc91SRichard Lowe 
3849d3bc91SRichard Lowe 
3949d3bc91SRichard Lowe 
4049d3bc91SRichard Lowe #define IS_64BIT(dbg) ((dbg)->de_flags & DW_DLC_SIZE_64 ? 1 : 0)
4149d3bc91SRichard Lowe #define ISA_IA64(dbg) ((dbg)->de_flags & DW_DLC_ISA_IA64 ? 1 : 0)
4249d3bc91SRichard Lowe 
4349d3bc91SRichard Lowe /* definition of sizes of types, given target machine */
4449d3bc91SRichard Lowe #define sizeof_sbyte(dbg) sizeof(Dwarf_Sbyte)
4549d3bc91SRichard Lowe #define sizeof_ubyte(dbg) sizeof(Dwarf_Ubyte)
4649d3bc91SRichard Lowe #define sizeof_uhalf(dbg) sizeof(Dwarf_Half)
4749d3bc91SRichard Lowe /* certain sizes not defined here, but set in dbg record.
4849d3bc91SRichard Lowe    See pro_init.c
4949d3bc91SRichard Lowe */
5049d3bc91SRichard Lowe 
5149d3bc91SRichard Lowe /* Computes amount of padding necessary to align n to a k-boundary. */
5249d3bc91SRichard Lowe /* Important: Assumes n, k both GREATER than zero. */
5349d3bc91SRichard Lowe #define PADDING(n, k) ( (k)-1 - ((n)-1)%(k) )
5449d3bc91SRichard Lowe 
5549d3bc91SRichard Lowe /* The following defines are only important for users of the
5649d3bc91SRichard Lowe ** producer part of libdwarf, and such should have these
5749d3bc91SRichard Lowe ** defined correctly (as necessary)
5849d3bc91SRichard Lowe ** by the #include <elf.h> done in pro_incl.h
5949d3bc91SRichard Lowe ** before the #include "pro_util.h".
6049d3bc91SRichard Lowe ** For others producer macros do not matter so 0 is a usable value, and
6149d3bc91SRichard Lowe ** zero values let compilation succeed on more non-MIPS architectures.
6249d3bc91SRichard Lowe ** A better approach would be welcome.
6349d3bc91SRichard Lowe */
6449d3bc91SRichard Lowe /* R_MIPS* are #define so #ifndef works */
6549d3bc91SRichard Lowe /* R_IA_64* are not necessarily #define (might be enum) so #ifndef
6649d3bc91SRichard Lowe    is useless, we use the configure script generating
67*07dc1947SRichard Lowe    HAVE_R_IA_64_DIR32LSB and HAVE_R_IA64_DIR32LSB.
6849d3bc91SRichard Lowe */
6949d3bc91SRichard Lowe #ifndef R_MIPS_64
7049d3bc91SRichard Lowe #define R_MIPS_64 0
7149d3bc91SRichard Lowe #endif
7249d3bc91SRichard Lowe #ifndef R_MIPS_32
7349d3bc91SRichard Lowe #define R_MIPS_32 0
7449d3bc91SRichard Lowe #endif
7549d3bc91SRichard Lowe #ifndef R_MIPS_SCN_DISP
7649d3bc91SRichard Lowe #define R_MIPS_SCN_DISP 0
7749d3bc91SRichard Lowe #endif
7849d3bc91SRichard Lowe 
79*07dc1947SRichard Lowe /* R_IA_64_DIR32LSB came before the now-standard R_IA64_DIR32LSB
80*07dc1947SRichard Lowe    (etc) was defined.  This now deals with either form,
81*07dc1947SRichard Lowe    preferring the new form if available.  */
82*07dc1947SRichard Lowe #ifdef HAVE_R_IA64_DIR32LSB
83*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR32LSB R_IA64_DIR32LSB
84*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR64LSB R_IA64_DIR64LSB
85*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL64LSB R_IA64_SEGREL64LSB
86*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL32LSB R_IA64_SEGREL32LSB
87*07dc1947SRichard Lowe #endif
88*07dc1947SRichard Lowe #if defined(HAVE_R_IA_64_DIR32LSB) && !defined(HAVE_R_IA64_DIR32LSB)
89*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR32LSB R_IA_64_DIR32LSB
90*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR64LSB R_IA_64_DIR64LSB
91*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL64LSB R_IA_64_SEGREL64LSB
92*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL32LSB R_IA_64_SEGREL32LSB
93*07dc1947SRichard Lowe #endif
94*07dc1947SRichard Lowe #if !defined(HAVE_R_IA_64_DIR32LSB) && !defined(HAVE_R_IA64_DIR32LSB)
95*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR32LSB 0
96*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_DIR64LSB 0
97*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL64LSB 0
98*07dc1947SRichard Lowe #define DWARF_PRO_R_IA64_SEGREL32LSB 0
9949d3bc91SRichard Lowe #endif
10049d3bc91SRichard Lowe 
101*07dc1947SRichard Lowe /*
102*07dc1947SRichard Lowe  * The default "I don't know" value can't be zero.
103*07dc1947SRichard Lowe  * Because that's the sentinel value that means "no relocation".
104*07dc1947SRichard Lowe  * In order to use this library in 'symbolic relocation mode we
105*07dc1947SRichard Lowe  * don't care if this value is the right relocation value,
106*07dc1947SRichard Lowe  * only that it's non-NULL.  So at the end, we define it
107*07dc1947SRichard Lowe  * to something sensible.
108*07dc1947SRichard Lowe  */
109*07dc1947SRichard Lowe 
110*07dc1947SRichard Lowe 
111*07dc1947SRichard Lowe 
112*07dc1947SRichard Lowe #if defined(sun)
113*07dc1947SRichard Lowe #if defined(sparc)
114*07dc1947SRichard Lowe #define Get_REL64_isa(dbg)         (R_SPARC_UA64)
115*07dc1947SRichard Lowe #define Get_REL32_isa(dbg)         (R_SPARC_UA32)
116*07dc1947SRichard Lowe #define Get_REL_SEGREL_isa(dbg)    (R_SPARC_NONE) /* I don't know! */
117*07dc1947SRichard Lowe #else  /* i386 */
118*07dc1947SRichard Lowe #define Get_REL64_isa(dbg)         (R_386_32)   /* Any non-zero value is ok */
119*07dc1947SRichard Lowe #define Get_REL32_isa(dbg)         (R_386_32)
120*07dc1947SRichard Lowe #define Get_REL_SEGREL_isa(dbg)    (R_386_NONE) /* I don't know! */
121*07dc1947SRichard Lowe #endif /* sparc || i386 */
122*07dc1947SRichard Lowe #else  /* !sun */
12349d3bc91SRichard Lowe #ifdef HAVE_SYS_IA64_ELF_H
12449d3bc91SRichard Lowe #define Get_REL64_isa(dbg)         (ISA_IA64(dbg) ? \
125*07dc1947SRichard Lowe     DWARF_PRO_R_IA64_DIR64LSB : R_MIPS_64)
12649d3bc91SRichard Lowe #define Get_REL32_isa(dbg)         (ISA_IA64(dbg) ? \
127*07dc1947SRichard Lowe     DWARF_PRO_R_IA64_DIR32LSB : R_MIPS_32)
12849d3bc91SRichard Lowe 
12949d3bc91SRichard Lowe 
13049d3bc91SRichard Lowe /* ia64 uses 32bit dwarf offsets for sections */
13149d3bc91SRichard Lowe #define Get_REL_SEGREL_isa(dbg)    (ISA_IA64(dbg) ? \
132*07dc1947SRichard Lowe     DWARF_PRO_R_IA64_SEGREL32LSB : R_MIPS_SCN_DISP)
133*07dc1947SRichard Lowe #else /* HAVE_SYS_IA64_ELF_H */
13449d3bc91SRichard Lowe 
13549d3bc91SRichard Lowe #if !defined(linux) && !defined(__BEOS__)
13649d3bc91SRichard Lowe #define Get_REL64_isa(dbg)         (R_MIPS_64)
13749d3bc91SRichard Lowe #define Get_REL32_isa(dbg)         (R_MIPS_32)
13849d3bc91SRichard Lowe #define Get_REL_SEGREL_isa(dbg)    (R_MIPS_SCN_DISP)
13949d3bc91SRichard Lowe #else
140*07dc1947SRichard Lowe #define Get_REL64_isa(dbg) (1)
141*07dc1947SRichard Lowe #define Get_REL32_isa(dbg) (1)   /* these are used on linux */
142*07dc1947SRichard Lowe #define Get_REL_SEGREL_isa(dbg) (1)   /* non zero values, see comments above */
14349d3bc91SRichard Lowe #endif
14449d3bc91SRichard Lowe 
145*07dc1947SRichard Lowe #endif /* HAVE_SYS_IA64_ELF_H */
146*07dc1947SRichard Lowe #endif /* !sun */
147*07dc1947SRichard Lowe 
148*07dc1947SRichard Lowe 
149