Add a generic pragma-handling infrastructure
[nasm.git] / output / codeview.c
blob579ac8d6671cbd1f059220347d6dd319d429e014
1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2017 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
9 * conditions are met:
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 * codeview.c Codeview Debug Format support for COFF
38 #include "version.h"
39 #include "compiler.h"
41 #include <stdio.h>
42 #include <stddef.h>
43 #include <stdlib.h>
45 #include "nasm.h"
46 #include "nasmlib.h"
47 #include "error.h"
48 #include "preproc.h"
49 #include "saa.h"
50 #include "hashtbl.h"
51 #include "outlib.h"
52 #include "pecoff.h"
53 #include "md5.h"
55 static void cv8_init(void);
56 static void cv8_linenum(const char *filename, int32_t linenumber,
57 int32_t segto);
58 static void cv8_deflabel(char *name, int32_t segment, int64_t offset,
59 int is_global, char *special);
60 static void cv8_typevalue(int32_t type);
61 static void cv8_output(int type, void *param);
62 static void cv8_cleanup(void);
64 const struct dfmt df_cv8 = {
65 "Codeview 8", /* .fullname */
66 "cv8", /* .shortname */
67 cv8_init, /* .init */
68 cv8_linenum, /* .linenum */
69 cv8_deflabel, /* .debug_deflabel */
70 null_debug_directive, /* .debug_directive */
71 cv8_typevalue, /* .debug_typevalue */
72 cv8_output, /* .debug_output */
73 cv8_cleanup, /* .cleanup */
74 NULL /* pragma list */
77 /*******************************************************************************
78 * dfmt callbacks
79 ******************************************************************************/
80 struct source_file;
82 struct source_file {
83 const char *filename;
84 char *fullname;
85 uint32_t fullnamelen;
87 struct source_file *next;
89 uint32_t filetbl_off;
90 uint32_t sourcetbl_off;
92 struct SAA *lines;
93 uint32_t num_lines;
95 unsigned char md5sum[MD5_HASHBYTES];
98 struct linepair {
99 uint32_t file_offset;
100 uint32_t linenumber;
103 enum symbol_type {
104 SYMTYPE_CODE,
105 SYMTYPE_PROC,
106 SYMTYPE_LDATA,
107 SYMTYPE_GDATA,
109 SYMTYPE_MAX
112 struct cv8_symbol {
113 enum symbol_type type;
114 char *name;
116 uint32_t secrel;
117 uint16_t section;
118 uint32_t size;
119 uint32_t typeindex;
121 enum symtype {
122 TYPE_UNREGISTERED = 0x0000, /* T_NOTYPE */
123 TYPE_BYTE = 0x0020,
124 TYPE_WORD = 0x0021,
125 TYPE_DWORD= 0x0022,
126 TYPE_QUAD = 0x0023,
128 TYPE_REAL32 = 0x0040,
129 TYPE_REAL64 = 0x0041,
130 TYPE_REAL80 = 0x0042,
131 TYPE_REAL128= 0x0043,
132 TYPE_REAL256= 0x0044,
133 TYPE_REAL512= 0x0045
134 } symtype;
137 struct cv8_state {
138 int symbol_sect;
139 int type_sect;
141 uint32_t text_offset;
143 struct source_file *source_files, **source_files_tail;
144 const char *last_filename;
145 struct source_file *last_source_file;
146 struct hash_table file_hash;
147 unsigned num_files;
148 uint32_t total_filename_len;
151 unsigned total_lines;
153 struct SAA *symbols;
154 struct cv8_symbol *last_sym;
155 unsigned num_syms[SYMTYPE_MAX];
156 unsigned symbol_lengths;
157 unsigned total_syms;
159 struct {
160 char *name;
161 size_t namebytes;
162 } outfile;
164 struct cv8_state cv8_state;
166 static void cv8_init(void)
168 const uint32_t sect_flags = IMAGE_SCN_MEM_READ |
169 IMAGE_SCN_MEM_DISCARDABLE |
170 IMAGE_SCN_CNT_INITIALIZED_DATA |
171 IMAGE_SCN_ALIGN_1BYTES;
173 cv8_state.symbol_sect = coff_make_section(".debug$S", sect_flags);
174 cv8_state.type_sect = coff_make_section(".debug$T", sect_flags);
176 cv8_state.text_offset = 0;
178 cv8_state.source_files = NULL;
179 cv8_state.source_files_tail = &cv8_state.source_files;
180 hash_init(&cv8_state.file_hash, HASH_MEDIUM);
182 cv8_state.num_files = 0;
183 cv8_state.total_filename_len = 0;
185 cv8_state.total_lines = 0;
187 cv8_state.symbols = saa_init(sizeof(struct cv8_symbol));
188 cv8_state.last_sym = NULL;
191 static struct source_file *register_file(const char *filename);
192 static struct coff_Section *find_section(int32_t segto);
194 static void cv8_linenum(const char *filename, int32_t linenumber,
195 int32_t segto)
197 struct coff_Section *s;
198 struct linepair *li;
199 struct source_file *file;
201 file = register_file(filename);
203 s = find_section(segto);
204 if (s == NULL)
205 return;
207 if ((s->flags & IMAGE_SCN_MEM_EXECUTE) == 0)
208 return;
210 li = saa_wstruct(file->lines);
211 li->file_offset = cv8_state.text_offset;
212 li->linenumber = linenumber;
214 file->num_lines++;
215 cv8_state.total_lines++;
218 static void cv8_deflabel(char *name, int32_t segment, int64_t offset,
219 int is_global, char *special)
221 struct cv8_symbol *sym;
222 struct coff_Section *s;
224 (void)special;
226 s = find_section(segment);
227 if (s == NULL)
228 return;
230 sym = saa_wstruct(cv8_state.symbols);
232 if (s->flags & IMAGE_SCN_MEM_EXECUTE)
233 sym->type = is_global ? SYMTYPE_PROC : SYMTYPE_CODE;
234 else
235 sym->type = is_global ? SYMTYPE_GDATA : SYMTYPE_LDATA;
236 cv8_state.num_syms[sym->type]++;
237 cv8_state.total_syms++;
239 sym->section = segment;
240 sym->secrel = offset;
241 sym->symtype = TYPE_UNREGISTERED;
242 sym->size = 0;
243 sym->typeindex = 0;
245 sym->name = nasm_strdup(name);
246 cv8_state.symbol_lengths += strlen(sym->name) + 1;
248 if (cv8_state.last_sym && cv8_state.last_sym->section == segment)
249 cv8_state.last_sym->size = offset - cv8_state.last_sym->secrel;
250 cv8_state.last_sym = sym;
253 static void cv8_typevalue(int32_t type)
255 if (!cv8_state.last_sym)
256 return;
257 if (cv8_state.last_sym->symtype != TYPE_UNREGISTERED)
258 return;
260 switch (TYM_TYPE(type)) {
261 case TY_BYTE:
262 cv8_state.last_sym->symtype = TYPE_BYTE;
263 break;
264 case TY_WORD:
265 cv8_state.last_sym->symtype = TYPE_WORD;
266 break;
267 case TY_DWORD:
268 cv8_state.last_sym->symtype = TYPE_DWORD;
269 break;
270 case TY_QWORD:
271 cv8_state.last_sym->symtype = TYPE_QUAD;
272 break;
273 case TY_FLOAT:
274 cv8_state.last_sym->symtype = TYPE_REAL32;
275 break;
276 case TY_TBYTE:
277 cv8_state.last_sym->symtype = TYPE_REAL80;
278 break;
279 case TY_OWORD:
280 cv8_state.last_sym->symtype = TYPE_REAL128;
281 break;
282 case TY_YWORD:
283 cv8_state.last_sym->symtype = TYPE_REAL256;
284 break;
285 case TY_UNKNOWN:
286 break;
287 case TY_LABEL:
288 break;
292 static void cv8_output(int type, void *param)
294 struct coff_DebugInfo *dinfo = param;
296 (void)type;
298 if (dinfo->section && dinfo->section->name &&
299 !strncmp(dinfo->section->name, ".text", 5))
300 cv8_state.text_offset += dinfo->size;
303 static void build_symbol_table(struct coff_Section *const sect);
304 static void build_type_table(struct coff_Section *const sect);
306 static void cv8_cleanup(void)
308 struct cv8_symbol *sym;
309 struct source_file *file;
311 struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect];
312 struct coff_Section *type_sect = coff_sects[cv8_state.type_sect];
314 cv8_state.outfile.name = nasm_realpath(coff_outfile);
315 cv8_state.outfile.namebytes = strlen(cv8_state.outfile.name) + 1;
317 build_symbol_table(symbol_sect);
318 build_type_table(type_sect);
320 list_for_each(file, cv8_state.source_files) {
321 nasm_free(file->fullname);
322 saa_free(file->lines);
323 free(file);
325 hash_free(&cv8_state.file_hash);
327 saa_rewind(cv8_state.symbols);
328 while ((sym = saa_rstruct(cv8_state.symbols)))
329 nasm_free(sym->name);
330 saa_free(cv8_state.symbols);
332 nasm_free(cv8_state.outfile.name);
335 /*******************************************************************************
336 * implementation
337 ******************************************************************************/
338 static void calc_md5(const char *const filename,
339 unsigned char sum[MD5_HASHBYTES])
341 int success = 0;
342 unsigned char *file_buf;
343 FILE *f;
344 MD5_CTX ctx;
346 f = pp_input_fopen(filename, NF_BINARY);
347 if (!f)
348 goto done;
350 file_buf = nasm_zalloc(BUFSIZ);
352 MD5Init(&ctx);
353 while (!feof(f)) {
354 size_t i = fread(file_buf, 1, BUFSIZ, f);
355 if (ferror(f))
356 goto done_0;
357 else if (i == 0)
358 break;
359 MD5Update(&ctx, file_buf, i);
361 MD5Final(sum, &ctx);
363 success = 1;
364 done_0:
365 nasm_free(file_buf);
366 fclose(f);
367 done:
368 if (!success) {
369 nasm_error(ERR_NONFATAL, "unable to hash file %s. "
370 "Debug information may be unavailable.\n",
371 filename);
373 return;
376 static struct source_file *register_file(const char *filename)
378 struct source_file *file;
379 void **filep;
380 char *fullpath;
381 struct hash_insert hi;
384 * The common case is that we are invoked with the same filename
385 * as we were last time. Make this a pointer comparison: this is
386 * safe because the NASM core code allocates each filename once
387 * and never frees it.
389 if (likely(cv8_state.last_filename == filename))
390 return cv8_state.last_source_file;
392 cv8_state.last_filename = filename;
394 filep = hash_find(&cv8_state.file_hash, filename, &hi);
395 if (likely(filep)) {
396 file = *filep;
397 } else {
398 /* New filename encounter */
400 fullpath = nasm_realpath(filename);
402 file = nasm_zalloc(sizeof(*file));
404 file->filename = filename;
405 file->fullname = fullpath;
406 file->fullnamelen = strlen(fullpath);
407 file->lines = saa_init(sizeof(struct linepair));
408 *cv8_state.source_files_tail = file;
409 cv8_state.source_files_tail = &file->next;
410 calc_md5(fullpath, file->md5sum);
412 hash_add(&hi, filename, file);
414 cv8_state.num_files++;
415 cv8_state.total_filename_len += file->fullnamelen + 1;
418 cv8_state.last_source_file = file;
419 return file;
422 static struct coff_Section *find_section(int32_t segto)
424 int i;
426 for (i = 0; i < coff_nsects; i++) {
427 struct coff_Section *sec;
429 sec = coff_sects[i];
430 if (segto == sec->index)
431 return sec;
433 return NULL;
436 static void register_reloc(struct coff_Section *const sect,
437 char *sym, uint32_t addr, uint16_t type)
439 struct coff_Reloc *r;
440 struct coff_Section *sec;
441 uint32_t i;
443 r = *sect->tail = nasm_malloc(sizeof(struct coff_Reloc));
444 sect->tail = &r->next;
445 r->next = NULL;
446 sect->nrelocs++;
448 r->address = addr;
449 r->symbase = SECT_SYMBOLS;
450 r->type = type;
452 r->symbol = 0;
453 for (i = 0; i < (uint32_t)coff_nsects; i++) {
454 sec = coff_sects[i];
455 if (!strcmp(sym, sec->name)) {
456 return;
458 r->symbol += 2;
461 saa_rewind(coff_syms);
462 for (i = 0; i < coff_nsyms; i++) {
463 struct coff_Symbol *s = saa_rstruct(coff_syms);
464 r->symbol++;
465 if (s->strpos == -1 && !strcmp(sym, s->name)) {
466 return;
467 } else if (s->strpos != -1) {
468 int res;
469 char *symname;
471 symname = nasm_malloc(s->namlen + 1);
472 saa_fread(coff_strs, s->strpos-4, symname, s->namlen);
473 symname[s->namlen] = '\0';
474 res = strcmp(sym, symname);
475 nasm_free(symname);
476 if (!res)
477 return;
480 nasm_panic(0, "codeview: relocation for unregistered symbol: %s", sym);
483 static inline void section_write32(struct coff_Section *sect, uint32_t val)
485 saa_write32(sect->data, val);
486 sect->len += 4;
489 static inline void section_write16(struct coff_Section *sect, uint16_t val)
491 saa_write16(sect->data, val);
492 sect->len += 2;
495 static inline void section_write8(struct coff_Section *sect, uint8_t val)
497 saa_write8(sect->data, val);
498 sect->len++;
501 static inline void section_wbytes(struct coff_Section *sect, const void *buf,
502 size_t len)
504 saa_wbytes(sect->data, buf, len);
505 sect->len += len;
508 static void write_filename_table(struct coff_Section *const sect)
510 uint32_t field_length;
511 uint32_t tbl_off = 1; /* offset starts at 1 to skip NULL entry */
512 struct source_file *file;
514 nasm_assert(cv8_state.source_files != NULL);
515 nasm_assert(cv8_state.num_files > 0);
516 nasm_assert(cv8_state.total_filename_len > 0);
518 field_length = 1 + cv8_state.total_filename_len;
520 section_write32(sect, 0x000000F3);
521 section_write32(sect, field_length);
523 section_write8(sect, 0);
525 list_for_each(file, cv8_state.source_files) {
526 section_wbytes(sect, file->fullname, file->fullnamelen + 1);
527 file->filetbl_off = tbl_off;
528 tbl_off += file->fullnamelen + 1;
532 static void write_sourcefile_table(struct coff_Section *const sect)
534 const uint32_t entry_size = 4 + 2 + MD5_HASHBYTES + 2;
536 uint32_t field_length = 0;
537 uint32_t tbl_off = 0;
538 struct source_file *file;
540 field_length = entry_size * cv8_state.num_files;
542 section_write32(sect, 0x000000F4);
543 section_write32(sect, field_length);
545 list_for_each(file, cv8_state.source_files) {
546 nasm_assert(file->filetbl_off > 0);
547 section_write32(sect, file->filetbl_off);
548 section_write16(sect, 0x0110);
549 section_wbytes(sect, file->md5sum, MD5_HASHBYTES);
550 section_write16(sect, 0);
552 file->sourcetbl_off = tbl_off;
553 tbl_off += entry_size;
557 static void write_linenumber_table(struct coff_Section *const sect)
559 const uint32_t file_field_len = 12;
560 const uint32_t line_field_len = 8;
562 int i;
563 uint32_t field_length = 0;
564 size_t field_base;
565 struct source_file *file;
566 struct coff_Section *s;
568 for (i = 0; i < coff_nsects; i++) {
569 if (!strncmp(coff_sects[i]->name, ".text", 5))
570 break;
573 if (i == coff_nsects)
574 return;
575 s = coff_sects[i];
577 field_length = 12;
578 field_length += (cv8_state.num_files * file_field_len);
579 field_length += (cv8_state.total_lines * line_field_len);
581 section_write32(sect, 0x000000F2);
582 section_write32(sect, field_length);
584 field_base = sect->len;
585 section_write32(sect, 0); /* SECREL, updated by relocation */
586 section_write16(sect, 0); /* SECTION, updated by relocation*/
587 section_write16(sect, 0); /* pad */
588 section_write32(sect, s->len);
590 register_reloc(sect, ".text", field_base,
591 win64 ? IMAGE_REL_AMD64_SECREL : IMAGE_REL_I386_SECREL);
593 register_reloc(sect, ".text", field_base + 4,
594 win64 ? IMAGE_REL_AMD64_SECTION : IMAGE_REL_I386_SECTION);
596 list_for_each(file, cv8_state.source_files) {
597 struct linepair *li;
599 /* source mapping */
600 section_write32(sect, file->sourcetbl_off);
601 section_write32(sect, file->num_lines);
602 section_write32(sect, file_field_len + (file->num_lines * line_field_len));
604 /* the pairs */
605 saa_rewind(file->lines);
606 while ((li = saa_rstruct(file->lines))) {
607 section_write32(sect, li->file_offset);
608 section_write32(sect, li->linenumber |= 0x80000000);
613 static uint16_t write_symbolinfo_obj(struct coff_Section *sect)
615 uint16_t obj_len;
617 obj_len = 2 + 4 + cv8_state.outfile.namebytes;
619 section_write16(sect, obj_len);
620 section_write16(sect, 0x1101);
621 section_write32(sect, 0); /* ASM language */
622 section_wbytes(sect, cv8_state.outfile.name, cv8_state.outfile.namebytes);
624 return obj_len;
627 static uint16_t write_symbolinfo_properties(struct coff_Section *sect,
628 const char *const creator_str)
630 /* https://github.com/Microsoft/microsoft-pdb/blob/1d60e041/include/cvinfo.h#L3313 */
631 uint16_t creator_len;
633 creator_len = 2 + 4 + 2 + 3*2 + 3*2 + strlen(creator_str)+1 + 2;
635 section_write16(sect, creator_len);
636 section_write16(sect, 0x1116);
637 section_write32(sect, 3); /* language/flags */
638 if (win64)
639 section_write16(sect, 0x00D0); /* machine */
640 else if (win32)
641 section_write16(sect, 0x0006); /* machine */
642 else
643 nasm_assert(!"neither win32 nor win64 are set!");
644 section_write16(sect, 0); /* verFEMajor */
645 section_write16(sect, 0); /* verFEMinor */
646 section_write16(sect, 0); /* verFEBuild */
648 /* BinScope/WACK insist on version >= 8.0.50727 */
649 section_write16(sect, 8); /* verMajor */
650 section_write16(sect, 0); /* verMinor */
651 section_write16(sect, 50727); /* verBuild */
653 section_wbytes(sect, creator_str, strlen(creator_str)+1); /* verSt */
655 * normally there would be key/value pairs here, but they aren't
656 * necessary. They are terminated by 2B
658 section_write16(sect, 0);
660 return creator_len;
663 static uint16_t write_symbolinfo_symbols(struct coff_Section *sect)
665 uint16_t len = 0, field_len;
666 uint32_t field_base;
667 struct cv8_symbol *sym;
669 saa_rewind(cv8_state.symbols);
670 while ((sym = saa_rstruct(cv8_state.symbols))) {
671 switch (sym->type) {
672 case SYMTYPE_LDATA:
673 case SYMTYPE_GDATA:
674 field_len = 12 + strlen(sym->name) + 1;
675 len += field_len - 2;
676 section_write16(sect, field_len);
677 if (sym->type == SYMTYPE_LDATA)
678 section_write16(sect, 0x110C);
679 else
680 section_write16(sect, 0x110D);
681 section_write32(sect, sym->symtype);
683 field_base = sect->len;
684 section_write32(sect, 0); /* SECREL */
685 section_write16(sect, 0); /* SECTION */
686 break;
687 case SYMTYPE_PROC:
688 case SYMTYPE_CODE:
689 field_len = 9 + strlen(sym->name) + 1;
690 len += field_len - 2;
691 section_write16(sect, field_len);
692 section_write16(sect, 0x1105);
694 field_base = sect->len;
695 section_write32(sect, 0); /* SECREL */
696 section_write16(sect, 0); /* SECTION */
697 section_write8(sect, 0); /* FLAG */
698 break;
699 default:
700 nasm_assert(!"unknown symbol type");
703 section_wbytes(sect, sym->name, strlen(sym->name) + 1);
705 register_reloc(sect, sym->name, field_base,
706 win64 ? IMAGE_REL_AMD64_SECREL :
707 IMAGE_REL_I386_SECREL);
708 register_reloc(sect, sym->name, field_base + 4,
709 win64 ? IMAGE_REL_AMD64_SECTION :
710 IMAGE_REL_I386_SECTION);
713 return len;
716 static void write_symbolinfo_table(struct coff_Section *const sect)
718 static const char creator_str[] = "The Netwide Assembler " NASM_VER;
719 uint16_t obj_length, creator_length, sym_length;
720 uint32_t field_length = 0, out_len;
722 nasm_assert(cv8_state.outfile.namebytes);
724 /* signature, language, outfile NULL */
725 obj_length = 2 + 4 + cv8_state.outfile.namebytes;
726 creator_length = 2 + 4 + 2 + 3*2 + 3*2 + strlen(creator_str)+1 + 2;
728 sym_length = ( cv8_state.num_syms[SYMTYPE_CODE] * 7) +
729 ( cv8_state.num_syms[SYMTYPE_PROC] * 7) +
730 ( cv8_state.num_syms[SYMTYPE_LDATA] * 10) +
731 ( cv8_state.num_syms[SYMTYPE_GDATA] * 10) +
732 cv8_state.symbol_lengths;
734 field_length = 2 + obj_length +
735 2 + creator_length +
736 (4 * cv8_state.total_syms) + sym_length;
738 section_write32(sect, 0x000000F1);
739 section_write32(sect, field_length);
741 /* for sub fields, length preceeds type */
743 out_len = write_symbolinfo_obj(sect);
744 nasm_assert(out_len == obj_length);
746 out_len = write_symbolinfo_properties(sect, creator_str);
747 nasm_assert(out_len == creator_length);
749 out_len = write_symbolinfo_symbols(sect);
750 nasm_assert(out_len == sym_length);
753 static inline void align4_table(struct coff_Section *const sect)
755 unsigned diff;
756 uint32_t zero = 0;
757 struct SAA *data = sect->data;
759 if (data->wptr % 4 == 0)
760 return;
762 diff = 4 - (data->wptr % 4);
763 if (diff)
764 section_wbytes(sect, &zero, diff);
767 static void build_symbol_table(struct coff_Section *const sect)
769 section_write32(sect, 0x00000004);
771 write_filename_table(sect);
772 align4_table(sect);
773 write_sourcefile_table(sect);
774 align4_table(sect);
775 write_linenumber_table(sect);
776 align4_table(sect);
777 write_symbolinfo_table(sect);
778 align4_table(sect);
781 static void build_type_table(struct coff_Section *const sect)
783 uint16_t field_len;
784 struct cv8_symbol *sym;
786 section_write32(sect, 0x00000004);
788 saa_rewind(cv8_state.symbols);
789 while ((sym = saa_rstruct(cv8_state.symbols))) {
790 if (sym->type != SYMTYPE_PROC)
791 continue;
793 /* proc leaf */
795 field_len = 2 + 4 + 4 + 4 + 2;
796 section_write16(sect, field_len);
797 section_write16(sect, 0x1008); /* PROC type */
799 section_write32(sect, 0x00000003); /* return type */
800 section_write32(sect, 0); /* calling convention (default) */
801 section_write32(sect, sym->typeindex);
802 section_write16(sect, 0); /* # params */
804 /* arglist */
806 field_len = 2 + 4;
807 section_write16(sect, field_len);
808 section_write16(sect, 0x1201); /* ARGLIST */
809 section_write32(sect, 0); /*num params */