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