Provide 64-bit support for ORG directive
[nasm/avx512.git] / output / outbin.c
blob0dfc3d8043bf2267c29f7dbbe292c3e974c13b8d
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 (void)debuginfo; /* placate optimizers */
210 struct Section *g, **gp;
211 struct Section *gs = NULL, **gsp;
212 struct Section *s, **sp;
213 struct Section *nobits = NULL, **nt;
214 struct Section *last_progbits;
215 struct bin_label *l;
216 struct Reloc *r;
217 uint64_t pend;
218 int h;
220 #ifdef DEBUG
221 fprintf(stdout,
222 "bin_cleanup: Sections were initially referenced in this order:\n");
223 for (h = 0, s = sections; s; h++, s = s->next)
224 fprintf(stdout, "%i. %s\n", h, s->name);
225 #endif
227 /* Assembly has completed, so now we need to generate the output file.
228 * Step 1: Separate progbits and nobits sections into separate lists.
229 * Step 2: Sort the progbits sections into their output order.
230 * Step 3: Compute start addresses for all progbits sections.
231 * Step 4: Compute vstart addresses for all sections.
232 * Step 5: Apply relocations.
233 * Step 6: Write the sections' data to the output file.
234 * Step 7: Generate the map file.
235 * Step 8: Release all allocated memory.
238 /* To do: Smart section-type adaptation could leave some empty sections
239 * without a defined type (progbits/nobits). Won't fix now since this
240 * feature will be disabled. */
242 /* Step 1: Split progbits and nobits sections into separate lists. */
244 nt = &nobits;
245 /* Move nobits sections into a separate list. Also pre-process nobits
246 * sections' attributes. */
247 for (sp = &sections->next, s = sections->next; s; s = *sp) { /* Skip progbits sections. */
248 if (s->flags & TYPE_PROGBITS) {
249 sp = &s->next;
250 continue;
252 /* Do some special pre-processing on nobits sections' attributes. */
253 if (s->flags & (START_DEFINED | ALIGN_DEFINED | FOLLOWS_DEFINED)) { /* Check for a mixture of real and virtual section attributes. */
254 if (s->
255 flags & (VSTART_DEFINED | VALIGN_DEFINED |
256 VFOLLOWS_DEFINED))
257 error(ERR_FATAL,
258 "cannot mix real and virtual attributes"
259 " in nobits section (%s)", s->name);
260 /* Real and virtual attributes mean the same thing for nobits sections. */
261 if (s->flags & START_DEFINED) {
262 s->vstart = s->start;
263 s->flags |= VSTART_DEFINED;
265 if (s->flags & ALIGN_DEFINED) {
266 s->valign = s->align;
267 s->flags |= VALIGN_DEFINED;
269 if (s->flags & FOLLOWS_DEFINED) {
270 s->vfollows = s->follows;
271 s->flags |= VFOLLOWS_DEFINED;
272 s->flags &= ~FOLLOWS_DEFINED;
275 /* Every section must have a start address. */
276 if (s->flags & VSTART_DEFINED) {
277 s->start = s->vstart;
278 s->flags |= START_DEFINED;
280 /* Move the section into the nobits list. */
281 *sp = s->next;
282 s->next = NULL;
283 *nt = s;
284 nt = &s->next;
287 /* Step 2: Sort the progbits sections into their output order. */
289 /* In Step 2 we move around sections in groups. A group
290 * begins with a section (group leader) that has a user-
291 * defined start address or follows section. The remainder
292 * of the group is made up of the sections that implicitly
293 * follow the group leader (i.e., they were defined after
294 * the group leader and were not given an explicit start
295 * address or follows section by the user). */
297 /* For anyone attempting to read this code:
298 * g (group) points to a group of sections, the first one of which has
299 * a user-defined start address or follows section.
300 * gp (g previous) holds the location of the pointer to g.
301 * gs (g scan) is a temp variable that we use to scan to the end of the group.
302 * gsp (gs previous) holds the location of the pointer to gs.
303 * nt (nobits tail) points to the nobits section-list tail.
306 /* Link all 'follows' groups to their proper position. To do
307 * this we need to know three things: the start of the group
308 * to relocate (g), the section it is following (s), and the
309 * end of the group we're relocating (gs). */
310 for (gp = &sections, g = sections; g; g = gs) { /* Find the next follows group that is out of place (g). */
311 if (!(g->flags & FOLLOWS_DEFINED)) {
312 while (g->next) {
313 if ((g->next->flags & FOLLOWS_DEFINED) &&
314 strcmp(g->name, g->next->follows))
315 break;
316 g = g->next;
318 if (!g->next)
319 break;
320 gp = &g->next;
321 g = g->next;
323 /* Find the section that this group follows (s). */
324 for (sp = &sections, s = sections;
325 s && strcmp(s->name, g->follows);
326 sp = &s->next, s = s->next) ;
327 if (!s)
328 error(ERR_FATAL, "section %s follows an invalid or"
329 " unknown section (%s)", g->name, g->follows);
330 if (s->next && (s->next->flags & FOLLOWS_DEFINED) &&
331 !strcmp(s->name, s->next->follows))
332 error(ERR_FATAL, "sections %s and %s can't both follow"
333 " section %s", g->name, s->next->name, s->name);
334 /* Find the end of the current follows group (gs). */
335 for (gsp = &g->next, gs = g->next;
336 gs && (gs != s) && !(gs->flags & START_DEFINED);
337 gsp = &gs->next, gs = gs->next) {
338 if (gs->next && (gs->next->flags & FOLLOWS_DEFINED) &&
339 strcmp(gs->name, gs->next->follows)) {
340 gsp = &gs->next;
341 gs = gs->next;
342 break;
345 /* Re-link the group after its follows section. */
346 *gsp = s->next;
347 s->next = g;
348 *gp = gs;
351 /* Link all 'start' groups to their proper position. Once
352 * again we need to know g, s, and gs (see above). The main
353 * difference is we already know g since we sort by moving
354 * groups from the 'unsorted' list into a 'sorted' list (g
355 * will always be the first section in the unsorted list). */
356 for (g = sections, sections = NULL; g; g = gs) { /* Find the section that we will insert this group before (s). */
357 for (sp = &sections, s = sections; s; sp = &s->next, s = s->next)
358 if ((s->flags & START_DEFINED) && (g->start < s->start))
359 break;
360 /* Find the end of the group (gs). */
361 for (gs = g->next, gsp = &g->next;
362 gs && !(gs->flags & START_DEFINED);
363 gsp = &gs->next, gs = gs->next) ;
364 /* Re-link the group before the target section. */
365 *sp = g;
366 *gsp = s;
369 /* Step 3: Compute start addresses for all progbits sections. */
371 /* Make sure we have an origin and a start address for the first section. */
372 if (origin_defined)
373 switch (sections->flags & (START_DEFINED | ALIGN_DEFINED)) {
374 case START_DEFINED | ALIGN_DEFINED:
375 case START_DEFINED:
376 /* Make sure this section doesn't begin before the origin. */
377 if (sections->start < origin)
378 error(ERR_FATAL, "section %s begins"
379 " before program origin", sections->name);
380 break;
381 case ALIGN_DEFINED:
382 sections->start = ((origin + sections->align - 1) &
383 ~(sections->align - 1));
384 break;
385 case 0:
386 sections->start = origin;
387 } else {
388 if (!(sections->flags & START_DEFINED))
389 sections->start = 0;
390 origin = sections->start;
392 sections->flags |= START_DEFINED;
394 /* Make sure each section has an explicit start address. If it
395 * doesn't, then compute one based its alignment and the end of
396 * the previous section. */
397 for (pend = sections->start, g = s = sections; g; g = g->next) { /* Find the next section that could cause an overlap situation
398 * (has a defined start address, and is not zero length). */
399 if (g == s)
400 for (s = g->next;
401 s && ((s->length == 0) || !(s->flags & START_DEFINED));
402 s = s->next) ;
403 /* Compute the start address of this section, if necessary. */
404 if (!(g->flags & START_DEFINED)) { /* Default to an alignment of 4 if unspecified. */
405 if (!(g->flags & ALIGN_DEFINED)) {
406 g->align = 4;
407 g->flags |= ALIGN_DEFINED;
409 /* Set the section start address. */
410 g->start = (pend + g->align - 1) & ~(g->align - 1);
411 g->flags |= START_DEFINED;
413 /* Ugly special case for progbits sections' virtual attributes:
414 * If there is a defined valign, but no vstart and no vfollows, then
415 * we valign after the previous progbits section. This case doesn't
416 * really make much sense for progbits sections with a defined start
417 * address, but it is possible and we must do *something*.
418 * Not-so-ugly special case:
419 * If a progbits section has no virtual attributes, we set the
420 * vstart equal to the start address. */
421 if (!(g->flags & (VSTART_DEFINED | VFOLLOWS_DEFINED))) {
422 if (g->flags & VALIGN_DEFINED)
423 g->vstart = (pend + g->valign - 1) & ~(g->valign - 1);
424 else
425 g->vstart = g->start;
426 g->flags |= VSTART_DEFINED;
428 /* Ignore zero-length sections. */
429 if (g->start < pend)
430 continue;
431 /* Compute the span of this section. */
432 pend = g->start + g->length;
433 /* Check for section overlap. */
434 if (s) {
435 if (g->start > s->start)
436 error(ERR_FATAL, "sections %s ~ %s and %s overlap!",
437 gs->name, g->name, s->name);
438 if (pend > s->start)
439 error(ERR_FATAL, "sections %s and %s overlap!",
440 g->name, s->name);
442 /* Remember this section as the latest >0 length section. */
443 gs = g;
446 /* Step 4: Compute vstart addresses for all sections. */
448 /* Attach the nobits sections to the end of the progbits sections. */
449 for (s = sections; s->next; s = s->next) ;
450 s->next = nobits;
451 last_progbits = s;
452 /* Scan for sections that don't have a vstart address. If we find one we'll
453 * attempt to compute its vstart. If we can't compute the vstart, we leave
454 * it alone and come back to it in a subsequent scan. We continue scanning
455 * and re-scanning until we've gone one full cycle without computing any
456 * vstarts. */
457 do { /* Do one full scan of the sections list. */
458 for (h = 0, g = sections; g; g = g->next) {
459 if (g->flags & VSTART_DEFINED)
460 continue;
461 /* Find the section that this one virtually follows. */
462 if (g->flags & VFOLLOWS_DEFINED) {
463 for (s = sections; s && strcmp(g->vfollows, s->name);
464 s = s->next) ;
465 if (!s)
466 error(ERR_FATAL,
467 "section %s vfollows unknown section (%s)",
468 g->name, g->vfollows);
469 } else if (g->ifollows != NULL)
470 for (s = sections; s && (s != g->ifollows); s = s->next) ;
471 /* The .bss section is the only one with ifollows = NULL. In this case we
472 * implicitly follow the last progbits section. */
473 else
474 s = last_progbits;
476 /* If the section we're following has a vstart, we can proceed. */
477 if (s->flags & VSTART_DEFINED) { /* Default to virtual alignment of four. */
478 if (!(g->flags & VALIGN_DEFINED)) {
479 g->valign = 4;
480 g->flags |= VALIGN_DEFINED;
482 /* Compute the vstart address. */
483 g->vstart =
484 (s->vstart + s->length + g->valign - 1) & ~(g->valign -
486 g->flags |= VSTART_DEFINED;
487 h++;
488 /* Start and vstart mean the same thing for nobits sections. */
489 if (g->flags & TYPE_NOBITS)
490 g->start = g->vstart;
493 } while (h);
495 /* Now check for any circular vfollows references, which will manifest
496 * themselves as sections without a defined vstart. */
497 for (h = 0, s = sections; s; s = s->next) {
498 if (!(s->flags & VSTART_DEFINED)) { /* Non-fatal errors after assembly has completed are generally a
499 * no-no, but we'll throw a fatal one eventually so it's ok. */
500 error(ERR_NONFATAL, "cannot compute vstart for section %s",
501 s->name);
502 h++;
505 if (h)
506 error(ERR_FATAL, "circular vfollows path detected");
508 #ifdef DEBUG
509 fprintf(stdout,
510 "bin_cleanup: Confirm final section order for output file:\n");
511 for (h = 0, s = sections; s && (s->flags & TYPE_PROGBITS);
512 h++, s = s->next)
513 fprintf(stdout, "%i. %s\n", h, s->name);
514 #endif
516 /* Step 5: Apply relocations. */
518 /* Prepare the sections for relocating. */
519 for (s = sections; s; s = s->next)
520 saa_rewind(s->contents);
521 /* Apply relocations. */
522 for (r = relocs; r; r = r->next) {
523 uint8_t *p, *q, mydata[8];
524 int64_t l;
526 saa_fread(r->target->contents, r->posn, mydata, r->bytes);
527 p = q = mydata;
528 l = *p++;
530 if (r->bytes > 1) {
531 l += ((int64_t)*p++) << 8;
532 if (r->bytes >= 4) {
533 l += ((int64_t)*p++) << 16;
534 l += ((int64_t)*p++) << 24;
536 if (r->bytes == 8) {
537 l += ((int64_t)*p++) << 32;
538 l += ((int64_t)*p++) << 40;
539 l += ((int64_t)*p++) << 48;
540 l += ((int64_t)*p++) << 56;
544 s = find_section_by_index(r->secref);
545 if (s) {
546 if (r->secref == s->start_index)
547 l += s->start;
548 else
549 l += s->vstart;
551 s = find_section_by_index(r->secrel);
552 if (s) {
553 if (r->secrel == s->start_index)
554 l -= s->start;
555 else
556 l -= s->vstart;
559 if (r->bytes >= 4)
560 WRITEDLONG(q, l);
561 else if (r->bytes == 2)
562 WRITESHORT(q, l);
563 else
564 *q++ = (uint8_t)(l & 0xFF);
565 saa_fwrite(r->target->contents, r->posn, mydata, r->bytes);
568 /* Step 6: Write the section data to the output file. */
570 /* Write the progbits sections to the output file. */
571 for (pend = origin, s = sections; s && (s->flags & TYPE_PROGBITS); s = s->next) { /* Skip zero-length sections. */
572 if (s->length == 0)
573 continue;
574 /* Pad the space between sections. */
575 for (h = s->start - pend; h; h--)
576 fputc('\0', fp);
577 /* Write the section to the output file. */
578 if (s->length > 0)
579 saa_fpwrite(s->contents, fp);
580 pend = s->start + s->length;
582 /* Done writing the file, so close it. */
583 fclose(fp);
585 /* Step 7: Generate the map file. */
587 if (map_control) {
588 const char *not_defined = { "not defined" };
590 /* Display input and output file names. */
591 fprintf(rf, "\n- NASM Map file ");
592 for (h = 63; h; h--)
593 fputc('-', rf);
594 fprintf(rf, "\n\nSource file: %s\nOutput file: %s\n\n",
595 infile, outfile);
597 if (map_control & MAP_ORIGIN) { /* Display program origin. */
598 fprintf(rf, "-- Program origin ");
599 for (h = 61; h; h--)
600 fputc('-', rf);
601 fprintf(rf, "\n\n%08"PRIX64"\n\n", origin);
603 /* Display sections summary. */
604 if (map_control & MAP_SUMMARY) {
605 fprintf(rf, "-- Sections (summary) ");
606 for (h = 57; h; h--)
607 fputc('-', rf);
608 fprintf(rf, "\n\nVstart Start Stop "
609 "Length Class Name\n");
610 for (s = sections; s; s = s->next) {
611 fprintf(rf, "%16"PRIX64" %16"PRIX64" %16"PRIX64" %08"PRIX64" ",
612 s->vstart, s->start, s->start + s->length,
613 s->length);
614 if (s->flags & TYPE_PROGBITS)
615 fprintf(rf, "progbits ");
616 else
617 fprintf(rf, "nobits ");
618 fprintf(rf, "%s\n", s->name);
620 fprintf(rf, "\n");
622 /* Display detailed section information. */
623 if (map_control & MAP_SECTIONS) {
624 fprintf(rf, "-- Sections (detailed) ");
625 for (h = 56; h; h--)
626 fputc('-', rf);
627 fprintf(rf, "\n\n");
628 for (s = sections; s; s = s->next) {
629 fprintf(rf, "---- Section %s ", s->name);
630 for (h = 65 - strlen(s->name); h; h--)
631 fputc('-', rf);
632 fprintf(rf, "\n\nclass: ");
633 if (s->flags & TYPE_PROGBITS)
634 fprintf(rf, "progbits");
635 else
636 fprintf(rf, "nobits");
637 fprintf(rf, "\nlength: %16"PRIX64"\nstart: %16"PRIX64""
638 "\nalign: ", s->length, s->start);
639 if (s->flags & ALIGN_DEFINED)
640 fprintf(rf, "%16"PRIX64"", s->align);
641 else
642 fprintf(rf, not_defined);
643 fprintf(rf, "\nfollows: ");
644 if (s->flags & FOLLOWS_DEFINED)
645 fprintf(rf, "%s", s->follows);
646 else
647 fprintf(rf, not_defined);
648 fprintf(rf, "\nvstart: %16"PRIX64"\nvalign: ", s->vstart);
649 if (s->flags & VALIGN_DEFINED)
650 fprintf(rf, "%16"PRIX64"", s->valign);
651 else
652 fprintf(rf, not_defined);
653 fprintf(rf, "\nvfollows: ");
654 if (s->flags & VFOLLOWS_DEFINED)
655 fprintf(rf, "%s", s->vfollows);
656 else
657 fprintf(rf, not_defined);
658 fprintf(rf, "\n\n");
661 /* Display symbols information. */
662 if (map_control & MAP_SYMBOLS) {
663 int32_t segment, offset;
665 fprintf(rf, "-- Symbols ");
666 for (h = 68; h; h--)
667 fputc('-', rf);
668 fprintf(rf, "\n\n");
669 if (no_seg_labels) {
670 fprintf(rf, "---- No Section ");
671 for (h = 63; h; h--)
672 fputc('-', rf);
673 fprintf(rf, "\n\nValue Name\n");
674 for (l = no_seg_labels; l; l = l->next) {
675 lookup_label(l->name, &segment, &offset);
676 fprintf(rf, "%08"PRIX32" %s\n", offset, l->name);
678 fprintf(rf, "\n\n");
680 for (s = sections; s; s = s->next) {
681 if (s->labels) {
682 fprintf(rf, "---- Section %s ", s->name);
683 for (h = 65 - strlen(s->name); h; h--)
684 fputc('-', rf);
685 fprintf(rf, "\n\nReal Virtual Name\n");
686 for (l = s->labels; l; l = l->next) {
687 lookup_label(l->name, &segment, &offset);
688 fprintf(rf, "%16"PRIX64" %16"PRIX64" %s\n",
689 s->start + offset, s->vstart + offset,
690 l->name);
692 fprintf(rf, "\n");
698 /* Close the report file. */
699 if (map_control && (rf != stdout) && (rf != stderr))
700 fclose(rf);
702 /* Step 8: Release all allocated memory. */
704 /* Free sections, label pointer structs, etc.. */
705 while (sections) {
706 s = sections;
707 sections = s->next;
708 saa_free(s->contents);
709 nasm_free(s->name);
710 if (s->flags & FOLLOWS_DEFINED)
711 nasm_free(s->follows);
712 if (s->flags & VFOLLOWS_DEFINED)
713 nasm_free(s->vfollows);
714 while (s->labels) {
715 l = s->labels;
716 s->labels = l->next;
717 nasm_free(l);
719 nasm_free(s);
722 /* Free no-section labels. */
723 while (no_seg_labels) {
724 l = no_seg_labels;
725 no_seg_labels = l->next;
726 nasm_free(l);
729 /* Free relocation structures. */
730 while (relocs) {
731 r = relocs->next;
732 nasm_free(relocs);
733 relocs = r;
737 static void bin_out(int32_t segto, const void *data, uint32_t type,
738 int32_t segment, int32_t wrt)
740 uint8_t *p, mydata[8];
741 struct Section *s;
742 int32_t realbytes;
745 if (wrt != NO_SEG) {
746 wrt = NO_SEG; /* continue to do _something_ */
747 error(ERR_NONFATAL, "WRT not supported by binary output format");
750 /* Handle absolute-assembly (structure definitions). */
751 if (segto == NO_SEG) {
752 if ((type & OUT_TYPMASK) != OUT_RESERVE)
753 error(ERR_NONFATAL, "attempt to assemble code in"
754 " [ABSOLUTE] space");
755 return;
758 /* Find the segment we are targeting. */
759 s = find_section_by_index(segto);
760 if (!s)
761 error(ERR_PANIC, "code directed to nonexistent segment?");
763 /* "Smart" section-type adaptation code. */
764 if (!(s->flags & TYPE_DEFINED)) {
765 if ((type & OUT_TYPMASK) == OUT_RESERVE)
766 s->flags |= TYPE_DEFINED | TYPE_NOBITS;
767 else
768 s->flags |= TYPE_DEFINED | TYPE_PROGBITS;
771 if ((s->flags & TYPE_NOBITS) && ((type & OUT_TYPMASK) != OUT_RESERVE))
772 error(ERR_WARNING, "attempt to initialize memory in a"
773 " nobits section: ignored");
775 if ((type & OUT_TYPMASK) == OUT_ADDRESS) {
776 if (segment != NO_SEG && !find_section_by_index(segment)) {
777 if (segment % 2)
778 error(ERR_NONFATAL, "binary output format does not support"
779 " segment base references");
780 else
781 error(ERR_NONFATAL, "binary output format does not support"
782 " external references");
783 segment = NO_SEG;
785 if (s->flags & TYPE_PROGBITS) {
786 if (segment != NO_SEG)
787 add_reloc(s, type & OUT_SIZMASK, segment, -1L);
788 p = mydata;
789 if ((type & OUT_SIZMASK) == 4)
790 WRITELONG(p, *(int32_t *)data);
791 else if ((type & OUT_SIZMASK) == 8)
792 WRITEDLONG(p, *(int64_t *)data);
793 else
794 WRITESHORT(p, *(int32_t *)data);
795 saa_wbytes(s->contents, mydata, type & OUT_SIZMASK);
797 s->length += type & OUT_SIZMASK;
798 } else if ((type & OUT_TYPMASK) == OUT_RAWDATA) {
799 type &= OUT_SIZMASK;
800 if (s->flags & TYPE_PROGBITS)
801 saa_wbytes(s->contents, data, type);
802 s->length += type;
803 } else if ((type & OUT_TYPMASK) == OUT_RESERVE) {
804 type &= OUT_SIZMASK;
805 if (s->flags & TYPE_PROGBITS) {
806 error(ERR_WARNING, "uninitialized space declared in"
807 " %s section: zeroing", s->name);
808 saa_wbytes(s->contents, NULL, type);
810 s->length += type;
811 } else if ((type & OUT_TYPMASK) == OUT_REL2ADR ||
812 (type & OUT_TYPMASK) == OUT_REL4ADR) {
813 realbytes = (type & OUT_TYPMASK);
814 if (realbytes == OUT_REL2ADR)
815 realbytes = 2;
816 else
817 realbytes = 4;
818 if (segment != NO_SEG && !find_section_by_index(segment)) {
819 if (segment % 2)
820 error(ERR_NONFATAL, "binary output format does not support"
821 " segment base references");
822 else
823 error(ERR_NONFATAL, "binary output format does not support"
824 " external references");
825 segment = NO_SEG;
827 if (s->flags & TYPE_PROGBITS) {
828 add_reloc(s, realbytes, segment, segto);
829 p = mydata;
830 if (realbytes == 4)
831 WRITELONG(p, *(int32_t *)data - realbytes - s->length);
832 else
833 WRITESHORT(p, *(int32_t *)data - realbytes - s->length);
834 saa_wbytes(s->contents, mydata, realbytes);
836 s->length += realbytes;
840 static void bin_deflabel(char *name, int32_t segment, int32_t offset,
841 int is_global, char *special)
843 (void)segment; /* Don't warn that this parameter is unused */
844 (void)offset; /* Don't warn that this parameter is unused */
846 if (special)
847 error(ERR_NONFATAL, "binary format does not support any"
848 " special symbol types");
849 else if (name[0] == '.' && name[1] == '.' && name[2] != '@')
850 error(ERR_NONFATAL, "unrecognised special symbol `%s'", name);
851 else if (is_global == 2)
852 error(ERR_NONFATAL, "binary output format does not support common"
853 " variables");
854 else {
855 struct Section *s;
856 struct bin_label ***ltp;
858 /* Remember label definition so we can look it up later when
859 * creating the map file. */
860 s = find_section_by_index(segment);
861 if (s)
862 ltp = &(s->labels_end);
863 else
864 ltp = &nsl_tail;
865 (**ltp) = nasm_malloc(sizeof(struct bin_label));
866 (**ltp)->name = name;
867 (**ltp)->next = NULL;
868 *ltp = &((**ltp)->next);
873 /* These constants and the following function are used
874 * by bin_secname() to parse attribute assignments. */
876 enum { ATTRIB_START, ATTRIB_ALIGN, ATTRIB_FOLLOWS,
877 ATTRIB_VSTART, ATTRIB_VALIGN, ATTRIB_VFOLLOWS,
878 ATTRIB_NOBITS, ATTRIB_PROGBITS
881 static int bin_read_attribute(char **line, int *attribute,
882 uint64_t *value)
884 expr *e;
885 int attrib_name_size;
886 struct tokenval tokval;
887 char *exp;
889 /* Skip whitespace. */
890 while (**line && isspace(**line))
891 (*line)++;
892 if (!**line)
893 return 0;
895 /* Figure out what attribute we're reading. */
896 if (!nasm_strnicmp(*line, "align=", 6)) {
897 *attribute = ATTRIB_ALIGN;
898 attrib_name_size = 6;
899 } else if (format_mode) {
900 if (!nasm_strnicmp(*line, "start=", 6)) {
901 *attribute = ATTRIB_START;
902 attrib_name_size = 6;
903 } else if (!nasm_strnicmp(*line, "follows=", 8)) {
904 *attribute = ATTRIB_FOLLOWS;
905 *line += 8;
906 return 1;
907 } else if (!nasm_strnicmp(*line, "vstart=", 7)) {
908 *attribute = ATTRIB_VSTART;
909 attrib_name_size = 7;
910 } else if (!nasm_strnicmp(*line, "valign=", 7)) {
911 *attribute = ATTRIB_VALIGN;
912 attrib_name_size = 7;
913 } else if (!nasm_strnicmp(*line, "vfollows=", 9)) {
914 *attribute = ATTRIB_VFOLLOWS;
915 *line += 9;
916 return 1;
917 } else if (!nasm_strnicmp(*line, "nobits", 6) &&
918 (isspace((*line)[6]) || ((*line)[6] == '\0'))) {
919 *attribute = ATTRIB_NOBITS;
920 *line += 6;
921 return 1;
922 } else if (!nasm_strnicmp(*line, "progbits", 8) &&
923 (isspace((*line)[8]) || ((*line)[8] == '\0'))) {
924 *attribute = ATTRIB_PROGBITS;
925 *line += 8;
926 return 1;
927 } else
928 return 0;
929 } else
930 return 0;
932 /* Find the end of the expression. */
933 if ((*line)[attrib_name_size] != '(') {
934 /* Single term (no parenthesis). */
935 exp = *line += attrib_name_size;
936 while (**line && !isspace(**line))
937 (*line)++;
938 if (**line) {
939 **line = '\0';
940 (*line)++;
942 } else {
943 char c;
944 int pcount = 1;
946 /* Full expression (delimited by parenthesis) */
947 exp = *line += attrib_name_size + 1;
948 while (1) {
949 (*line) += strcspn(*line, "()'\"");
950 if (**line == '(') {
951 ++(*line);
952 ++pcount;
954 if (**line == ')') {
955 ++(*line);
956 --pcount;
957 if (!pcount)
958 break;
960 if ((**line == '"') || (**line == '\'')) {
961 c = **line;
962 while (**line) {
963 ++(*line);
964 if (**line == c)
965 break;
967 if (!**line) {
968 error(ERR_NONFATAL,
969 "invalid syntax in `section' directive");
970 return -1;
972 ++(*line);
974 if (!**line) {
975 error(ERR_NONFATAL, "expecting `)'");
976 return -1;
979 *(*line - 1) = '\0'; /* Terminate the expression. */
982 /* Check for no value given. */
983 if (!*exp) {
984 error(ERR_WARNING, "No value given to attribute in"
985 " `section' directive");
986 return -1;
989 /* Read and evaluate the expression. */
990 stdscan_reset();
991 stdscan_bufptr = exp;
992 tokval.t_type = TOKEN_INVALID;
993 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
994 if (e) {
995 if (!is_really_simple(e)) {
996 error(ERR_NONFATAL, "section attribute value must be"
997 " a critical expression");
998 return -1;
1000 } else {
1001 error(ERR_NONFATAL, "Invalid attribute value"
1002 " specified in `section' directive.");
1003 return -1;
1005 *value = (uint64_t)reloc_value(e);
1006 return 1;
1009 static void bin_assign_attributes(struct Section *sec, char *astring)
1011 int attribute, check;
1012 uint64_t value;
1013 char *p;
1015 while (1) { /* Get the next attribute. */
1016 check = bin_read_attribute(&astring, &attribute, &value);
1017 /* Skip bad attribute. */
1018 if (check == -1)
1019 continue;
1020 /* Unknown section attribute, so skip it and warn the user. */
1021 if (!check) {
1022 if (!*astring)
1023 break; /* End of line. */
1024 else {
1025 p = astring;
1026 while (*astring && !isspace(*astring))
1027 astring++;
1028 if (*astring) {
1029 *astring = '\0';
1030 astring++;
1032 error(ERR_WARNING, "ignoring unknown section attribute:"
1033 " \"%s\"", p);
1035 continue;
1038 switch (attribute) { /* Handle nobits attribute. */
1039 case ATTRIB_NOBITS:
1040 if ((sec->flags & TYPE_DEFINED)
1041 && (sec->flags & TYPE_PROGBITS))
1042 error(ERR_NONFATAL,
1043 "attempt to change section type"
1044 " from progbits to nobits");
1045 else
1046 sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
1047 continue;
1049 /* Handle progbits attribute. */
1050 case ATTRIB_PROGBITS:
1051 if ((sec->flags & TYPE_DEFINED) && (sec->flags & TYPE_NOBITS))
1052 error(ERR_NONFATAL, "attempt to change section type"
1053 " from nobits to progbits");
1054 else
1055 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1056 continue;
1058 /* Handle align attribute. */
1059 case ATTRIB_ALIGN:
1060 if (!format_mode && (!strcmp(sec->name, ".text")))
1061 error(ERR_NONFATAL, "cannot specify an alignment"
1062 " to the .text section");
1063 else {
1064 if (!value || ((value - 1) & value))
1065 error(ERR_NONFATAL, "argument to `align' is not a"
1066 " power of two");
1067 else { /* Alignment is already satisfied if the previous
1068 * align value is greater. */
1069 if ((sec->flags & ALIGN_DEFINED)
1070 && (value < sec->align))
1071 value = sec->align;
1073 /* Don't allow a conflicting align value. */
1074 if ((sec->flags & START_DEFINED)
1075 && (sec->start & (value - 1)))
1076 error(ERR_NONFATAL,
1077 "`align' value conflicts "
1078 "with section start address");
1079 else {
1080 sec->align = value;
1081 sec->flags |= ALIGN_DEFINED;
1085 continue;
1087 /* Handle valign attribute. */
1088 case ATTRIB_VALIGN:
1089 if (!value || ((value - 1) & value))
1090 error(ERR_NONFATAL, "argument to `valign' is not a"
1091 " power of two");
1092 else { /* Alignment is already satisfied if the previous
1093 * align value is greater. */
1094 if ((sec->flags & VALIGN_DEFINED) && (value < sec->valign))
1095 value = sec->valign;
1097 /* Don't allow a conflicting valign value. */
1098 if ((sec->flags & VSTART_DEFINED)
1099 && (sec->vstart & (value - 1)))
1100 error(ERR_NONFATAL,
1101 "`valign' value conflicts "
1102 "with `vstart' address");
1103 else {
1104 sec->valign = value;
1105 sec->flags |= VALIGN_DEFINED;
1108 continue;
1110 /* Handle start attribute. */
1111 case ATTRIB_START:
1112 if (sec->flags & FOLLOWS_DEFINED)
1113 error(ERR_NONFATAL, "cannot combine `start' and `follows'"
1114 " section attributes");
1115 else if ((sec->flags & START_DEFINED) && (value != sec->start))
1116 error(ERR_NONFATAL, "section start address redefined");
1117 else {
1118 sec->start = value;
1119 sec->flags |= START_DEFINED;
1120 if (sec->flags & ALIGN_DEFINED) {
1121 if (sec->start & (sec->align - 1))
1122 error(ERR_NONFATAL, "`start' address conflicts"
1123 " with section alignment");
1124 sec->flags ^= ALIGN_DEFINED;
1127 continue;
1129 /* Handle vstart attribute. */
1130 case ATTRIB_VSTART:
1131 if (sec->flags & VFOLLOWS_DEFINED)
1132 error(ERR_NONFATAL,
1133 "cannot combine `vstart' and `vfollows'"
1134 " section attributes");
1135 else if ((sec->flags & VSTART_DEFINED)
1136 && (value != sec->vstart))
1137 error(ERR_NONFATAL,
1138 "section virtual start address"
1139 " (vstart) redefined");
1140 else {
1141 sec->vstart = value;
1142 sec->flags |= VSTART_DEFINED;
1143 if (sec->flags & VALIGN_DEFINED) {
1144 if (sec->vstart & (sec->valign - 1))
1145 error(ERR_NONFATAL, "`vstart' address conflicts"
1146 " with `valign' value");
1147 sec->flags ^= VALIGN_DEFINED;
1150 continue;
1152 /* Handle follows attribute. */
1153 case ATTRIB_FOLLOWS:
1154 p = astring;
1155 astring += strcspn(astring, " \t");
1156 if (astring == p)
1157 error(ERR_NONFATAL, "expecting section name for `follows'"
1158 " attribute");
1159 else {
1160 *(astring++) = '\0';
1161 if (sec->flags & START_DEFINED)
1162 error(ERR_NONFATAL,
1163 "cannot combine `start' and `follows'"
1164 " section attributes");
1165 sec->follows = nasm_strdup(p);
1166 sec->flags |= FOLLOWS_DEFINED;
1168 continue;
1170 /* Handle vfollows attribute. */
1171 case ATTRIB_VFOLLOWS:
1172 if (sec->flags & VSTART_DEFINED)
1173 error(ERR_NONFATAL,
1174 "cannot combine `vstart' and `vfollows'"
1175 " section attributes");
1176 else {
1177 p = astring;
1178 astring += strcspn(astring, " \t");
1179 if (astring == p)
1180 error(ERR_NONFATAL,
1181 "expecting section name for `vfollows'"
1182 " attribute");
1183 else {
1184 *(astring++) = '\0';
1185 sec->vfollows = nasm_strdup(p);
1186 sec->flags |= VFOLLOWS_DEFINED;
1189 continue;
1194 static void bin_define_section_labels(void)
1196 static int labels_defined = 0;
1197 struct Section *sec;
1198 char *label_name;
1199 size_t base_len;
1201 if (labels_defined)
1202 return;
1203 for (sec = sections; sec; sec = sec->next) {
1204 base_len = strlen(sec->name) + 8;
1205 label_name = nasm_malloc(base_len + 8);
1206 strcpy(label_name, "section.");
1207 strcpy(label_name + 8, sec->name);
1209 /* section.<name>.start */
1210 strcpy(label_name + base_len, ".start");
1211 define_label(label_name, sec->start_index, 0L,
1212 NULL, 0, 0, bin_get_ofmt(), error);
1214 /* section.<name>.vstart */
1215 strcpy(label_name + base_len, ".vstart");
1216 define_label(label_name, sec->vstart_index, 0L,
1217 NULL, 0, 0, bin_get_ofmt(), error);
1219 nasm_free(label_name);
1221 labels_defined = 1;
1224 static int32_t bin_secname(char *name, int pass, int *bits)
1226 char *p;
1227 struct Section *sec;
1229 /* bin_secname is called with *name = NULL at the start of each
1230 * pass. Use this opportunity to establish the default section
1231 * (default is BITS-16 ".text" segment).
1233 if (!name) { /* Reset ORG and section attributes at the start of each pass. */
1234 origin_defined = 0;
1235 for (sec = sections; sec; sec = sec->next)
1236 sec->flags &= ~(START_DEFINED | VSTART_DEFINED |
1237 ALIGN_DEFINED | VALIGN_DEFINED);
1239 /* Define section start and vstart labels. */
1240 if (format_mode && (pass != 1))
1241 bin_define_section_labels();
1243 /* Establish the default (.text) section. */
1244 *bits = 16;
1245 sec = find_section_by_name(".text");
1246 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1247 current_section = sec->vstart_index;
1248 return current_section;
1251 /* Attempt to find the requested section. If it does not
1252 * exist, create it. */
1253 p = name;
1254 while (*p && !isspace(*p))
1255 p++;
1256 if (*p)
1257 *p++ = '\0';
1258 sec = find_section_by_name(name);
1259 if (!sec) {
1260 sec = create_section(name);
1261 if (!strcmp(name, ".data"))
1262 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1263 else if (!strcmp(name, ".bss")) {
1264 sec->flags |= TYPE_DEFINED | TYPE_NOBITS;
1265 sec->ifollows = NULL;
1266 } else if (!format_mode) {
1267 error(ERR_NONFATAL, "section name must be "
1268 ".text, .data, or .bss");
1269 return current_section;
1273 /* Handle attribute assignments. */
1274 if (pass != 1)
1275 bin_assign_attributes(sec, p);
1277 #ifndef ABIN_SMART_ADAPT
1278 /* The following line disables smart adaptation of
1279 * PROGBITS/NOBITS section types (it forces sections to
1280 * default to PROGBITS). */
1281 if ((pass != 1) && !(sec->flags & TYPE_DEFINED))
1282 sec->flags |= TYPE_DEFINED | TYPE_PROGBITS;
1283 #endif
1285 /* Set the current section and return. */
1286 current_section = sec->vstart_index;
1287 return current_section;
1290 static int bin_directive(char *directive, char *args, int pass)
1292 /* Handle ORG directive */
1293 if (!nasm_stricmp(directive, "org")) {
1294 struct tokenval tokval;
1295 uint64_t value;
1296 expr *e;
1298 stdscan_reset();
1299 stdscan_bufptr = args;
1300 tokval.t_type = TOKEN_INVALID;
1301 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
1302 if (e) {
1303 if (!is_really_simple(e))
1304 error(ERR_NONFATAL, "org value must be a critical"
1305 " expression");
1306 else {
1307 value = reloc_value(e);
1308 /* Check for ORG redefinition. */
1309 if (origin_defined && (value != origin))
1310 error(ERR_NONFATAL, "program origin redefined");
1311 else {
1312 origin = value;
1313 origin_defined = 1;
1316 } else
1317 error(ERR_NONFATAL, "No or invalid offset specified"
1318 " in ORG directive.");
1319 return 1;
1322 /* The 'map' directive allows the user to generate section
1323 * and symbol information to stdout, stderr, or to a file. */
1324 else if (format_mode && !nasm_stricmp(directive, "map")) {
1325 char *p;
1327 if (pass != 1)
1328 return 1;
1329 args += strspn(args, " \t");
1330 while (*args) {
1331 p = args;
1332 args += strcspn(args, " \t");
1333 if (*args != '\0')
1334 *(args++) = '\0';
1335 if (!nasm_stricmp(p, "all"))
1336 map_control |=
1337 MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS | MAP_SYMBOLS;
1338 else if (!nasm_stricmp(p, "brief"))
1339 map_control |= MAP_ORIGIN | MAP_SUMMARY;
1340 else if (!nasm_stricmp(p, "sections"))
1341 map_control |= MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS;
1342 else if (!nasm_stricmp(p, "segments"))
1343 map_control |= MAP_ORIGIN | MAP_SUMMARY | MAP_SECTIONS;
1344 else if (!nasm_stricmp(p, "symbols"))
1345 map_control |= MAP_SYMBOLS;
1346 else if (!rf) {
1347 if (!nasm_stricmp(p, "stdout"))
1348 rf = stdout;
1349 else if (!nasm_stricmp(p, "stderr"))
1350 rf = stderr;
1351 else { /* Must be a filename. */
1352 rf = fopen(p, "wt");
1353 if (!rf) {
1354 error(ERR_WARNING, "unable to open map file `%s'",
1356 map_control = 0;
1357 return 1;
1360 } else
1361 error(ERR_WARNING, "map file already specified");
1363 if (map_control == 0)
1364 map_control |= MAP_ORIGIN | MAP_SUMMARY;
1365 if (!rf)
1366 rf = stdout;
1367 return 1;
1369 return 0;
1372 static void bin_filename(char *inname, char *outname, efunc error)
1374 standard_extension(inname, outname, "", error);
1375 infile = inname;
1376 outfile = outname;
1379 static int32_t bin_segbase(int32_t segment)
1381 return segment;
1384 static int bin_set_info(enum geninfo type, char **val)
1386 (void)type;
1387 (void)val;
1388 return 0;
1391 static void bin_init(FILE * afp, efunc errfunc, ldfunc ldef, evalfunc eval)
1393 fp = afp;
1394 error = errfunc;
1396 (void)eval; /* Don't warn that this parameter is unused. */
1397 (void)ldef; /* Placate optimizers. */
1399 maxbits = 64; /* Support 64-bit Segments */
1400 relocs = NULL;
1401 reloctail = &relocs;
1402 origin_defined = 0;
1403 no_seg_labels = NULL;
1404 nsl_tail = &no_seg_labels;
1405 format_mode = 1; /* Extended bin format
1406 * (set this to zero for old bin format). */
1408 /* Create default section (.text). */
1409 sections = last_section = nasm_malloc(sizeof(struct Section));
1410 last_section->next = NULL;
1411 last_section->name = nasm_strdup(".text");
1412 last_section->contents = saa_init(1L);
1413 last_section->follows = last_section->vfollows = 0;
1414 last_section->ifollows = NULL;
1415 last_section->length = 0;
1416 last_section->flags = TYPE_DEFINED | TYPE_PROGBITS;
1417 last_section->labels = NULL;
1418 last_section->labels_end = &(last_section->labels);
1419 last_section->start_index = seg_alloc();
1420 last_section->vstart_index = current_section = seg_alloc();
1423 struct ofmt of_bin = {
1424 "flat-form binary files (e.g. DOS .COM, .SYS)",
1425 "bin",
1426 NULL,
1427 null_debug_arr,
1428 &null_debug_form,
1429 bin_stdmac,
1430 bin_init,
1431 bin_set_info,
1432 bin_out,
1433 bin_deflabel,
1434 bin_secname,
1435 bin_segbase,
1436 bin_directive,
1437 bin_filename,
1438 bin_cleanup
1441 /* This is needed for bin_define_section_labels() */
1442 struct ofmt *bin_get_ofmt(void)
1444 return &of_bin;
1447 #endif /* #ifdef OF_BIN */