]>
git.saurik.com Git - apple/boot.git/blob - i386/nasm/outaout.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
24 /* outaout.c output routines for the Netwide Assembler to produce
25 * Linux a.out object files
27 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
28 * Julian Hall. All rights reserved. The software is
29 * redistributable under the licence given in the file "Licence"
30 * distributed in the NASM archive.
42 #if defined OF_AOUT || defined OF_AOUTB
44 #define RELTYPE_ABSOLUTE 0x00
45 #define RELTYPE_RELATIVE 0x01
46 #define RELTYPE_GOTPC 0x01 /* no explicit GOTPC in a.out */
47 #define RELTYPE_GOTOFF 0x10
48 #define RELTYPE_GOT 0x10 /* distinct from GOTOFF bcos sym not sect */
49 #define RELTYPE_PLT 0x21
50 #define RELTYPE_SYMFLAG 0x08
54 long address
; /* relative to _start_ of section */
55 long symbol
; /* symbol number or -ve section id */
56 int bytes
; /* 2 or 4 */
57 int reltype
; /* see above */
61 long strpos
; /* string table position of name */
62 int type
; /* symbol type - see flags below */
63 long value
; /* address, or COMMON variable size */
64 long size
; /* size for data or function exports */
65 long segment
; /* back-reference used by gsym_reloc */
66 struct Symbol
*next
; /* list of globals in each section */
67 struct Symbol
*nextfwd
; /* list of unresolved-size symbols */
68 char *name
; /* for unresolved-size symbols */
69 long symnum
; /* index into symbol table */
73 * Section IDs - used in Reloc.symbol when negative, and in
74 * Symbol.type when positive.
76 #define SECT_ABS 2 /* absolute value */
77 #define SECT_TEXT 4 /* text section */
78 #define SECT_DATA 6 /* data section */
79 #define SECT_BSS 8 /* bss section */
80 #define SECT_MASK 0xE /* mask out any of the above */
83 * More flags used in Symbol.type.
85 #define SYM_GLOBAL 1 /* it's a global symbol */
86 #define SYM_DATA 0x100 /* used for shared libs */
87 #define SYM_FUNCTION 0x200 /* used for shared libs */
88 #define SYM_WITH_SIZE 0x4000 /* not output; internal only */
91 * Bit more explanation of symbol types: SECT_xxx denotes a local
92 * symbol. SECT_xxx|SYM_GLOBAL denotes a global symbol, defined in
93 * this module. Just SYM_GLOBAL, with zero value, denotes an
94 * external symbol referenced in this module. And just SYM_GLOBAL,
95 * but with a non-zero value, declares a C `common' variable, of
101 unsigned long len
, size
, nrelocs
;
103 struct Reloc
*head
, **tail
;
104 struct Symbol
*gsyms
, *asym
;
107 static struct Section stext
, sdata
, sbss
;
109 static struct SAA
*syms
;
110 static unsigned long nsyms
;
112 static struct RAA
*bsym
;
114 static struct SAA
*strs
;
115 static unsigned long strslen
;
117 static struct Symbol
*fwds
;
121 static evalfunc evaluate
;
126 static void aout_write(void);
127 static void aout_write_relocs(struct Reloc
*);
128 static void aout_write_syms(void);
129 static void aout_sect_write(struct Section
*, unsigned char *, unsigned long);
130 static void aout_pad_sections(void);
131 static void aout_fixup_relocs(struct Section
*);
134 * Special section numbers which are used to define special
135 * symbols, which can be used with WRT to provide PIC relocation
138 static long aout_gotpc_sect
, aout_gotoff_sect
;
139 static long aout_got_sect
, aout_plt_sect
;
140 static long aout_sym_sect
;
142 static void aoutg_init(FILE *fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
) {
146 (void) ldef
; /* placate optimisers */
147 stext
.data
= saa_init(1L); stext
.head
= NULL
; stext
.tail
= &stext
.head
;
148 sdata
.data
= saa_init(1L); sdata
.head
= NULL
; sdata
.tail
= &sdata
.head
;
149 stext
.len
= stext
.size
= sdata
.len
= sdata
.size
= sbss
.len
= 0;
150 stext
.nrelocs
= sdata
.nrelocs
= 0;
151 stext
.gsyms
= sdata
.gsyms
= sbss
.gsyms
= NULL
;
152 stext
.index
= seg_alloc();
153 sdata
.index
= seg_alloc();
154 sbss
.index
= seg_alloc();
155 stext
.asym
= sdata
.asym
= sbss
.asym
= NULL
;
156 syms
= saa_init((long)sizeof(struct Symbol
));
166 static void aout_init(FILE *fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
) {
168 aoutg_init (fp
, errfunc
, ldef
, eval
);
170 aout_gotpc_sect
= aout_gotoff_sect
= aout_got_sect
=
171 aout_plt_sect
= aout_sym_sect
= NO_SEG
;
178 extern struct ofmt of_aoutb
;
180 static void aoutb_init(FILE *fp
, efunc errfunc
, ldfunc ldef
, evalfunc eval
) {
182 aoutg_init (fp
, errfunc
, ldef
, eval
);
184 is_pic
= 0x00; /* may become 0x40 */
186 aout_gotpc_sect
= seg_alloc();
187 ldef("..gotpc", aout_gotpc_sect
+1, 0L, NULL
, FALSE
,FALSE
,&of_aoutb
,error
);
188 aout_gotoff_sect
= seg_alloc();
189 ldef("..gotoff", aout_gotoff_sect
+1, 0L,NULL
,FALSE
,FALSE
,&of_aoutb
,error
);
190 aout_got_sect
= seg_alloc();
191 ldef("..got", aout_got_sect
+1, 0L, NULL
, FALSE
,FALSE
,&of_aoutb
,error
);
192 aout_plt_sect
= seg_alloc();
193 ldef("..plt", aout_plt_sect
+1, 0L, NULL
, FALSE
,FALSE
,&of_aoutb
,error
);
194 aout_sym_sect
= seg_alloc();
195 ldef("..sym", aout_sym_sect
+1, 0L, NULL
, FALSE
,FALSE
,&of_aoutb
,error
);
200 static void aout_cleanup(void) {
204 aout_fixup_relocs(&stext
);
205 aout_fixup_relocs(&sdata
);
208 saa_free (stext
.data
);
211 stext
.head
= stext
.head
->next
;
214 saa_free (sdata
.data
);
217 sdata
.head
= sdata
.head
->next
;
225 static long aout_section_names (char *name
, int pass
, int *bits
) {
227 * Default to 32 bits.
235 if (!strcmp(name
, ".text"))
237 else if (!strcmp(name
, ".data"))
239 else if (!strcmp(name
, ".bss"))
245 static void aout_deflabel (char *name
, long segment
, long offset
,
246 int is_global
, char *special
) {
249 int special_used
= FALSE
;
251 if (name
[0] == '.' && name
[1] == '.' && name
[2] != '@') {
253 * This is a NASM special symbol. We never allow it into
254 * the a.out symbol table, even if it's a valid one. If it
255 * _isn't_ a valid one, we should barf immediately.
257 if (strcmp(name
, "..gotpc") && strcmp(name
, "..gotoff") &&
258 strcmp(name
, "..got") && strcmp(name
, "..plt") &&
259 strcmp(name
, "..sym"))
260 error (ERR_NONFATAL
, "unrecognised special symbol `%s'", name
);
264 if (is_global
== 3) {
267 * Fix up a forward-reference symbol size from the first
270 for (s
= &fwds
; *s
; s
= &(*s
)->nextfwd
)
271 if (!strcmp((*s
)->name
, name
)) {
272 struct tokenval tokval
;
276 while (*p
&& !isspace(*p
)) p
++;
277 while (*p
&& isspace(*p
)) p
++;
280 tokval
.t_type
= TOKEN_INVALID
;
281 e
= evaluate(stdscan
, NULL
, &tokval
, NULL
, 1, error
, NULL
);
284 error (ERR_NONFATAL
, "cannot use relocatable"
285 " expression as symbol size");
287 (*s
)->size
= reloc_value(e
);
291 * Remove it from the list of unresolved sizes.
293 nasm_free ((*s
)->name
);
297 return; /* it wasn't an important one */
300 saa_wbytes (strs
, name
, (long)(1+strlen(name
)));
301 strslen
+= 1+strlen(name
);
303 sym
= saa_wstruct (syms
);
306 sym
->type
= is_global
? SYM_GLOBAL
: 0;
307 sym
->segment
= segment
;
308 if (segment
== NO_SEG
)
309 sym
->type
|= SECT_ABS
;
310 else if (segment
== stext
.index
) {
311 sym
->type
|= SECT_TEXT
;
313 sym
->next
= stext
.gsyms
;
315 } else if (!stext
.asym
)
317 } else if (segment
== sdata
.index
) {
318 sym
->type
|= SECT_DATA
;
320 sym
->next
= sdata
.gsyms
;
322 } else if (!sdata
.asym
)
324 } else if (segment
== sbss
.index
) {
325 sym
->type
|= SECT_BSS
;
327 sym
->next
= sbss
.gsyms
;
329 } else if (!sbss
.asym
)
332 sym
->type
= SYM_GLOBAL
;
336 sym
->value
= (sym
->type
== SYM_GLOBAL
? 0 : offset
);
338 if (is_global
&& sym
->type
!= SYM_GLOBAL
) {
340 * Global symbol exported _from_ this module. We must check
341 * the special text for type information.
345 int n
= strcspn(special
, " ");
347 if (!nasm_strnicmp(special
, "function", n
))
348 sym
->type
|= SYM_FUNCTION
;
349 else if (!nasm_strnicmp(special
, "data", n
) ||
350 !nasm_strnicmp(special
, "object", n
))
351 sym
->type
|= SYM_DATA
;
353 error(ERR_NONFATAL
, "unrecognised symbol type `%.*s'",
356 struct tokenval tokval
;
361 error(ERR_NONFATAL
, "Linux a.out does not support"
362 " symbol size information");
364 while (special
[n
] && isspace(special
[n
]))
367 * We have a size expression; attempt to
370 sym
->type
|= SYM_WITH_SIZE
;
372 stdscan_bufptr
= special
+n
;
373 tokval
.t_type
= TOKEN_INVALID
;
374 e
= evaluate(stdscan
, NULL
, &tokval
, &fwd
, 0, error
, NULL
);
378 sym
->name
= nasm_strdup(name
);
381 error (ERR_NONFATAL
, "cannot use relocatable"
382 " expression as symbol size");
384 sym
->size
= reloc_value(e
);
393 * define the references from external-symbol segment numbers
394 * to these symbol records.
396 if (segment
!= NO_SEG
&& segment
!= stext
.index
&&
397 segment
!= sdata
.index
&& segment
!= sbss
.index
)
398 bsym
= raa_write (bsym
, segment
, nsyms
);
402 if (sym
->type
& SYM_WITH_SIZE
)
403 nsyms
++; /* and another for the size */
405 if (special
&& !special_used
)
406 error(ERR_NONFATAL
, "no special symbol features supported here");
409 static void aout_add_reloc (struct Section
*sect
, long segment
,
410 int reltype
, int bytes
) {
413 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
414 sect
->tail
= &r
->next
;
417 r
->address
= sect
->len
;
418 r
->symbol
= (segment
== NO_SEG
? -SECT_ABS
:
419 segment
== stext
.index
? -SECT_TEXT
:
420 segment
== sdata
.index
? -SECT_DATA
:
421 segment
== sbss
.index
? -SECT_BSS
:
422 raa_read(bsym
, segment
));
423 r
->reltype
= reltype
;
425 r
->reltype
|= RELTYPE_SYMFLAG
;
432 * This routine deals with ..got and ..sym relocations: the more
433 * complicated kinds. In shared-library writing, some relocations
434 * with respect to global symbols must refer to the precise symbol
435 * rather than referring to an offset from the base of the section
436 * _containing_ the symbol. Such relocations call to this routine,
437 * which searches the symbol list for the symbol in question.
439 * RELTYPE_GOT references require the _exact_ symbol address to be
440 * used; RELTYPE_ABSOLUTE references can be at an offset from the
441 * symbol. The boolean argument `exact' tells us this.
443 * Return value is the adjusted value of `addr', having become an
444 * offset from the symbol rather than the section. Should always be
445 * zero when returning from an exact call.
447 * Limitation: if you define two symbols at the same place,
448 * confusion will occur.
450 * Inefficiency: we search, currently, using a linked list which
451 * isn't even necessarily sorted.
453 static long aout_add_gsym_reloc (struct Section
*sect
,
454 long segment
, long offset
,
455 int type
, int bytes
, int exact
) {
456 struct Symbol
*sym
, *sm
, *shead
;
460 * First look up the segment to find whether it's text, data,
461 * bss or an external symbol.
464 if (segment
== stext
.index
)
466 else if (segment
== sdata
.index
)
468 else if (segment
== sbss
.index
)
471 if (exact
&& offset
!= 0)
472 error (ERR_NONFATAL
, "unable to find a suitable global symbol"
473 " for this reference");
475 aout_add_reloc (sect
, segment
, type
, bytes
);
481 * Find a symbol pointing _exactly_ at this one.
483 for (sym
= shead
; sym
; sym
= sym
->next
)
484 if (sym
->value
== offset
)
488 * Find the nearest symbol below this one.
491 for (sm
= shead
; sm
; sm
= sm
->next
)
492 if (sm
->value
<= offset
&& (!sym
|| sm
->value
> sym
->value
))
496 error (ERR_NONFATAL
, "unable to find a suitable global symbol"
497 " for this reference");
501 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
502 sect
->tail
= &r
->next
;
505 r
->address
= sect
->len
;
506 r
->symbol
= sym
->symnum
;
507 r
->reltype
= type
| RELTYPE_SYMFLAG
;
512 return offset
- sym
->value
;
516 * This routine deals with ..gotoff relocations. These _must_ refer
517 * to a symbol, due to a perversity of *BSD's PIC implementation,
518 * and it must be a non-global one as well; so we store `asym', the
519 * first nonglobal symbol defined in each section, and always work
520 * from that. Relocation type is always RELTYPE_GOTOFF.
522 * Return value is the adjusted value of `addr', having become an
523 * offset from the `asym' symbol rather than the section.
525 static long aout_add_gotoff_reloc (struct Section
*sect
, long segment
,
526 long offset
, int bytes
) {
531 * First look up the segment to find whether it's text, data,
532 * bss or an external symbol.
535 if (segment
== stext
.index
)
537 else if (segment
== sdata
.index
)
539 else if (segment
== sbss
.index
)
542 error (ERR_NONFATAL
, "`..gotoff' relocations require a non-global"
543 " symbol in the section");
545 r
= *sect
->tail
= nasm_malloc(sizeof(struct Reloc
));
546 sect
->tail
= &r
->next
;
549 r
->address
= sect
->len
;
550 r
->symbol
= asym
->symnum
;
551 r
->reltype
= RELTYPE_GOTOFF
;
556 return offset
- asym
->value
;
559 static void aout_out (long segto
, void *data
, unsigned long type
,
560 long segment
, long wrt
) {
562 long realbytes
= type
& OUT_SIZMASK
;
564 unsigned char mydata
[4], *p
;
569 * handle absolute-assembly (structure definitions)
571 if (segto
== NO_SEG
) {
572 if (type
!= OUT_RESERVE
)
573 error (ERR_NONFATAL
, "attempt to assemble code in [ABSOLUTE]"
578 if (segto
== stext
.index
)
580 else if (segto
== sdata
.index
)
582 else if (segto
== sbss
.index
)
585 error(ERR_WARNING
, "attempt to assemble code in"
586 " segment %d: defaulting to `.text'", segto
);
590 if (!s
&& type
!= OUT_RESERVE
) {
591 error(ERR_WARNING
, "attempt to initialise memory in the"
592 " BSS section: ignored");
593 if (type
== OUT_REL2ADR
)
595 else if (type
== OUT_REL4ADR
)
597 sbss
.len
+= realbytes
;
601 if (type
== OUT_RESERVE
) {
603 error(ERR_WARNING
, "uninitialised space declared in"
604 " %s section: zeroing",
605 (segto
== stext
.index
? "code" : "data"));
606 aout_sect_write (s
, NULL
, realbytes
);
608 sbss
.len
+= realbytes
;
609 } else if (type
== OUT_RAWDATA
) {
610 if (segment
!= NO_SEG
)
611 error(ERR_PANIC
, "OUT_RAWDATA with other than NO_SEG");
612 aout_sect_write (s
, data
, realbytes
);
613 } else if (type
== OUT_ADDRESS
) {
614 addr
= *(long *)data
;
615 if (segment
!= NO_SEG
) {
617 error(ERR_NONFATAL
, "a.out format does not support"
618 " segment base references");
621 aout_add_reloc (s
, segment
, RELTYPE_ABSOLUTE
, realbytes
);
623 error (ERR_NONFATAL
, "Linux a.out format does not support"
625 wrt
= NO_SEG
; /* we can at least _try_ to continue */
626 } else if (wrt
== aout_gotpc_sect
+1) {
628 aout_add_reloc (s
, segment
, RELTYPE_GOTPC
, realbytes
);
629 } else if (wrt
== aout_gotoff_sect
+1) {
631 addr
= aout_add_gotoff_reloc (s
, segment
,
633 } else if (wrt
== aout_got_sect
+1) {
635 addr
= aout_add_gsym_reloc (s
, segment
, addr
, RELTYPE_GOT
,
637 } else if (wrt
== aout_sym_sect
+1) {
638 addr
= aout_add_gsym_reloc (s
, segment
, addr
,
639 RELTYPE_ABSOLUTE
, realbytes
,
641 } else if (wrt
== aout_plt_sect
+1) {
643 error(ERR_NONFATAL
, "a.out format cannot produce non-PC-"
644 "relative PLT references");
646 error (ERR_NONFATAL
, "a.out format does not support this"
648 wrt
= NO_SEG
; /* we can at least _try_ to continue */
654 WRITESHORT (p
, addr
);
657 aout_sect_write (s
, mydata
, realbytes
);
658 } else if (type
== OUT_REL2ADR
) {
659 if (segment
== segto
)
660 error(ERR_PANIC
, "intra-segment OUT_REL2ADR");
661 if (segment
!= NO_SEG
&& segment
% 2) {
662 error(ERR_NONFATAL
, "a.out format does not support"
663 " segment base references");
666 aout_add_reloc (s
, segment
, RELTYPE_RELATIVE
, 2);
668 error (ERR_NONFATAL
, "Linux a.out format does not support"
670 wrt
= NO_SEG
; /* we can at least _try_ to continue */
671 } else if (wrt
== aout_plt_sect
+1) {
673 aout_add_reloc (s
, segment
, RELTYPE_PLT
, 2);
674 } else if (wrt
== aout_gotpc_sect
+1 ||
675 wrt
== aout_gotoff_sect
+1 ||
676 wrt
== aout_got_sect
+1) {
677 error(ERR_NONFATAL
, "a.out format cannot produce PC-"
678 "relative GOT references");
680 error (ERR_NONFATAL
, "a.out format does not support this"
682 wrt
= NO_SEG
; /* we can at least _try_ to continue */
686 WRITESHORT (p
, *(long*)data
-(realbytes
+ s
->len
));
687 aout_sect_write (s
, mydata
, 2L);
688 } else if (type
== OUT_REL4ADR
) {
689 if (segment
== segto
)
690 error(ERR_PANIC
, "intra-segment OUT_REL4ADR");
691 if (segment
!= NO_SEG
&& segment
% 2) {
692 error(ERR_NONFATAL
, "a.out format does not support"
693 " segment base references");
696 aout_add_reloc (s
, segment
, RELTYPE_RELATIVE
, 4);
698 error (ERR_NONFATAL
, "Linux a.out format does not support"
700 wrt
= NO_SEG
; /* we can at least _try_ to continue */
701 } else if (wrt
== aout_plt_sect
+1) {
703 aout_add_reloc (s
, segment
, RELTYPE_PLT
, 4);
704 } else if (wrt
== aout_gotpc_sect
+1 ||
705 wrt
== aout_gotoff_sect
+1 ||
706 wrt
== aout_got_sect
+1) {
707 error(ERR_NONFATAL
, "a.out format cannot produce PC-"
708 "relative GOT references");
710 error (ERR_NONFATAL
, "a.out format does not support this"
712 wrt
= NO_SEG
; /* we can at least _try_ to continue */
716 WRITELONG (p
, *(long*)data
-(realbytes
+ s
->len
));
717 aout_sect_write (s
, mydata
, 4L);
721 static void aout_pad_sections(void) {
722 static unsigned char pad
[] = { 0x90, 0x90, 0x90, 0x90 };
724 * Pad each of the text and data sections with NOPs until their
725 * length is a multiple of four. (NOP == 0x90.) Also increase
726 * the length of the BSS section similarly.
728 aout_sect_write (&stext
, pad
, (-(long)stext
.len
) & 3);
729 aout_sect_write (&sdata
, pad
, (-(long)sdata
.len
) & 3);
730 sbss
.len
= (sbss
.len
+ 3) & ~3;
734 * a.out files have the curious property that all references to
735 * things in the data or bss sections are done by addresses which
736 * are actually relative to the start of the _text_ section, in the
737 * _file_. (No relation to what happens after linking. No idea why
738 * this should be so. It's very strange.) So we have to go through
739 * the relocation table, _after_ the final size of each section is
740 * known, and fix up the relocations pointed to.
742 static void aout_fixup_relocs(struct Section
*sect
) {
745 saa_rewind (sect
->data
);
746 for (r
= sect
->head
; r
; r
= r
->next
) {
747 unsigned char *p
, *q
, blk
[4];
750 saa_fread (sect
->data
, r
->address
, blk
, (long)r
->bytes
);
754 l
+= ((long)*p
++) << 8;
756 l
+= ((long)*p
++) << 16;
757 l
+= ((long)*p
++) << 24;
760 if (r
->symbol
== -SECT_DATA
)
762 else if (r
->symbol
== -SECT_BSS
)
763 l
+= stext
.len
+ sdata
.len
;
766 else if (r
->bytes
== 2)
770 saa_fwrite (sect
->data
, r
->address
, blk
, (long)r
->bytes
);
774 static void aout_write(void) {
776 * Emit the a.out header.
778 /* OMAGIC, M_386 or MID_I386, no flags */
779 fwritelong (bsd
? 0x07018600 | is_pic
: 0x640107L
, aoutfp
);
780 fwritelong (stext
.len
, aoutfp
);
781 fwritelong (sdata
.len
, aoutfp
);
782 fwritelong (sbss
.len
, aoutfp
);
783 fwritelong (nsyms
* 12, aoutfp
); /* length of symbol table */
784 fwritelong (0L, aoutfp
); /* object files have no entry point */
785 fwritelong (stext
.nrelocs
* 8, aoutfp
); /* size of text relocs */
786 fwritelong (sdata
.nrelocs
* 8, aoutfp
); /* size of data relocs */
789 * Write out the code section and the data section.
791 saa_fpwrite (stext
.data
, aoutfp
);
792 saa_fpwrite (sdata
.data
, aoutfp
);
795 * Write out the relocations.
797 aout_write_relocs (stext
.head
);
798 aout_write_relocs (sdata
.head
);
801 * Write the symbol table.
806 * And the string table.
808 fwritelong (strslen
+4, aoutfp
); /* length includes length count */
809 saa_fpwrite (strs
, aoutfp
);
812 static void aout_write_relocs (struct Reloc
*r
) {
816 fwritelong (r
->address
, aoutfp
);
822 word2
|= r
->reltype
<< 24;
823 word2
|= (r
->bytes
== 1 ? 0 :
824 r
->bytes
== 2 ? 0x2000000L
: 0x4000000L
);
825 fwritelong (word2
, aoutfp
);
831 static void aout_write_syms (void) {
835 for (i
=0; i
<(int)nsyms
; i
++) {
836 struct Symbol
*sym
= saa_rstruct(syms
);
837 fwritelong (sym
->strpos
, aoutfp
);
838 fwritelong ((long)sym
->type
& ~SYM_WITH_SIZE
, aoutfp
);
840 * Fix up the symbol value now we know the final section
843 if ((sym
->type
& SECT_MASK
) == SECT_DATA
)
844 sym
->value
+= stext
.len
;
845 if ((sym
->type
& SECT_MASK
) == SECT_BSS
)
846 sym
->value
+= stext
.len
+ sdata
.len
;
847 fwritelong (sym
->value
, aoutfp
);
849 * Output a size record if necessary.
851 if (sym
->type
& SYM_WITH_SIZE
) {
852 fwritelong(sym
->strpos
, aoutfp
);
853 fwritelong(0x0DL
, aoutfp
); /* special value: means size */
854 fwritelong(sym
->size
, aoutfp
);
855 i
++; /* use up another of `nsyms' */
860 static void aout_sect_write (struct Section
*sect
,
861 unsigned char *data
, unsigned long len
) {
862 saa_wbytes (sect
->data
, data
, len
);
866 static long aout_segbase (long segment
) {
870 static int aout_directive (char *directive
, char *value
, int pass
) {
874 static void aout_filename (char *inname
, char *outname
, efunc error
) {
875 standard_extension (inname
, outname
, ".o", error
);
878 static char *aout_stdmac
[] = {
879 "%define __SECT__ [section .text]",
883 #endif /* OF_AOUT || OF_AOUTB */
887 struct ofmt of_aout
= {
888 "Linux a.out object files",
905 struct ofmt of_aoutb
= {
906 "NetBSD/FreeBSD a.out object files",