Added Dev-Cpp Makefile
[nasm/sigaren-mirror.git] / output / outbin.c
blobcd4675241742d9139d055be12f30b873fb6efceb
1 /* outbin.c output routines for the Netwide Assembler to produce
2 * flat-form binary files
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 /* This is the extended version of NASM's original binary output
11 * format. It is backward compatible with the original BIN format,
12 * and contains support for multiple sections and advanced section
13 * ordering.
15 * Feature summary:
17 * - Users can create an arbitrary number of sections; they are not
18 * limited to just ".text", ".data", and ".bss".
20 * - Sections can be either progbits or nobits type.
22 * - You can specify that they be aligned at a certian boundary
23 * following the previous section ("align="), or positioned at an
24 * arbitrary byte-granular location ("start=").
26 * - You can specify a "virtual" start address for a section, which
27 * will be used for the calculation for all address references
28 * with respect to that section ("vstart=").
30 * - The ORG directive, as well as the section/segment directive
31 * arguments ("align=", "start=", "vstart="), can take a critical
32 * expression as their value. For example: "align=(1 << 12)".
34 * - You can generate map files using the 'map' directive.
38 /* Uncomment the following define if you want sections to adapt
39 * their progbits/nobits state depending on what type of
40 * instructions are issued, rather than defaulting to progbits.
41 * Note that this behavior violates the specification.
43 #define ABIN_SMART_ADAPT
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include <ctype.h>
51 #include <inttypes.h>
53 #include "nasm.h"
54 #include "nasmlib.h"
55 #include "labels.h"
56 #include "eval.h"
57 #include "outform.h"
59 #ifdef OF_BIN
61 struct ofmt *bin_get_ofmt(); /* Prototype goes here since no header file. */
63 static FILE *fp, *rf = NULL;
64 static efunc error;
66 /* Section flags keep track of which attributes the user has defined. */
67 #define START_DEFINED 0x001
68 #define ALIGN_DEFINED 0x002
69 #define FOLLOWS_DEFINED 0x004
70 #define VSTART_DEFINED 0x008
71 #define VALIGN_DEFINED 0x010
72 #define VFOLLOWS_DEFINED 0x020
73 #define TYPE_DEFINED 0x040
74 #define TYPE_PROGBITS 0x080
75 #define TYPE_NOBITS 0x100
77 /* This struct is used to keep track of symbols for map-file generation. */
78 static struct bin_label {
79 int8_t *name;
80 struct bin_label *next;
81 } *no_seg_labels, **nsl_tail;
83 static struct Section {
84 int8_t *name;
85 struct SAA *contents;
86 int32_t length; /* section length in bytes */
88 /* Section attributes */
89 int flags; /* see flag definitions above */
90 uint32_t align; /* section alignment */
91 uint32_t valign; /* notional section alignment */
92 uint32_t start; /* section start address */
93 uint32_t vstart; /* section virtual start address */
94 int8_t *follows; /* the section that this one will follow */
95 int8_t *vfollows; /* the section that this one will notionally follow */
96 int32_t start_index; /* NASM section id for non-relocated version */
97 int32_t vstart_index; /* the NASM section id */
99 struct bin_label *labels; /* linked-list of label handles for map output. */
100 struct bin_label **labels_end; /* Holds address of end of labels list. */
101 struct Section *ifollows; /* Points to previous section (implicit follows). */
102 struct Section *next; /* This links sections with a defined start address. */
104 /* The extended bin format allows for sections to have a "virtual"
105 * start address. This is accomplished by creating two sections:
106 * one beginning at the Load Memory Address and the other beginning
107 * at the Virtual Memory Address. The LMA section is only used to
108 * define the section.<section_name>.start label, but there isn't
109 * any other good way for us to handle that label.
112 } *sections, *last_section;
114 static struct Reloc {
115 struct Reloc *next;
116 int32_t posn;
117 int32_t bytes;
118 int32_t secref;
119 int32_t secrel;
120 struct Section *target;
121 } *relocs, **reloctail;
123 extern int8_t *stdscan_bufptr;
124 extern int lookup_label(int8_t *label, int32_t *segment, int32_t *offset);
126 static uint8_t format_mode; /* 0 = original bin, 1 = extended bin */
127 static int32_t current_section; /* only really needed if format_mode = 0 */
128 static uint32_t origin;
129 static int origin_defined;
131 /* Stuff we need for map-file generation. */
132 #define MAP_ORIGIN 1
133 #define MAP_SUMMARY 2
134 #define MAP_SECTIONS 4
135 #define MAP_SYMBOLS 8
136 static int map_control = 0;
137 static int8_t *infile, *outfile;
139 static const int8_t *bin_stdmac[] = {
140 "%define __SECT__ [section .text]",
141 "%imacro org 1+.nolist",
142 "[org %1]",
143 "%endmacro",
144 "%macro __NASM_CDecl__ 1",
145 "%endmacro",
146 NULL
149 static void add_reloc(struct Section *s, int32_t bytes, int32_t secref,
150 int32_t secrel)
152 struct Reloc *r;
154 r = *reloctail = nasm_malloc(sizeof(struct Reloc));
155 reloctail = &r->next;
156 r->next = NULL;
157 r->posn = s->length;
158 r->bytes = bytes;
159 r->secref = secref;
160 r->secrel = secrel;
161 r->target = s;
164 static struct Section *find_section_by_name(const int8_t *name)
166 struct Section *s;
168 for (s = sections; s; s = s->next)
169 if (!strcmp(s->name, name))
170 break;
171 return s;
174 static struct Section *find_section_by_index(int32_t index)
176 struct Section *s;
178 for (s = sections; s; s = s->next)
179 if ((index == s->vstart_index) || (index == s->start_index))
180 break;
181 return s;
184 static struct Section *create_section(int8_t *name)
185 { /* Create a new section. */
186 last_section->next = nasm_malloc(sizeof(struct Section));
187 last_section->next->ifollows = last_section;
188 last_section = last_section->next;
189 last_section->labels = NULL;
190 last_section->labels_end = &(last_section->labels);
192 /* Initialize section attributes. */
193 last_section->name = nasm_strdup(name);
194 last_section->contents = saa_init(1L);
195 last_section->follows = last_section->vfollows = 0;
196 last_section->length = 0;
197 last_section->flags = 0;
198 last_section->next = NULL;
200 /* Register our sections with NASM. */
201 last_section->vstart_index = seg_alloc();
202 last_section->start_index = seg_alloc();
203 return last_section;
206 static void bin_cleanup(int debuginfo)
208 struct Section *g, **gp;
209 struct Section *gs = NULL, **gsp;
210 struct Section *s, **sp;
211 struct Section *nobits = NULL, **nt;
212 struct Section *last_progbits;
213 struct bin_label *l;
214 struct Reloc *r;
215 uint32_t pend;
216 int h;
218 #ifdef DEBUG
219 fprintf(stdout,
220 "bin_cleanup: Sections were initially referenced in this order:\n");
221 for (h = 0, s = sections; s; h++, s = s->next)
222 fprintf(stdout, "%i. %s\n", h, s->name);
223 #endif
225 /* Assembly has completed, so now we need to generate the output file.
226 * Step 1: Separate progbits and nobits sections into separate lists.
227 * Step 2: Sort the progbits sections into their output order.
228 * Step 3: Compute start addresses for all progbits sections.
229 * Step 4: Compute vstart addresses for all sections.
230 * Step 5: Apply relocations.
231 * Step 6: Write the sections' data to the output file.
232 * Step 7: Generate the map file.
233 * Step 8: Release all allocated memory.
236 /* To do: Smart section-type adaptation could leave some empty sections
237 * without a defined type (progbits/nobits). Won't fix now since this
238 * feature will be disabled. */
240 /* Step 1: Split progbits and nobits sections into separate lists. */
242 nt = &nobits;
243 /* Move nobits sections into a separate list. Also pre-process nobits
244 * sections' attributes. */
245 for (sp = &sections->next, s = sections->next; s; s = *sp) { /* Skip progbits sections. */
246 if (s->flags & TYPE_PROGBITS) {
247 sp = &s->next;
248 continue;
250 /* Do some special pre-processing on nobits sections' attributes. */
251 if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */
252 if (s->
253 flags & (VSTART_DEFINED | VALIGN_DEFINED |
254 VFOLLOWS_DEFINED))
255 error(ERR_FATAL,
256 "cannot mix real and virtual attributes"
257 " in nobits section (%s)", s->name);
258 /* Real and virtual attributes mean the same thing for nobits sections. */
259 if (s->flags & START_DEFINED) {
260 s->vstart = s->start;
261 s->flags |= VSTART_DEFINED;
263 if (s->flags & ALIGN_DEFINED) {
264 s->valign = s->align;
265 s->flags |= VALIGN_DEFINED;
267 if (s->flags & FOLLOWS_DEFINED) {
268 s->vfollows = s->follows;
269 s->flags |= VFOLLOWS_DEFINED;
270 s->flags &= ~FOLLOWS_DEFINED;
273 /* Every section must have a start address. */
274 if (s->flags & VSTART_DEFINED) {
275 s->start = s->vstart;
276 s->flags |= START_DEFINED;
278 /* Move the section into the nobits list. */
279 *sp = s->next;
280 s->next = NULL;
281 *nt = s;
282 nt = &s->next;
285 /* Step 2: Sort the progbits sections into their output order. */
287 /* In Step 2 we move around sections in groups. A group
288 * begins with a section (group leader) that has a user-
289 * defined start address or follows section. The remainder
290 * of the group is made up of the sections that implicitly
291 * follow the group leader (i.e., they were defined after
292 * the group leader and were not given an explicit start
293 * address or follows section by the user). */
295 /* For anyone attempting to read this code:
296 * g (group) points to a group of sections, the first one of which has
297 * a user-defined start address or follows section.
298 * gp (g previous) holds the location of the pointer to g.
299 * gs (g scan) is a temp variable that we use to scan to the end of the group.
300 * gsp (gs previous) holds the location of the pointer to gs.
301 * nt (nobits tail) points to the nobits section-list tail.
304 /* Link all 'follows' groups to their proper position. To do
305 * this we need to know three things: the start of the group
306 * to relocate (g), the section it is following (s), and the
307 * end of the group we're relocating (gs). */
308 for (gp = &sections, g = sections; g; g = gs) { /* Find the next follows group that is out of place (g). */
309 if (!(g->flags & FOLLOWS_DEFINED)) {
310 while (g->next) {
311 if ((g->next->flags & FOLLOWS_DEFINED) &&
312 strcmp(g->name, g->next->follows))
313 break;
314 g = g->next;
316 if (!g->next)
317 break;
318 gp = &g->next;
319 g = g->next;
321 /* Find the section that this group follows (s). */
322 for (sp = &sections, s = sections;
323 s && strcmp(s->name, g->follows);
324 sp = &s->next, s = s->next) ;
325 if (!s)
326 error(ERR_FATAL, "section %s follows an invalid or"
327 " unknown section (%s)", g->name, g->follows);
328 if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
329 !strcmp(s->name, s->next->follows))
330 error(ERR_FATAL, "sections %s and %s can't both follow"
331 " section %s", g->name, s->next->name, s->name);
332 /* Find the end of the current follows group (gs). */
333 for (gsp = &g->next, gs = g->next;
334 gs && (gs != s) && !(gs->flags & START_DEFINED);
335 gsp = &gs->next, gs = gs->next) {
336 if (gs->next && (gs->next->flags & FOLLOWS_DEFINED) &&
337 strcmp(gs->name, gs->next->follows)) {
338 gsp = &gs->next;
339 gs = gs->next;
340 break;
343 /* Re-link the group after its follows section. */
344 *gsp = s->next;
345 s->next = g;
346 *gp = gs;
349 /* Link all 'start' groups to their proper position. Once
350 * again we need to know g, s, and gs (see above). The main
351 * difference is we already know g since we sort by moving
352 * groups from the 'unsorted' list into a 'sorted' list (g
353 * will always be the first section in the unsorted list). */
354 for (g = sections, sections = NULL; g; g = gs) { /* Find the section that we will insert this group before (s). */
355 for (sp = &sections, s = sections; s; sp = &s->next, s = s->next)
356 if ((s->flags & START_DEFINED) && (g->start < s->start))
357 break;
358 /* Find the end of the group (gs). */
359 for (gs = g->next, gsp = &g->next;
360 gs && !(gs->flags & START_DEFINED);
361 gsp = &gs->next, gs = gs->next) ;
362 /* Re-link the group before the target section. */
363 *sp = g;
364 *gsp = s;
367 /* Step 3: Compute start addresses for all progbits sections. */
369 /* Make sure we have an origin and a start address for the first section. */
370 if (origin_defined)
371 switch (sections->flags & (START_DEFINED | ALIGN_DEFINED)) {
372 case START_DEFINED | ALIGN_DEFINED:
373 case START_DEFINED:
374 /* Make sure this section doesn't begin before the origin. */
375 if (sections->start < origin)
376 error(ERR_FATAL, "section %s begins"
377 " before program origin", sections->name);
378 break;
379 case ALIGN_DEFINED:
380 sections->start = ((origin + sections->align - 1) &
381 ~(sections->align - 1));
382 break;
383 case 0:
384 sections->start = origin;
385 } else {
386 if (!(sections->flags & START_DEFINED))
387 sections->start = 0;
388 origin = sections->start;
390 sections->flags |= START_DEFINED;
392 /* Make sure each section has an explicit start address. If it
393 * doesn't, then compute one based its alignment and the end of
394 * the previous section. */
395 for (pend = sections->start, g = s = sections; g; g = g->next) { /* Find the next section that could cause an overlap situation
396 * (has a defined start address, and is not zero length). */
397 if (g == s)
398 for (s = g->next;
399 s && ((s->length == 0) || !(s->flags & START_DEFINED));
400 s = s->next) ;
401 /* Compute the start address of this section, if necessary. */
402 if (!(g->flags & START_DEFINED)) { /* Default to an alignment of 4 if unspecified. */
403 if (!(g->flags & ALIGN_DEFINED)) {
404 g->align = 4;
405 g->flags |= ALIGN_DEFINED;
407 /* Set the section start address. */
408 g->start = (pend + g->align - 1) & ~(g->align - 1);
409 g->flags |= START_DEFINED;
411 /* Ugly special case for progbits sections' virtual attributes:
412 * If there is a defined valign, but no vstart and no vfollows, then
413 * we valign after the previous progbits section. This case doesn't
414 * really make much sense for progbits sections with a defined start
415 * address, but it is possible and we must do *something*.
416 * Not-so-ugly special case:
417 * If a progbits section has no virtual attributes, we set the
418 * vstart equal to the start address. */
419 if (!(g->flags & (VSTART_DEFINED | VFOLLOWS_DEFINED))) {
420 if (g->flags & VALIGN_DEFINED)
421 g->vstart = (pend + g->valign - 1) & ~(g->valign - 1);
422 else
423 g->vstart = g->start;
424 g->flags |= VSTART_DEFINED;
426 /* Ignore zero-length sections. */
427 if (g->start < pend)
428 continue;
429 /* Compute the span of this section. */
430 pend = g->start + g->length;
431 /* Check for section overlap. */
432 if (s) {
433 if (g->start > s->start)
434 error(ERR_FATAL, "sections %s ~ %s and %s overlap!",
435 gs->name, g->name, s->name);
436 if (pend > s->start)
437 error(ERR_FATAL, "sections %s and %s overlap!",
438 g->name, s->name);
440 /* Remember this section as the latest >0 length section. */
441 gs = g;
444 /* Step 4: Compute vstart addresses for all sections. */
446 /* Attach the nobits sections to the end of the progbits sections. */
447 for (s = sections; s->next; s = s->next) ;
448 s->next = nobits;
449 last_progbits = s;
450 /* Scan for sections that don't have a vstart address. If we find one we'll
451 * attempt to compute its vstart. If we can't compute the vstart, we leave
452 * it alone and come back to it in a subsequent scan. We continue scanning
453 * and re-scanning until we've gone one full cycle without computing any
454 * vstarts. */
455 do { /* Do one full scan of the sections list. */
456 for (h = 0, g = sections; g; g = g->next) {
457 if (g->flags & VSTART_DEFINED)
458 continue;
459 /* Find the section that this one virtually follows. */
460 if (g->flags & VFOLLOWS_DEFINED) {
461 for (s = sections; s && strcmp(g->vfollows, s->name);
462 s = s->next) ;
463 if (!s)
464 error(ERR_FATAL,
465 "section %s vfollows unknown section (%s)",
466 g->name, g->vfollows);
467 } else if (g->ifollows != NULL)
468 for (s = sections; s && (s != g->ifollows); s = s->next) ;
469 /* The .bss section is the only one with ifollows = NULL. In this case we
470 * implicitly follow the last progbits section. */
471 else
472 s = last_progbits;
474 /* If the section we're following has a vstart, we can proceed. */
475 if (s->flags & VSTART_DEFINED) { /* Default to virtual alignment of four. */
476 if (!(g->flags & VALIGN_DEFINED)) {
477 g->valign = 4;
478 g->flags |= VALIGN_DEFINED;
480 /* Compute the vstart address. */
481 g->vstart =
482 (s->vstart + s->length + g->valign - 1) & ~(g->valign -
484 g->flags |= VSTART_DEFINED;
485 h++;
486 /* Start and vstart mean the same thing for nobits sections. */
487 if (g->flags & TYPE_NOBITS)
488 g->start = g->vstart;
491 } while (h);
493 /* Now check for any circular vfollows references, which will manifest
494 * themselves as sections without a defined vstart. */
495 for (h = 0, s = sections; s; s = s->next) {
496 if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a
497 * no-no, but we'll throw a fatal one eventually so it's ok. */
498 error(ERR_NONFATAL, "cannot compute vstart for section %s",
499 s->name);
500 h++;
503 if (h)
504 error(ERR_FATAL, "circular vfollows path detected");
506 #ifdef DEBUG
507 fprintf(stdout,
508 "bin_cleanup: Confirm final section order for output file:\n");
509 for (h = 0, s = sections; s && (s->flags & TYPE_PROGBITS);
510 h++, s = s->next)
511 fprintf(stdout, "%i. %s\n", h, s->name);
512 #endif
514 /* Step 5: Apply relocations. */
516 /* Prepare the sections for relocating. */
517 for (s = sections; s; s = s->next)
518 saa_rewind(s->contents);
519 /* Apply relocations. */
520 for (r = relocs; r; r = r->next) {
521 uint8_t *p, *q, mydata[8];
522 int64_t l;
524 saa_fread(r->target->contents, r->posn, mydata, r->bytes);
525 p = q = mydata;
526 l = *p++;
528 if (r->bytes > 1) {
529 l += ((int64_t)*p++) << 8;
530 if (r->bytes >= 4) {
531 l += ((int64_t)*p++) << 16;
532 l += ((int64_t)*p++) << 24;
534 if (r->bytes == 8) {
535 l += ((int64_t)*p++) << 32;
536 l += ((int64_t)*p++) << 40;
537 l += ((int64_t)*p++) << 48;
538 l += ((int64_t)*p++) << 56;
542 s = find_section_by_index(r->secref);
543 if (s) {
544 if (r->secref == s->start_index)
545 l += s->start;
546 else
547 l += s->vstart;
549 s = find_section_by_index(r->secrel);
550 if (s) {
551 if (r->secrel == s->start_index)
552 l -= s->start;
553 else
554 l -= s->vstart;
557 if (r->bytes >= 4)
558 WRITEDLONG(q, l);
559 else if (r->bytes == 2)
560 WRITESHORT(q, l);
561 else
562 *q++ = (uint8_t)(l & 0xFF);
563 saa_fwrite(r->target->contents, r->posn, mydata, r->bytes);
566 /* Step 6: Write the section data to the output file. */
568 /* Write the progbits sections to the output file. */
569 for (pend = origin, s = sections; s && (s->flags & TYPE_PROGBITS); s = s->next) { /* Skip zero-length sections. */
570 if (s->length == 0)
571 continue;
572 /* Pad the space between sections. */
573 for (h = s->start - pend; h; h--)
574 fputc('\0', fp);
575 /* Write the section to the output file. */
576 if (s->length > 0)
577 saa_fpwrite(s->contents, fp);
578 pend = s->start + s->length;
580 /* Done writing the file, so close it. */
581 fclose(fp);
583 /* Step 7: Generate the map file. */
585 if (map_control) {
586 const int8_t *not_defined = { "not defined" };
588 /* Display input and output file names. */
589 fprintf(rf, "\n- NASM Map file ");
590 for (h = 63; h; h--)
591 fputc('-', rf);
592 fprintf(rf, "\n\nSource file: %s\nOutput file: %s\n\n",
593 infile, outfile);
595 if (map_control & MAP_ORIGIN) { /* Display program origin. */
596 fprintf(rf, "-- Program origin ");
597 for (h = 61; h; h--)
598 fputc('-', rf);
599 fprintf(rf, "\n\n%08lX\n\n", origin);
601 /* Display sections summary. */
602 if (map_control & MAP_SUMMARY) {
603 fprintf(rf, "-- Sections (summary) ");
604 for (h = 57; h; h--)
605 fputc('-', rf);
606 fprintf(rf, "\n\nVstart Start Stop "
607 "Length Class Name\n");
608 for (s = sections; s; s = s->next) {
609 fprintf(rf, "%08lX %08lX %08lX %08lX ",
610 s->vstart, s->start, s->start + s->length,
611 s->length);
612 if (s->flags & TYPE_PROGBITS)
613 fprintf(rf, "progbits ");
614 else
615 fprintf(rf, "nobits ");
616 fprintf(rf, "%s\n", s->name);
618 fprintf(rf, "\n");
620 /* Display detailed section information. */
621 if (map_control & MAP_SECTIONS) {
622 fprintf(rf, "-- Sections (detailed) ");
623 for (h = 56; h; h--)
624 fputc('-', rf);
625 fprintf(rf, "\n\n");
626 for (s = sections; s; s = s->next) {
627 fprintf(rf, "---- Section %s ", s->name);
628 for (h = 65 - strlen(s->name); h; h--)
629 fputc('-', rf);
630 fprintf(rf, "\n\nclass: ");
631 if (s->flags & TYPE_PROGBITS)
632 fprintf(rf, "progbits");
633 else
634 fprintf(rf, "nobits");
635 fprintf(rf, "\nlength: %08lX\nstart: %08lX"
636 "\nalign: ", s->length, s->start);
637 if (s->flags & ALIGN_DEFINED)
638 fprintf(rf, "%08lX", s->align);
639 else
640 fprintf(rf, not_defined);
641 fprintf(rf, "\nfollows: ");
642 if (s->flags & FOLLOWS_DEFINED)
643 fprintf(rf, "%s", s->follows);
644 else
645 fprintf(rf, not_defined);
646 fprintf(rf, "\nvstart: %08lX\nvalign: ", s->vstart);
647 if (s->flags & VALIGN_DEFINED)
648 fprintf(rf, "%08lX", s->valign);
649 else
650 fprintf(rf, not_defined);
651 fprintf(rf, "\nvfollows: ");
652 if (s->flags & VFOLLOWS_DEFINED)
653 fprintf(rf, "%s", s->vfollows);
654 else
655 fprintf(rf, not_defined);
656 fprintf(rf, "\n\n");
659 /* Display symbols information. */
660 if (map_control & MAP_SYMBOLS) {
661 int32_t segment, offset;
663 fprintf(rf, "-- Symbols ");
664 for (h = 68; h; h--)
665 fputc('-', rf);
666 fprintf(rf, "\n\n");
667 if (no_seg_labels) {
668 fprintf(rf, "---- No Section ");
669 for (h = 63; h; h--)
670 fputc('-', rf);
671 fprintf(rf, "\n\nValue Name\n");
672 for (l = no_seg_labels; l; l = l->next) {
673 lookup_label(l->name, &segment, &offset);
674 fprintf(rf, "%08lX %s\n", offset, l->name);
676 fprintf(rf, "\n\n");
678 for (s = sections; s; s = s->next) {
679 if (s->labels) {
680 fprintf(rf, "---- Section %s ", s->name);
681 for (h = 65 - strlen(s->name); h; h--)
682 fputc('-', rf);
683 fprintf(rf, "\n\nReal Virtual Name\n");
684 for (l = s->labels; l; l = l->next) {
685 lookup_label(l->name, &segment, &offset);
686 fprintf(rf, "%08lX %08lX %s\n",
687 s->start + offset, s->vstart + offset,
688 l->name);
690 fprintf(rf, "\n");
696 /* Close the report file. */
697 if (map_control && (rf != stdout) && (rf != stderr))
698 fclose(rf);
700 /* Step 8: Release all allocated memory. */
702 /* Free sections, label pointer structs, etc.. */
703 while (sections) {
704 s = sections;
705 sections = s->next;
706 saa_free(s->contents);
707 nasm_free(s->name);
708 if (s->flags & FOLLOWS_DEFINED)
709 nasm_free(s->follows);
710 if (s->flags & VFOLLOWS_DEFINED)
711 nasm_free(s->vfollows);
712 while (s->labels) {
713 l = s->labels;
714 s->labels = l->next;
715 nasm_free(l);
717 nasm_free(s);
720 /* Free no-section labels. */
721 while (no_seg_labels) {
722 l = no_seg_labels;
723 no_seg_labels = l->next;
724 nasm_free(l);
727 /* Free relocation structures. */
728 while (relocs) {
729 r = relocs->next;
730 nasm_free(relocs);
731 relocs = r;
735 static void bin_out(int32_t segto, const void *data, uint32_t type,
736 int32_t segment, int32_t wrt)
738 uint8_t *p, mydata[8];
739 struct Section *s;
740 int32_t realbytes;
743 if (wrt != NO_SEG) {
744 wrt = NO_SEG; /* continue to do _something_ */
745 error(ERR_NONFATAL, "WRT not supported by binary output format");
748 /* Handle absolute-assembly (structure definitions). */
749 if (segto == NO_SEG) {
750 if ((type & OUT_TYPMASK) != OUT_RESERVE)
751 error(ERR_NONFATAL, "attempt to assemble code in"
752 " [ABSOLUTE] space");
753 return;
756 /* Find the segment we are targeting. */
757 s = find_section_by_index(segto);
758 if (!s)
759 error(ERR_PANIC, "code directed to nonexistent segment?");
761 /* "Smart" section-type adaptation code. */
762 if (!(s->flags & TYPE_DEFINED)) {
763 if ((type & OUT_TYPMASK) == OUT_RESERVE)
764 s->flags |= TYPE_DEFINED | TYPE_NOBITS;
765 else
766 s->flags |= TYPE_DEFINED | TYPE_PROGBITS;
769 if ((s->flags & TYPE_NOBITS) && ((type & OUT_TYPMASK) != OUT_RESERVE))
770 error(ERR_WARNING, "attempt to initialize memory in a"
771 " nobits section: ignored");
773 if ((type & OUT_TYPMASK) == OUT_ADDRESS) {
774 if (segment != NO_SEG && !find_section_by_index(segment)) {
775 if (segment % 2)
776 error(ERR_NONFATAL, "binary output format does not support"
777 " segment base references");
778 else
779 error(ERR_NONFATAL, "binary output format does not support"
780 " external references");
781 segment = NO_SEG;
783 if (s->flags & TYPE_PROGBITS) {
784 if (segment != NO_SEG)
785 add_reloc(s, type & OUT_SIZMASK, segment, -1L);
786 p = mydata;
787 if ((type & OUT_SIZMASK) == 4)
788 WRITELONG(p, *(int32_t *)data);
789 else if ((type & OUT_SIZMASK) == 8)
790 WRITEDLONG(p, *(int64_t *)data);
791 else
792 WRITESHORT(p, *(int32_t *)data);
793 saa_wbytes(s->contents, mydata, type & OUT_SIZMASK);
795 s->length += type & OUT_SIZMASK;
796 } else if ((type & OUT_TYPMASK) == OUT_RAWDATA) {
797 type &= OUT_SIZMASK;
798 if (s->flags & TYPE_PROGBITS)
799 saa_wbytes(s->contents, data, type);
800 s->length += type;
801 } else if ((type & OUT_TYPMASK) == OUT_RESERVE) {
802 type &= OUT_SIZMASK;
803 if (s->flags & TYPE_PROGBITS) {
804 error(ERR_WARNING, "uninitialized space declared in"
805 " %s section: zeroing", s->name);
806 saa_wbytes(s->contents, NULL, type);
808 s->length += type;
809 } else if ((type & OUT_TYPMASK) == OUT_REL2ADR ||
810 (type & OUT_TYPMASK) == OUT_REL4ADR) {
811 realbytes = (type & OUT_TYPMASK);
812 if (realbytes == OUT_REL2ADR)
813 realbytes = 2;
814 else
815 realbytes = 4;
816 if (segment != NO_SEG && !find_section_by_index(segment)) {
817 if (segment % 2)
818 error(ERR_NONFATAL, "binary output format does not support"
819 " segment base references");
820 else
821 error(ERR_NONFATAL, "binary output format does not support"
822 " external references");
823 segment = NO_SEG;
825 if (s->flags & TYPE_PROGBITS) {
826 add_reloc(s, realbytes, segment, segto);
827 p = mydata;
828 if (realbytes == 4)
829 WRITELONG(p, *(int32_t *)data - realbytes - s->length);
830 else
831 WRITESHORT(p, *(int32_t *)data - realbytes - s->length);
832 saa_wbytes(s->contents, mydata, realbytes);
834 s->length += realbytes;
838 static void bin_deflabel(int8_t *name, int32_t segment, int32_t offset,
839 int is_global, int8_t *special)
841 (void)segment; /* Don't warn that this parameter is unused */
842 (void)offset; /* Don't warn that this parameter is unused */
844 if (special)
845 error(ERR_NONFATAL, "binary format does not support any"
846 " special symbol types");
847 else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
848 error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
849 else if (is_global == 2)
850 error(ERR_NONFATAL, "binary output format does not support common"
851 " variables");
852 else {
853 struct Section *s;
854 struct bin_label ***ltp;
856 /* Remember label definition so we can look it up later when
857 * creating the map file. */
858 s = find_section_by_index(segment);
859 if (s)
860 ltp = &(s->labels_end);
861 else
862 ltp = &nsl_tail;
863 (**ltp) = nasm_malloc(sizeof(struct bin_label));
864 (**ltp)->name = name;
865 (**ltp)->next = NULL;
866 *ltp = &((**ltp)->next);
871 /* These constants and the following function are used
872 * by bin_secname() to parse attribute assignments. */
874 enum { ATTRIB_START, ATTRIB_ALIGN, ATTRIB_FOLLOWS,
875 ATTRIB_VSTART, ATTRIB_VALIGN, ATTRIB_VFOLLOWS,
876 ATTRIB_NOBITS, ATTRIB_PROGBITS
879 static int bin_read_attribute(int8_t **line, int *attribute,
880 uint32_t *value)
882 expr *e;
883 int attrib_name_size;
884 struct tokenval tokval;
885 int8_t *exp;
887 /* Skip whitespace. */
888 while (**line && isspace(**line))
889 (*line)++;
890 if (!**line)
891 return 0;
893 /* Figure out what attribute we're reading. */
894 if (!nasm_strnicmp(*line, "align=", 6)) {
895 *attribute = ATTRIB_ALIGN;
896 attrib_name_size = 6;
897 } else if (format_mode) {
898 if (!nasm_strnicmp(*line, "start=", 6)) {
899 *attribute = ATTRIB_START;
900 attrib_name_size = 6;
901 } else if (!nasm_strnicmp(*line, "follows=", 8)) {
902 *attribute = ATTRIB_FOLLOWS;
903 *line += 8;
904 return 1;
905 } else if (!nasm_strnicmp(*line, "vstart=", 7)) {
906 *attribute = ATTRIB_VSTART;
907 attrib_name_size = 7;
908 } else if (!nasm_strnicmp(*line, "valign=", 7)) {
909 *attribute = ATTRIB_VALIGN;
910 attrib_name_size = 7;
911 } else if (!nasm_strnicmp(*line, "vfollows=", 9)) {
912 *attribute = ATTRIB_VFOLLOWS;
913 *line += 9;
914 return 1;
915 } else if (!nasm_strnicmp(*line, "nobits", 6) &&
916 (isspace((*line)[6]) || ((*line)[6] == '\0'))) {
917 *attribute = ATTRIB_NOBITS;
918 *line += 6;
919 return 1;
920 } else if (!nasm_strnicmp(*line, "progbits", 8) &&
921 (isspace((*line)[8]) || ((*line)[8] == '\0'))) {
922 *attribute = ATTRIB_PROGBITS;
923 *line += 8;
924 return 1;
925 } else
926 return 0;
927 } else
928 return 0;
930 /* Find the end of the expression. */
931 if ((*line)[attrib_name_size] != '(') {
932 /* Single term (no parenthesis). */
933 exp = *line += attrib_name_size;
934 while (**line && !isspace(**line))
935 (*line)++;
936 if (**line) {
937 **line = '\0';
938 (*line)++;
940 } else {
941 int8_t c;
942 int pcount = 1;
944 /* Full expression (delimited by parenthesis) */
945 exp = *line += attrib_name_size + 1;
946 while (1) {
947 (*line) += strcspn(*line, "()'\"");
948 if (**line == '(') {
949 ++(*line);
950 ++pcount;
952 if (**line == ')') {
953 ++(*line);
954 --pcount;
955 if (!pcount)
956 break;
958 if ((**line == '"') || (**line == '\'')) {
959 c = **line;
960 while (**line) {
961 ++(*line);
962 if (**line == c)
963 break;
965 if (!**line) {
966 error(ERR_NONFATAL,
967 "invalid syntax in `section' directive");
968 return -1;
970 ++(*line);
972 if (!**line) {
973 error(ERR_NONFATAL, "expecting `)'");
974 return -1;
977 *(*line - 1) = '\0'; /* Terminate the expression. */
980 /* Check for no value given. */
981 if (!*exp) {
982 error(ERR_WARNING, "No value given to attribute in"
983 " `section' directive");
984 return -1;
987 /* Read and evaluate the expression. */
988 stdscan_reset();
989 stdscan_bufptr = exp;
990 tokval.t_type = TOKEN_INVALID;
991 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
992 if (e) {
993 if (!is_really_simple(e)) {
994 error(ERR_NONFATAL, "section attribute value must be"
995 " a critical expression");
996 return -1;
998 } else {
999 error(ERR_NONFATAL, "Invalid attribute value"
1000 " specified in `section' directive.");
1001 return -1;
1003 *value = (uint32_t)reloc_value(e);
1004 return 1;
1007 static void bin_assign_attributes(struct Section *sec, int8_t *astring)
1009 int attribute, check;
1010 uint32_t value;
1011 int8_t *p;
1013 while (1) { /* Get the next attribute. */
1014 check = bin_read_attribute(&astring, &attribute, &value);
1015 /* Skip bad attribute. */
1016 if (check == -1)
1017 continue;
1018 /* Unknown section attribute, so skip it and warn the user. */
1019 if (!check) {
1020 if (!*astring)
1021 break; /* End of line. */
1022 else {
1023 p = astring;
1024 while (*astring && !isspace(*astring))
1025 astring++;
1026 if (*astring) {
1027 *astring = '\0';
1028 astring++;
1030 error(ERR_WARNING, "ignoring unknown section attribute:"
1031 " \"%s\"", p);
1033 continue;
1036 switch (attribute) { /* Handle nobits attribute. */
1037 case ATTRIB_NOBITS:
1038 if ((sec->flags & TYPE_DEFINED)
1039 && (sec->flags & TYPE_PROGBITS))
1040 error(ERR_NONFATAL,
1041 "attempt to change section type"
1042 " from progbits to nobits");
1043 else
1044 sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
1045 continue;
1047 /* Handle progbits attribute. */
1048 case ATTRIB_PROGBITS:
1049 if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
1050 error(ERR_NONFATAL, "attempt to change section type"
1051 " from nobits to progbits");
1052 else
1053 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1054 continue;
1056 /* Handle align attribute. */
1057 case ATTRIB_ALIGN:
1058 if (!format_mode && (!strcmp(sec->name, ".text")))
1059 error(ERR_NONFATAL, "cannot specify an alignment"
1060 " to the .text section");
1061 else {
1062 if (!value || ((value - 1) & value))
1063 error(ERR_NONFATAL, "argument to `align' is not a"
1064 " power of two");
1065 else { /* Alignment is already satisfied if the previous
1066 * align value is greater. */
1067 if ((sec->flags & ALIGN_DEFINED)
1068 && (value < sec->align))
1069 value = sec->align;
1071 /* Don't allow a conflicting align value. */
1072 if ((sec->flags & START_DEFINED)
1073 && (sec->start & (value - 1)))
1074 error(ERR_NONFATAL,
1075 "`align' value conflicts "
1076 "with section start address");
1077 else {
1078 sec->align = value;
1079 sec->flags |= ALIGN_DEFINED;
1083 continue;
1085 /* Handle valign attribute. */
1086 case ATTRIB_VALIGN:
1087 if (!value || ((value - 1) & value))
1088 error(ERR_NONFATAL, "argument to `valign' is not a"
1089 " power of two");
1090 else { /* Alignment is already satisfied if the previous
1091 * align value is greater. */
1092 if ((sec->flags & VALIGN_DEFINED) && (value < sec->valign))
1093 value = sec->valign;
1095 /* Don't allow a conflicting valign value. */
1096 if ((sec->flags & VSTART_DEFINED)
1097 && (sec->vstart & (value - 1)))
1098 error(ERR_NONFATAL,
1099 "`valign' value conflicts "
1100 "with `vstart' address");
1101 else {
1102 sec->valign = value;
1103 sec->flags |= VALIGN_DEFINED;
1106 continue;
1108 /* Handle start attribute. */
1109 case ATTRIB_START:
1110 if (sec->flags & FOLLOWS_DEFINED)
1111 error(ERR_NONFATAL, "cannot combine `start' and `follows'"
1112 " section attributes");
1113 else if (value < 0)
1114 error(ERR_NONFATAL, "attempt to specify a negative"
1115 " section start address");
1116 else if ((sec->flags & START_DEFINED) && (value != sec->start))
1117 error(ERR_NONFATAL, "section start address redefined");
1118 else {
1119 sec->start = value;
1120 sec->flags |= START_DEFINED;
1121 if (sec->flags & ALIGN_DEFINED) {
1122 if (sec->start & (sec->align - 1))
1123 error(ERR_NONFATAL, "`start' address conflicts"
1124 " with section alignment");
1125 sec->flags ^= ALIGN_DEFINED;
1128 continue;
1130 /* Handle vstart attribute. */
1131 case ATTRIB_VSTART:
1132 if (sec->flags & VFOLLOWS_DEFINED)
1133 error(ERR_NONFATAL,
1134 "cannot combine `vstart' and `vfollows'"
1135 " section attributes");
1136 else if ((sec->flags & VSTART_DEFINED)
1137 && (value != sec->vstart))
1138 error(ERR_NONFATAL,
1139 "section virtual start address"
1140 " (vstart) redefined");
1141 else {
1142 sec->vstart = value;
1143 sec->flags |= VSTART_DEFINED;
1144 if (sec->flags & VALIGN_DEFINED) {
1145 if (sec->vstart & (sec->valign - 1))
1146 error(ERR_NONFATAL, "`vstart' address conflicts"
1147 " with `valign' value");
1148 sec->flags ^= VALIGN_DEFINED;
1151 continue;
1153 /* Handle follows attribute. */
1154 case ATTRIB_FOLLOWS:
1155 p = astring;
1156 astring += strcspn(astring, " \t");
1157 if (astring == p)
1158 error(ERR_NONFATAL, "expecting section name for `follows'"
1159 " attribute");
1160 else {
1161 *(astring++) = '\0';
1162 if (sec->flags & START_DEFINED)
1163 error(ERR_NONFATAL,
1164 "cannot combine `start' and `follows'"
1165 " section attributes");
1166 sec->follows = nasm_strdup(p);
1167 sec->flags |= FOLLOWS_DEFINED;
1169 continue;
1171 /* Handle vfollows attribute. */
1172 case ATTRIB_VFOLLOWS:
1173 if (sec->flags & VSTART_DEFINED)
1174 error(ERR_NONFATAL,
1175 "cannot combine `vstart' and `vfollows'"
1176 " section attributes");
1177 else {
1178 p = astring;
1179 astring += strcspn(astring, " \t");
1180 if (astring == p)
1181 error(ERR_NONFATAL,
1182 "expecting section name for `vfollows'"
1183 " attribute");
1184 else {
1185 *(astring++) = '\0';
1186 sec->vfollows = nasm_strdup(p);
1187 sec->flags |= VFOLLOWS_DEFINED;
1190 continue;
1195 static void bin_define_section_labels()
1197 static int labels_defined = 0;
1198 struct Section *sec;
1199 int8_t *label_name;
1200 size_t base_len;
1202 if (labels_defined)
1203 return;
1204 for (sec = sections; sec; sec = sec->next) {
1205 base_len = strlen(sec->name) + 8;
1206 label_name = nasm_malloc(base_len + 8);
1207 strcpy(label_name, "section.");
1208 strcpy(label_name + 8, sec->name);
1210 /* section.<name>.start */
1211 strcpy(label_name + base_len, ".start");
1212 define_label(label_name, sec->start_index, 0L,
1213 NULL, 0, 0, bin_get_ofmt(), error);
1215 /* section.<name>.vstart */
1216 strcpy(label_name + base_len, ".vstart");
1217 define_label(label_name, sec->vstart_index, 0L,
1218 NULL, 0, 0, bin_get_ofmt(), error);
1220 nasm_free(label_name);
1222 labels_defined = 1;
1225 static int32_t bin_secname(int8_t *name, int pass, int *bits)
1227 int8_t *p;
1228 struct Section *sec;
1230 /* bin_secname is called with *name = NULL at the start of each
1231 * pass. Use this opportunity to establish the default section
1232 * (default is BITS-16 ".text" segment).
1234 if (!name) { /* Reset ORG and section attributes at the start of each pass. */
1235 origin_defined = 0;
1236 for (sec = sections; sec; sec = sec->next)
1237 sec->flags &= ~(START_DEFINED | VSTART_DEFINED |
1238 ALIGN_DEFINED | VALIGN_DEFINED);
1240 /* Define section start and vstart labels. */
1241 if (format_mode && (pass != 1))
1242 bin_define_section_labels();
1244 /* Establish the default (.text) section. */
1245 *bits = 16;
1246 sec = find_section_by_name(".text");
1247 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1248 current_section = sec->vstart_index;
1249 return current_section;
1252 /* Attempt to find the requested section. If it does not
1253 * exist, create it. */
1254 p = name;
1255 while (*p && !isspace(*p))
1256 p++;
1257 if (*p)
1258 *p++ = '\0';
1259 sec = find_section_by_name(name);
1260 if (!sec) {
1261 sec = create_section(name);
1262 if (!strcmp(name, ".data"))
1263 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1264 else if (!strcmp(name, ".bss")) {
1265 sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
1266 sec->ifollows = NULL;
1267 } else if (!format_mode) {
1268 error(ERR_NONFATAL, "section name must be "
1269 ".text, .data, or .bss");
1270 return current_section;
1274 /* Handle attribute assignments. */
1275 if (pass != 1)
1276 bin_assign_attributes(sec, p);
1278 #ifndef ABIN_SMART_ADAPT
1279 /* The following line disables smart adaptation of
1280 * PROGBITS/NOBITS section types (it forces sections to
1281 * default to PROGBITS). */
1282 if ((pass != 1) && !(sec->flags & TYPE_DEFINED))
1283 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1284 #endif
1286 /* Set the current section and return. */
1287 current_section = sec->vstart_index;
1288 return current_section;
1291 static int bin_directive(int8_t *directive, int8_t *args, int pass)
1293 /* Handle ORG directive */
1294 if (!nasm_stricmp(directive, "org")) {
1295 struct tokenval tokval;
1296 uint32_t value;
1297 expr *e;
1299 stdscan_reset();
1300 stdscan_bufptr = args;
1301 tokval.t_type = TOKEN_INVALID;
1302 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
1303 if (e) {
1304 if (!is_really_simple(e))
1305 error(ERR_NONFATAL, "org value must be a critical"
1306 " expression");
1307 else {
1308 value = reloc_value(e);
1309 /* Check for ORG redefinition. */
1310 if (origin_defined && (value != origin))
1311 error(ERR_NONFATAL, "program origin redefined");
1312 else {
1313 origin = value;
1314 origin_defined = 1;
1317 } else
1318 error(ERR_NONFATAL, "No or invalid offset specified"
1319 " in ORG directive.");
1320 return 1;
1323 /* The 'map' directive allows the user to generate section
1324 * and symbol information to stdout, stderr, or to a file. */
1325 else if (format_mode && !nasm_stricmp(directive, "map")) {
1326 int8_t *p;
1328 if (pass != 1)
1329 return 1;
1330 args += strspn(args, " \t");
1331 while (*args) {
1332 p = args;
1333 args += strcspn(args, " \t");
1334 if (*args != '\0')
1335 *(args++) = '\0';
1336 if (!nasm_stricmp(p, "all"))
1337 map_control |=
1338 MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS | MAP_SYMBOLS;
1339 else if (!nasm_stricmp(p, "brief"))
1340 map_control |= MAP_ORIGIN | MAP_SUMMARY;
1341 else if (!nasm_stricmp(p, "sections"))
1342 map_control |= MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS;
1343 else if (!nasm_stricmp(p, "segments"))
1344 map_control |= MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS;
1345 else if (!nasm_stricmp(p, "symbols"))
1346 map_control |= MAP_SYMBOLS;
1347 else if (!rf) {
1348 if (!nasm_stricmp(p, "stdout"))
1349 rf = stdout;
1350 else if (!nasm_stricmp(p, "stderr"))
1351 rf = stderr;
1352 else { /* Must be a filename. */
1353 rf = fopen(p, "wt");
1354 if (!rf) {
1355 error(ERR_WARNING, "unable to open map file `%s'",
1357 map_control = 0;
1358 return 1;
1361 } else
1362 error(ERR_WARNING, "map file already specified");
1364 if (map_control == 0)
1365 map_control |= MAP_ORIGIN | MAP_SUMMARY;
1366 if (!rf)
1367 rf = stdout;
1368 return 1;
1370 return 0;
1373 static void bin_filename(int8_t *inname, int8_t *outname, efunc error)
1375 standard_extension(inname, outname, "", error);
1376 infile = inname;
1377 outfile = outname;
1380 static int32_t bin_segbase(int32_t segment)
1382 return segment;
1385 static int bin_set_info(enum geninfo type, int8_t **val)
1387 return 0;
1390 static void bin_init(FILE * afp, efunc errfunc, ldfunc ldef, evalfunc eval)
1392 fp = afp;
1393 error = errfunc;
1395 (void)eval; /* Don't warn that this parameter is unused. */
1396 (void)ldef; /* Placate optimizers. */
1398 maxbits = 64; /* Support 64-bit Segments */
1399 relocs = NULL;
1400 reloctail = &relocs;
1401 origin_defined = 0;
1402 no_seg_labels = NULL;
1403 nsl_tail = &no_seg_labels;
1404 format_mode = 1; /* Extended bin format
1405 * (set this to zero for old bin format). */
1407 /* Create default section (.text). */
1408 sections = last_section = nasm_malloc(sizeof(struct Section));
1409 last_section->next = NULL;
1410 last_section->name = nasm_strdup(".text");
1411 last_section->contents = saa_init(1L);
1412 last_section->follows = last_section->vfollows = 0;
1413 last_section->ifollows = NULL;
1414 last_section->length = 0;
1415 last_section->flags = TYPE_DEFINED | TYPE_PROGBITS;
1416 last_section->labels = NULL;
1417 last_section->labels_end = &(last_section->labels);
1418 last_section->start_index = seg_alloc();
1419 last_section->vstart_index = current_section = seg_alloc();
1422 struct ofmt of_bin = {
1423 "flat-form binary files (e.g. DOS .COM, .SYS)",
1424 "bin",
1425 NULL,
1426 null_debug_arr,
1427 &null_debug_form,
1428 bin_stdmac,
1429 bin_init,
1430 bin_set_info,
1431 bin_out,
1432 bin_deflabel,
1433 bin_secname,
1434 bin_segbase,
1435 bin_directive,
1436 bin_filename,
1437 bin_cleanup
1440 /* This is needed for bin_define_section_labels() */
1441 struct ofmt *bin_get_ofmt()
1443 return &of_bin;
1446 #endif /* #ifdef OF_BIN */