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