1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2009 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * outaout.c output routines for the Netwide Assembler to produce
36 * Linux a.out object files
53 #include "output/outform.h"
54 #include "output/outlib.h"
56 #if defined OF_AOUT || defined OF_AOUTB
58 #define RELTYPE_ABSOLUTE 0x00
59 #define RELTYPE_RELATIVE 0x01
60 #define RELTYPE_GOTPC 0x01 /* no explicit GOTPC in a.out */
61 #define RELTYPE_GOTOFF 0x10
62 #define RELTYPE_GOT 0x10 /* distinct from GOTOFF bcos sym not sect */
63 #define RELTYPE_PLT 0x21
64 #define RELTYPE_SYMFLAG 0x08
68 int32_t address
; /* relative to _start_ of section */
69 int32_t symbol
; /* symbol number or -ve section id */
70 int bytes
; /* 2 or 4 */
71 int reltype
; /* see above */
75 int32_t strpos
; /* string table position of name */
76 int type
; /* symbol type - see flags below */
77 int32_t value
; /* address, or COMMON variable size */
78 int32_t size
; /* size for data or function exports */
79 int32_t segment
; /* back-reference used by gsym_reloc */
80 struct Symbol
*next
; /* list of globals in each section */
81 struct Symbol
*nextfwd
; /* list of unresolved-size symbols */
82 char *name
; /* for unresolved-size symbols */
83 int32_t symnum
; /* index into symbol table */
87 * Section IDs - used in Reloc.symbol when negative, and in
88 * Symbol.type when positive.
90 #define SECT_ABS 2 /* absolute value */
91 #define SECT_TEXT 4 /* text section */
92 #define SECT_DATA 6 /* data section */
93 #define SECT_BSS 8 /* bss section */
94 #define SECT_MASK 0xE /* mask out any of the above */
97 * More flags used in Symbol.type.
99 #define SYM_GLOBAL 1 /* it's a global symbol */
100 #define SYM_DATA 0x100 /* used for shared libs */
101 #define SYM_FUNCTION 0x200 /* used for shared libs */
102 #define SYM_WITH_SIZE 0x4000 /* not output; internal only */
105 * Bit more explanation of symbol types: SECT_xxx denotes a local
106 * symbol. SECT_xxx|SYM_GLOBAL denotes a global symbol, defined in
107 * this module. Just SYM_GLOBAL, with zero value, denotes an
108 * external symbol referenced in this module. And just SYM_GLOBAL,
109 * but with a non-zero value, declares a C `common' variable, of
115 uint32_t len
, size
, nrelocs
;
117 struct Reloc
*head
, **tail
;
118 struct Symbol
*gsyms
, *asym
;
121 static struct Section stext
, sdata
, sbss
;
123 static struct SAA
*syms
;
124 static uint32_t nsyms
;
126 static struct RAA
*bsym
;
128 static struct SAA
*strs
;
129 static uint32_t strslen
;
131 static struct Symbol
*fwds
;
136 static void aout_write(void);
137 static void aout_write_relocs(struct Reloc
*);
138 static void aout_write_syms(void);
139 static void aout_sect_write(struct Section
*, const uint8_t *,
141 static void aout_pad_sections(void);
142 static void aout_fixup_relocs(struct Section
*);
145 * Special section numbers which are used to define special
146 * symbols, which can be used with WRT to provide PIC relocation
149 static int32_t aout_gotpc_sect
, aout_gotoff_sect
;
150 static int32_t aout_got_sect
, aout_plt_sect
;
151 static int32_t aout_sym_sect
;
153 static void aoutg_init(void)
155 stext
.data
= saa_init(1L);
157 stext
.tail
= &stext
.head
;
158 sdata
.data
= saa_init(1L);
160 sdata
.tail
= &sdata
.head
;
161 stext
.len
= stext
.size
= sdata
.len
= sdata
.size
= sbss
.len
= 0;
162 stext
.nrelocs
= sdata
.nrelocs
= 0;
163 stext
.gsyms
= sdata
.gsyms
= sbss
.gsyms
= NULL
;
164 stext
.index
= seg_alloc();
165 sdata
.index
= seg_alloc();
166 sbss
.index
= seg_alloc();
167 stext
.asym
= sdata
.asym
= sbss
.asym
= NULL
;
168 syms
= saa_init((int32_t)sizeof(struct Symbol
));
178 static void aout_init(void)
183 aout_gotpc_sect
= aout_gotoff_sect
= aout_got_sect
=
184 aout_plt_sect
= aout_sym_sect
= NO_SEG
;
191 extern struct ofmt of_aoutb
;
193 static void aoutb_init(void)
198 is_pic
= 0x00; /* may become 0x40 */
200 aout_gotpc_sect
= seg_alloc();
201 define_label("..gotpc", aout_gotpc_sect
+ 1, 0L, NULL
, false, false);
202 aout_gotoff_sect
= seg_alloc();
203 define_label("..gotoff", aout_gotoff_sect
+ 1, 0L, NULL
, false, false);
204 aout_got_sect
= seg_alloc();
205 define_label("..got", aout_got_sect
+ 1, 0L, NULL
, false, false);
206 aout_plt_sect
= seg_alloc();
207 define_label("..plt", aout_plt_sect
+ 1, 0L, NULL
, false, false);
208 aout_sym_sect
= seg_alloc();
209 define_label("..sym", aout_sym_sect
+ 1, 0L, NULL
, false, false);
214 static void aout_cleanup(int debuginfo
)
221 aout_fixup_relocs(&stext
);
222 aout_fixup_relocs(&sdata
);
224 saa_free(stext
.data
);
227 stext
.head
= stext
.head
->next
;
230 saa_free(sdata
.data
);
233 sdata
.head
= sdata
.head
->next
;
241 static int32_t aout_section_names(char *name
, int pass
, int *bits
)
247 * Default to 32 bits.
255 if (!strcmp(name
, ".text"))
257 else if (!strcmp(name
, ".data"))
259 else if (!strcmp(name
, ".bss"))
265 static void aout_deflabel(char *name
, int32_t segment
, int64_t offset
,
266 int is_global
, char *special
)
268 int pos
= strslen
+ 4;
270 int special_used
= false;
272 if (name
[0] == '.' && name
[1] == '.' && name
[2] != '@') {
274 * This is a NASM special symbol. We never allow it into
275 * the a.out symbol table, even if it's a valid one. If it
276 * _isn't_ a valid one, we should barf immediately.
278 if (strcmp(name
, "..gotpc") && strcmp(name
, "..gotoff") &&
279 strcmp(name
, "..got") && strcmp(name
, "..plt") &&
280 strcmp(name
, "..sym"))
281 nasm_error(ERR_NONFATAL
, "unrecognised special symbol `%s'", name
);
285 if (is_global
== 3) {
288 * Fix up a forward-reference symbol size from the first
291 for (s
= &fwds
; *s
; s
= &(*s
)->nextfwd
)
292 if (!strcmp((*s
)->name
, name
)) {
293 struct tokenval tokval
;
297 while (*p
&& !nasm_isspace(*p
))
299 while (*p
&& nasm_isspace(*p
))
303 tokval
.t_type
= TOKEN_INVALID
;
304 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, 1, nasm_error
, NULL
);
307 nasm_error(ERR_NONFATAL
, "cannot use relocatable"
308 " expression as symbol size");
310 (*s
)->size
= reloc_value(e
);
314 * Remove it from the list of unresolved sizes.
316 nasm_free((*s
)->name
);
320 return; /* it wasn't an important one */
323 saa_wbytes(strs
, name
, (int32_t)(1 + strlen(name
)));
324 strslen
+= 1 + strlen(name
);
326 sym
= saa_wstruct(syms
);
329 sym
->type
= is_global
? SYM_GLOBAL
: 0;
330 sym
->segment
= segment
;
331 if (segment
== NO_SEG
)
332 sym
->type
|= SECT_ABS
;
333 else if (segment
== stext
.index
) {
334 sym
->type
|= SECT_TEXT
;
336 sym
->next
= stext
.gsyms
;
338 } else if (!stext
.asym
)
340 } else if (segment
== sdata
.index
) {
341 sym
->type
|= SECT_DATA
;
343 sym
->next
= sdata
.gsyms
;
345 } else if (!sdata
.asym
)
347 } else if (segment
== sbss
.index
) {
348 sym
->type
|= SECT_BSS
;
350 sym
->next
= sbss
.gsyms
;
352 } else if (!sbss
.asym
)
355 sym
->type
= SYM_GLOBAL
;
359 sym
->value
= (sym
->type
== SYM_GLOBAL
? 0 : offset
);
361 if (is_global
&& sym
->type
!= SYM_GLOBAL
) {
363 * Global symbol exported _from_ this module. We must check
364 * the special text for type information.
368 int n
= strcspn(special
, " ");
370 if (!nasm_strnicmp(special
, "function", n
))
371 sym
->type
|= SYM_FUNCTION
;
372 else if (!nasm_strnicmp(special
, "data", n
) ||
373 !nasm_strnicmp(special
, "object", n
))
374 sym
->type
|= SYM_DATA
;
376 nasm_error(ERR_NONFATAL
, "unrecognised symbol type `%.*s'",
379 struct tokenval tokval
;
382 char *saveme
= stdscan_get();
385 nasm_error(ERR_NONFATAL
, "Linux a.out does not support"
386 " symbol size information");
388 while (special
[n
] && nasm_isspace(special
[n
]))
391 * We have a size expression; attempt to
394 sym
->type
|= SYM_WITH_SIZE
;
396 stdscan_set(special
+ n
);
397 tokval
.t_type
= TOKEN_INVALID
;
398 e
= evaluate(stdscan
, NULL
, &tokval
, &fwd
, 0, nasm_error
,
403 sym
->name
= nasm_strdup(name
);
406 nasm_error(ERR_NONFATAL
, "cannot use relocatable"
407 " expression as symbol size");
409 sym
->size
= reloc_value(e
);
419 * define the references from external-symbol segment numbers
420 * to these symbol records.
422 if (segment
!= NO_SEG
&& segment
!= stext
.index
&&
423 segment
!= sdata
.index
&& segment
!= sbss
.index
)
424 bsym
= raa_write(bsym
, segment
, nsyms
);
428 if (sym
->type
& SYM_WITH_SIZE
)
429 nsyms
++; /* and another for the size */
431 if (special
&& !special_used
)
432 nasm_error(ERR_NONFATAL
, "no special symbol features supported here");
435 static void aout_add_reloc(struct Section
*sect
, int32_t segment
,
436 int reltype
, int bytes
)
440 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
441 sect
->tail
= &r
->next
;
444 r
->address
= sect
->len
;
445 r
->symbol
= (segment
== NO_SEG
? -SECT_ABS
:
446 segment
== stext
.index
? -SECT_TEXT
:
447 segment
== sdata
.index
? -SECT_DATA
:
448 segment
== sbss
.index
? -SECT_BSS
:
449 raa_read(bsym
, segment
));
450 r
->reltype
= reltype
;
452 r
->reltype
|= RELTYPE_SYMFLAG
;
459 * This routine deals with ..got and ..sym relocations: the more
460 * complicated kinds. In shared-library writing, some relocations
461 * with respect to global symbols must refer to the precise symbol
462 * rather than referring to an offset from the base of the section
463 * _containing_ the symbol. Such relocations call to this routine,
464 * which searches the symbol list for the symbol in question.
466 * RELTYPE_GOT references require the _exact_ symbol address to be
467 * used; RELTYPE_ABSOLUTE references can be at an offset from the
468 * symbol. The boolean argument `exact' tells us this.
470 * Return value is the adjusted value of `addr', having become an
471 * offset from the symbol rather than the section. Should always be
472 * zero when returning from an exact call.
474 * Limitation: if you define two symbols at the same place,
475 * confusion will occur.
477 * Inefficiency: we search, currently, using a linked list which
478 * isn't even necessarily sorted.
480 static int32_t aout_add_gsym_reloc(struct Section
*sect
,
481 int32_t segment
, int32_t offset
,
482 int type
, int bytes
, int exact
)
484 struct Symbol
*sym
, *sm
, *shead
;
488 * First look up the segment to find whether it's text, data,
489 * bss or an external symbol.
492 if (segment
== stext
.index
)
494 else if (segment
== sdata
.index
)
496 else if (segment
== sbss
.index
)
499 if (exact
&& offset
!= 0)
500 nasm_error(ERR_NONFATAL
, "unable to find a suitable global symbol"
501 " for this reference");
503 aout_add_reloc(sect
, segment
, type
, bytes
);
509 * Find a symbol pointing _exactly_ at this one.
511 list_for_each(sym
, shead
)
512 if (sym
->value
== offset
)
516 * Find the nearest symbol below this one.
519 list_for_each(sm
, shead
)
520 if (sm
->value
<= offset
&& (!sym
|| sm
->value
> sym
->value
))
524 nasm_error(ERR_NONFATAL
, "unable to find a suitable global symbol"
525 " for this reference");
529 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
530 sect
->tail
= &r
->next
;
533 r
->address
= sect
->len
;
534 r
->symbol
= sym
->symnum
;
535 r
->reltype
= type
| RELTYPE_SYMFLAG
;
540 return offset
- sym
->value
;
544 * This routine deals with ..gotoff relocations. These _must_ refer
545 * to a symbol, due to a perversity of *BSD's PIC implementation,
546 * and it must be a non-global one as well; so we store `asym', the
547 * first nonglobal symbol defined in each section, and always work
548 * from that. Relocation type is always RELTYPE_GOTOFF.
550 * Return value is the adjusted value of `addr', having become an
551 * offset from the `asym' symbol rather than the section.
553 static int32_t aout_add_gotoff_reloc(struct Section
*sect
, int32_t segment
,
554 int32_t offset
, int bytes
)
560 * First look up the segment to find whether it's text, data,
561 * bss or an external symbol.
564 if (segment
== stext
.index
)
566 else if (segment
== sdata
.index
)
568 else if (segment
== sbss
.index
)
571 nasm_error(ERR_NONFATAL
, "`..gotoff' relocations require a non-global"
572 " symbol in the section");
574 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
575 sect
->tail
= &r
->next
;
578 r
->address
= sect
->len
;
579 r
->symbol
= asym
->symnum
;
580 r
->reltype
= RELTYPE_GOTOFF
;
585 return offset
- asym
->value
;
588 static void aout_out(int32_t segto
, const void *data
,
589 enum out_type type
, uint64_t size
,
590 int32_t segment
, int32_t wrt
)
594 uint8_t mydata
[4], *p
;
597 * handle absolute-assembly (structure definitions)
599 if (segto
== NO_SEG
) {
600 if (type
!= OUT_RESERVE
)
601 nasm_error(ERR_NONFATAL
, "attempt to assemble code in [ABSOLUTE]"
606 if (segto
== stext
.index
)
608 else if (segto
== sdata
.index
)
610 else if (segto
== sbss
.index
)
613 nasm_error(ERR_WARNING
, "attempt to assemble code in"
614 " segment %d: defaulting to `.text'", segto
);
618 if (!s
&& type
!= OUT_RESERVE
) {
619 nasm_error(ERR_WARNING
, "attempt to initialize memory in the"
620 " BSS section: ignored");
621 sbss
.len
+= realsize(type
, size
);
625 if (type
== OUT_RESERVE
) {
627 nasm_error(ERR_WARNING
, "uninitialized space declared in"
628 " %s section: zeroing",
629 (segto
== stext
.index
? "code" : "data"));
630 aout_sect_write(s
, NULL
, size
);
633 } else if (type
== OUT_RAWDATA
) {
634 if (segment
!= NO_SEG
)
635 nasm_error(ERR_PANIC
, "OUT_RAWDATA with other than NO_SEG");
636 aout_sect_write(s
, data
, size
);
637 } else if (type
== OUT_ADDRESS
) {
638 addr
= *(int64_t *)data
;
639 if (segment
!= NO_SEG
) {
641 nasm_error(ERR_NONFATAL
, "a.out format does not support"
642 " segment base references");
645 aout_add_reloc(s
, segment
, RELTYPE_ABSOLUTE
,
648 nasm_error(ERR_NONFATAL
,
649 "Linux a.out format does not support"
651 wrt
= NO_SEG
; /* we can at least _try_ to continue */
652 } else if (wrt
== aout_gotpc_sect
+ 1) {
654 aout_add_reloc(s
, segment
, RELTYPE_GOTPC
, size
);
655 } else if (wrt
== aout_gotoff_sect
+ 1) {
657 addr
= aout_add_gotoff_reloc(s
, segment
,
659 } else if (wrt
== aout_got_sect
+ 1) {
662 aout_add_gsym_reloc(s
, segment
, addr
, RELTYPE_GOT
,
664 } else if (wrt
== aout_sym_sect
+ 1) {
665 addr
= aout_add_gsym_reloc(s
, segment
, addr
,
666 RELTYPE_ABSOLUTE
, size
,
668 } else if (wrt
== aout_plt_sect
+ 1) {
670 nasm_error(ERR_NONFATAL
,
671 "a.out format cannot produce non-PC-"
672 "relative PLT references");
674 nasm_error(ERR_NONFATAL
,
675 "a.out format does not support this"
677 wrt
= NO_SEG
; /* we can at least _try_ to continue */
686 aout_sect_write(s
, mydata
, size
);
687 } else if (type
== OUT_REL2ADR
) {
688 if (segment
== segto
)
689 nasm_error(ERR_PANIC
, "intra-segment OUT_REL2ADR");
690 if (segment
!= NO_SEG
&& segment
% 2) {
691 nasm_error(ERR_NONFATAL
, "a.out format does not support"
692 " segment base references");
695 aout_add_reloc(s
, segment
, RELTYPE_RELATIVE
, 2);
697 nasm_error(ERR_NONFATAL
, "Linux a.out format does not support"
699 wrt
= NO_SEG
; /* we can at least _try_ to continue */
700 } else if (wrt
== aout_plt_sect
+ 1) {
702 aout_add_reloc(s
, segment
, RELTYPE_PLT
, 2);
703 } else if (wrt
== aout_gotpc_sect
+ 1 ||
704 wrt
== aout_gotoff_sect
+ 1 ||
705 wrt
== aout_got_sect
+ 1) {
706 nasm_error(ERR_NONFATAL
, "a.out format cannot produce PC-"
707 "relative GOT references");
709 nasm_error(ERR_NONFATAL
, "a.out format does not support this"
711 wrt
= NO_SEG
; /* we can at least _try_ to continue */
715 WRITESHORT(p
, *(int64_t *)data
- (size
+ s
->len
));
716 aout_sect_write(s
, mydata
, 2L);
717 } else if (type
== OUT_REL4ADR
) {
718 if (segment
== segto
)
719 nasm_error(ERR_PANIC
, "intra-segment OUT_REL4ADR");
720 if (segment
!= NO_SEG
&& segment
% 2) {
721 nasm_error(ERR_NONFATAL
, "a.out format does not support"
722 " segment base references");
725 aout_add_reloc(s
, segment
, RELTYPE_RELATIVE
, 4);
727 nasm_error(ERR_NONFATAL
, "Linux a.out format does not support"
729 wrt
= NO_SEG
; /* we can at least _try_ to continue */
730 } else if (wrt
== aout_plt_sect
+ 1) {
732 aout_add_reloc(s
, segment
, RELTYPE_PLT
, 4);
733 } else if (wrt
== aout_gotpc_sect
+ 1 ||
734 wrt
== aout_gotoff_sect
+ 1 ||
735 wrt
== aout_got_sect
+ 1) {
736 nasm_error(ERR_NONFATAL
, "a.out format cannot produce PC-"
737 "relative GOT references");
739 nasm_error(ERR_NONFATAL
, "a.out format does not support this"
741 wrt
= NO_SEG
; /* we can at least _try_ to continue */
745 WRITELONG(p
, *(int64_t *)data
- (size
+ s
->len
));
746 aout_sect_write(s
, mydata
, 4L);
750 static void aout_pad_sections(void)
752 static uint8_t pad
[] = { 0x90, 0x90, 0x90, 0x90 };
754 * Pad each of the text and data sections with NOPs until their
755 * length is a multiple of four. (NOP == 0x90.) Also increase
756 * the length of the BSS section similarly.
758 aout_sect_write(&stext
, pad
, (-(int32_t)stext
.len
) & 3);
759 aout_sect_write(&sdata
, pad
, (-(int32_t)sdata
.len
) & 3);
760 sbss
.len
= ALIGN(sbss
.len
, 4);
764 * a.out files have the curious property that all references to
765 * things in the data or bss sections are done by addresses which
766 * are actually relative to the start of the _text_ section, in the
767 * _file_. (No relation to what happens after linking. No idea why
768 * this should be so. It's very strange.) So we have to go through
769 * the relocation table, _after_ the final size of each section is
770 * known, and fix up the relocations pointed to.
772 static void aout_fixup_relocs(struct Section
*sect
)
776 saa_rewind(sect
->data
);
777 list_for_each(r
, sect
->head
) {
778 uint8_t *p
, *q
, blk
[4];
781 saa_fread(sect
->data
, r
->address
, blk
, (int32_t)r
->bytes
);
785 l
+= ((int32_t)*p
++) << 8;
787 l
+= ((int32_t)*p
++) << 16;
788 l
+= ((int32_t)*p
++) << 24;
791 if (r
->symbol
== -SECT_DATA
)
793 else if (r
->symbol
== -SECT_BSS
)
794 l
+= stext
.len
+ sdata
.len
;
797 else if (r
->bytes
== 2)
801 saa_fwrite(sect
->data
, r
->address
, blk
, (int32_t)r
->bytes
);
805 static void aout_write(void)
808 * Emit the a.out header.
810 /* OMAGIC, M_386 or MID_I386, no flags */
811 fwriteint32_t(bsd
? 0x07018600 | is_pic
: 0x640107L
, ofile
);
812 fwriteint32_t(stext
.len
, ofile
);
813 fwriteint32_t(sdata
.len
, ofile
);
814 fwriteint32_t(sbss
.len
, ofile
);
815 fwriteint32_t(nsyms
* 12, ofile
); /* length of symbol table */
816 fwriteint32_t(0L, ofile
); /* object files have no entry point */
817 fwriteint32_t(stext
.nrelocs
* 8, ofile
); /* size of text relocs */
818 fwriteint32_t(sdata
.nrelocs
* 8, ofile
); /* size of data relocs */
821 * Write out the code section and the data section.
823 saa_fpwrite(stext
.data
, ofile
);
824 saa_fpwrite(sdata
.data
, ofile
);
827 * Write out the relocations.
829 aout_write_relocs(stext
.head
);
830 aout_write_relocs(sdata
.head
);
833 * Write the symbol table.
838 * And the string table.
840 fwriteint32_t(strslen
+ 4, ofile
); /* length includes length count */
841 saa_fpwrite(strs
, ofile
);
844 static void aout_write_relocs(struct Reloc
*r
)
846 list_for_each(r
, r
) {
849 fwriteint32_t(r
->address
, ofile
);
855 word2
|= r
->reltype
<< 24;
856 word2
|= (r
->bytes
== 1 ? 0 :
857 r
->bytes
== 2 ? 0x2000000L
: 0x4000000L
);
858 fwriteint32_t(word2
, ofile
);
862 static void aout_write_syms(void)
867 for (i
= 0; i
< nsyms
; i
++) {
868 struct Symbol
*sym
= saa_rstruct(syms
);
869 fwriteint32_t(sym
->strpos
, ofile
);
870 fwriteint32_t((int32_t)sym
->type
& ~SYM_WITH_SIZE
, ofile
);
872 * Fix up the symbol value now we know the final section
875 if ((sym
->type
& SECT_MASK
) == SECT_DATA
)
876 sym
->value
+= stext
.len
;
877 if ((sym
->type
& SECT_MASK
) == SECT_BSS
)
878 sym
->value
+= stext
.len
+ sdata
.len
;
879 fwriteint32_t(sym
->value
, ofile
);
881 * Output a size record if necessary.
883 if (sym
->type
& SYM_WITH_SIZE
) {
884 fwriteint32_t(sym
->strpos
, ofile
);
885 fwriteint32_t(0x0DL
, ofile
); /* special value: means size */
886 fwriteint32_t(sym
->size
, ofile
);
887 i
++; /* use up another of `nsyms' */
892 static void aout_sect_write(struct Section
*sect
,
893 const uint8_t *data
, uint32_t len
)
895 saa_wbytes(sect
->data
, data
, len
);
899 static int32_t aout_segbase(int32_t segment
)
904 static void aout_filename(char *inname
, char *outname
)
906 standard_extension(inname
, outname
, ".o");
909 extern macros_t aout_stdmac
[];
911 #endif /* OF_AOUT || OF_AOUTB */
915 struct ofmt of_aout
= {
916 "Linux a.out object files",
938 struct ofmt of_aoutb
= {
939 "NetBSD/FreeBSD a.out object files",