xref: /openbsd-src/gnu/usr.bin/binutils-2.17/gas/config/obj-elf.h (revision 3d8817e467ea46cf4772788d6804dd293abfb01a)
1*3d8817e4Smiod /* ELF object file format.
2*3d8817e4Smiod    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3*3d8817e4Smiod    2002, 2003, 2004 Free Software Foundation, Inc.
4*3d8817e4Smiod 
5*3d8817e4Smiod    This file is part of GAS, the GNU Assembler.
6*3d8817e4Smiod 
7*3d8817e4Smiod    GAS is free software; you can redistribute it and/or modify
8*3d8817e4Smiod    it under the terms of the GNU General Public License as published by
9*3d8817e4Smiod    the Free Software Foundation; either version 2, or (at your option)
10*3d8817e4Smiod    any later version.
11*3d8817e4Smiod 
12*3d8817e4Smiod    GAS is distributed in the hope that it will be useful,
13*3d8817e4Smiod    but WITHOUT ANY WARRANTY; without even the implied warranty of
14*3d8817e4Smiod    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*3d8817e4Smiod    GNU General Public License for more details.
16*3d8817e4Smiod 
17*3d8817e4Smiod    You should have received a copy of the GNU General Public License
18*3d8817e4Smiod    along with GAS; see the file COPYING.  If not, write to the Free
19*3d8817e4Smiod    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20*3d8817e4Smiod    02110-1301, USA.  */
21*3d8817e4Smiod 
22*3d8817e4Smiod /* HP PA-RISC support was contributed by the Center for Software Science
23*3d8817e4Smiod    at the University of Utah.  */
24*3d8817e4Smiod 
25*3d8817e4Smiod #ifndef _OBJ_ELF_H
26*3d8817e4Smiod #define _OBJ_ELF_H
27*3d8817e4Smiod 
28*3d8817e4Smiod #define OBJ_ELF 1
29*3d8817e4Smiod 
30*3d8817e4Smiod /* Note that all macros in this file should be wrapped in #ifndef, for
31*3d8817e4Smiod    sake of obj-multi.h which includes this file.  */
32*3d8817e4Smiod 
33*3d8817e4Smiod #ifndef OUTPUT_FLAVOR
34*3d8817e4Smiod #define OUTPUT_FLAVOR bfd_target_elf_flavour
35*3d8817e4Smiod #endif
36*3d8817e4Smiod 
37*3d8817e4Smiod #include "bfd.h"
38*3d8817e4Smiod 
39*3d8817e4Smiod #define BYTES_IN_WORD 4		/* for now */
40*3d8817e4Smiod #include "bfd/elf-bfd.h"
41*3d8817e4Smiod 
42*3d8817e4Smiod #include "targ-cpu.h"
43*3d8817e4Smiod 
44*3d8817e4Smiod #ifdef TC_ALPHA
45*3d8817e4Smiod #define ECOFF_DEBUGGING (alpha_flag_mdebug > 0)
46*3d8817e4Smiod extern int alpha_flag_mdebug;
47*3d8817e4Smiod #endif
48*3d8817e4Smiod 
49*3d8817e4Smiod /* For now, always set ECOFF_DEBUGGING for a MIPS target.  */
50*3d8817e4Smiod #ifdef TC_MIPS
51*3d8817e4Smiod #define ECOFF_DEBUGGING mips_flag_mdebug
52*3d8817e4Smiod extern int mips_flag_mdebug;
53*3d8817e4Smiod #endif /* TC_MIPS */
54*3d8817e4Smiod 
55*3d8817e4Smiod #ifdef OBJ_MAYBE_ECOFF
56*3d8817e4Smiod #ifndef ECOFF_DEBUGGING
57*3d8817e4Smiod #define ECOFF_DEBUGGING 1
58*3d8817e4Smiod #endif
59*3d8817e4Smiod #endif
60*3d8817e4Smiod 
61*3d8817e4Smiod /* Additional information we keep for each symbol.  */
62*3d8817e4Smiod struct elf_obj_sy
63*3d8817e4Smiod {
64*3d8817e4Smiod   /* Whether the symbol has been marked as local.  */
65*3d8817e4Smiod   int local;
66*3d8817e4Smiod 
67*3d8817e4Smiod   /* Use this to keep track of .size expressions that involve
68*3d8817e4Smiod      differences that we can't compute yet.  */
69*3d8817e4Smiod   expressionS *size;
70*3d8817e4Smiod 
71*3d8817e4Smiod   /* The name specified by the .symver directive.  */
72*3d8817e4Smiod   char *versioned_name;
73*3d8817e4Smiod 
74*3d8817e4Smiod #ifdef ECOFF_DEBUGGING
75*3d8817e4Smiod   /* If we are generating ECOFF debugging information, we need some
76*3d8817e4Smiod      additional fields for each symbol.  */
77*3d8817e4Smiod   struct efdr *ecoff_file;
78*3d8817e4Smiod   struct localsym *ecoff_symbol;
79*3d8817e4Smiod   valueT ecoff_extern_size;
80*3d8817e4Smiod #endif
81*3d8817e4Smiod };
82*3d8817e4Smiod 
83*3d8817e4Smiod #define OBJ_SYMFIELD_TYPE struct elf_obj_sy
84*3d8817e4Smiod 
85*3d8817e4Smiod /* Symbol fields used by the ELF back end.  */
86*3d8817e4Smiod #define ELF_TARGET_SYMBOL_FIELDS int local:1;
87*3d8817e4Smiod 
88*3d8817e4Smiod /* Don't change this; change ELF_TARGET_SYMBOL_FIELDS instead.  */
89*3d8817e4Smiod #ifndef TARGET_SYMBOL_FIELDS
90*3d8817e4Smiod #define TARGET_SYMBOL_FIELDS ELF_TARGET_SYMBOL_FIELDS
91*3d8817e4Smiod #endif
92*3d8817e4Smiod 
93*3d8817e4Smiod /* #include "targ-cpu.h" */
94*3d8817e4Smiod 
95*3d8817e4Smiod #ifndef FALSE
96*3d8817e4Smiod #define FALSE 0
97*3d8817e4Smiod #define TRUE  !FALSE
98*3d8817e4Smiod #endif
99*3d8817e4Smiod 
100*3d8817e4Smiod #ifndef obj_begin
101*3d8817e4Smiod #define obj_begin() elf_begin ()
102*3d8817e4Smiod #endif
103*3d8817e4Smiod extern void elf_begin (void);
104*3d8817e4Smiod 
105*3d8817e4Smiod /* should be conditional on address size! */
106*3d8817e4Smiod #define elf_symbol(asymbol) ((elf_symbol_type *) (&(asymbol)->the_bfd))
107*3d8817e4Smiod 
108*3d8817e4Smiod #ifndef S_GET_SIZE
109*3d8817e4Smiod #define S_GET_SIZE(S) \
110*3d8817e4Smiod   (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_size)
111*3d8817e4Smiod #endif
112*3d8817e4Smiod #ifndef S_SET_SIZE
113*3d8817e4Smiod #define S_SET_SIZE(S,V) \
114*3d8817e4Smiod   (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_size = (V))
115*3d8817e4Smiod #endif
116*3d8817e4Smiod 
117*3d8817e4Smiod #ifndef S_GET_ALIGN
118*3d8817e4Smiod #define S_GET_ALIGN(S) \
119*3d8817e4Smiod   (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_value)
120*3d8817e4Smiod #endif
121*3d8817e4Smiod #ifndef S_SET_ALIGN
122*3d8817e4Smiod #define S_SET_ALIGN(S,V) \
123*3d8817e4Smiod   (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_value = (V))
124*3d8817e4Smiod #endif
125*3d8817e4Smiod 
126*3d8817e4Smiod int elf_s_get_other (symbolS *);
127*3d8817e4Smiod #ifndef S_GET_OTHER
128*3d8817e4Smiod #define S_GET_OTHER(S)	(elf_s_get_other (S))
129*3d8817e4Smiod #endif
130*3d8817e4Smiod #ifndef S_SET_OTHER
131*3d8817e4Smiod #define S_SET_OTHER(S,V) \
132*3d8817e4Smiod   (elf_symbol (symbol_get_bfdsym (S))->internal_elf_sym.st_other = (V))
133*3d8817e4Smiod #endif
134*3d8817e4Smiod 
135*3d8817e4Smiod extern asection *gdb_section;
136*3d8817e4Smiod 
137*3d8817e4Smiod #ifndef obj_sec_set_private_data
138*3d8817e4Smiod #define obj_sec_set_private_data(B, S) \
139*3d8817e4Smiod   if (! BFD_SEND ((B), _new_section_hook, ((B), (S)))) \
140*3d8817e4Smiod     as_fatal (_("can't allocate ELF private section data: %s"),	\
141*3d8817e4Smiod 	      bfd_errmsg (bfd_get_error ()))
142*3d8817e4Smiod #endif
143*3d8817e4Smiod 
144*3d8817e4Smiod #ifndef obj_frob_file
145*3d8817e4Smiod #define obj_frob_file  elf_frob_file
146*3d8817e4Smiod #endif
147*3d8817e4Smiod extern void elf_frob_file (void);
148*3d8817e4Smiod 
149*3d8817e4Smiod #ifndef obj_frob_file_before_adjust
150*3d8817e4Smiod #define obj_frob_file_before_adjust  elf_frob_file_before_adjust
151*3d8817e4Smiod #endif
152*3d8817e4Smiod extern void elf_frob_file_before_adjust (void);
153*3d8817e4Smiod 
154*3d8817e4Smiod #ifndef obj_frob_file_after_relocs
155*3d8817e4Smiod #define obj_frob_file_after_relocs  elf_frob_file_after_relocs
156*3d8817e4Smiod #endif
157*3d8817e4Smiod extern void elf_frob_file_after_relocs (void);
158*3d8817e4Smiod 
159*3d8817e4Smiod /* If the target doesn't have special processing for labels, take care of
160*3d8817e4Smiod    dwarf2 output at the object file level.  */
161*3d8817e4Smiod #ifndef tc_frob_label
162*3d8817e4Smiod #include "dwarf2dbg.h"
163*3d8817e4Smiod #define obj_frob_label  dwarf2_emit_label
164*3d8817e4Smiod #endif
165*3d8817e4Smiod 
166*3d8817e4Smiod #ifndef obj_app_file
167*3d8817e4Smiod #define obj_app_file elf_file_symbol
168*3d8817e4Smiod #endif
169*3d8817e4Smiod extern void elf_file_symbol (const char *, int);
170*3d8817e4Smiod 
171*3d8817e4Smiod extern void obj_elf_section_change_hook (void);
172*3d8817e4Smiod 
173*3d8817e4Smiod extern void obj_elf_section (int);
174*3d8817e4Smiod extern void obj_elf_previous (int);
175*3d8817e4Smiod extern void obj_elf_version (int);
176*3d8817e4Smiod extern void obj_elf_common (int);
177*3d8817e4Smiod extern void obj_elf_data (int);
178*3d8817e4Smiod extern void obj_elf_text (int);
179*3d8817e4Smiod extern void obj_elf_change_section
180*3d8817e4Smiod   (const char *, int, int, int, const char *, int, int);
181*3d8817e4Smiod extern struct fix *obj_elf_vtable_inherit (int);
182*3d8817e4Smiod extern struct fix *obj_elf_vtable_entry (int);
183*3d8817e4Smiod 
184*3d8817e4Smiod /* BFD wants to write the udata field, which is a no-no for the
185*3d8817e4Smiod    predefined section symbols in bfd/section.c.  They are read-only.  */
186*3d8817e4Smiod #ifndef obj_sec_sym_ok_for_reloc
187*3d8817e4Smiod #define obj_sec_sym_ok_for_reloc(SEC)	((SEC)->owner != 0)
188*3d8817e4Smiod #endif
189*3d8817e4Smiod 
190*3d8817e4Smiod void elf_obj_read_begin_hook (void);
191*3d8817e4Smiod #ifndef obj_read_begin_hook
192*3d8817e4Smiod #define obj_read_begin_hook	elf_obj_read_begin_hook
193*3d8817e4Smiod #endif
194*3d8817e4Smiod 
195*3d8817e4Smiod void elf_obj_symbol_new_hook (symbolS *);
196*3d8817e4Smiod #ifndef obj_symbol_new_hook
197*3d8817e4Smiod #define obj_symbol_new_hook	elf_obj_symbol_new_hook
198*3d8817e4Smiod #endif
199*3d8817e4Smiod 
200*3d8817e4Smiod void elf_copy_symbol_attributes (symbolS *, symbolS *);
201*3d8817e4Smiod #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES
202*3d8817e4Smiod #define OBJ_COPY_SYMBOL_ATTRIBUTES(DEST, SRC) \
203*3d8817e4Smiod   (elf_copy_symbol_attributes (DEST, SRC))
204*3d8817e4Smiod #endif
205*3d8817e4Smiod 
206*3d8817e4Smiod #ifndef SEPARATE_STAB_SECTIONS
207*3d8817e4Smiod /* Avoid ifndef each separate macro setting by wrapping the whole of the
208*3d8817e4Smiod    stab group on the assumption that whoever sets SEPARATE_STAB_SECTIONS
209*3d8817e4Smiod    caters to ECOFF_DEBUGGING and the right setting of INIT_STAB_SECTIONS
210*3d8817e4Smiod    and OBJ_PROCESS_STAB too, without needing the tweaks below.  */
211*3d8817e4Smiod 
212*3d8817e4Smiod /* Stabs go in a separate section.  */
213*3d8817e4Smiod #define SEPARATE_STAB_SECTIONS 1
214*3d8817e4Smiod 
215*3d8817e4Smiod /* We need 12 bytes at the start of the section to hold some initial
216*3d8817e4Smiod    information.  */
217*3d8817e4Smiod extern void obj_elf_init_stab_section (segT);
218*3d8817e4Smiod #define INIT_STAB_SECTION(seg) obj_elf_init_stab_section (seg)
219*3d8817e4Smiod 
220*3d8817e4Smiod #ifdef ECOFF_DEBUGGING
221*3d8817e4Smiod /* We smuggle stabs in ECOFF rather than using a separate section.
222*3d8817e4Smiod    The Irix linker can not handle a separate stabs section.  */
223*3d8817e4Smiod 
224*3d8817e4Smiod #undef  SEPARATE_STAB_SECTIONS
225*3d8817e4Smiod #define SEPARATE_STAB_SECTIONS (!ECOFF_DEBUGGING)
226*3d8817e4Smiod 
227*3d8817e4Smiod #undef  INIT_STAB_SECTION
228*3d8817e4Smiod #define INIT_STAB_SECTION(seg) \
229*3d8817e4Smiod   ((void) (ECOFF_DEBUGGING ? 0 : (obj_elf_init_stab_section (seg), 0)))
230*3d8817e4Smiod 
231*3d8817e4Smiod #undef OBJ_PROCESS_STAB
232*3d8817e4Smiod #define OBJ_PROCESS_STAB(seg, what, string, type, other, desc)		\
233*3d8817e4Smiod   if (ECOFF_DEBUGGING)							\
234*3d8817e4Smiod     ecoff_stab ((seg), (what), (string), (type), (other), (desc))
235*3d8817e4Smiod #endif /* ECOFF_DEBUGGING */
236*3d8817e4Smiod 
237*3d8817e4Smiod #endif /* SEPARATE_STAB_SECTIONS not defined.  */
238*3d8817e4Smiod 
239*3d8817e4Smiod extern void elf_frob_symbol (symbolS *, int *);
240*3d8817e4Smiod #ifndef obj_frob_symbol
241*3d8817e4Smiod #define obj_frob_symbol(symp, punt) elf_frob_symbol (symp, &punt)
242*3d8817e4Smiod #endif
243*3d8817e4Smiod 
244*3d8817e4Smiod extern void elf_pop_insert (void);
245*3d8817e4Smiod #ifndef obj_pop_insert
246*3d8817e4Smiod #define obj_pop_insert()	elf_pop_insert()
247*3d8817e4Smiod #endif
248*3d8817e4Smiod 
249*3d8817e4Smiod #ifndef OBJ_MAYBE_ELF
250*3d8817e4Smiod #define obj_ecoff_set_ext elf_ecoff_set_ext
251*3d8817e4Smiod struct ecoff_extr;
252*3d8817e4Smiod extern void elf_ecoff_set_ext (symbolS *, struct ecoff_extr *);
253*3d8817e4Smiod #endif
254*3d8817e4Smiod extern asection *elf_com_section_ptr;
255*3d8817e4Smiod extern symbolS * elf_common_parse (int ignore ATTRIBUTE_UNUSED, symbolS *symbolP,
256*3d8817e4Smiod 				   addressT size);
257*3d8817e4Smiod 
258*3d8817e4Smiod #endif /* _OBJ_ELF_H */
259