changed sprintf to more secure snprintf to prevent vulnerability to buffer
[nasm.git] / output / outelf.c
blob16c25d108555ed76af2a5513f59905a8e459b52e
1 /* outelf.c output routines for the Netwide Assembler to produce
2 * ELF32 (i386 of course) object file format
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 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
15 #include "nasm.h"
16 #include "nasmlib.h"
17 #include "outform.h"
19 #ifdef OF_ELF
22 * Relocation types.
24 enum reloc_type {
25 R_386_32 = 1, /* ordinary absolute relocation */
26 R_386_PC32 = 2, /* PC-relative relocation */
27 R_386_GOT32 = 3, /* an offset into GOT */
28 R_386_PLT32 = 4, /* a PC-relative offset into PLT */
29 R_386_COPY = 5, /* ??? */
30 R_386_GLOB_DAT = 6, /* ??? */
31 R_386_JUMP_SLOT = 7, /* ??? */
32 R_386_RELATIVE = 8, /* ??? */
33 R_386_GOTOFF = 9, /* an offset from GOT base */
34 R_386_GOTPC = 10, /* a PC-relative offset _to_ GOT */
35 /* These are GNU extensions, but useful */
36 R_386_16 = 20, /* A 16-bit absolute relocation */
37 R_386_PC16 = 21, /* A 16-bit PC-relative relocation */
38 R_386_8 = 22, /* An 8-bit absolute relocation */
39 R_386_PC8 = 23 /* An 8-bit PC-relative relocation */
42 struct Reloc {
43 struct Reloc *next;
44 long address; /* relative to _start_ of section */
45 long symbol; /* ELF symbol info thingy */
46 int type; /* type of relocation */
49 struct Symbol {
50 long strpos; /* string table position of name */
51 long section; /* section ID of the symbol */
52 int type; /* symbol type */
53 long value; /* address, or COMMON variable align */
54 long size; /* size of symbol */
55 long globnum; /* symbol table offset if global */
56 struct Symbol *next; /* list of globals in each section */
57 struct Symbol *nextfwd; /* list of unresolved-size symbols */
58 char *name; /* used temporarily if in above list */
61 #define SHT_PROGBITS 1
62 #define SHT_NOBITS 8
64 #define SHF_WRITE 1
65 #define SHF_ALLOC 2
66 #define SHF_EXECINSTR 4
68 struct Section {
69 struct SAA *data;
70 unsigned long len, size, nrelocs;
71 long index;
72 int type; /* SHT_PROGBITS or SHT_NOBITS */
73 int align; /* alignment: power of two */
74 unsigned long flags; /* section flags */
75 char *name;
76 struct SAA *rel;
77 long rellen;
78 struct Reloc *head, **tail;
79 struct Symbol *gsyms; /* global symbols in section */
82 #define SECT_DELTA 32
83 static struct Section **sects;
84 static int nsects, sectlen;
86 #define SHSTR_DELTA 256
87 static char *shstrtab;
88 static int shstrtablen, shstrtabsize;
90 static struct SAA *syms;
91 static unsigned long nlocals, nglobs;
93 static long def_seg;
95 static struct RAA *bsym;
97 static struct SAA *strs;
98 static unsigned long strslen;
100 static FILE *elffp;
101 static efunc error;
102 static evalfunc evaluate;
104 static struct Symbol *fwds;
106 static char elf_module[FILENAME_MAX];
108 extern struct ofmt of_elf;
110 #define SHN_ABS 0xFFF1
111 #define SHN_COMMON 0xFFF2
112 #define SHN_UNDEF 0
114 #define SYM_SECTION 0x04
115 #define SYM_GLOBAL 0x10
116 #define SYM_DATA 0x01
117 #define SYM_FUNCTION 0x02
119 #define GLOBAL_TEMP_BASE 16 /* bigger than any constant sym id */
121 #define SEG_ALIGN 16 /* alignment of sections in file */
122 #define SEG_ALIGN_1 (SEG_ALIGN-1)
124 static const char align_str[SEG_ALIGN] = ""; /* ANSI will pad this with 0s */
126 #define ELF_MAX_SECTIONS 16 /* really 10, but let's play safe */
127 static struct ELF_SECTDATA {
128 void *data;
129 long len;
130 int is_saa;
131 } *elf_sects;
132 static int elf_nsect;
133 static long elf_foffs;
135 static void elf_write(void);
136 static void elf_sect_write(struct Section *, const unsigned char *, unsigned long);
137 static void elf_section_header (int, int, int, void *, int, long,
138 int, int, int, int);
139 static void elf_write_sections (void);
140 static struct SAA *elf_build_symtab (long *, long *);
141 static struct SAA *elf_build_reltab (long *, struct Reloc *);
142 static void add_sectname (char *, char *);
145 /* this stuff is needed for the stabs debugging format */
146 #define N_SO 0x64 /* ID for main source file */
147 #define N_SOL 0x84 /* ID for sub-source file */
148 #define N_BINCL 0x82
149 #define N_EINCL 0xA2
150 #define N_SLINE 0x44
151 #define TY_STABSSYMLIN 0x40 /* ouch */
153 struct stabentry {
154 unsigned long n_strx;
155 unsigned char n_type;
156 unsigned char n_other;
157 unsigned short n_desc;
158 unsigned long n_value;
161 struct erel {
162 int offset,info;
165 struct symlininfo {
166 int offset;
167 int section; /* section index */
168 char *name; /* shallow-copied pointer of section name */
171 struct linelist {
172 struct symlininfo info;
173 int line;
174 char *filename;
175 struct linelist * next;
176 struct linelist * last;
179 static struct linelist *stabslines=0;
180 static int stabs_immcall=0;
181 static int currentline=0;
182 static int numlinestabs=0;
183 static char * stabs_filename=0;
184 static int symtabsection;
185 static unsigned char *stabbuf=0,*stabstrbuf=0,*stabrelbuf=0;
186 static int stablen,stabstrlen,stabrellen;
188 static struct dfmt df_stabs;
190 void stabs_init(struct ofmt *,void *,FILE *,efunc );
191 void stabs_linenum(const char *filename,long linenumber,long);
192 void stabs_deflabel(char *,long ,long ,int ,char *);
193 void stabs_directive(const char *,const char *);
194 void stabs_typevalue(long );
195 void stabs_output(int ,void *);
196 void stabs_generate();
197 void stabs_cleanup();
199 /* end of stabs debugging stuff */
203 * Special section numbers which are used to define ELF special
204 * symbols, which can be used with WRT to provide PIC relocation
205 * types.
207 static long elf_gotpc_sect, elf_gotoff_sect;
208 static long elf_got_sect, elf_plt_sect;
209 static long elf_sym_sect;
211 static void elf_init(FILE *fp, efunc errfunc, ldfunc ldef, evalfunc eval)
213 elffp = fp;
214 error = errfunc;
215 evaluate = eval;
216 (void) ldef; /* placate optimisers */
217 sects = NULL;
218 nsects = sectlen = 0;
219 syms = saa_init((long)sizeof(struct Symbol));
220 nlocals = nglobs = 0;
221 bsym = raa_init();
222 strs = saa_init(1L);
223 saa_wbytes (strs, "\0", 1L);
224 saa_wbytes (strs, elf_module, (long)(strlen(elf_module)+1));
225 strslen = 2+strlen(elf_module);
226 shstrtab = NULL;
227 shstrtablen = shstrtabsize = 0;;
228 add_sectname ("", "");
230 fwds = NULL;
232 elf_gotpc_sect = seg_alloc();
233 ldef("..gotpc", elf_gotpc_sect+1, 0L, NULL, FALSE, FALSE, &of_elf, error);
234 elf_gotoff_sect = seg_alloc();
235 ldef("..gotoff", elf_gotoff_sect+1, 0L, NULL, FALSE, FALSE,&of_elf,error);
236 elf_got_sect = seg_alloc();
237 ldef("..got", elf_got_sect+1, 0L, NULL, FALSE, FALSE, &of_elf, error);
238 elf_plt_sect = seg_alloc();
239 ldef("..plt", elf_plt_sect+1, 0L, NULL, FALSE, FALSE, &of_elf, error);
240 elf_sym_sect = seg_alloc();
241 ldef("..sym", elf_sym_sect+1, 0L, NULL, FALSE, FALSE, &of_elf, error);
243 def_seg = seg_alloc();
246 static void elf_cleanup(int debuginfo)
248 struct Reloc *r;
249 int i;
251 (void) debuginfo;
253 elf_write();
254 fclose (elffp);
255 for (i=0; i<nsects; i++) {
256 if (sects[i]->type != SHT_NOBITS)
257 saa_free (sects[i]->data);
258 if (sects[i]->head)
259 saa_free (sects[i]->rel);
260 while (sects[i]->head) {
261 r = sects[i]->head;
262 sects[i]->head = sects[i]->head->next;
263 nasm_free (r);
266 nasm_free (sects);
267 saa_free (syms);
268 raa_free (bsym);
269 saa_free (strs);
270 if (of_elf.current_dfmt) {
271 of_elf.current_dfmt->cleanup();
275 static void add_sectname (char *firsthalf, char *secondhalf)
277 int len = strlen(firsthalf)+strlen(secondhalf);
278 while (shstrtablen + len + 1 > shstrtabsize)
279 shstrtab = nasm_realloc (shstrtab, (shstrtabsize += SHSTR_DELTA));
280 strcpy (shstrtab+shstrtablen, firsthalf);
281 strcat (shstrtab+shstrtablen, secondhalf);
282 shstrtablen += len+1;
285 static int elf_make_section (char *name, int type, int flags, int align)
287 struct Section *s;
289 s = nasm_malloc (sizeof(*s));
291 if (type != SHT_NOBITS)
292 s->data = saa_init (1L);
293 s->head = NULL;
294 s->tail = &s->head;
295 s->len = s->size = 0;
296 s->nrelocs = 0;
297 if (!strcmp(name, ".text"))
298 s->index = def_seg;
299 else
300 s->index = seg_alloc();
301 add_sectname ("", name);
302 s->name = nasm_malloc (1+strlen(name));
303 strcpy (s->name, name);
304 s->type = type;
305 s->flags = flags;
306 s->align = align;
307 s->gsyms = NULL;
309 if (nsects >= sectlen)
310 sects = nasm_realloc (sects, (sectlen += SECT_DELTA)*sizeof(*sects));
311 sects[nsects++] = s;
313 return nsects-1;
316 static long elf_section_names (char *name, int pass, int *bits)
318 char *p;
319 int flags_and, flags_or, type, align, i;
322 * Default is 32 bits.
324 if (!name) {
325 *bits = 32;
326 return def_seg;
329 p = name;
330 while (*p && !isspace(*p)) p++;
331 if (*p) *p++ = '\0';
332 flags_and = flags_or = type = align = 0;
334 while (*p && isspace(*p)) p++;
335 while (*p) {
336 char *q = p;
337 while (*p && !isspace(*p)) p++;
338 if (*p) *p++ = '\0';
339 while (*p && isspace(*p)) p++;
341 if (!nasm_strnicmp(q, "align=", 6)) {
342 align = atoi(q+6);
343 if (align == 0)
344 align = 1;
345 if ( (align-1) & align ) { /* means it's not a power of two */
346 error (ERR_NONFATAL, "section alignment %d is not"
347 " a power of two", align);
348 align = 1;
350 } else if (!nasm_stricmp(q, "alloc")) {
351 flags_and |= SHF_ALLOC;
352 flags_or |= SHF_ALLOC;
353 } else if (!nasm_stricmp(q, "noalloc")) {
354 flags_and |= SHF_ALLOC;
355 flags_or &= ~SHF_ALLOC;
356 } else if (!nasm_stricmp(q, "exec")) {
357 flags_and |= SHF_EXECINSTR;
358 flags_or |= SHF_EXECINSTR;
359 } else if (!nasm_stricmp(q, "noexec")) {
360 flags_and |= SHF_EXECINSTR;
361 flags_or &= ~SHF_EXECINSTR;
362 } else if (!nasm_stricmp(q, "write")) {
363 flags_and |= SHF_WRITE;
364 flags_or |= SHF_WRITE;
365 } else if (!nasm_stricmp(q, "nowrite")) {
366 flags_and |= SHF_WRITE;
367 flags_or &= ~SHF_WRITE;
368 } else if (!nasm_stricmp(q, "progbits")) {
369 type = SHT_PROGBITS;
370 } else if (!nasm_stricmp(q, "nobits")) {
371 type = SHT_NOBITS;
375 if (!strcmp(name, ".comment") ||
376 !strcmp(name, ".shstrtab") ||
377 !strcmp(name, ".symtab") ||
378 !strcmp(name, ".strtab")) {
379 error (ERR_NONFATAL, "attempt to redefine reserved section"
380 "name `%s'", name);
381 return NO_SEG;
384 for (i=0; i<nsects; i++)
385 if (!strcmp(name, sects[i]->name))
386 break;
387 if (i == nsects) {
388 if (!strcmp(name, ".text"))
389 i = elf_make_section (name, SHT_PROGBITS,
390 SHF_ALLOC | SHF_EXECINSTR, 16);
391 else if (!strcmp(name, ".rodata"))
392 i = elf_make_section (name, SHT_PROGBITS,
393 SHF_ALLOC, 4);
394 else if (!strcmp(name, ".data"))
395 i = elf_make_section (name, SHT_PROGBITS,
396 SHF_ALLOC | SHF_WRITE, 4);
397 else if (!strcmp(name, ".bss"))
398 i = elf_make_section (name, SHT_NOBITS,
399 SHF_ALLOC | SHF_WRITE, 4);
400 else
401 i = elf_make_section (name, SHT_PROGBITS, SHF_ALLOC, 1);
402 if (type)
403 sects[i]->type = type;
404 if (align)
405 sects[i]->align = align;
406 sects[i]->flags &= ~flags_and;
407 sects[i]->flags |= flags_or;
408 } else if (pass == 1) {
409 if (type || align || flags_and)
410 error (ERR_WARNING, "section attributes ignored on"
411 " redeclaration of section `%s'", name);
414 return sects[i]->index;
417 static void elf_deflabel (char *name, long segment, long offset,
418 int is_global, char *special)
420 int pos = strslen;
421 struct Symbol *sym;
422 int special_used = FALSE;
424 #if defined(DEBUG) && DEBUG>2
425 fprintf(stderr, " elf_deflabel: %s, seg=%ld, off=%ld, is_global=%d, %s\n",
426 name, segment, offset, is_global, special);
427 #endif
428 if (name[0] == '.' && name[1] == '.' && name[2] != '@') {
430 * This is a NASM special symbol. We never allow it into
431 * the ELF symbol table, even if it's a valid one. If it
432 * _isn't_ a valid one, we should barf immediately.
434 if (strcmp(name, "..gotpc") && strcmp(name, "..gotoff") &&
435 strcmp(name, "..got") && strcmp(name, "..plt") &&
436 strcmp(name, "..sym"))
437 error (ERR_NONFATAL, "unrecognised special symbol `%s'", name);
438 return;
441 if (is_global == 3) {
442 struct Symbol **s;
444 * Fix up a forward-reference symbol size from the first
445 * pass.
447 for (s = &fwds; *s; s = &(*s)->nextfwd)
448 if (!strcmp((*s)->name, name)) {
449 struct tokenval tokval;
450 expr *e;
451 char *p = special;
453 while (*p && !isspace(*p)) p++;
454 while (*p && isspace(*p)) p++;
455 stdscan_reset();
456 stdscan_bufptr = p;
457 tokval.t_type = TOKEN_INVALID;
458 e = evaluate(stdscan, NULL, &tokval, NULL, 1, error, NULL);
459 if (e) {
460 if (!is_simple(e))
461 error (ERR_NONFATAL, "cannot use relocatable"
462 " expression as symbol size");
463 else
464 (*s)->size = reloc_value(e);
468 * Remove it from the list of unresolved sizes.
470 nasm_free ((*s)->name);
471 *s = (*s)->nextfwd;
472 return;
474 return; /* it wasn't an important one */
477 saa_wbytes (strs, name, (long)(1+strlen(name)));
478 strslen += 1+strlen(name);
480 sym = saa_wstruct (syms);
482 sym->strpos = pos;
483 sym->type = is_global ? SYM_GLOBAL : 0;
484 sym->size = 0;
485 if (segment == NO_SEG)
486 sym->section = SHN_ABS;
487 else {
488 int i;
489 sym->section = SHN_UNDEF;
490 if (nsects == 0 && segment == def_seg) {
491 int tempint;
492 if (segment != elf_section_names (".text", 2, &tempint))
493 error (ERR_PANIC, "strange segment conditions in ELF driver");
494 sym->section = nsects;
495 } else {
496 for (i=0; i<nsects; i++)
497 if (segment == sects[i]->index) {
498 sym->section = i+1;
499 break;
504 if (is_global == 2) {
505 sym->size = offset;
506 sym->value = 0;
507 sym->section = SHN_COMMON;
509 * We have a common variable. Check the special text to see
510 * if it's a valid number and power of two; if so, store it
511 * as the alignment for the common variable.
513 if (special) {
514 int err;
515 sym->value = readnum (special, &err);
516 if (err)
517 error(ERR_NONFATAL, "alignment constraint `%s' is not a"
518 " valid number", special);
519 else if ( (sym->value | (sym->value-1)) != 2*sym->value - 1)
520 error(ERR_NONFATAL, "alignment constraint `%s' is not a"
521 " power of two", special);
523 special_used = TRUE;
524 } else
525 sym->value = (sym->section == SHN_UNDEF ? 0 : offset);
527 if (sym->type == SYM_GLOBAL) {
529 * There's a problem here that needs fixing.
530 * If sym->section == SHN_ABS, then the first line of the
531 * else section causes a core dump, because its a reference
532 * beyond the end of the section array.
533 * This behaviour is exhibited by this code:
534 * GLOBAL crash_nasm
535 * crash_nasm equ 0
537 * I'm not sure how to procede, because I haven't got the
538 * first clue about how ELF works, so I don't know what to
539 * do with it. Furthermore, I'm not sure what the rest of this
540 * section of code does. Help?
542 * For now, I'll see if doing absolutely nothing with it will
543 * work...
545 if (sym->section == SHN_UNDEF || sym->section == SHN_COMMON)
547 bsym = raa_write (bsym, segment, nglobs);
549 else if (sym->section != SHN_ABS)
552 * This is a global symbol; so we must add it to the linked
553 * list of global symbols in its section. We'll push it on
554 * the beginning of the list, because it doesn't matter
555 * much which end we put it on and it's easier like this.
557 * In addition, we check the special text for symbol
558 * type and size information.
560 sym->next = sects[sym->section-1]->gsyms;
561 sects[sym->section-1]->gsyms = sym;
563 if (special) {
564 int n = strcspn(special, " ");
566 if (!nasm_strnicmp(special, "function", n))
567 sym->type |= SYM_FUNCTION;
568 else if (!nasm_strnicmp(special, "data", n) ||
569 !nasm_strnicmp(special, "object", n))
570 sym->type |= SYM_DATA;
571 else
572 error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
573 n, special);
574 if (special[n]) {
575 struct tokenval tokval;
576 expr *e;
577 int fwd = FALSE;
578 char *saveme=stdscan_bufptr; /* bugfix? fbk 8/10/00 */
580 while (special[n] && isspace(special[n]))
581 n++;
583 * We have a size expression; attempt to
584 * evaluate it.
586 stdscan_reset();
587 stdscan_bufptr = special+n;
588 tokval.t_type = TOKEN_INVALID;
589 e = evaluate(stdscan, NULL, &tokval, &fwd, 0, error, NULL);
590 if (fwd) {
591 sym->nextfwd = fwds;
592 fwds = sym;
593 sym->name = nasm_strdup(name);
594 } else if (e) {
595 if (!is_simple(e))
596 error (ERR_NONFATAL, "cannot use relocatable"
597 " expression as symbol size");
598 else
599 sym->size = reloc_value(e);
601 stdscan_bufptr=saveme; /* bugfix? fbk 8/10/00 */
603 special_used = TRUE;
606 sym->globnum = nglobs;
607 nglobs++;
608 } else
609 nlocals++;
611 if (special && !special_used)
612 error(ERR_NONFATAL, "no special symbol features supported here");
615 static void elf_add_reloc (struct Section *sect, long segment,
616 int type)
618 struct Reloc *r;
620 r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
621 sect->tail = &r->next;
622 r->next = NULL;
624 r->address = sect->len;
625 if (segment == NO_SEG)
626 r->symbol = 2;
627 else {
628 int i;
629 r->symbol = 0;
630 for (i=0; i<nsects; i++)
631 if (segment == sects[i]->index)
632 r->symbol = i+3;
633 if (!r->symbol)
634 r->symbol = GLOBAL_TEMP_BASE + raa_read(bsym, segment);
636 r->type = type;
638 sect->nrelocs++;
642 * This routine deals with ..got and ..sym relocations: the more
643 * complicated kinds. In shared-library writing, some relocations
644 * with respect to global symbols must refer to the precise symbol
645 * rather than referring to an offset from the base of the section
646 * _containing_ the symbol. Such relocations call to this routine,
647 * which searches the symbol list for the symbol in question.
649 * R_386_GOT32 references require the _exact_ symbol address to be
650 * used; R_386_32 references can be at an offset from the symbol.
651 * The boolean argument `exact' tells us this.
653 * Return value is the adjusted value of `addr', having become an
654 * offset from the symbol rather than the section. Should always be
655 * zero when returning from an exact call.
657 * Limitation: if you define two symbols at the same place,
658 * confusion will occur.
660 * Inefficiency: we search, currently, using a linked list which
661 * isn't even necessarily sorted.
663 static long elf_add_gsym_reloc (struct Section *sect,
664 long segment, long offset,
665 int type, int exact)
667 struct Reloc *r;
668 struct Section *s;
669 struct Symbol *sym, *sm;
670 int i;
673 * First look up the segment/offset pair and find a global
674 * symbol corresponding to it. If it's not one of our segments,
675 * then it must be an external symbol, in which case we're fine
676 * doing a normal elf_add_reloc after first sanity-checking
677 * that the offset from the symbol is zero.
679 s = NULL;
680 for (i=0; i<nsects; i++)
681 if (segment == sects[i]->index) {
682 s = sects[i];
683 break;
685 if (!s) {
686 if (exact && offset != 0)
687 error (ERR_NONFATAL, "unable to find a suitable global symbol"
688 " for this reference");
689 else
690 elf_add_reloc (sect, segment, type);
691 return offset;
694 if (exact) {
696 * Find a symbol pointing _exactly_ at this one.
698 for (sym = s->gsyms; sym; sym = sym->next)
699 if (sym->value == offset)
700 break;
701 } else {
703 * Find the nearest symbol below this one.
705 sym = NULL;
706 for (sm = s->gsyms; sm; sm = sm->next)
707 if (sm->value <= offset && (!sym || sm->value > sym->value))
708 sym = sm;
710 if (!sym && exact) {
711 error (ERR_NONFATAL, "unable to find a suitable global symbol"
712 " for this reference");
713 return 0;
716 r = *sect->tail = nasm_malloc(sizeof(struct Reloc));
717 sect->tail = &r->next;
718 r->next = NULL;
720 r->address = sect->len;
721 r->symbol = GLOBAL_TEMP_BASE + sym->globnum;
722 r->type = type;
724 sect->nrelocs++;
726 return offset - sym->value;
729 static void elf_out (long segto, const void *data, unsigned long type,
730 long segment, long wrt)
732 struct Section *s;
733 long realbytes = type & OUT_SIZMASK;
734 long addr;
735 unsigned char mydata[4], *p;
736 int i;
737 static struct symlininfo sinfo;
739 type &= OUT_TYPMASK;
742 * handle absolute-assembly (structure definitions)
744 if (segto == NO_SEG) {
745 if (type != OUT_RESERVE)
746 error (ERR_NONFATAL, "attempt to assemble code in [ABSOLUTE]"
747 " space");
748 return;
751 s = NULL;
752 for (i=0; i<nsects; i++)
753 if (segto == sects[i]->index) {
754 s = sects[i];
755 break;
757 if (!s) {
758 int tempint; /* ignored */
759 if (segto != elf_section_names (".text", 2, &tempint))
760 error (ERR_PANIC, "strange segment conditions in ELF driver");
761 else {
762 s = sects[nsects-1];
763 i=nsects-1;
767 /* again some stabs debugging stuff */
768 if (of_elf.current_dfmt) {
769 sinfo.offset=s->len;
770 sinfo.section=i;
771 sinfo.name=s->name;
772 of_elf.current_dfmt->debug_output(TY_STABSSYMLIN,&sinfo);
774 /* end of debugging stuff */
776 if (s->type == SHT_NOBITS && type != OUT_RESERVE) {
777 error(ERR_WARNING, "attempt to initialise memory in"
778 " BSS section `%s': ignored", s->name);
779 if (type == OUT_REL2ADR)
780 realbytes = 2;
781 else if (type == OUT_REL4ADR)
782 realbytes = 4;
783 s->len += realbytes;
784 return;
787 if (type == OUT_RESERVE) {
788 if (s->type == SHT_PROGBITS) {
789 error(ERR_WARNING, "uninitialised space declared in"
790 " non-BSS section `%s': zeroing", s->name);
791 elf_sect_write (s, NULL, realbytes);
792 } else
793 s->len += realbytes;
794 } else if (type == OUT_RAWDATA) {
795 if (segment != NO_SEG)
796 error(ERR_PANIC, "OUT_RAWDATA with other than NO_SEG");
797 elf_sect_write (s, data, realbytes);
798 } else if (type == OUT_ADDRESS) {
799 int gnu16 = 0;
800 addr = *(long *)data;
801 if (segment != NO_SEG) {
802 if (segment % 2) {
803 error(ERR_NONFATAL, "ELF format does not support"
804 " segment base references");
805 } else {
806 if (wrt == NO_SEG) {
807 if ( realbytes == 2 ) {
808 gnu16 = 1;
809 elf_add_reloc (s, segment, R_386_16);
810 } else {
811 elf_add_reloc (s, segment, R_386_32);
813 } else if (wrt == elf_gotpc_sect+1) {
815 * The user will supply GOT relative to $$. ELF
816 * will let us have GOT relative to $. So we
817 * need to fix up the data item by $-$$.
819 addr += s->len;
820 elf_add_reloc (s, segment, R_386_GOTPC);
821 } else if (wrt == elf_gotoff_sect+1) {
822 elf_add_reloc (s, segment, R_386_GOTOFF);
823 } else if (wrt == elf_got_sect+1) {
824 addr = elf_add_gsym_reloc (s, segment, addr,
825 R_386_GOT32, TRUE);
826 } else if (wrt == elf_sym_sect+1) {
827 if ( realbytes == 2 ) {
828 gnu16 = 1;
829 addr = elf_add_gsym_reloc (s, segment, addr,
830 R_386_16, FALSE);
831 } else {
832 addr = elf_add_gsym_reloc (s, segment, addr,
833 R_386_32, FALSE);
835 } else if (wrt == elf_plt_sect+1) {
836 error(ERR_NONFATAL, "ELF format cannot produce non-PC-"
837 "relative PLT references");
838 } else {
839 error (ERR_NONFATAL, "ELF format does not support this"
840 " use of WRT");
841 wrt = NO_SEG; /* we can at least _try_ to continue */
845 p = mydata;
846 if (gnu16) {
847 error(ERR_WARNING|ERR_WARN_GNUELF,
848 "16-bit relocations in ELF is a GNU extension");
849 WRITESHORT (p, addr);
850 } else {
851 if (realbytes != 4 && segment != NO_SEG) {
852 error (ERR_NONFATAL, "Unsupported non-32-bit ELF relocation");
854 WRITELONG (p, addr);
856 elf_sect_write (s, mydata, realbytes);
857 } else if (type == OUT_REL2ADR) {
858 if (segment == segto)
859 error(ERR_PANIC, "intra-segment OUT_REL2ADR");
860 if (segment != NO_SEG && segment % 2) {
861 error(ERR_NONFATAL, "ELF format does not support"
862 " segment base references");
863 } else {
864 if (wrt == NO_SEG) {
865 error (ERR_WARNING|ERR_WARN_GNUELF,
866 "16-bit relocations in ELF is a GNU extension");
867 elf_add_reloc (s, segment, R_386_PC16);
868 } else {
869 error (ERR_NONFATAL, "Unsupported non-32-bit ELF relocation");
872 p = mydata;
873 WRITESHORT (p, *(long*)data - realbytes);
874 elf_sect_write (s, mydata, 2L);
875 } else if (type == OUT_REL4ADR) {
876 if (segment == segto)
877 error(ERR_PANIC, "intra-segment OUT_REL4ADR");
878 if (segment != NO_SEG && segment % 2) {
879 error(ERR_NONFATAL, "ELF format does not support"
880 " segment base references");
881 } else {
882 if (wrt == NO_SEG) {
883 elf_add_reloc (s, segment, R_386_PC32);
884 } else if (wrt == elf_plt_sect+1) {
885 elf_add_reloc (s, segment, R_386_PLT32);
886 } else if (wrt == elf_gotpc_sect+1 ||
887 wrt == elf_gotoff_sect+1 ||
888 wrt == elf_got_sect+1) {
889 error(ERR_NONFATAL, "ELF format cannot produce PC-"
890 "relative GOT references");
891 } else {
892 error (ERR_NONFATAL, "ELF format does not support this"
893 " use of WRT");
894 wrt = NO_SEG; /* we can at least _try_ to continue */
897 p = mydata;
898 WRITELONG (p, *(long*)data - realbytes);
899 elf_sect_write (s, mydata, 4L);
903 static void elf_write(void)
905 int nsections, align;
906 int scount;
907 char *p;
908 int commlen;
909 char comment[64];
910 int i;
912 struct SAA *symtab;
913 long symtablen, symtablocal;
916 * Work out how many sections we will have. We have SHN_UNDEF,
917 * then the flexible user sections, then the four fixed
918 * sections `.comment', `.shstrtab', `.symtab' and `.strtab',
919 * then optionally relocation sections for the user sections.
921 if (of_elf.current_dfmt == &df_stabs)
922 nsections=8;
923 else
924 nsections = 5; /* SHN_UNDEF and the fixed ones */
926 add_sectname ("", ".comment");
927 add_sectname ("", ".shstrtab");
928 add_sectname ("", ".symtab");
929 add_sectname ("", ".strtab");
930 for (i=0; i<nsects; i++) {
931 nsections++; /* for the section itself */
932 if (sects[i]->head) {
933 nsections++; /* for its relocations */
934 add_sectname (".rel", sects[i]->name);
938 if (of_elf.current_dfmt == &df_stabs) {
939 /* in case the debug information is wanted, just add these three sections... */
940 add_sectname("",".stab");
941 add_sectname("",".stabstr");
942 add_sectname(".rel",".stab");
946 * Do the comment.
948 *comment = '\0';
949 commlen = 2+sprintf(comment+1, "The Netwide Assembler %s", NASM_VER);
952 * Output the ELF header.
954 fwrite ("\177ELF\1\1\1\0\0\0\0\0\0\0\0\0", 16, 1, elffp);
955 fwriteshort (1, elffp); /* ET_REL relocatable file */
956 fwriteshort (3, elffp); /* EM_386 processor ID */
957 fwritelong (1L, elffp); /* EV_CURRENT file format version */
958 fwritelong (0L, elffp); /* no entry point */
959 fwritelong (0L, elffp); /* no program header table */
960 fwritelong (0x40L, elffp); /* section headers straight after
961 * ELF header plus alignment */
962 fwritelong (0L, elffp); /* 386 defines no special flags */
963 fwriteshort (0x34, elffp); /* size of ELF header */
964 fwriteshort (0, elffp); /* no program header table, again */
965 fwriteshort (0, elffp); /* still no program header table */
966 fwriteshort (0x28, elffp); /* size of section header */
967 fwriteshort (nsections, elffp); /* number of sections */
968 fwriteshort (nsects+2, elffp); /* string table section index for
969 * section header table */
970 fwritelong (0L, elffp); /* align to 0x40 bytes */
971 fwritelong (0L, elffp);
972 fwritelong (0L, elffp);
975 * Build the symbol table and relocation tables.
977 symtab = elf_build_symtab (&symtablen, &symtablocal);
978 for (i=0; i<nsects; i++)
979 if (sects[i]->head)
980 sects[i]->rel = elf_build_reltab (&sects[i]->rellen,
981 sects[i]->head);
984 * Now output the section header table.
987 elf_foffs = 0x40 + 0x28 * nsections;
988 align = ((elf_foffs+SEG_ALIGN_1) & ~SEG_ALIGN_1) - elf_foffs;
989 elf_foffs += align;
990 elf_nsect = 0;
991 elf_sects = nasm_malloc(sizeof(*elf_sects) * (2 * nsects + 10));
993 elf_section_header (0, 0, 0, NULL, FALSE, 0L, 0, 0, 0, 0); /* SHN_UNDEF */
994 scount=1; /* needed for the stabs debugging to track the symtable section */
995 p = shstrtab+1;
996 for (i=0; i<nsects; i++) {
997 elf_section_header (p - shstrtab, sects[i]->type, sects[i]->flags,
998 (sects[i]->type == SHT_PROGBITS ?
999 sects[i]->data : NULL), TRUE,
1000 sects[i]->len, 0, 0, sects[i]->align, 0);
1001 p += strlen(p)+1;
1002 scount++; /* dito */
1004 elf_section_header (p - shstrtab, 1, 0, comment, FALSE,
1005 (long)commlen, 0, 0, 1, 0);/* .comment */
1006 scount++; /* dito */
1007 p += strlen(p)+1;
1008 elf_section_header (p - shstrtab, 3, 0, shstrtab, FALSE,
1009 (long)shstrtablen, 0, 0, 1, 0);/* .shstrtab */
1010 scount++; /* dito */
1011 p += strlen(p)+1;
1012 elf_section_header (p - shstrtab, 2, 0, symtab, TRUE,
1013 symtablen, nsects+4, symtablocal, 4, 16);/* .symtab */
1014 symtabsection = scount; /* now we got the symtab section index in the ELF file */
1015 p += strlen(p)+1;
1016 elf_section_header (p - shstrtab, 3, 0, strs, TRUE,
1017 strslen, 0, 0, 1, 0); /* .strtab */
1018 for (i=0; i<nsects; i++) if (sects[i]->head) {
1019 p += strlen(p)+1;
1020 elf_section_header (p - shstrtab, 9, 0, sects[i]->rel, TRUE,
1021 sects[i]->rellen, nsects+3, i+1, 4, 8);
1023 if (of_elf.current_dfmt == &df_stabs) {
1024 /* for debugging information, create the last three sections
1025 which are the .stab , .stabstr and .rel.stab sections respectively */
1027 /* this function call creates the stab sections in memory */
1028 stabs_generate();
1030 if ((stabbuf)&&(stabstrbuf)&&(stabrelbuf)) {
1031 p += strlen(p)+1;
1032 elf_section_header(p-shstrtab,1,0,stabbuf,0,stablen,nsections-2,0,4,12);
1034 p += strlen(p)+1;
1035 elf_section_header(p-shstrtab,3,0,stabstrbuf,0,stabstrlen,0,0,4,0);
1037 p += strlen(p)+1;
1038 /* link -> symtable info -> section to refer to */
1039 elf_section_header(p-shstrtab,9,0,stabrelbuf,0,stabrellen,symtabsection,nsections-3,4,8);
1042 fwrite (align_str, align, 1, elffp);
1045 * Now output the sections.
1047 elf_write_sections();
1049 nasm_free (elf_sects);
1050 saa_free (symtab);
1053 static struct SAA *elf_build_symtab (long *len, long *local)
1055 struct SAA *s = saa_init(1L);
1056 struct Symbol *sym;
1057 unsigned char entry[16], *p;
1058 int i;
1060 *len = *local = 0;
1063 * First, an all-zeros entry, required by the ELF spec.
1065 saa_wbytes (s, NULL, 16L); /* null symbol table entry */
1066 *len += 16;
1067 (*local)++;
1070 * Next, an entry for the file name.
1072 p = entry;
1073 WRITELONG (p, 1); /* we know it's 1st thing in strtab */
1074 WRITELONG (p, 0); /* no value */
1075 WRITELONG (p, 0); /* no size either */
1076 WRITESHORT (p, 4); /* type FILE */
1077 WRITESHORT (p, SHN_ABS);
1078 saa_wbytes (s, entry, 16L);
1079 *len += 16;
1080 (*local)++;
1083 * Now some standard symbols defining the segments, for relocation
1084 * purposes.
1086 for (i = 1; i <= nsects+1; i++) {
1087 p = entry;
1088 WRITELONG (p, 0); /* no symbol name */
1089 WRITELONG (p, 0); /* offset zero */
1090 WRITELONG (p, 0); /* size zero */
1091 WRITESHORT (p, 3); /* local section-type thing */
1092 WRITESHORT (p, (i==1 ? SHN_ABS : i-1)); /* the section id */
1093 saa_wbytes (s, entry, 16L);
1094 *len += 16;
1095 (*local)++;
1099 * Now the other local symbols.
1101 saa_rewind (syms);
1102 while ( (sym = saa_rstruct (syms)) ) {
1103 if (sym->type & SYM_GLOBAL)
1104 continue;
1105 p = entry;
1106 WRITELONG (p, sym->strpos);
1107 WRITELONG (p, sym->value);
1108 WRITELONG (p, sym->size);
1109 WRITESHORT (p, sym->type); /* local non-typed thing */
1110 WRITESHORT (p, sym->section);
1111 saa_wbytes (s, entry, 16L);
1112 *len += 16;
1113 (*local)++;
1117 * Now the global symbols.
1119 saa_rewind (syms);
1120 while ( (sym = saa_rstruct (syms)) ) {
1121 if (!(sym->type & SYM_GLOBAL))
1122 continue;
1123 p = entry;
1124 WRITELONG (p, sym->strpos);
1125 WRITELONG (p, sym->value);
1126 WRITELONG (p, sym->size);
1127 WRITESHORT (p, sym->type); /* global non-typed thing */
1128 WRITESHORT (p, sym->section);
1129 saa_wbytes (s, entry, 16L);
1130 *len += 16;
1133 return s;
1136 static struct SAA *elf_build_reltab (long *len, struct Reloc *r) {
1137 struct SAA *s;
1138 unsigned char *p, entry[8];
1140 if (!r)
1141 return NULL;
1143 s = saa_init(1L);
1144 *len = 0;
1146 while (r) {
1147 long sym = r->symbol;
1149 if (sym >= GLOBAL_TEMP_BASE)
1150 sym += -GLOBAL_TEMP_BASE + (nsects+3) + nlocals;
1152 p = entry;
1153 WRITELONG (p, r->address);
1154 WRITELONG (p, (sym << 8) + r->type);
1155 saa_wbytes (s, entry, 8L);
1156 *len += 8;
1158 r = r->next;
1161 return s;
1164 static void elf_section_header (int name, int type, int flags,
1165 void *data, int is_saa, long datalen,
1166 int link, int info, int align, int eltsize)
1168 elf_sects[elf_nsect].data = data;
1169 elf_sects[elf_nsect].len = datalen;
1170 elf_sects[elf_nsect].is_saa = is_saa;
1171 elf_nsect++;
1173 fwritelong ((long)name, elffp);
1174 fwritelong ((long)type, elffp);
1175 fwritelong ((long)flags, elffp);
1176 fwritelong (0L, elffp); /* no address, ever, in object files */
1177 fwritelong (type == 0 ? 0L : elf_foffs, elffp);
1178 fwritelong (datalen, elffp);
1179 if (data)
1180 elf_foffs += (datalen+SEG_ALIGN_1) & ~SEG_ALIGN_1;
1181 fwritelong ((long)link, elffp);
1182 fwritelong ((long)info, elffp);
1183 fwritelong ((long)align, elffp);
1184 fwritelong ((long)eltsize, elffp);
1187 static void elf_write_sections (void)
1189 int i;
1190 for (i = 0; i < elf_nsect; i++)
1191 if (elf_sects[i].data) {
1192 long len = elf_sects[i].len;
1193 long reallen = (len+SEG_ALIGN_1) & ~SEG_ALIGN_1;
1194 long align = reallen - len;
1195 if (elf_sects[i].is_saa)
1196 saa_fpwrite (elf_sects[i].data, elffp);
1197 else
1198 fwrite (elf_sects[i].data, len, 1, elffp);
1199 fwrite (align_str, align, 1, elffp);
1203 static void elf_sect_write (struct Section *sect,
1204 const unsigned char *data, unsigned long len)
1206 saa_wbytes (sect->data, data, len);
1207 sect->len += len;
1210 static long elf_segbase (long segment)
1212 return segment;
1215 static int elf_directive (char *directive, char *value, int pass)
1217 return 0;
1220 static void elf_filename (char *inname, char *outname, efunc error)
1222 strcpy(elf_module, inname);
1223 standard_extension (inname, outname, ".o", error);
1226 static const char *elf_stdmac[] = {
1227 "%define __SECT__ [section .text]",
1228 "%macro __NASM_CDecl__ 1",
1229 "%define $_%1 $%1",
1230 "%endmacro",
1231 NULL
1233 static int elf_set_info(enum geninfo type, char **val)
1235 return 0;
1238 static struct dfmt df_stabs = {
1239 "ELF32 (i386) stabs debug format for Linux",
1240 "stabs",
1241 stabs_init,
1242 stabs_linenum,
1243 stabs_deflabel,
1244 stabs_directive,
1245 stabs_typevalue,
1246 stabs_output,
1247 stabs_cleanup
1250 struct dfmt *elf_debugs_arr[2]={&df_stabs,NULL};
1252 struct ofmt of_elf = {
1253 "ELF32 (i386) object files (e.g. Linux)",
1254 "elf",
1255 NULL,
1256 elf_debugs_arr,
1257 &null_debug_form,
1258 elf_stdmac,
1259 elf_init,
1260 elf_set_info,
1261 elf_out,
1262 elf_deflabel,
1263 elf_section_names,
1264 elf_segbase,
1265 elf_directive,
1266 elf_filename,
1267 elf_cleanup
1270 /* again, the stabs debugging stuff (code) */
1272 void stabs_init(struct ofmt *of,void *id,FILE *fp,efunc error)
1276 void stabs_linenum(const char *filename,long linenumber,long segto)
1278 if (!stabs_filename) {
1279 stabs_filename = (char *)nasm_malloc(strlen(filename)+1);
1280 strcpy(stabs_filename,filename);
1281 } else {
1282 if (strcmp(stabs_filename,filename)) {
1283 /* yep, a memory leak...this program is one-shot anyway, so who cares...
1284 in fact, this leak comes in quite handy to maintain a list of files
1285 encountered so far in the symbol lines... */
1287 /* why not nasm_free(stabs_filename); we're done with the old one */
1289 stabs_filename = (char *)nasm_malloc(strlen(filename)+1);
1290 strcpy(stabs_filename,filename);
1293 stabs_immcall=1;
1294 currentline=linenumber;
1297 void stabs_deflabel(char *name,long segment,long offset,int is_global,char *special)
1301 void stabs_directive(const char *directive,const char *params)
1305 void stabs_typevalue(long type)
1309 void stabs_output(int type,void *param)
1311 struct symlininfo *s;
1312 struct linelist *el;
1313 if (type==TY_STABSSYMLIN) {
1314 if (stabs_immcall) {
1315 s=(struct symlininfo *)param;
1316 if (strcmp( s->name,".text")) return; /* we are only interested in the text stuff */
1317 numlinestabs++;
1318 el=(struct linelist *)nasm_malloc(sizeof(struct linelist));
1319 el->info.offset=s->offset;
1320 el->info.section=s->section;
1321 el->info.name=s->name;
1322 el->line=currentline;
1323 el->filename=stabs_filename;
1324 el->next=0;
1325 if (stabslines) {
1326 stabslines->last->next=el;
1327 stabslines->last=el;
1328 } else {
1329 stabslines=el;
1330 stabslines->last=el;
1334 stabs_immcall=0;
1337 #define WRITE_STAB(p,n_strx,n_type,n_other,n_desc,n_value) \
1338 do {\
1339 WRITELONG(p,n_strx); \
1340 WRITECHAR(p,n_type); \
1341 WRITECHAR(p,n_other); \
1342 WRITESHORT(p,n_desc); \
1343 WRITELONG(p,n_value); \
1344 } while (0)
1346 /* for creating the .stab , .stabstr and .rel.stab sections in memory */
1348 void stabs_generate(void)
1350 int i,numfiles,strsize,numstabs=0,currfile,mainfileindex;
1351 unsigned char *sbuf,*ssbuf,*rbuf,*sptr,*rptr;
1352 char **allfiles;
1353 int *fileidx;
1355 struct linelist *ptr;
1357 ptr=stabslines;
1359 allfiles = (char **)nasm_malloc(numlinestabs*sizeof(char *));
1360 for (i=0;i<numlinestabs;i++) allfiles[i]=0;
1361 numfiles=0;
1362 while (ptr) {
1363 if (numfiles==0) {
1364 allfiles[0]=ptr->filename;
1365 numfiles++;
1366 } else {
1367 for (i=0;i<numfiles;i++) {
1368 if (!strcmp(allfiles[i],ptr->filename)) break;
1370 if (i>=numfiles) {
1371 allfiles[i]=ptr->filename;
1372 numfiles++;
1375 ptr=ptr->next;
1377 strsize=1;
1378 fileidx = (int *)nasm_malloc(numfiles*sizeof(int));
1379 for (i=0;i<numfiles;i++) {
1380 fileidx[i]=strsize;
1381 strsize+=strlen(allfiles[i])+1;
1383 mainfileindex=0;
1384 for (i=0;i<numfiles;i++) {
1385 if (!strcmp(allfiles[i],elf_module)) {
1386 mainfileindex=i;
1387 break;
1392 /* worst case size of the stab buffer would be:
1393 the sourcefiles changes each line, which would mean 1 SOL, 1 SYMLIN per line
1395 sbuf = (unsigned char *)nasm_malloc((numlinestabs*2+3)*sizeof(struct stabentry));
1397 ssbuf = (unsigned char *)nasm_malloc(strsize);
1399 rbuf = (unsigned char *)nasm_malloc(numlinestabs*8*(2+3));
1400 rptr=rbuf;
1402 for (i=0;i<numfiles;i++) {
1403 strcpy((char *)ssbuf+fileidx[i],allfiles[i]);
1405 ssbuf[0]=0;
1407 stabstrlen = strsize; /* set global variable for length of stab strings */
1409 sptr=sbuf;
1410 /* this is the first stab, its strx points to the filename of the
1411 the source-file, the n_desc field should be set to the number
1412 of remaining stabs
1414 WRITE_STAB(sptr, fileidx[0], 0, 0, 0, strlen(allfiles[0]+12));
1416 ptr=stabslines;
1417 numstabs = 0;
1419 if ( ptr ) {
1420 /* this is the stab for the main source file */
1421 WRITE_STAB(sptr, fileidx[mainfileindex], N_SO, 0, 0, 0);
1423 /* relocation stuff */
1424 /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
1425 WRITELONG(rptr, (sptr-sbuf)-4);
1426 WRITELONG(rptr, ((ptr->info.section+3)<<8)|R_386_32);
1428 numstabs++;
1429 currfile=mainfileindex;
1432 while (ptr) {
1433 if (strcmp(allfiles[currfile],ptr->filename)) {
1434 /* oops file has changed... */
1435 for (i=0;i<numfiles;i++) if (!strcmp(allfiles[i],ptr->filename)) break;
1436 currfile=i;
1437 WRITE_STAB(sptr,fileidx[currfile],N_SOL,0,0,ptr->info.offset);
1438 numstabs++;
1440 /* relocation stuff */
1441 /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
1442 WRITELONG(rptr, (sptr-sbuf)-4);
1443 WRITELONG(rptr, ((ptr->info.section+3)<<8)|R_386_32);
1446 WRITE_STAB(sptr,0,N_SLINE,0,ptr->line,ptr->info.offset);
1447 numstabs++;
1449 /* relocation stuff */
1450 /* IS THIS SANE? WHAT DOES SECTION+3 MEAN HERE? */
1451 WRITELONG(rptr, (sptr-sbuf)-4);
1452 WRITELONG(rptr, ((ptr->info.section+3)<<8)|R_386_32);
1454 ptr=ptr->next;
1459 ((struct stabentry *)sbuf)->n_desc=numstabs;
1461 nasm_free(allfiles);
1462 nasm_free(fileidx);
1464 stablen = (sptr-sbuf);
1465 stabrellen=(rptr-rbuf);
1466 stabrelbuf= rbuf;
1467 stabbuf = sbuf;
1468 stabstrbuf = ssbuf;
1471 void stabs_cleanup() {
1472 struct linelist *ptr,*del;
1473 if (!stabslines) return;
1474 ptr=stabslines;
1475 while (ptr) {
1476 del=ptr;
1477 ptr=ptr->next;
1478 nasm_free(del);
1480 if (stabbuf) nasm_free(stabbuf);
1481 if (stabrelbuf) nasm_free(stabrelbuf);
1482 if (stabstrbuf) nasm_free(stabstrbuf);
1485 #endif /* OF_ELF */