Version 0.99.03
[nasm/avx512.git] / output / outbin.c
bloba1c51c8f930d99d7c599189845bde0cd8b83e17e
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 "stdscan.h"
56 #include "labels.h"
57 #include "eval.h"
58 #include "outform.h"
60 #ifdef OF_BIN
62 struct ofmt *bin_get_ofmt(); /* Prototype goes here since no header file. */
64 static FILE *fp, *rf = NULL;
65 static efunc error;
67 /* Section flags keep track of which attributes the user has defined. */
68 #define START_DEFINED 0x001
69 #define ALIGN_DEFINED 0x002
70 #define FOLLOWS_DEFINED 0x004
71 #define VSTART_DEFINED 0x008
72 #define VALIGN_DEFINED 0x010
73 #define VFOLLOWS_DEFINED 0x020
74 #define TYPE_DEFINED 0x040
75 #define TYPE_PROGBITS 0x080
76 #define TYPE_NOBITS 0x100
78 /* This struct is used to keep track of symbols for map-file generation. */
79 static struct bin_label {
80 char *name;
81 struct bin_label *next;
82 } *no_seg_labels, **nsl_tail;
84 static struct Section {
85 char *name;
86 struct SAA *contents;
87 int64_t length; /* section length in bytes */
89 /* Section attributes */
90 int flags; /* see flag definitions above */
91 uint64_t align; /* section alignment */
92 uint64_t valign; /* notional section alignment */
93 uint64_t start; /* section start address */
94 uint64_t vstart; /* section virtual start address */
95 char *follows; /* the section that this one will follow */
96 char *vfollows; /* the section that this one will notionally follow */
97 int32_t start_index; /* NASM section id for non-relocated version */
98 int32_t vstart_index; /* the NASM section id */
100 struct bin_label *labels; /* linked-list of label handles for map output. */
101 struct bin_label **labels_end; /* Holds address of end of labels list. */
102 struct Section *ifollows; /* Points to previous section (implicit follows). */
103 struct Section *next; /* This links sections with a defined start address. */
105 /* The extended bin format allows for sections to have a "virtual"
106 * start address. This is accomplished by creating two sections:
107 * one beginning at the Load Memory Address and the other beginning
108 * at the Virtual Memory Address. The LMA section is only used to
109 * define the section.<section_name>.start label, but there isn't
110 * any other good way for us to handle that label.
113 } *sections, *last_section;
115 static struct Reloc {
116 struct Reloc *next;
117 int32_t posn;
118 int32_t bytes;
119 int32_t secref;
120 int32_t secrel;
121 struct Section *target;
122 } *relocs, **reloctail;
124 extern char *stdscan_bufptr;
125 extern int lookup_label(char *label, int32_t *segment, int32_t *offset);
127 static uint8_t format_mode; /* 0 = original bin, 1 = extended bin */
128 static int32_t current_section; /* only really needed if format_mode = 0 */
129 static uint64_t origin;
130 static int origin_defined;
132 /* Stuff we need for map-file generation. */
133 #define MAP_ORIGIN 1
134 #define MAP_SUMMARY 2
135 #define MAP_SECTIONS 4
136 #define MAP_SYMBOLS 8
137 static int map_control = 0;
138 static char *infile, *outfile;
140 static const char *bin_stdmac[] = {
141 "%define __SECT__ [section .text]",
142 "%imacro org 1+.nolist",
143 "[org %1]",
144 "%endmacro",
145 "%macro __NASM_CDecl__ 1",
146 "%endmacro",
147 NULL
150 static void add_reloc(struct Section *s, int32_t bytes, int32_t secref,
151 int32_t secrel)
153 struct Reloc *r;
155 r = *reloctail = nasm_malloc(sizeof(struct Reloc));
156 reloctail = &r->next;
157 r->next = NULL;
158 r->posn = s->length;
159 r->bytes = bytes;
160 r->secref = secref;
161 r->secrel = secrel;
162 r->target = s;
165 static struct Section *find_section_by_name(const char *name)
167 struct Section *s;
169 for (s = sections; s; s = s->next)
170 if (!strcmp(s->name, name))
171 break;
172 return s;
175 static struct Section *find_section_by_index(int32_t index)
177 struct Section *s;
179 for (s = sections; s; s = s->next)
180 if ((index == s->vstart_index) || (index == s->start_index))
181 break;
182 return s;
185 static struct Section *create_section(char *name)
186 { /* Create a new section. */
187 last_section->next = nasm_malloc(sizeof(struct Section));
188 last_section->next->ifollows = last_section;
189 last_section = last_section->next;
190 last_section->labels = NULL;
191 last_section->labels_end = &(last_section->labels);
193 /* Initialize section attributes. */
194 last_section->name = nasm_strdup(name);
195 last_section->contents = saa_init(1L);
196 last_section->follows = last_section->vfollows = 0;
197 last_section->length = 0;
198 last_section->flags = 0;
199 last_section->next = NULL;
201 /* Register our sections with NASM. */
202 last_section->vstart_index = seg_alloc();
203 last_section->start_index = seg_alloc();
204 return last_section;
207 static void bin_cleanup(int debuginfo)
209 struct Section *g, **gp;
210 struct Section *gs = NULL, **gsp;
211 struct Section *s, **sp;
212 struct Section *nobits = NULL, **nt;
213 struct Section *last_progbits;
214 struct bin_label *l;
215 struct Reloc *r;
216 uint64_t pend;
217 int h;
219 (void)debuginfo; /* placate optimizers */
221 #ifdef DEBUG
222 fprintf(stdout,
223 "bin_cleanup: Sections were initially referenced in this order:\n");
224 for (h = 0, s = sections; s; h++, s = s->next)
225 fprintf(stdout, "%i. %s\n", h, s->name);
226 #endif
228 /* Assembly has completed, so now we need to generate the output file.
229 * Step 1: Separate progbits and nobits sections into separate lists.
230 * Step 2: Sort the progbits sections into their output order.
231 * Step 3: Compute start addresses for all progbits sections.
232 * Step 4: Compute vstart addresses for all sections.
233 * Step 5: Apply relocations.
234 * Step 6: Write the sections' data to the output file.
235 * Step 7: Generate the map file.
236 * Step 8: Release all allocated memory.
239 /* To do: Smart section-type adaptation could leave some empty sections
240 * without a defined type (progbits/nobits). Won't fix now since this
241 * feature will be disabled. */
243 /* Step 1: Split progbits and nobits sections into separate lists. */
245 nt = &nobits;
246 /* Move nobits sections into a separate list. Also pre-process nobits
247 * sections' attributes. */
248 for (sp = &sections->next, s = sections->next; s; s = *sp) { /* Skip progbits sections. */
249 if (s->flags & TYPE_PROGBITS) {
250 sp = &s->next;
251 continue;
253 /* Do some special pre-processing on nobits sections' attributes. */
254 if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */
255 if (s->
256 flags & (VSTART_DEFINED | VALIGN_DEFINED |
257 VFOLLOWS_DEFINED))
258 error(ERR_FATAL,
259 "cannot mix real and virtual attributes"
260 " in nobits section (%s)", s->name);
261 /* Real and virtual attributes mean the same thing for nobits sections. */
262 if (s->flags & START_DEFINED) {
263 s->vstart = s->start;
264 s->flags |= VSTART_DEFINED;
266 if (s->flags & ALIGN_DEFINED) {
267 s->valign = s->align;
268 s->flags |= VALIGN_DEFINED;
270 if (s->flags & FOLLOWS_DEFINED) {
271 s->vfollows = s->follows;
272 s->flags |= VFOLLOWS_DEFINED;
273 s->flags &= ~FOLLOWS_DEFINED;
276 /* Every section must have a start address. */
277 if (s->flags & VSTART_DEFINED) {
278 s->start = s->vstart;
279 s->flags |= START_DEFINED;
281 /* Move the section into the nobits list. */
282 *sp = s->next;
283 s->next = NULL;
284 *nt = s;
285 nt = &s->next;
288 /* Step 2: Sort the progbits sections into their output order. */
290 /* In Step 2 we move around sections in groups. A group
291 * begins with a section (group leader) that has a user-
292 * defined start address or follows section. The remainder
293 * of the group is made up of the sections that implicitly
294 * follow the group leader (i.e., they were defined after
295 * the group leader and were not given an explicit start
296 * address or follows section by the user). */
298 /* For anyone attempting to read this code:
299 * g (group) points to a group of sections, the first one of which has
300 * a user-defined start address or follows section.
301 * gp (g previous) holds the location of the pointer to g.
302 * gs (g scan) is a temp variable that we use to scan to the end of the group.
303 * gsp (gs previous) holds the location of the pointer to gs.
304 * nt (nobits tail) points to the nobits section-list tail.
307 /* Link all 'follows' groups to their proper position. To do
308 * this we need to know three things: the start of the group
309 * to relocate (g), the section it is following (s), and the
310 * end of the group we're relocating (gs). */
311 for (gp = &sections, g = sections; g; g = gs) { /* Find the next follows group that is out of place (g). */
312 if (!(g->flags & FOLLOWS_DEFINED)) {
313 while (g->next) {
314 if ((g->next->flags & FOLLOWS_DEFINED) &&
315 strcmp(g->name, g->next->follows))
316 break;
317 g = g->next;
319 if (!g->next)
320 break;
321 gp = &g->next;
322 g = g->next;
324 /* Find the section that this group follows (s). */
325 for (sp = &sections, s = sections;
326 s && strcmp(s->name, g->follows);
327 sp = &s->next, s = s->next) ;
328 if (!s)
329 error(ERR_FATAL, "section %s follows an invalid or"
330 " unknown section (%s)", g->name, g->follows);
331 if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
332 !strcmp(s->name, s->next->follows))
333 error(ERR_FATAL, "sections %s and %s can't both follow"
334 " section %s", g->name, s->next->name, s->name);
335 /* Find the end of the current follows group (gs). */
336 for (gsp = &g->next, gs = g->next;
337 gs && (gs != s) && !(gs->flags & START_DEFINED);
338 gsp = &gs->next, gs = gs->next) {
339 if (gs->next && (gs->next->flags & FOLLOWS_DEFINED) &&
340 strcmp(gs->name, gs->next->follows)) {
341 gsp = &gs->next;
342 gs = gs->next;
343 break;
346 /* Re-link the group after its follows section. */
347 *gsp = s->next;
348 s->next = g;
349 *gp = gs;
352 /* Link all 'start' groups to their proper position. Once
353 * again we need to know g, s, and gs (see above). The main
354 * difference is we already know g since we sort by moving
355 * groups from the 'unsorted' list into a 'sorted' list (g
356 * will always be the first section in the unsorted list). */
357 for (g = sections, sections = NULL; g; g = gs) { /* Find the section that we will insert this group before (s). */
358 for (sp = &sections, s = sections; s; sp = &s->next, s = s->next)
359 if ((s->flags & START_DEFINED) && (g->start < s->start))
360 break;
361 /* Find the end of the group (gs). */
362 for (gs = g->next, gsp = &g->next;
363 gs && !(gs->flags & START_DEFINED);
364 gsp = &gs->next, gs = gs->next) ;
365 /* Re-link the group before the target section. */
366 *sp = g;
367 *gsp = s;
370 /* Step 3: Compute start addresses for all progbits sections. */
372 /* Make sure we have an origin and a start address for the first section. */
373 if (origin_defined)
374 switch (sections->flags & (START_DEFINED | ALIGN_DEFINED)) {
375 case START_DEFINED | ALIGN_DEFINED:
376 case START_DEFINED:
377 /* Make sure this section doesn't begin before the origin. */
378 if (sections->start < origin)
379 error(ERR_FATAL, "section %s begins"
380 " before program origin", sections->name);
381 break;
382 case ALIGN_DEFINED:
383 sections->start = ((origin + sections->align - 1) &
384 ~(sections->align - 1));
385 break;
386 case 0:
387 sections->start = origin;
388 } else {
389 if (!(sections->flags & START_DEFINED))
390 sections->start = 0;
391 origin = sections->start;
393 sections->flags |= START_DEFINED;
395 /* Make sure each section has an explicit start address. If it
396 * doesn't, then compute one based its alignment and the end of
397 * the previous section. */
398 for (pend = sections->start, g = s = sections; g; g = g->next) { /* Find the next section that could cause an overlap situation
399 * (has a defined start address, and is not zero length). */
400 if (g == s)
401 for (s = g->next;
402 s && ((s->length == 0) || !(s->flags & START_DEFINED));
403 s = s->next) ;
404 /* Compute the start address of this section, if necessary. */
405 if (!(g->flags & START_DEFINED)) { /* Default to an alignment of 4 if unspecified. */
406 if (!(g->flags & ALIGN_DEFINED)) {
407 g->align = 4;
408 g->flags |= ALIGN_DEFINED;
410 /* Set the section start address. */
411 g->start = (pend + g->align - 1) & ~(g->align - 1);
412 g->flags |= START_DEFINED;
414 /* Ugly special case for progbits sections' virtual attributes:
415 * If there is a defined valign, but no vstart and no vfollows, then
416 * we valign after the previous progbits section. This case doesn't
417 * really make much sense for progbits sections with a defined start
418 * address, but it is possible and we must do *something*.
419 * Not-so-ugly special case:
420 * If a progbits section has no virtual attributes, we set the
421 * vstart equal to the start address. */
422 if (!(g->flags & (VSTART_DEFINED | VFOLLOWS_DEFINED))) {
423 if (g->flags & VALIGN_DEFINED)
424 g->vstart = (pend + g->valign - 1) & ~(g->valign - 1);
425 else
426 g->vstart = g->start;
427 g->flags |= VSTART_DEFINED;
429 /* Ignore zero-length sections. */
430 if (g->start < pend)
431 continue;
432 /* Compute the span of this section. */
433 pend = g->start + g->length;
434 /* Check for section overlap. */
435 if (s) {
436 if (g->start > s->start)
437 error(ERR_FATAL, "sections %s ~ %s and %s overlap!",
438 gs->name, g->name, s->name);
439 if (pend > s->start)
440 error(ERR_FATAL, "sections %s and %s overlap!",
441 g->name, s->name);
443 /* Remember this section as the latest >0 length section. */
444 gs = g;
447 /* Step 4: Compute vstart addresses for all sections. */
449 /* Attach the nobits sections to the end of the progbits sections. */
450 for (s = sections; s->next; s = s->next) ;
451 s->next = nobits;
452 last_progbits = s;
453 /* Scan for sections that don't have a vstart address. If we find one we'll
454 * attempt to compute its vstart. If we can't compute the vstart, we leave
455 * it alone and come back to it in a subsequent scan. We continue scanning
456 * and re-scanning until we've gone one full cycle without computing any
457 * vstarts. */
458 do { /* Do one full scan of the sections list. */
459 for (h = 0, g = sections; g; g = g->next) {
460 if (g->flags & VSTART_DEFINED)
461 continue;
462 /* Find the section that this one virtually follows. */
463 if (g->flags & VFOLLOWS_DEFINED) {
464 for (s = sections; s && strcmp(g->vfollows, s->name);
465 s = s->next) ;
466 if (!s)
467 error(ERR_FATAL,
468 "section %s vfollows unknown section (%s)",
469 g->name, g->vfollows);
470 } else if (g->ifollows != NULL)
471 for (s = sections; s && (s != g->ifollows); s = s->next) ;
472 /* The .bss section is the only one with ifollows = NULL. In this case we
473 * implicitly follow the last progbits section. */
474 else
475 s = last_progbits;
477 /* If the section we're following has a vstart, we can proceed. */
478 if (s->flags & VSTART_DEFINED) { /* Default to virtual alignment of four. */
479 if (!(g->flags & VALIGN_DEFINED)) {
480 g->valign = 4;
481 g->flags |= VALIGN_DEFINED;
483 /* Compute the vstart address. */
484 g->vstart =
485 (s->vstart + s->length + g->valign - 1) & ~(g->valign -
487 g->flags |= VSTART_DEFINED;
488 h++;
489 /* Start and vstart mean the same thing for nobits sections. */
490 if (g->flags & TYPE_NOBITS)
491 g->start = g->vstart;
494 } while (h);
496 /* Now check for any circular vfollows references, which will manifest
497 * themselves as sections without a defined vstart. */
498 for (h = 0, s = sections; s; s = s->next) {
499 if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a
500 * no-no, but we'll throw a fatal one eventually so it's ok. */
501 error(ERR_NONFATAL, "cannot compute vstart for section %s",
502 s->name);
503 h++;
506 if (h)
507 error(ERR_FATAL, "circular vfollows path detected");
509 #ifdef DEBUG
510 fprintf(stdout,
511 "bin_cleanup: Confirm final section order for output file:\n");
512 for (h = 0, s = sections; s && (s->flags & TYPE_PROGBITS);
513 h++, s = s->next)
514 fprintf(stdout, "%i. %s\n", h, s->name);
515 #endif
517 /* Step 5: Apply relocations. */
519 /* Prepare the sections for relocating. */
520 for (s = sections; s; s = s->next)
521 saa_rewind(s->contents);
522 /* Apply relocations. */
523 for (r = relocs; r; r = r->next) {
524 uint8_t *p, *q, mydata[8];
525 int64_t l;
527 saa_fread(r->target->contents, r->posn, mydata, r->bytes);
528 p = q = mydata;
529 l = *p++;
531 if (r->bytes > 1) {
532 l += ((int64_t)*p++) << 8;
533 if (r->bytes >= 4) {
534 l += ((int64_t)*p++) << 16;
535 l += ((int64_t)*p++) << 24;
537 if (r->bytes == 8) {
538 l += ((int64_t)*p++) << 32;
539 l += ((int64_t)*p++) << 40;
540 l += ((int64_t)*p++) << 48;
541 l += ((int64_t)*p++) << 56;
545 s = find_section_by_index(r->secref);
546 if (s) {
547 if (r->secref == s->start_index)
548 l += s->start;
549 else
550 l += s->vstart;
552 s = find_section_by_index(r->secrel);
553 if (s) {
554 if (r->secrel == s->start_index)
555 l -= s->start;
556 else
557 l -= s->vstart;
560 if (r->bytes >= 4)
561 WRITEDLONG(q, l);
562 else if (r->bytes == 2)
563 WRITESHORT(q, l);
564 else
565 *q++ = (uint8_t)(l & 0xFF);
566 saa_fwrite(r->target->contents, r->posn, mydata, r->bytes);
569 /* Step 6: Write the section data to the output file. */
571 /* Write the progbits sections to the output file. */
572 for (pend = origin, s = sections; s && (s->flags & TYPE_PROGBITS); s = s->next) { /* Skip zero-length sections. */
573 if (s->length == 0)
574 continue;
575 /* Pad the space between sections. */
576 for (h = s->start - pend; h; h--)
577 fputc('\0', fp);
578 /* Write the section to the output file. */
579 if (s->length > 0)
580 saa_fpwrite(s->contents, fp);
581 pend = s->start + s->length;
583 /* Done writing the file, so close it. */
584 fclose(fp);
586 /* Step 7: Generate the map file. */
588 if (map_control) {
589 const char *not_defined = { "not defined" };
591 /* Display input and output file names. */
592 fprintf(rf, "\n- NASM Map file ");
593 for (h = 63; h; h--)
594 fputc('-', rf);
595 fprintf(rf, "\n\nSource file: %s\nOutput file: %s\n\n",
596 infile, outfile);
598 if (map_control & MAP_ORIGIN) { /* Display program origin. */
599 fprintf(rf, "-- Program origin ");
600 for (h = 61; h; h--)
601 fputc('-', rf);
602 fprintf(rf, "\n\n%08"PRIX64"\n\n", origin);
604 /* Display sections summary. */
605 if (map_control & MAP_SUMMARY) {
606 fprintf(rf, "-- Sections (summary) ");
607 for (h = 57; h; h--)
608 fputc('-', rf);
609 fprintf(rf, "\n\nVstart Start Stop "
610 "Length Class Name\n");
611 for (s = sections; s; s = s->next) {
612 fprintf(rf, "%16"PRIX64" %16"PRIX64" %16"PRIX64" %08"PRIX64" ",
613 s->vstart, s->start, s->start + s->length,
614 s->length);
615 if (s->flags & TYPE_PROGBITS)
616 fprintf(rf, "progbits ");
617 else
618 fprintf(rf, "nobits ");
619 fprintf(rf, "%s\n", s->name);
621 fprintf(rf, "\n");
623 /* Display detailed section information. */
624 if (map_control & MAP_SECTIONS) {
625 fprintf(rf, "-- Sections (detailed) ");
626 for (h = 56; h; h--)
627 fputc('-', rf);
628 fprintf(rf, "\n\n");
629 for (s = sections; s; s = s->next) {
630 fprintf(rf, "---- Section %s ", s->name);
631 for (h = 65 - strlen(s->name); h; h--)
632 fputc('-', rf);
633 fprintf(rf, "\n\nclass: ");
634 if (s->flags & TYPE_PROGBITS)
635 fprintf(rf, "progbits");
636 else
637 fprintf(rf, "nobits");
638 fprintf(rf, "\nlength: %16"PRIX64"\nstart: %16"PRIX64""
639 "\nalign: ", s->length, s->start);
640 if (s->flags & ALIGN_DEFINED)
641 fprintf(rf, "%16"PRIX64"", s->align);
642 else
643 fprintf(rf, not_defined);
644 fprintf(rf, "\nfollows: ");
645 if (s->flags & FOLLOWS_DEFINED)
646 fprintf(rf, "%s", s->follows);
647 else
648 fprintf(rf, not_defined);
649 fprintf(rf, "\nvstart: %16"PRIX64"\nvalign: ", s->vstart);
650 if (s->flags & VALIGN_DEFINED)
651 fprintf(rf, "%16"PRIX64"", s->valign);
652 else
653 fprintf(rf, not_defined);
654 fprintf(rf, "\nvfollows: ");
655 if (s->flags & VFOLLOWS_DEFINED)
656 fprintf(rf, "%s", s->vfollows);
657 else
658 fprintf(rf, not_defined);
659 fprintf(rf, "\n\n");
662 /* Display symbols information. */
663 if (map_control & MAP_SYMBOLS) {
664 int32_t segment, offset;
666 fprintf(rf, "-- Symbols ");
667 for (h = 68; h; h--)
668 fputc('-', rf);
669 fprintf(rf, "\n\n");
670 if (no_seg_labels) {
671 fprintf(rf, "---- No Section ");
672 for (h = 63; h; h--)
673 fputc('-', rf);
674 fprintf(rf, "\n\nValue Name\n");
675 for (l = no_seg_labels; l; l = l->next) {
676 lookup_label(l->name, &segment, &offset);
677 fprintf(rf, "%08"PRIX32" %s\n", offset, l->name);
679 fprintf(rf, "\n\n");
681 for (s = sections; s; s = s->next) {
682 if (s->labels) {
683 fprintf(rf, "---- Section %s ", s->name);
684 for (h = 65 - strlen(s->name); h; h--)
685 fputc('-', rf);
686 fprintf(rf, "\n\nReal Virtual Name\n");
687 for (l = s->labels; l; l = l->next) {
688 lookup_label(l->name, &segment, &offset);
689 fprintf(rf, "%16"PRIX64" %16"PRIX64" %s\n",
690 s->start + offset, s->vstart + offset,
691 l->name);
693 fprintf(rf, "\n");
699 /* Close the report file. */
700 if (map_control && (rf != stdout) && (rf != stderr))
701 fclose(rf);
703 /* Step 8: Release all allocated memory. */
705 /* Free sections, label pointer structs, etc.. */
706 while (sections) {
707 s = sections;
708 sections = s->next;
709 saa_free(s->contents);
710 nasm_free(s->name);
711 if (s->flags & FOLLOWS_DEFINED)
712 nasm_free(s->follows);
713 if (s->flags & VFOLLOWS_DEFINED)
714 nasm_free(s->vfollows);
715 while (s->labels) {
716 l = s->labels;
717 s->labels = l->next;
718 nasm_free(l);
720 nasm_free(s);
723 /* Free no-section labels. */
724 while (no_seg_labels) {
725 l = no_seg_labels;
726 no_seg_labels = l->next;
727 nasm_free(l);
730 /* Free relocation structures. */
731 while (relocs) {
732 r = relocs->next;
733 nasm_free(relocs);
734 relocs = r;
738 static void bin_out(int32_t segto, const void *data, uint32_t type,
739 int32_t segment, int32_t wrt)
741 uint8_t *p, mydata[8];
742 struct Section *s;
743 int32_t realbytes;
746 if (wrt != NO_SEG) {
747 wrt = NO_SEG; /* continue to do _something_ */
748 error(ERR_NONFATAL, "WRT not supported by binary output format");
751 /* Handle absolute-assembly (structure definitions). */
752 if (segto == NO_SEG) {
753 if ((type & OUT_TYPMASK) != OUT_RESERVE)
754 error(ERR_NONFATAL, "attempt to assemble code in"
755 " [ABSOLUTE] space");
756 return;
759 /* Find the segment we are targeting. */
760 s = find_section_by_index(segto);
761 if (!s)
762 error(ERR_PANIC, "code directed to nonexistent segment?");
764 /* "Smart" section-type adaptation code. */
765 if (!(s->flags & TYPE_DEFINED)) {
766 if ((type & OUT_TYPMASK) == OUT_RESERVE)
767 s->flags |= TYPE_DEFINED | TYPE_NOBITS;
768 else
769 s->flags |= TYPE_DEFINED | TYPE_PROGBITS;
772 if ((s->flags & TYPE_NOBITS) && ((type & OUT_TYPMASK) != OUT_RESERVE))
773 error(ERR_WARNING, "attempt to initialize memory in a"
774 " nobits section: ignored");
776 if ((type & OUT_TYPMASK) == OUT_ADDRESS) {
777 if (segment != NO_SEG && !find_section_by_index(segment)) {
778 if (segment % 2)
779 error(ERR_NONFATAL, "binary output format does not support"
780 " segment base references");
781 else
782 error(ERR_NONFATAL, "binary output format does not support"
783 " external references");
784 segment = NO_SEG;
786 if (s->flags & TYPE_PROGBITS) {
787 if (segment != NO_SEG)
788 add_reloc(s, type & OUT_SIZMASK, segment, -1L);
789 p = mydata;
790 if ((type & OUT_SIZMASK) == 4)
791 WRITELONG(p, *(int32_t *)data);
792 else if ((type & OUT_SIZMASK) == 8)
793 WRITEDLONG(p, *(int64_t *)data);
794 else
795 WRITESHORT(p, *(int32_t *)data);
796 saa_wbytes(s->contents, mydata, type & OUT_SIZMASK);
798 s->length += type & OUT_SIZMASK;
799 } else if ((type & OUT_TYPMASK) == OUT_RAWDATA) {
800 type &= OUT_SIZMASK;
801 if (s->flags & TYPE_PROGBITS)
802 saa_wbytes(s->contents, data, type);
803 s->length += type;
804 } else if ((type & OUT_TYPMASK) == OUT_RESERVE) {
805 type &= OUT_SIZMASK;
806 if (s->flags & TYPE_PROGBITS) {
807 error(ERR_WARNING, "uninitialized space declared in"
808 " %s section: zeroing", s->name);
809 saa_wbytes(s->contents, NULL, type);
811 s->length += type;
812 } else if ((type & OUT_TYPMASK) == OUT_REL2ADR ||
813 (type & OUT_TYPMASK) == OUT_REL4ADR) {
814 realbytes = (type & OUT_TYPMASK);
815 if (realbytes == OUT_REL2ADR)
816 realbytes = 2;
817 else
818 realbytes = 4;
819 if (segment != NO_SEG && !find_section_by_index(segment)) {
820 if (segment % 2)
821 error(ERR_NONFATAL, "binary output format does not support"
822 " segment base references");
823 else
824 error(ERR_NONFATAL, "binary output format does not support"
825 " external references");
826 segment = NO_SEG;
828 if (s->flags & TYPE_PROGBITS) {
829 add_reloc(s, realbytes, segment, segto);
830 p = mydata;
831 if (realbytes == 4)
832 WRITELONG(p, *(int32_t *)data - realbytes - s->length);
833 else
834 WRITESHORT(p, *(int32_t *)data - realbytes - s->length);
835 saa_wbytes(s->contents, mydata, realbytes);
837 s->length += realbytes;
841 static void bin_deflabel(char *name, int32_t segment, int32_t offset,
842 int is_global, char *special)
844 (void)segment; /* Don't warn that this parameter is unused */
845 (void)offset; /* Don't warn that this parameter is unused */
847 if (special)
848 error(ERR_NONFATAL, "binary format does not support any"
849 " special symbol types");
850 else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
851 error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
852 else if (is_global == 2)
853 error(ERR_NONFATAL, "binary output format does not support common"
854 " variables");
855 else {
856 struct Section *s;
857 struct bin_label ***ltp;
859 /* Remember label definition so we can look it up later when
860 * creating the map file. */
861 s = find_section_by_index(segment);
862 if (s)
863 ltp = &(s->labels_end);
864 else
865 ltp = &nsl_tail;
866 (**ltp) = nasm_malloc(sizeof(struct bin_label));
867 (**ltp)->name = name;
868 (**ltp)->next = NULL;
869 *ltp = &((**ltp)->next);
874 /* These constants and the following function are used
875 * by bin_secname() to parse attribute assignments. */
877 enum { ATTRIB_START, ATTRIB_ALIGN, ATTRIB_FOLLOWS,
878 ATTRIB_VSTART, ATTRIB_VALIGN, ATTRIB_VFOLLOWS,
879 ATTRIB_NOBITS, ATTRIB_PROGBITS
882 static int bin_read_attribute(char **line, int *attribute,
883 uint64_t *value)
885 expr *e;
886 int attrib_name_size;
887 struct tokenval tokval;
888 char *exp;
890 /* Skip whitespace. */
891 while (**line && isspace(**line))
892 (*line)++;
893 if (!**line)
894 return 0;
896 /* Figure out what attribute we're reading. */
897 if (!nasm_strnicmp(*line, "align=", 6)) {
898 *attribute = ATTRIB_ALIGN;
899 attrib_name_size = 6;
900 } else if (format_mode) {
901 if (!nasm_strnicmp(*line, "start=", 6)) {
902 *attribute = ATTRIB_START;
903 attrib_name_size = 6;
904 } else if (!nasm_strnicmp(*line, "follows=", 8)) {
905 *attribute = ATTRIB_FOLLOWS;
906 *line += 8;
907 return 1;
908 } else if (!nasm_strnicmp(*line, "vstart=", 7)) {
909 *attribute = ATTRIB_VSTART;
910 attrib_name_size = 7;
911 } else if (!nasm_strnicmp(*line, "valign=", 7)) {
912 *attribute = ATTRIB_VALIGN;
913 attrib_name_size = 7;
914 } else if (!nasm_strnicmp(*line, "vfollows=", 9)) {
915 *attribute = ATTRIB_VFOLLOWS;
916 *line += 9;
917 return 1;
918 } else if (!nasm_strnicmp(*line, "nobits", 6) &&
919 (isspace((*line)[6]) || ((*line)[6] == '\0'))) {
920 *attribute = ATTRIB_NOBITS;
921 *line += 6;
922 return 1;
923 } else if (!nasm_strnicmp(*line, "progbits", 8) &&
924 (isspace((*line)[8]) || ((*line)[8] == '\0'))) {
925 *attribute = ATTRIB_PROGBITS;
926 *line += 8;
927 return 1;
928 } else
929 return 0;
930 } else
931 return 0;
933 /* Find the end of the expression. */
934 if ((*line)[attrib_name_size] != '(') {
935 /* Single term (no parenthesis). */
936 exp = *line += attrib_name_size;
937 while (**line && !isspace(**line))
938 (*line)++;
939 if (**line) {
940 **line = '\0';
941 (*line)++;
943 } else {
944 char c;
945 int pcount = 1;
947 /* Full expression (delimited by parenthesis) */
948 exp = *line += attrib_name_size + 1;
949 while (1) {
950 (*line) += strcspn(*line, "()'\"");
951 if (**line == '(') {
952 ++(*line);
953 ++pcount;
955 if (**line == ')') {
956 ++(*line);
957 --pcount;
958 if (!pcount)
959 break;
961 if ((**line == '"') || (**line == '\'')) {
962 c = **line;
963 while (**line) {
964 ++(*line);
965 if (**line == c)
966 break;
968 if (!**line) {
969 error(ERR_NONFATAL,
970 "invalid syntax in `section' directive");
971 return -1;
973 ++(*line);
975 if (!**line) {
976 error(ERR_NONFATAL, "expecting `)'");
977 return -1;
980 *(*line - 1) = '\0'; /* Terminate the expression. */
983 /* Check for no value given. */
984 if (!*exp) {
985 error(ERR_WARNING, "No value given to attribute in"
986 " `section' directive");
987 return -1;
990 /* Read and evaluate the expression. */
991 stdscan_reset();
992 stdscan_bufptr = exp;
993 tokval.t_type = TOKEN_INVALID;
994 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
995 if (e) {
996 if (!is_really_simple(e)) {
997 error(ERR_NONFATAL, "section attribute value must be"
998 " a critical expression");
999 return -1;
1001 } else {
1002 error(ERR_NONFATAL, "Invalid attribute value"
1003 " specified in `section' directive.");
1004 return -1;
1006 *value = (uint64_t)reloc_value(e);
1007 return 1;
1010 static void bin_assign_attributes(struct Section *sec, char *astring)
1012 int attribute, check;
1013 uint64_t value;
1014 char *p;
1016 while (1) { /* Get the next attribute. */
1017 check = bin_read_attribute(&astring, &attribute, &value);
1018 /* Skip bad attribute. */
1019 if (check == -1)
1020 continue;
1021 /* Unknown section attribute, so skip it and warn the user. */
1022 if (!check) {
1023 if (!*astring)
1024 break; /* End of line. */
1025 else {
1026 p = astring;
1027 while (*astring && !isspace(*astring))
1028 astring++;
1029 if (*astring) {
1030 *astring = '\0';
1031 astring++;
1033 error(ERR_WARNING, "ignoring unknown section attribute:"
1034 " \"%s\"", p);
1036 continue;
1039 switch (attribute) { /* Handle nobits attribute. */
1040 case ATTRIB_NOBITS:
1041 if ((sec->flags & TYPE_DEFINED)
1042 && (sec->flags & TYPE_PROGBITS))
1043 error(ERR_NONFATAL,
1044 "attempt to change section type"
1045 " from progbits to nobits");
1046 else
1047 sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
1048 continue;
1050 /* Handle progbits attribute. */
1051 case ATTRIB_PROGBITS:
1052 if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
1053 error(ERR_NONFATAL, "attempt to change section type"
1054 " from nobits to progbits");
1055 else
1056 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1057 continue;
1059 /* Handle align attribute. */
1060 case ATTRIB_ALIGN:
1061 if (!format_mode && (!strcmp(sec->name, ".text")))
1062 error(ERR_NONFATAL, "cannot specify an alignment"
1063 " to the .text section");
1064 else {
1065 if (!value || ((value - 1) & value))
1066 error(ERR_NONFATAL, "argument to `align' is not a"
1067 " power of two");
1068 else { /* Alignment is already satisfied if the previous
1069 * align value is greater. */
1070 if ((sec->flags & ALIGN_DEFINED)
1071 && (value < sec->align))
1072 value = sec->align;
1074 /* Don't allow a conflicting align value. */
1075 if ((sec->flags & START_DEFINED)
1076 && (sec->start & (value - 1)))
1077 error(ERR_NONFATAL,
1078 "`align' value conflicts "
1079 "with section start address");
1080 else {
1081 sec->align = value;
1082 sec->flags |= ALIGN_DEFINED;
1086 continue;
1088 /* Handle valign attribute. */
1089 case ATTRIB_VALIGN:
1090 if (!value || ((value - 1) & value))
1091 error(ERR_NONFATAL, "argument to `valign' is not a"
1092 " power of two");
1093 else { /* Alignment is already satisfied if the previous
1094 * align value is greater. */
1095 if ((sec->flags & VALIGN_DEFINED) && (value < sec->valign))
1096 value = sec->valign;
1098 /* Don't allow a conflicting valign value. */
1099 if ((sec->flags & VSTART_DEFINED)
1100 && (sec->vstart & (value - 1)))
1101 error(ERR_NONFATAL,
1102 "`valign' value conflicts "
1103 "with `vstart' address");
1104 else {
1105 sec->valign = value;
1106 sec->flags |= VALIGN_DEFINED;
1109 continue;
1111 /* Handle start attribute. */
1112 case ATTRIB_START:
1113 if (sec->flags & FOLLOWS_DEFINED)
1114 error(ERR_NONFATAL, "cannot combine `start' and `follows'"
1115 " section attributes");
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(void)
1197 static int labels_defined = 0;
1198 struct Section *sec;
1199 char *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(char *name, int pass, int *bits)
1227 char *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(char *directive, char *args, int pass)
1293 /* Handle ORG directive */
1294 if (!nasm_stricmp(directive, "org")) {
1295 struct tokenval tokval;
1296 uint64_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 char *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(char *inname, char *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, char **val)
1387 (void)type;
1388 (void)val;
1389 return 0;
1392 static void bin_init(FILE * afp, efunc errfunc, ldfunc ldef, evalfunc eval)
1394 fp = afp;
1395 error = errfunc;
1397 (void)eval; /* Don't warn that this parameter is unused. */
1398 (void)ldef; /* Placate optimizers. */
1400 maxbits = 64; /* Support 64-bit Segments */
1401 relocs = NULL;
1402 reloctail = &relocs;
1403 origin_defined = 0;
1404 no_seg_labels = NULL;
1405 nsl_tail = &no_seg_labels;
1406 format_mode = 1; /* Extended bin format
1407 * (set this to zero for old bin format). */
1409 /* Create default section (.text). */
1410 sections = last_section = nasm_malloc(sizeof(struct Section));
1411 last_section->next = NULL;
1412 last_section->name = nasm_strdup(".text");
1413 last_section->contents = saa_init(1L);
1414 last_section->follows = last_section->vfollows = 0;
1415 last_section->ifollows = NULL;
1416 last_section->length = 0;
1417 last_section->flags = TYPE_DEFINED | TYPE_PROGBITS;
1418 last_section->labels = NULL;
1419 last_section->labels_end = &(last_section->labels);
1420 last_section->start_index = seg_alloc();
1421 last_section->vstart_index = current_section = seg_alloc();
1424 struct ofmt of_bin = {
1425 "flat-form binary files (e.g. DOS .COM, .SYS)",
1426 "bin",
1427 NULL,
1428 null_debug_arr,
1429 &null_debug_form,
1430 bin_stdmac,
1431 bin_init,
1432 bin_set_info,
1433 bin_out,
1434 bin_deflabel,
1435 bin_secname,
1436 bin_segbase,
1437 bin_directive,
1438 bin_filename,
1439 bin_cleanup
1442 /* This is needed for bin_define_section_labels() */
1443 struct ofmt *bin_get_ofmt(void)
1445 return &of_bin;
1448 #endif /* #ifdef OF_BIN */