* elf.c, elfcode.h, libelf.h: Serious reorganization.
[deliverable/binutils-gdb.git] / bfd / libelf.h
CommitLineData
db232882
KR
1/* BFD back-end data structures for ELF files.
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5This file is part of BFD, the Binary File Descriptor library.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#ifndef _LIBELF_H_
22#define _LIBELF_H_ 1
23
81187b54
KR
24#include "elf/common.h"
25#include "elf/internal.h"
26#include "elf/external.h"
27
638616ca
KR
28/* This CAT4 hack is to avoid a problem with some strict ANSI C preprocessors.
29 The problem is, "32_" is not a valid preprocessing token, and we don't
30 want extra underscores (e.g., "elf_32_"). The XCAT2 macro will cause the
31 inner CAT macros to be evaluated first, producing still-valid pp-tokens.
32 Then the final concatenation can be done. (Sigh.) */
7d9bb6da
KR
33#ifdef SABER
34#define CAT4(a,b,c,d) a##b##c##d
35#else
638616ca
KR
36#ifdef __STDC__
37#define XCAT2(a,b) CAT(a,b)
38#define CAT4(a,b,c,d) XCAT2(CAT(a,b),CAT(c,d))
39#else
40#define CAT4(a,b,c,d) a/**/b/**/c/**/d
41#endif
7d9bb6da 42#endif
638616ca 43
998ce1e0 44/* If size isn't specified as 64 or 32, NAME macro should fail. */
9942e684 45#ifndef NAME
7050286d 46#if ARCH_SIZE==64
638616ca 47#define NAME(x,y) CAT4(x,64,_,y)
998ce1e0
KR
48#endif
49#if ARCH_SIZE==32
638616ca 50#define NAME(x,y) CAT4(x,32,_,y)
9942e684
KR
51#endif
52#endif
53
638616ca
KR
54#define ElfNAME(X) NAME(Elf,X)
55#define elfNAME(X) NAME(elf,X)
56
db232882
KR
57typedef struct
58{
59 asymbol symbol;
268f94ac 60 Elf_Internal_Sym internal_elf_sym;
db232882
KR
61 /* these are used for the generation of .stabX symbols (?) */
62 short desc;
63 unsigned char type;
64 char other;
7050286d
KR
65 union
66 {
67 unsigned int hppa_arg_reloc;
68 PTR any;
69 }
70 tc_data;
998ce1e0
KR
71 Elf32_External_Sym native_elf_sym;
72} elf32_symbol_type;
db232882 73
998ce1e0
KR
74typedef struct
75{
76 asymbol symbol;
77 Elf_Internal_Sym internal_elf_sym;
78 /* these are used for the generation of .stabX symbols (?) */
79 short desc;
80 unsigned char type;
81 char other;
82 union
83 {
84 unsigned int hppa_arg_reloc;
85 PTR any;
86 }
87 tc_data;
88 Elf64_External_Sym native_elf_sym;
89} elf64_symbol_type;
7050286d 90
268f94ac 91struct elf_backend_data
7050286d
KR
92{
93 int use_rela_p;
94 int elf_64_p;
81187b54 95 enum bfd_architecture arch;
7050286d 96 void (*elf_info_to_howto) PARAMS ((bfd *, arelent *,
268f94ac 97 Elf_Internal_Rela *));
7050286d 98 void (*elf_info_to_howto_rel) PARAMS ((bfd *, arelent *,
268f94ac 99 Elf_Internal_Rel *));
32090b8e 100 void (*write_relocs) PARAMS ((bfd *, asection *, PTR));
db232882 101
8e40bcd8
KR
102 /* @@ I really don't think this should be here. I don't know what
103 global_sym is supposed to be used for, but I doubt it's something
104 that would be considered global, e.g., if you've got a program
105 reading and writing many BFDs. My hunch is that it's specific to
106 the output BFD. If not, put a comment here explaining why. */
998ce1e0
KR
107 /* @@ Was pointer to elfNAME(symbol_type). This makes it size-
108 independent. */
109 PTR global_sym;
81187b54
KR
110};
111
32090b8e
KR
112struct bfd_elf_arch_map {
113 enum bfd_architecture bfd_arch;
114 int elf_arch;
115};
116
117extern const struct bfd_elf_arch_map bfd_elf_arch_map[];
118extern const int bfd_elf_arch_map_size;
119
120struct bfd_elf_section_data {
121 Elf_Internal_Shdr this_hdr;
122 Elf_Internal_Shdr rel_hdr;
123 int this_idx, rel_idx;
124#if 0
125 Elf_Internal_Shdr str_hdr;
126 int str_idx;
127#endif
128};
129#define elf_section_data(sec) ((struct bfd_elf_section_data*)sec->used_by_bfd)
130#define shdr_name(abfd,shdr) (elf_shstrtab (abfd)->tab + (shdr)->sh_name)
131
132#define get_elf_backend_data(abfd) \
133 ((struct elf_backend_data *) (abfd)->xvec->backend_data)
134
135struct strtab
136{
137 char *tab;
138 int nentries;
139 int length;
140};
141
142/* Some private data is stashed away for future use using the tdata pointer
143 in the bfd structure. */
144
145struct elf_obj_tdata
146{
147 Elf_Internal_Ehdr elf_header[1]; /* Actual data, but ref like ptr */
148 Elf_Internal_Shdr **elf_sect_ptr;
149 struct strtab *strtab_ptr;
150 int num_locals;
151 int num_globals;
152 int *symtab_map;
153 PTR raw_syms; /* Elf_External_Sym* */
154 Elf_Internal_Sym *internal_syms;
155 PTR symbols; /* elf_symbol_type */
156/* struct strtab *shstrtab;*/
157 Elf_Internal_Shdr symtab_hdr;
158 Elf_Internal_Shdr shstrtab_hdr;
159 Elf_Internal_Shdr strtab_hdr;
160 int symtab_section, shstrtab_section, strtab_section;
161 file_ptr next_file_pos;
162 void *prstatus; /* The raw /proc prstatus structure */
163 void *prpsinfo; /* The raw /proc prpsinfo structure */
164};
165
166#define elf_tdata(bfd) ((bfd) -> tdata.elf_obj_data)
167#define elf_elfheader(bfd) (elf_tdata(bfd) -> elf_header)
168#define elf_elfsections(bfd) (elf_tdata(bfd) -> elf_sect_ptr)
169#define elf_shstrtab(bfd) (elf_tdata(bfd) -> strtab_ptr)
170#define elf_onesymtab(bfd) (elf_tdata(bfd) -> symtab_section)
171#define elf_num_locals(bfd) (elf_tdata(bfd) -> num_locals)
172#define elf_num_globals(bfd) (elf_tdata(bfd) -> num_globals)
173#define elf_symtab_map(bfd) (elf_tdata(bfd) -> symtab_map)
174#define core_prpsinfo(bfd) (elf_tdata(bfd) -> prpsinfo)
175#define core_prstatus(bfd) (elf_tdata(bfd) -> prstatus)
176#define obj_symbols(bfd) ((elf_symbol_type*)(elf_tdata(bfd) -> symbols))
177#define obj_raw_syms(bfd) ((Elf_External_Sym*)(elf_tdata(bfd) -> raw_syms))
178#define obj_internal_syms(bfd) (elf_tdata(bfd) -> internal_syms)
179
180extern char * elf_string_from_elf_section PARAMS ((bfd *, unsigned, unsigned));
181extern char * elf_get_str_section PARAMS ((bfd *, unsigned));
182
183#define bfd_elf32_mkobject bfd_elf_mkobject
184#define bfd_elf64_mkobject bfd_elf_mkobject
185#define elf_mkobject bfd_elf_mkobject
186
7e37f9ff
KR
187extern unsigned long elf_hash PARAMS ((CONST unsigned char *));
188
32090b8e
KR
189extern bfd_reloc_status_type bfd_elf_generic_reloc PARAMS ((bfd *,
190 arelent *,
191 asymbol *,
192 PTR,
193 asection *,
194 bfd *));
998ce1e0 195extern boolean bfd_elf_mkobject PARAMS ((bfd *));
9942e684 196extern boolean bfd_elf32_write_object_contents PARAMS ((bfd *));
32090b8e
KR
197extern boolean bfd_elf64_write_object_contents PARAMS ((bfd *));
198
199extern bfd_target *bfd_elf32_object_p PARAMS ((bfd *));
200extern bfd_target *bfd_elf32_core_file_p PARAMS ((bfd *));
9942e684
KR
201extern char *bfd_elf32_core_file_failing_command PARAMS ((bfd *));
202extern int bfd_elf32_core_file_failing_signal PARAMS ((bfd *));
203extern boolean bfd_elf32_core_file_matches_executable_p PARAMS ((bfd *,
204 bfd *));
205extern boolean bfd_elf32_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
206 file_ptr,
207 bfd_size_type));
7050286d 208
9942e684
KR
209extern unsigned int bfd_elf32_get_symtab_upper_bound PARAMS ((bfd *));
210extern unsigned int bfd_elf32_get_symtab PARAMS ((bfd *, asymbol **));
211extern unsigned int bfd_elf32_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
212extern unsigned int bfd_elf32_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
213 arelent **,
214 asymbol **));
215extern asymbol *bfd_elf32_make_empty_symbol PARAMS ((bfd *));
216extern void bfd_elf32_print_symbol PARAMS ((bfd *, PTR, asymbol *,
217 bfd_print_symbol_type));
218extern void bfd_elf32_get_symbol_info PARAMS ((bfd *, asymbol *,
7050286d 219 symbol_info *));
9942e684
KR
220extern alent *bfd_elf32_get_lineno PARAMS ((bfd *, asymbol *));
221extern boolean bfd_elf32_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
222 unsigned long));
223extern boolean bfd_elf32_find_nearest_line PARAMS ((bfd *, asection *,
224 asymbol **,
225 bfd_vma, CONST char **,
226 CONST char **,
227 unsigned int *));
228extern int bfd_elf32_sizeof_headers PARAMS ((bfd *, boolean));
32090b8e 229extern void bfd_elf32__write_relocs PARAMS ((bfd *, asection *, PTR));
e6858d1b 230extern boolean bfd_elf32_new_section_hook PARAMS ((bfd *, asection *));
81187b54
KR
231
232/* If the target doesn't have reloc handling written yet: */
9942e684
KR
233extern void bfd_elf32_no_info_to_howto PARAMS ((bfd *, arelent *,
234 Elf32_Internal_Rela *));
db232882 235
7d9bb6da
KR
236extern bfd_target *bfd_elf64_object_p PARAMS ((bfd *));
237extern bfd_target *bfd_elf64_core_file_p PARAMS ((bfd *));
7d9bb6da
KR
238extern char *bfd_elf64_core_file_failing_command PARAMS ((bfd *));
239extern int bfd_elf64_core_file_failing_signal PARAMS ((bfd *));
240extern boolean bfd_elf64_core_file_matches_executable_p PARAMS ((bfd *,
241 bfd *));
242extern boolean bfd_elf64_set_section_contents PARAMS ((bfd *, sec_ptr, PTR,
243 file_ptr,
244 bfd_size_type));
245
246extern unsigned int bfd_elf64_get_symtab_upper_bound PARAMS ((bfd *));
247extern unsigned int bfd_elf64_get_symtab PARAMS ((bfd *, asymbol **));
248extern unsigned int bfd_elf64_get_reloc_upper_bound PARAMS ((bfd *, sec_ptr));
249extern unsigned int bfd_elf64_canonicalize_reloc PARAMS ((bfd *, sec_ptr,
250 arelent **,
251 asymbol **));
252extern asymbol *bfd_elf64_make_empty_symbol PARAMS ((bfd *));
253extern void bfd_elf64_print_symbol PARAMS ((bfd *, PTR, asymbol *,
254 bfd_print_symbol_type));
255extern void bfd_elf64_get_symbol_info PARAMS ((bfd *, asymbol *,
256 symbol_info *));
257extern alent *bfd_elf64_get_lineno PARAMS ((bfd *, asymbol *));
258extern boolean bfd_elf64_set_arch_mach PARAMS ((bfd *, enum bfd_architecture,
259 unsigned long));
260extern boolean bfd_elf64_find_nearest_line PARAMS ((bfd *, asection *,
261 asymbol **,
262 bfd_vma, CONST char **,
263 CONST char **,
264 unsigned int *));
265extern int bfd_elf64_sizeof_headers PARAMS ((bfd *, boolean));
32090b8e 266extern void bfd_elf64__write_relocs PARAMS ((bfd *, asection *, PTR));
7d9bb6da
KR
267extern boolean bfd_elf64_new_section_hook PARAMS ((bfd *, asection *));
268
269/* If the target doesn't have reloc handling written yet: */
270extern void bfd_elf64_no_info_to_howto PARAMS ((bfd *, arelent *,
271 Elf64_Internal_Rela *));
272
db232882 273#endif /* _LIBELF_H_ */
This page took 0.050159 seconds and 4 git commands to generate.