Apply Nindent to all .c and .h files
[nasm/avx512.git] / output / outcoff.c
blob547f4db7b85e5b47538044b46420021169103dec
1 /* outcoff.c output routines for the Netwide Assembler to produce
2 * COFF object files (for DJGPP and Win32)
4 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
5 * Julian Hall. All rights reserved. The software is
6 * redistributable under the licence given in the file "Licence"
7 * distributed in the NASM archive.
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <time.h>
16 #include "nasm.h"
17 #include "nasmlib.h"
18 #include "outform.h"
20 #if defined(OF_COFF) || defined(OF_WIN32)
23 * Notes on COFF:
25 * (0) When I say `standard COFF' below, I mean `COFF as output and
26 * used by DJGPP'. I assume DJGPP gets it right.
28 * (1) Win32 appears to interpret the term `relative relocation'
29 * differently from standard COFF. Standard COFF understands a
30 * relative relocation to mean that during relocation you add the
31 * address of the symbol you're referencing, and subtract the base
32 * address of the section you're in. Win32 COFF, by contrast, seems
33 * to add the address of the symbol and then subtract the address
34 * of THE BYTE AFTER THE RELOCATED DWORD. Hence the two formats are
35 * subtly incompatible.
37 * (2) Win32 doesn't bother putting any flags in the header flags
38 * field (at offset 0x12 into the file).
40 * (3) Win32 uses some extra flags into the section header table:
41 * it defines flags 0x80000000 (writable), 0x40000000 (readable)
42 * and 0x20000000 (executable), and uses them in the expected
43 * combinations. It also defines 0x00100000 through 0x00700000 for
44 * section alignments of 1 through 64 bytes.
46 * (4) Both standard COFF and Win32 COFF seem to use the DWORD
47 * field directly after the section name in the section header
48 * table for something strange: they store what the address of the
49 * section start point _would_ be, if you laid all the sections end
50 * to end starting at zero. Dunno why. Microsoft's documentation
51 * lists this field as "Virtual Size of Section", which doesn't
52 * seem to fit at all. In fact, Win32 even includes non-linked
53 * sections such as .drectve in this calculation.
55 * (5) Standard COFF does something very strange to common
56 * variables: the relocation point for a common variable is as far
57 * _before_ the variable as its size stretches out _after_ it. So
58 * we must fix up common variable references. Win32 seems to be
59 * sensible on this one.
62 /* Flag which version of COFF we are currently outputting. */
63 static int win32;
65 struct Reloc {
66 struct Reloc *next;
67 long address; /* relative to _start_ of section */
68 long symbol; /* symbol number */
69 enum {
70 SECT_SYMBOLS,
71 ABS_SYMBOL,
72 REAL_SYMBOLS
73 } symbase; /* relocation for symbol number :) */
74 int relative; /* TRUE or FALSE */
77 struct Symbol {
78 char name[9];
79 long strpos; /* string table position of name */
80 int section; /* section number where it's defined
81 * - in COFF codes, not NASM codes */
82 int is_global; /* is it a global symbol or not? */
83 long value; /* address, or COMMON variable size */
86 static FILE *coffp;
87 static efunc error;
88 static char coff_infile[FILENAME_MAX];
90 struct Section {
91 struct SAA *data;
92 unsigned long len;
93 int nrelocs;
94 long index;
95 struct Reloc *head, **tail;
96 unsigned long flags; /* section flags */
97 char name[9];
98 long pos, relpos;
101 #define TEXT_FLAGS (win32 ? 0x60500020L : 0x20L)
102 #define DATA_FLAGS (win32 ? 0xC0300040L : 0x40L)
103 #define BSS_FLAGS (win32 ? 0xC0300080L : 0x80L)
104 #define INFO_FLAGS 0x00100A00L
105 #define RDATA_FLAGS (win32 ? 0x40400040L : 0x40L)
107 #define SECT_DELTA 32
108 static struct Section **sects;
109 static int nsects, sectlen;
111 static struct SAA *syms;
112 static unsigned long nsyms;
114 static long def_seg;
116 static int initsym;
118 static struct RAA *bsym, *symval;
120 static struct SAA *strs;
121 static unsigned long strslen;
123 static void coff_gen_init(FILE *, efunc);
124 static void coff_sect_write(struct Section *, const unsigned char *,
125 unsigned long);
126 static void coff_write(void);
127 static void coff_section_header(char *, long, long, long, long, int, long);
128 static void coff_write_relocs(struct Section *);
129 static void coff_write_symbols(void);
131 static void coff_win32_init(FILE * fp, efunc errfunc,
132 ldfunc ldef, evalfunc eval)
134 win32 = TRUE;
135 (void)ldef; /* placate optimisers */
136 coff_gen_init(fp, errfunc);
139 static void coff_std_init(FILE * fp, efunc errfunc, ldfunc ldef,
140 evalfunc eval)
142 win32 = FALSE;
143 (void)ldef; /* placate optimisers */
144 coff_gen_init(fp, errfunc);
147 static void coff_gen_init(FILE * fp, efunc errfunc)
150 coffp = fp;
151 error = errfunc;
152 sects = NULL;
153 nsects = sectlen = 0;
154 syms = saa_init((long)sizeof(struct Symbol));
155 nsyms = 0;
156 bsym = raa_init();
157 symval = raa_init();
158 strs = saa_init(1L);
159 strslen = 0;
160 def_seg = seg_alloc();
163 static void coff_cleanup(int debuginfo)
165 struct Reloc *r;
166 int i;
168 (void)debuginfo;
170 coff_write();
171 fclose(coffp);
172 for (i = 0; i < nsects; i++) {
173 if (sects[i]->data)
174 saa_free(sects[i]->data);
175 while (sects[i]->head) {
176 r = sects[i]->head;
177 sects[i]->head = sects[i]->head->next;
178 nasm_free(r);
180 nasm_free(sects[i]);
182 nasm_free(sects);
183 saa_free(syms);
184 raa_free(bsym);
185 raa_free(symval);
186 saa_free(strs);
189 static int coff_make_section(char *name, unsigned long flags)
191 struct Section *s;
193 s = nasm_malloc(sizeof(*s));
195 if (flags != BSS_FLAGS)
196 s->data = saa_init(1L);
197 else
198 s->data = NULL;
199 s->head = NULL;
200 s->tail = &s->head;
201 s->len = 0;
202 s->nrelocs = 0;
203 if (!strcmp(name, ".text"))
204 s->index = def_seg;
205 else
206 s->index = seg_alloc();
207 strncpy(s->name, name, 8);
208 s->name[8] = '\0';
209 s->flags = flags;
211 if (nsects >= sectlen)
212 sects =
213 nasm_realloc(sects, (sectlen += SECT_DELTA) * sizeof(*sects));
214 sects[nsects++] = s;
216 return nsects - 1;
219 static long coff_section_names(char *name, int pass, int *bits)
221 char *p;
222 unsigned long flags, align_and = ~0L, align_or = 0L;
223 int i;
226 * Default is 32 bits.
228 if (!name)
229 *bits = 32;
231 if (!name)
232 return def_seg;
234 p = name;
235 while (*p && !isspace(*p))
236 p++;
237 if (*p)
238 *p++ = '\0';
239 if (strlen(name) > 8) {
240 error(ERR_WARNING, "COFF section names limited to 8 characters:"
241 " truncating");
242 name[8] = '\0';
244 flags = 0;
246 while (*p && isspace(*p))
247 p++;
248 while (*p) {
249 char *q = p;
250 while (*p && !isspace(*p))
251 p++;
252 if (*p)
253 *p++ = '\0';
254 while (*p && isspace(*p))
255 p++;
257 if (!nasm_stricmp(q, "code") || !nasm_stricmp(q, "text")) {
258 flags = TEXT_FLAGS;
259 } else if (!nasm_stricmp(q, "data")) {
260 flags = DATA_FLAGS;
261 } else if (!nasm_stricmp(q, "rdata")) {
262 if (win32)
263 flags = RDATA_FLAGS;
264 else {
265 flags = DATA_FLAGS; /* gotta do something */
266 error(ERR_NONFATAL, "standard COFF does not support"
267 " read-only data sections");
269 } else if (!nasm_stricmp(q, "bss")) {
270 flags = BSS_FLAGS;
271 } else if (!nasm_stricmp(q, "info")) {
272 if (win32)
273 flags = INFO_FLAGS;
274 else {
275 flags = DATA_FLAGS; /* gotta do something */
276 error(ERR_NONFATAL, "standard COFF does not support"
277 " informational sections");
279 } else if (!nasm_strnicmp(q, "align=", 6)) {
280 if (!win32)
281 error(ERR_NONFATAL, "standard COFF does not support"
282 " section alignment specification");
283 else {
284 if (q[6 + strspn(q + 6, "0123456789")])
285 error(ERR_NONFATAL,
286 "argument to `align' is not numeric");
287 else {
288 unsigned int align = atoi(q + 6);
289 if (!align || ((align - 1) & align))
290 error(ERR_NONFATAL, "argument to `align' is not a"
291 " power of two");
292 else if (align > 64)
293 error(ERR_NONFATAL, "Win32 cannot align sections"
294 " to better than 64-byte boundaries");
295 else {
296 align_and = ~0x00F00000L;
297 align_or = (align == 1 ? 0x00100000L :
298 align == 2 ? 0x00200000L :
299 align == 4 ? 0x00300000L :
300 align == 8 ? 0x00400000L :
301 align == 16 ? 0x00500000L :
302 align ==
303 32 ? 0x00600000L : 0x00700000L);
310 for (i = 0; i < nsects; i++)
311 if (!strcmp(name, sects[i]->name))
312 break;
313 if (i == nsects) {
314 if (!flags) {
315 if (!strcmp(name, ".data"))
316 flags = DATA_FLAGS;
317 else if (!strcmp(name, ".rdata"))
318 flags = RDATA_FLAGS;
319 else if (!strcmp(name, ".bss"))
320 flags = BSS_FLAGS;
321 else
322 flags = TEXT_FLAGS;
324 i = coff_make_section(name, flags);
325 if (flags)
326 sects[i]->flags = flags;
327 sects[i]->flags &= align_and;
328 sects[i]->flags |= align_or;
329 } else if (pass == 1) {
330 if (flags)
331 error(ERR_WARNING, "section attributes ignored on"
332 " redeclaration of section `%s'", name);
335 return sects[i]->index;
338 static void coff_deflabel(char *name, long segment, long offset,
339 int is_global, char *special)
341 int pos = strslen + 4;
342 struct Symbol *sym;
344 if (special)
345 error(ERR_NONFATAL, "binary format does not support any"
346 " special symbol types");
348 if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
349 error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
350 return;
353 if (strlen(name) > 8) {
354 saa_wbytes(strs, name, (long)(1 + strlen(name)));
355 strslen += 1 + strlen(name);
356 } else
357 pos = -1;
359 sym = saa_wstruct(syms);
361 sym->strpos = pos;
362 if (pos == -1)
363 strcpy(sym->name, name);
364 sym->is_global = !!is_global;
365 if (segment == NO_SEG)
366 sym->section = -1; /* absolute symbol */
367 else {
368 int i;
369 sym->section = 0;
370 for (i = 0; i < nsects; i++)
371 if (segment == sects[i]->index) {
372 sym->section = i + 1;
373 break;
375 if (!sym->section)
376 sym->is_global = TRUE;
378 if (is_global == 2)
379 sym->value = offset;
380 else
381 sym->value = (sym->section == 0 ? 0 : offset);
384 * define the references from external-symbol segment numbers
385 * to these symbol records.
387 if (sym->section == 0)
388 bsym = raa_write(bsym, segment, nsyms);
390 if (segment != NO_SEG)
391 symval = raa_write(symval, segment, sym->section ? 0 : sym->value);
393 nsyms++;
396 static long coff_add_reloc(struct Section *sect, long segment,
397 int relative)
399 struct Reloc *r;
401 r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
402 sect->tail = &r->next;
403 r->next = NULL;
405 r->address = sect->len;
406 if (segment == NO_SEG)
407 r->symbol = 0, r->symbase = ABS_SYMBOL;
408 else {
409 int i;
410 r->symbase = REAL_SYMBOLS;
411 for (i = 0; i < nsects; i++)
412 if (segment == sects[i]->index) {
413 r->symbol = i * 2;
414 r->symbase = SECT_SYMBOLS;
415 break;
417 if (r->symbase == REAL_SYMBOLS)
418 r->symbol = raa_read(bsym, segment);
420 r->relative = relative;
422 sect->nrelocs++;
425 * Return the fixup for standard COFF common variables.
427 if (r->symbase == REAL_SYMBOLS && !win32)
428 return raa_read(symval, segment);
429 else
430 return 0;
433 static void coff_out(long segto, const void *data, unsigned long type,
434 long segment, long wrt)
436 struct Section *s;
437 long realbytes = type & OUT_SIZMASK;
438 unsigned char mydata[4], *p;
439 int i;
441 if (wrt != NO_SEG) {
442 wrt = NO_SEG; /* continue to do _something_ */
443 error(ERR_NONFATAL, "WRT not supported by COFF output formats");
446 type &= OUT_TYPMASK;
449 * handle absolute-assembly (structure definitions)
451 if (segto == NO_SEG) {
452 if (type != OUT_RESERVE)
453 error(ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
454 " space");
455 return;
458 s = NULL;
459 for (i = 0; i < nsects; i++)
460 if (segto == sects[i]->index) {
461 s = sects[i];
462 break;
464 if (!s) {
465 int tempint; /* ignored */
466 if (segto != coff_section_names(".text", 2, &tempint))
467 error(ERR_PANIC, "strange segment conditions in COFF driver");
468 else
469 s = sects[nsects - 1];
472 if (!s->data && type != OUT_RESERVE) {
473 error(ERR_WARNING, "attempt to initialise memory in"
474 " BSS section `%s': ignored", s->name);
475 if (type == OUT_REL2ADR)
476 realbytes = 2;
477 else if (type == OUT_REL4ADR)
478 realbytes = 4;
479 s->len += realbytes;
480 return;
483 if (type == OUT_RESERVE) {
484 if (s->data) {
485 error(ERR_WARNING, "uninitialised space declared in"
486 " non-BSS section `%s': zeroing", s->name);
487 coff_sect_write(s, NULL, realbytes);
488 } else
489 s->len += realbytes;
490 } else if (type == OUT_RAWDATA) {
491 if (segment != NO_SEG)
492 error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
493 coff_sect_write(s, data, realbytes);
494 } else if (type == OUT_ADDRESS) {
495 if (realbytes != 4 && (segment != NO_SEG || wrt != NO_SEG))
496 error(ERR_NONFATAL, "COFF format does not support non-32-bit"
497 " relocations");
498 else {
499 long fix = 0;
500 if (segment != NO_SEG || wrt != NO_SEG) {
501 if (wrt != NO_SEG) {
502 error(ERR_NONFATAL, "COFF format does not support"
503 " WRT types");
504 } else if (segment % 2) {
505 error(ERR_NONFATAL, "COFF format does not support"
506 " segment base references");
507 } else
508 fix = coff_add_reloc(s, segment, FALSE);
510 p = mydata;
511 WRITELONG(p, *(long *)data + fix);
512 coff_sect_write(s, mydata, realbytes);
514 } else if (type == OUT_REL2ADR) {
515 error(ERR_NONFATAL, "COFF format does not support 16-bit"
516 " relocations");
517 } else if (type == OUT_REL4ADR) {
518 if (segment == segto)
519 error(ERR_PANIC, "intra-segment OUT_REL4ADR");
520 else if (segment == NO_SEG && win32)
521 error(ERR_NONFATAL, "Win32 COFF does not correctly support"
522 " relative references to absolute addresses");
523 else {
524 long fix = 0;
525 if (segment != NO_SEG && segment % 2) {
526 error(ERR_NONFATAL, "COFF format does not support"
527 " segment base references");
528 } else
529 fix = coff_add_reloc(s, segment, TRUE);
530 p = mydata;
531 if (win32) {
532 WRITELONG(p, *(long *)data + 4 - realbytes + fix);
533 } else {
534 WRITELONG(p, *(long *)data - (realbytes + s->len) + fix);
536 coff_sect_write(s, mydata, 4L);
541 static void coff_sect_write(struct Section *sect,
542 const unsigned char *data, unsigned long len)
544 saa_wbytes(sect->data, data, len);
545 sect->len += len;
548 typedef struct tagString {
549 struct tagString *Next;
550 int len;
551 char *String;
552 } STRING;
554 #define EXPORT_SECTION_NAME ".drectve"
555 #define EXPORT_SECTION_FLAGS INFO_FLAGS
557 #define EXPORT_SECTION_NAME ".text"
558 #define EXPORT_SECTION_FLAGS TEXT_FLAGS
561 static STRING *Exports = NULL;
562 static struct Section *directive_sec;
563 void AddExport(char *name)
565 STRING *rvp = Exports, *newS;
567 newS = (STRING *) nasm_malloc(sizeof(STRING));
568 newS->len = strlen(name);
569 newS->Next = NULL;
570 newS->String = (char *)nasm_malloc(newS->len + 1);
571 strcpy(newS->String, name);
572 if (rvp == NULL) {
573 int i;
574 for (i = 0; i < nsects; i++)
576 if (!strcmp(EXPORT_SECTION_NAME, sects[i]->name))
577 break;
578 if (i == nsects)
579 directive_sec =
580 sects[coff_make_section
581 (EXPORT_SECTION_NAME, EXPORT_SECTION_FLAGS)];
582 else
583 directive_sec = sects[i];
584 Exports = newS;
585 } else {
586 while (rvp->Next) {
587 if (!strcmp(rvp->String, name))
588 return;
589 rvp = rvp->Next;
591 rvp->Next = newS;
595 void BuildExportTable(void)
597 STRING *rvp = Exports, *next;
598 unsigned char buf[256];
599 int len;
600 if (rvp == NULL)
601 return;
602 while (rvp) {
603 len = sprintf((char *)buf, "-export:%s ", rvp->String);
604 coff_sect_write(directive_sec, buf, len);
605 rvp = rvp->Next;
608 next = Exports;
609 while ((rvp = next)) {
610 next = rvp->Next;
611 nasm_free(rvp->String);
612 nasm_free(rvp);
614 Exports = NULL;
617 static int coff_directives(char *directive, char *value, int pass)
619 if (!strcmp(directive, "export")) {
620 char *q, *name;
622 if (pass == 2)
623 return 1; /* ignore in pass two */
624 name = q = value;
625 while (*q && !isspace(*q))
626 q++;
627 if (isspace(*q)) {
628 *q++ = '\0';
629 while (*q && isspace(*q))
630 q++;
633 if (!*name) {
634 error(ERR_NONFATAL, "`export' directive requires export name");
635 return 1;
637 if (*q) {
638 error(ERR_NONFATAL, "unrecognised export qualifier `%s'", q);
639 return 1;
641 AddExport(name);
642 return 1;
644 return 0;
647 static void coff_write(void)
649 long pos, sympos, vsize;
650 int i;
652 BuildExportTable(); /* fill in the .drectve section with -export's */
654 * Work out how big the file will get. Calculate the start of
655 * the `real' symbols at the same time.
657 pos = 0x14 + 0x28 * nsects;
658 initsym = 3; /* two for the file, one absolute */
659 for (i = 0; i < nsects; i++) {
660 if (sects[i]->data) {
661 sects[i]->pos = pos;
662 pos += sects[i]->len;
663 sects[i]->relpos = pos;
664 pos += 10 * sects[i]->nrelocs;
665 } else
666 sects[i]->pos = sects[i]->relpos = 0L;
667 initsym += 2; /* two for each section */
669 sympos = pos;
672 * Output the COFF header.
674 fwriteshort(0x14C, coffp); /* MACHINE_i386 */
675 fwriteshort(nsects, coffp); /* number of sections */
676 fwritelong(time(NULL), coffp); /* time stamp */
677 fwritelong(sympos, coffp);
678 fwritelong(nsyms + initsym, coffp);
679 fwriteshort(0, coffp); /* no optional header */
680 /* Flags: 32-bit, no line numbers. Win32 doesn't even bother with them. */
681 fwriteshort(win32 ? 0 : 0x104, coffp);
684 * Output the section headers.
686 vsize = 0L;
687 for (i = 0; i < nsects; i++) {
688 coff_section_header(sects[i]->name, vsize, sects[i]->len,
689 sects[i]->pos, sects[i]->relpos,
690 sects[i]->nrelocs, sects[i]->flags);
691 vsize += sects[i]->len;
695 * Output the sections and their relocations.
697 for (i = 0; i < nsects; i++)
698 if (sects[i]->data) {
699 saa_fpwrite(sects[i]->data, coffp);
700 coff_write_relocs(sects[i]);
704 * Output the symbol and string tables.
706 coff_write_symbols();
707 fwritelong(strslen + 4, coffp); /* length includes length count */
708 saa_fpwrite(strs, coffp);
711 static void coff_section_header(char *name, long vsize,
712 long datalen, long datapos,
713 long relpos, int nrelocs, long flags)
715 char padname[8];
717 memset(padname, 0, 8);
718 strncpy(padname, name, 8);
719 fwrite(padname, 8, 1, coffp);
720 fwritelong(vsize, coffp);
721 fwritelong(0L, coffp); /* RVA/offset - we ignore */
722 fwritelong(datalen, coffp);
723 fwritelong(datapos, coffp);
724 fwritelong(relpos, coffp);
725 fwritelong(0L, coffp); /* no line numbers - we don't do 'em */
726 fwriteshort(nrelocs, coffp);
727 fwriteshort(0, coffp); /* again, no line numbers */
728 fwritelong(flags, coffp);
731 static void coff_write_relocs(struct Section *s)
733 struct Reloc *r;
735 for (r = s->head; r; r = r->next) {
736 fwritelong(r->address, coffp);
737 fwritelong(r->symbol + (r->symbase == REAL_SYMBOLS ? initsym :
738 r->symbase == ABS_SYMBOL ? initsym - 1 :
739 r->symbase == SECT_SYMBOLS ? 2 : 0),
740 coffp);
742 * Strange: Microsoft's COFF documentation says 0x03 for an
743 * absolute relocation, but both Visual C++ and DJGPP agree
744 * that in fact it's 0x06. I'll use 0x06 until someone
745 * argues.
747 fwriteshort(r->relative ? 0x14 : 0x06, coffp);
751 static void coff_symbol(char *name, long strpos, long value,
752 int section, int type, int aux)
754 char padname[8];
756 if (name) {
757 memset(padname, 0, 8);
758 strncpy(padname, name, 8);
759 fwrite(padname, 8, 1, coffp);
760 } else {
761 fwritelong(0L, coffp);
762 fwritelong(strpos, coffp);
764 fwritelong(value, coffp);
765 fwriteshort(section, coffp);
766 fwriteshort(0, coffp);
767 fputc(type, coffp);
768 fputc(aux, coffp);
771 static void coff_write_symbols(void)
773 char filename[18];
774 unsigned long i;
777 * The `.file' record, and the file name auxiliary record.
779 coff_symbol(".file", 0L, 0L, -2, 0x67, 1);
780 memset(filename, 0, 18);
781 strncpy(filename, coff_infile, 18);
782 fwrite(filename, 18, 1, coffp);
785 * The section records, with their auxiliaries.
787 memset(filename, 0, 18); /* useful zeroed buffer */
789 for (i = 0; i < nsects; i++) {
790 coff_symbol(sects[i]->name, 0L, 0L, i + 1, 3, 1);
791 fwritelong(sects[i]->len, coffp);
792 fwriteshort(sects[i]->nrelocs, coffp);
793 fwrite(filename, 12, 1, coffp);
797 * The absolute symbol, for relative-to-absolute relocations.
799 coff_symbol(".absolut", 0L, 0L, -1, 3, 0);
802 * The real symbols.
804 saa_rewind(syms);
805 for (i = 0; i < nsyms; i++) {
806 struct Symbol *sym = saa_rstruct(syms);
807 coff_symbol(sym->strpos == -1 ? sym->name : NULL,
808 sym->strpos, sym->value, sym->section,
809 sym->is_global ? 2 : 3, 0);
813 static long coff_segbase(long segment)
815 return segment;
818 static void coff_std_filename(char *inname, char *outname, efunc error)
820 strcpy(coff_infile, inname);
821 standard_extension(inname, outname, ".o", error);
824 static void coff_win32_filename(char *inname, char *outname, efunc error)
826 strcpy(coff_infile, inname);
827 standard_extension(inname, outname, ".obj", error);
830 static const char *coff_stdmac[] = {
831 "%define __SECT__ [section .text]",
832 "%macro __NASM_CDecl__ 1",
833 "%endmacro",
834 "%imacro export 1+.nolist",
835 "[export %1]",
836 "%endmacro",
837 NULL
840 static int coff_set_info(enum geninfo type, char **val)
842 return 0;
844 #endif /* defined(OF_COFF) || defined(OF_WIN32) */
846 #ifdef OF_COFF
848 struct ofmt of_coff = {
849 "COFF (i386) object files (e.g. DJGPP for DOS)",
850 "coff",
851 NULL,
852 null_debug_arr,
853 &null_debug_form,
854 coff_stdmac,
855 coff_std_init,
856 coff_set_info,
857 coff_out,
858 coff_deflabel,
859 coff_section_names,
860 coff_segbase,
861 coff_directives,
862 coff_std_filename,
863 coff_cleanup
866 #endif
868 #ifdef OF_WIN32
870 struct ofmt of_win32 = {
871 "Microsoft Win32 (i386) object files",
872 "win32",
873 NULL,
874 null_debug_arr,
875 &null_debug_form,
876 coff_stdmac,
877 coff_win32_init,
878 coff_set_info,
879 coff_out,
880 coff_deflabel,
881 coff_section_names,
882 coff_segbase,
883 coff_directives,
884 coff_win32_filename,
885 coff_cleanup
888 #endif