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