1 1.1 christos /* coff object file format 2 1.10 christos Copyright (C) 1989-2025 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos This file is part of GAS. 5 1.1 christos 6 1.1 christos GAS is free software; you can redistribute it and/or modify 7 1.1 christos it under the terms of the GNU General Public License as published by 8 1.1 christos the Free Software Foundation; either version 3, or (at your option) 9 1.1 christos any later version. 10 1.1 christos 11 1.1 christos GAS is distributed in the hope that it will be useful, 12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 1.1 christos GNU General Public License for more details. 15 1.1 christos 16 1.1 christos You should have received a copy of the GNU General Public License 17 1.1 christos along with GAS; see the file COPYING. If not, write to the Free 18 1.1 christos Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 19 1.1 christos 02110-1301, USA. */ 20 1.1 christos 21 1.1 christos #ifndef OBJ_FORMAT_H 22 1.1 christos #define OBJ_FORMAT_H 23 1.1 christos 24 1.1 christos #define OBJ_COFF 1 25 1.1 christos 26 1.1 christos #include "targ-cpu.h" 27 1.1 christos 28 1.1 christos /* This internal_lineno crap is to stop namespace pollution from the 29 1.1 christos bfd internal coff headerfile. */ 30 1.1 christos #define internal_lineno bfd_internal_lineno 31 1.1 christos #include "coff/internal.h" 32 1.1 christos #undef internal_lineno 33 1.1 christos 34 1.1 christos /* CPU-specific setup: */ 35 1.1 christos 36 1.1 christos #ifdef TC_ARM 37 1.1 christos #include "coff/arm.h" 38 1.1 christos #ifndef TARGET_FORMAT 39 1.1 christos #define TARGET_FORMAT "coff-arm" 40 1.1 christos #endif 41 1.1 christos #endif 42 1.1 christos 43 1.9 christos #ifdef TC_AARCH64 44 1.9 christos #include "coff/aarch64.h" 45 1.9 christos #endif 46 1.9 christos 47 1.1 christos #ifdef TC_PPC 48 1.1 christos #include "coff/rs6000.h" 49 1.1 christos #endif 50 1.1 christos 51 1.1 christos #ifdef TC_I386 52 1.10 christos #include "coff/x86.h" 53 1.1 christos #ifndef TARGET_FORMAT 54 1.1 christos #ifdef TE_PEP 55 1.1 christos #define TARGET_FORMAT "coff-x86-64" 56 1.1 christos #else 57 1.1 christos #define TARGET_FORMAT "coff-i386" 58 1.1 christos #endif 59 1.1 christos #endif 60 1.1 christos #endif 61 1.1 christos 62 1.1 christos #ifdef TC_Z80 63 1.1 christos #include "coff/z80.h" 64 1.1 christos #define TARGET_FORMAT "coff-z80" 65 1.1 christos #endif 66 1.1 christos 67 1.1 christos #ifdef TC_Z8K 68 1.1 christos #include "coff/z8k.h" 69 1.1 christos #define TARGET_FORMAT "coff-z8k" 70 1.1 christos #endif 71 1.1 christos 72 1.1 christos #ifdef TC_SH 73 1.1 christos 74 1.1 christos #ifdef TE_PE 75 1.1 christos #define COFF_WITH_PE 76 1.1 christos #endif 77 1.1 christos 78 1.1 christos #include "coff/sh.h" 79 1.1 christos 80 1.1 christos #ifdef TE_PE 81 1.1 christos #define TARGET_FORMAT "pe-shl" 82 1.1 christos #else 83 1.1 christos 84 1.1 christos #define TARGET_FORMAT \ 85 1.1 christos (!target_big_endian \ 86 1.1 christos ? (sh_small ? "coff-shl-small" : "coff-shl") \ 87 1.1 christos : (sh_small ? "coff-sh-small" : "coff-sh")) 88 1.1 christos 89 1.1 christos #endif 90 1.1 christos #endif 91 1.1 christos 92 1.1 christos #ifdef TC_TIC30 93 1.1 christos #include "coff/tic30.h" 94 1.1 christos #define TARGET_FORMAT "coff-tic30" 95 1.1 christos #endif 96 1.1 christos 97 1.1 christos #ifdef TC_TIC4X 98 1.1 christos #include "coff/tic4x.h" 99 1.1 christos #define TARGET_FORMAT "coff2-tic4x" 100 1.1 christos #endif 101 1.1 christos 102 1.1 christos #ifdef TC_TIC54X 103 1.1 christos #include "coff/tic54x.h" 104 1.1 christos #define TARGET_FORMAT "coff1-c54x" 105 1.1 christos #endif 106 1.1 christos 107 1.1 christos #ifdef TC_MCORE 108 1.1 christos #include "coff/mcore.h" 109 1.1 christos #ifndef TARGET_FORMAT 110 1.1 christos #define TARGET_FORMAT "pe-mcore" 111 1.1 christos #endif 112 1.1 christos #endif 113 1.1 christos 114 1.1 christos #ifdef TE_PE 115 1.1 christos #define obj_set_weak_hook pecoff_obj_set_weak_hook 116 1.1 christos #define obj_clear_weak_hook pecoff_obj_clear_weak_hook 117 1.1 christos #endif 118 1.1 christos 119 1.1 christos #ifndef OBJ_COFF_MAX_AUXENTRIES 120 1.1 christos #define OBJ_COFF_MAX_AUXENTRIES 1 121 1.1 christos #endif 122 1.1 christos 123 1.1 christos #define obj_symbol_new_hook coff_obj_symbol_new_hook 124 1.1 christos #define obj_symbol_clone_hook coff_obj_symbol_clone_hook 125 1.1 christos #define obj_read_begin_hook coff_obj_read_begin_hook 126 1.1 christos 127 1.1 christos #include "bfd/libcoff.h" 128 1.1 christos 129 1.1 christos #define OUTPUT_FLAVOR bfd_target_coff_flavour 130 1.1 christos 131 1.8 christos /* COFF symbol flags. See SF_* macros. */ 132 1.1 christos #define OBJ_SYMFIELD_TYPE unsigned long 133 1.1 christos 134 1.1 christos /* We can't use the predefined section symbols in bfd/section.c, as 135 1.1 christos COFF symbols have extra fields. See bfd/libcoff.h:coff_symbol_type. */ 136 1.1 christos #ifndef obj_sec_sym_ok_for_reloc 137 1.1 christos #define obj_sec_sym_ok_for_reloc(SEC) ((SEC)->owner != 0) 138 1.1 christos #endif 139 1.1 christos 140 1.1 christos #define SYM_AUXENT(S) \ 141 1.1 christos (&coffsymbol (symbol_get_bfdsym (S))->native[1].u.auxent) 142 1.1 christos #define SYM_AUXINFO(S) \ 143 1.1 christos (&coffsymbol (symbol_get_bfdsym (S))->native[1]) 144 1.1 christos 145 1.1 christos /* The number of auxiliary entries. */ 146 1.1 christos #define S_GET_NUMBER_AUXILIARY(s) \ 147 1.1 christos (coffsymbol (symbol_get_bfdsym (s))->native->u.syment.n_numaux) 148 1.1 christos /* The number of auxiliary entries. */ 149 1.1 christos #define S_SET_NUMBER_AUXILIARY(s, v) (S_GET_NUMBER_AUXILIARY (s) = (v)) 150 1.1 christos 151 1.1 christos /* True if a symbol name is in the string table, i.e. its length is > 8. */ 152 1.1 christos #define S_IS_STRING(s) (strlen (S_GET_NAME (s)) > 8 ? 1 : 0) 153 1.1 christos 154 1.1 christos /* Auxiliary entry macros. SA_ stands for symbol auxiliary. */ 155 1.1 christos /* Omit the tv related fields. */ 156 1.1 christos /* Accessors. */ 157 1.1 christos 158 1.9 christos #define SA_GET_SYM_TAGNDX(s) (SYM_AUXENT (s)->x_sym.x_tagndx.u32) 159 1.1 christos #define SA_GET_SYM_LNNO(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno) 160 1.1 christos #define SA_GET_SYM_SIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size) 161 1.1 christos #define SA_GET_SYM_FSIZE(s) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize) 162 1.1 christos #define SA_GET_SYM_LNNOPTR(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr) 163 1.1 christos #define SA_GET_SYM_ENDNDX(s) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_endndx) 164 1.1 christos #define SA_GET_SYM_DIMEN(s,i) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)]) 165 1.1 christos #define SA_GET_FILE_FNAME(s) (SYM_AUXENT (s)->x_file.x_fname) 166 1.1 christos #define SA_GET_SCN_SCNLEN(s) (SYM_AUXENT (s)->x_scn.x_scnlen) 167 1.1 christos #define SA_GET_SCN_NRELOC(s) (SYM_AUXENT (s)->x_scn.x_nreloc) 168 1.1 christos #define SA_GET_SCN_NLINNO(s) (SYM_AUXENT (s)->x_scn.x_nlinno) 169 1.1 christos 170 1.1 christos #define SA_SET_SYM_LNNO(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_lnno = (v)) 171 1.1 christos #define SA_SET_SYM_SIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_lnsz.x_size = (v)) 172 1.1 christos #define SA_SET_SYM_FSIZE(s,v) (SYM_AUXENT (s)->x_sym.x_misc.x_fsize = (v)) 173 1.1 christos #define SA_SET_SYM_LNNOPTR(s,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_fcn.x_lnnoptr = (v)) 174 1.1 christos #define SA_SET_SYM_DIMEN(s,i,v) (SYM_AUXENT (s)->x_sym.x_fcnary.x_ary.x_dimen[(i)] = (v)) 175 1.1 christos #define SA_SET_FILE_FNAME(s,v) strncpy (SYM_AUXENT (s)->x_file.x_fname, (v), FILNMLEN) 176 1.1 christos #define SA_SET_SCN_SCNLEN(s,v) (SYM_AUXENT (s)->x_scn.x_scnlen = (v)) 177 1.1 christos #define SA_SET_SCN_NRELOC(s,v) (SYM_AUXENT (s)->x_scn.x_nreloc = (v)) 178 1.1 christos #define SA_SET_SCN_NLINNO(s,v) (SYM_AUXENT (s)->x_scn.x_nlinno = (v)) 179 1.1 christos 180 1.8 christos #ifdef OBJ_XCOFF 181 1.8 christos #define SA_GET_SECT_SCNLEN(s) (SYM_AUXENT (s)->x_sect.x_scnlen) 182 1.8 christos #define SA_GET_SECT_NRELOC(s) (SYM_AUXENT (s)->x_sect.x_nreloc) 183 1.8 christos #define SA_SET_SECT_SCNLEN(s,v) (SYM_AUXENT (s)->x_sect.x_scnlen = (v)) 184 1.8 christos #define SA_SET_SECT_NRELOC(s,v) (SYM_AUXENT (s)->x_sect.x_nreloc = (v)) 185 1.8 christos #endif 186 1.1 christos 187 1.8 christos /* Internal use only definitions. SF_ stands for symbol flags. These 188 1.8 christos values can be assigned to OBJ_SYMFIELD_TYPE obj field of a symbolS. */ 189 1.3 christos 190 1.1 christos #define SF_NORMAL_MASK 0x0000ffff /* bits 12-15 are general purpose. */ 191 1.3 christos 192 1.1 christos #define SF_STATICS 0x00001000 /* Mark the .text & all symbols. */ 193 1.1 christos #define SF_DEFINED 0x00002000 /* Symbol is defined in this file. */ 194 1.1 christos #define SF_STRING 0x00004000 /* Symbol name length > 8. */ 195 1.1 christos #define SF_LOCAL 0x00008000 /* Symbol must not be emitted. */ 196 1.3 christos 197 1.1 christos #define SF_DEBUG_MASK 0xffff0000 /* bits 16-31 are debug info. */ 198 1.3 christos 199 1.1 christos #define SF_FUNCTION 0x00010000 /* The symbol is a function. */ 200 1.1 christos #define SF_PROCESS 0x00020000 /* Process symbol before write. */ 201 1.1 christos #define SF_TAGGED 0x00040000 /* Is associated with a tag. */ 202 1.1 christos #define SF_TAG 0x00080000 /* Is a tag. */ 203 1.1 christos #define SF_DEBUG 0x00100000 /* Is in debug or abs section. */ 204 1.1 christos #define SF_GET_SEGMENT 0x00200000 /* Get the section of the forward symbol. */ 205 1.1 christos /* All other bits are unused. */ 206 1.1 christos 207 1.1 christos /* Accessors. */ 208 1.1 christos #define SF_GET(s) (* symbol_get_obj (s)) 209 1.1 christos #define SF_GET_DEBUG(s) (symbol_get_bfdsym (s)->flags & BSF_DEBUGGING) 210 1.1 christos #define SF_SET_DEBUG(s) (symbol_get_bfdsym (s)->flags |= BSF_DEBUGGING) 211 1.1 christos #define SF_GET_NORMAL_FIELD(s) (SF_GET (s) & SF_NORMAL_MASK) 212 1.1 christos #define SF_GET_DEBUG_FIELD(s) (SF_GET (s) & SF_DEBUG_MASK) 213 1.1 christos #define SF_GET_FILE(s) (SF_GET (s) & SF_FILE) 214 1.1 christos #define SF_GET_STATICS(s) (SF_GET (s) & SF_STATICS) 215 1.1 christos #define SF_GET_DEFINED(s) (SF_GET (s) & SF_DEFINED) 216 1.1 christos #define SF_GET_STRING(s) (SF_GET (s) & SF_STRING) 217 1.1 christos #define SF_GET_LOCAL(s) (SF_GET (s) & SF_LOCAL) 218 1.1 christos #define SF_GET_FUNCTION(s) (SF_GET (s) & SF_FUNCTION) 219 1.1 christos #define SF_GET_PROCESS(s) (SF_GET (s) & SF_PROCESS) 220 1.1 christos #define SF_GET_TAGGED(s) (SF_GET (s) & SF_TAGGED) 221 1.1 christos #define SF_GET_TAG(s) (SF_GET (s) & SF_TAG) 222 1.1 christos #define SF_GET_GET_SEGMENT(s) (SF_GET (s) & SF_GET_SEGMENT) 223 1.1 christos 224 1.1 christos /* Modifiers. */ 225 1.1 christos #define SF_SET(s,v) (SF_GET (s) = (v)) 226 1.1 christos #define SF_SET_NORMAL_FIELD(s,v)(SF_GET (s) |= ((v) & SF_NORMAL_MASK)) 227 1.1 christos #define SF_SET_DEBUG_FIELD(s,v) (SF_GET (s) |= ((v) & SF_DEBUG_MASK)) 228 1.1 christos #define SF_SET_FILE(s) (SF_GET (s) |= SF_FILE) 229 1.1 christos #define SF_SET_STATICS(s) (SF_GET (s) |= SF_STATICS) 230 1.1 christos #define SF_SET_DEFINED(s) (SF_GET (s) |= SF_DEFINED) 231 1.1 christos #define SF_SET_STRING(s) (SF_GET (s) |= SF_STRING) 232 1.1 christos #define SF_SET_LOCAL(s) (SF_GET (s) |= SF_LOCAL) 233 1.1 christos #define SF_CLEAR_LOCAL(s) (SF_GET (s) &= ~SF_LOCAL) 234 1.1 christos #define SF_SET_FUNCTION(s) (SF_GET (s) |= SF_FUNCTION) 235 1.1 christos #define SF_SET_PROCESS(s) (SF_GET (s) |= SF_PROCESS) 236 1.1 christos #define SF_SET_TAGGED(s) (SF_GET (s) |= SF_TAGGED) 237 1.1 christos #define SF_SET_TAG(s) (SF_GET (s) |= SF_TAG) 238 1.1 christos #define SF_SET_GET_SEGMENT(s) (SF_GET (s) |= SF_GET_SEGMENT) 239 1.1 christos 240 1.1 christos 241 1.1 christos /* Line number handling. */ 242 1.1 christos extern int text_lineno_number; 243 1.1 christos extern int coff_line_base; 244 1.1 christos extern int coff_n_line_nos; 245 1.1 christos 246 1.1 christos #define obj_emit_lineno(WHERE, LINE, FILE_START) abort () 247 1.8 christos #define obj_app_file(name) c_dot_file_symbol (name) 248 1.10 christos #define obj_assign_symbol(S) coff_assign_symbol (S) 249 1.1 christos #define obj_frob_symbol(S,P) coff_frob_symbol (S, & P) 250 1.1 christos #define obj_frob_section(S) coff_frob_section (S) 251 1.1 christos #define obj_frob_file_after_relocs() coff_frob_file_after_relocs () 252 1.1 christos #ifndef obj_adjust_symtab 253 1.1 christos #define obj_adjust_symtab() coff_adjust_symtab () 254 1.1 christos #endif 255 1.1 christos 256 1.1 christos /* Forward the segment of a forwarded symbol, handle assignments that 257 1.1 christos just copy symbol values, etc. */ 258 1.1 christos #ifndef OBJ_COPY_SYMBOL_ATTRIBUTES 259 1.1 christos #ifndef TE_I386AIX 260 1.1 christos #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \ 261 1.1 christos (SF_GET_GET_SEGMENT (dest) \ 262 1.1 christos ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \ 263 1.1 christos : 0) 264 1.1 christos #else 265 1.1 christos #define OBJ_COPY_SYMBOL_ATTRIBUTES(dest, src) \ 266 1.1 christos (SF_GET_GET_SEGMENT (dest) && S_GET_SEGMENT (dest) == SEG_UNKNOWN \ 267 1.1 christos ? (S_SET_SEGMENT (dest, S_GET_SEGMENT (src)), 0) \ 268 1.1 christos : 0) 269 1.1 christos #endif 270 1.1 christos #endif 271 1.1 christos 272 1.10 christos extern void coff_pop_insert (void); 273 1.1 christos #ifndef obj_pop_insert 274 1.10 christos #define obj_pop_insert() coff_pop_insert () 275 1.1 christos #endif 276 1.1 christos 277 1.1 christos /* In COFF, if a symbol is defined using .def/.val SYM/.endef, it's OK 278 1.1 christos to redefine the symbol later on. This can happen if C symbols use 279 1.1 christos a prefix, and a symbol is defined both with and without the prefix, 280 1.1 christos as in start/_start/__start in gcc/libgcc1-test.c. */ 281 1.1 christos #define RESOLVE_SYMBOL_REDEFINITION(sym) \ 282 1.1 christos (SF_GET_GET_SEGMENT (sym) \ 283 1.8 christos ? (sym->frag = frag_now, \ 284 1.1 christos S_SET_VALUE (sym, frag_now_fix ()), \ 285 1.1 christos S_SET_SEGMENT (sym, now_seg), \ 286 1.1 christos 0) \ 287 1.1 christos : 0) 288 1.1 christos 289 1.1 christos /* Stabs in a coff file go into their own section. */ 290 1.1 christos #define SEPARATE_STAB_SECTIONS 1 291 1.1 christos 292 1.1 christos /* We need 12 bytes at the start of the section to hold some initial 293 1.1 christos information. */ 294 1.9 christos #define INIT_STAB_SECTION(stab, str) obj_coff_init_stab_section (stab, str) 295 1.1 christos 296 1.1 christos /* Store the number of relocations in the section aux entry. */ 297 1.8 christos #ifdef OBJ_XCOFF 298 1.8 christos #define SET_SECTION_RELOCS(sec, relocs, n) \ 299 1.8 christos do { \ 300 1.8 christos symbolS * sectSym = section_symbol (sec); \ 301 1.8 christos if (S_GET_STORAGE_CLASS (sectSym) == C_DWARF) \ 302 1.8 christos SA_SET_SECT_NRELOC (sectSym, n); \ 303 1.8 christos else \ 304 1.8 christos SA_SET_SCN_NRELOC (sectSym, n); \ 305 1.8 christos } while (0) 306 1.8 christos #else 307 1.1 christos #define SET_SECTION_RELOCS(sec, relocs, n) \ 308 1.1 christos SA_SET_SCN_NRELOC (section_symbol (sec), n) 309 1.8 christos #endif 310 1.1 christos 311 1.1 christos extern int S_SET_DATA_TYPE (symbolS *, int); 312 1.1 christos extern int S_SET_STORAGE_CLASS (symbolS *, int); 313 1.1 christos extern int S_GET_STORAGE_CLASS (symbolS *); 314 1.1 christos extern void SA_SET_SYM_ENDNDX (symbolS *, symbolS *); 315 1.1 christos extern void coff_add_linesym (symbolS *); 316 1.8 christos extern void c_dot_file_symbol (const char *); 317 1.10 christos extern void coff_assign_symbol (symbolS *); 318 1.1 christos extern void coff_frob_symbol (symbolS *, int *); 319 1.1 christos extern void coff_adjust_symtab (void); 320 1.1 christos extern void coff_frob_section (segT); 321 1.1 christos extern void coff_adjust_section_syms (bfd *, asection *, void *); 322 1.1 christos extern void coff_frob_file_after_relocs (void); 323 1.1 christos extern void coff_obj_symbol_new_hook (symbolS *); 324 1.1 christos extern void coff_obj_symbol_clone_hook (symbolS *, symbolS *); 325 1.1 christos extern void coff_obj_read_begin_hook (void); 326 1.1 christos #ifdef TE_PE 327 1.1 christos extern void pecoff_obj_set_weak_hook (symbolS *); 328 1.1 christos extern void pecoff_obj_clear_weak_hook (symbolS *); 329 1.1 christos #endif 330 1.1 christos extern void obj_coff_section (int); 331 1.1 christos extern segT obj_coff_add_segment (const char *); 332 1.10 christos extern void obj_coff_def (int); 333 1.1 christos extern segT s_get_segment (symbolS *); 334 1.1 christos #ifndef tc_coff_symbol_emit_hook 335 1.1 christos extern void tc_coff_symbol_emit_hook (symbolS *); 336 1.1 christos #endif 337 1.1 christos extern void obj_coff_pe_handle_link_once (void); 338 1.9 christos extern void obj_coff_init_stab_section (segT, segT); 339 1.1 christos extern void c_section_header (struct internal_scnhdr *, 340 1.1 christos char *, long, long, long, long, 341 1.1 christos long, long, long, long); 342 1.1 christos extern void obj_coff_seh_do_final (void); 343 1.1 christos 344 1.1 christos #ifndef obj_coff_generate_pdata 345 1.1 christos #define obj_coff_generate_pdata obj_coff_seh_do_final 346 1.1 christos #endif 347 1.1 christos 348 1.1 christos 349 1.1 christos #endif /* OBJ_FORMAT_H */ 350