openwcom.mak: BR 3392381: update to work for the current master
[nasm.git] / output / codeview.c
blob6962eabaff54b4883eb4ea47528a6a8f92840615
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 "preproc.h"
48 #include "saa.h"
49 #include "hashtbl.h"
50 #include "outlib.h"
51 #include "pecoff.h"
52 #include "md5.h"
54 static void cv8_init(void);
55 static void cv8_linenum(const char *filename, int32_t linenumber,
56 int32_t segto);
57 static void cv8_deflabel(char *name, int32_t segment, int64_t offset,
58 int is_global, char *special);
59 static void cv8_typevalue(int32_t type);
60 static void cv8_output(int type, void *param);
61 static void cv8_cleanup(void);
63 const struct dfmt df_cv8 = {
64 "Codeview 8", /* .fullname */
65 "cv8", /* .shortname */
66 cv8_init, /* .init */
67 cv8_linenum, /* .linenum */
68 cv8_deflabel, /* .debug_deflabel */
69 null_debug_directive, /* .debug_directive */
70 cv8_typevalue, /* .debug_typevalue */
71 cv8_output, /* .debug_output */
72 cv8_cleanup, /* .cleanup */
75 /*******************************************************************************
76 * dfmt callbacks
77 ******************************************************************************/
78 struct source_file;
80 struct source_file {
81 const char *filename;
82 char *fullname;
83 uint32_t fullnamelen;
85 struct source_file *next;
87 uint32_t filetbl_off;
88 uint32_t sourcetbl_off;
90 struct SAA *lines;
91 uint32_t num_lines;
93 unsigned char md5sum[MD5_HASHBYTES];
96 struct linepair {
97 uint32_t file_offset;
98 uint32_t linenumber;
101 enum symbol_type {
102 SYMTYPE_CODE,
103 SYMTYPE_PROC,
104 SYMTYPE_LDATA,
105 SYMTYPE_GDATA,
107 SYMTYPE_MAX
110 struct cv8_symbol {
111 enum symbol_type type;
112 char *name;
114 uint32_t secrel;
115 uint16_t section;
116 uint32_t size;
117 uint32_t typeindex;
119 enum symtype {
120 TYPE_UNREGISTERED = 0x0000, /* T_NOTYPE */
121 TYPE_BYTE = 0x0020,
122 TYPE_WORD = 0x0021,
123 TYPE_DWORD= 0x0022,
124 TYPE_QUAD = 0x0023,
126 TYPE_REAL32 = 0x0040,
127 TYPE_REAL64 = 0x0041,
128 TYPE_REAL80 = 0x0042,
129 TYPE_REAL128= 0x0043,
130 TYPE_REAL256= 0x0044,
131 TYPE_REAL512= 0x0045
132 } symtype;
135 struct cv8_state {
136 int symbol_sect;
137 int type_sect;
139 uint32_t text_offset;
141 struct source_file *source_files, **source_files_tail;
142 const char *last_filename;
143 struct source_file *last_source_file;
144 struct hash_table file_hash;
145 unsigned num_files;
146 uint32_t total_filename_len;
149 unsigned total_lines;
151 struct SAA *symbols;
152 struct cv8_symbol *last_sym;
153 unsigned num_syms[SYMTYPE_MAX];
154 unsigned symbol_lengths;
155 unsigned total_syms;
157 struct {
158 char *name;
159 size_t namebytes;
160 } outfile;
162 struct cv8_state cv8_state;
164 static void cv8_init(void)
166 const uint32_t sect_flags = IMAGE_SCN_MEM_READ |
167 IMAGE_SCN_MEM_DISCARDABLE |
168 IMAGE_SCN_CNT_INITIALIZED_DATA |
169 IMAGE_SCN_ALIGN_1BYTES;
171 cv8_state.symbol_sect = coff_make_section(".debug$S", sect_flags);
172 cv8_state.type_sect = coff_make_section(".debug$T", sect_flags);
174 cv8_state.text_offset = 0;
176 cv8_state.source_files = NULL;
177 cv8_state.source_files_tail = &cv8_state.source_files;
178 hash_init(&cv8_state.file_hash, HASH_MEDIUM);
180 cv8_state.num_files = 0;
181 cv8_state.total_filename_len = 0;
183 cv8_state.total_lines = 0;
185 cv8_state.symbols = saa_init(sizeof(struct cv8_symbol));
186 cv8_state.last_sym = NULL;
189 static struct source_file *register_file(const char *filename);
190 static struct coff_Section *find_section(int32_t segto);
192 static void cv8_linenum(const char *filename, int32_t linenumber,
193 int32_t segto)
195 struct coff_Section *s;
196 struct linepair *li;
197 struct source_file *file;
199 file = register_file(filename);
201 s = find_section(segto);
202 if (s == NULL)
203 return;
205 if ((s->flags & IMAGE_SCN_MEM_EXECUTE) == 0)
206 return;
208 li = saa_wstruct(file->lines);
209 li->file_offset = cv8_state.text_offset;
210 li->linenumber = linenumber;
212 file->num_lines++;
213 cv8_state.total_lines++;
216 static void cv8_deflabel(char *name, int32_t segment, int64_t offset,
217 int is_global, char *special)
219 struct cv8_symbol *sym;
220 struct coff_Section *s;
222 (void)special;
224 s = find_section(segment);
225 if (s == NULL)
226 return;
228 sym = saa_wstruct(cv8_state.symbols);
230 if (s->flags & IMAGE_SCN_MEM_EXECUTE)
231 sym->type = is_global ? SYMTYPE_PROC : SYMTYPE_CODE;
232 else
233 sym->type = is_global ? SYMTYPE_GDATA : SYMTYPE_LDATA;
234 cv8_state.num_syms[sym->type]++;
235 cv8_state.total_syms++;
237 sym->section = segment;
238 sym->secrel = offset;
239 sym->symtype = TYPE_UNREGISTERED;
240 sym->size = 0;
241 sym->typeindex = 0;
243 sym->name = nasm_strdup(name);
244 cv8_state.symbol_lengths += strlen(sym->name) + 1;
246 if (cv8_state.last_sym && cv8_state.last_sym->section == segment)
247 cv8_state.last_sym->size = offset - cv8_state.last_sym->secrel;
248 cv8_state.last_sym = sym;
251 static void cv8_typevalue(int32_t type)
253 if (!cv8_state.last_sym)
254 return;
255 if (cv8_state.last_sym->symtype != TYPE_UNREGISTERED)
256 return;
258 switch (TYM_TYPE(type)) {
259 case TY_BYTE:
260 cv8_state.last_sym->symtype = TYPE_BYTE;
261 break;
262 case TY_WORD:
263 cv8_state.last_sym->symtype = TYPE_WORD;
264 break;
265 case TY_DWORD:
266 cv8_state.last_sym->symtype = TYPE_DWORD;
267 break;
268 case TY_QWORD:
269 cv8_state.last_sym->symtype = TYPE_QUAD;
270 break;
271 case TY_FLOAT:
272 cv8_state.last_sym->symtype = TYPE_REAL32;
273 break;
274 case TY_TBYTE:
275 cv8_state.last_sym->symtype = TYPE_REAL80;
276 break;
277 case TY_OWORD:
278 cv8_state.last_sym->symtype = TYPE_REAL128;
279 break;
280 case TY_YWORD:
281 cv8_state.last_sym->symtype = TYPE_REAL256;
282 break;
283 case TY_UNKNOWN:
284 break;
285 case TY_LABEL:
286 break;
290 static void cv8_output(int type, void *param)
292 struct coff_DebugInfo *dinfo = param;
294 (void)type;
296 if (dinfo->section && dinfo->section->name &&
297 !strncmp(dinfo->section->name, ".text", 5))
298 cv8_state.text_offset += dinfo->size;
301 static void build_symbol_table(struct coff_Section *const sect);
302 static void build_type_table(struct coff_Section *const sect);
304 static void cv8_cleanup(void)
306 struct cv8_symbol *sym;
307 struct source_file *file;
309 struct coff_Section *symbol_sect = coff_sects[cv8_state.symbol_sect];
310 struct coff_Section *type_sect = coff_sects[cv8_state.type_sect];
312 cv8_state.outfile.name = nasm_realpath(coff_outfile);
313 cv8_state.outfile.namebytes = strlen(cv8_state.outfile.name) + 1;
315 build_symbol_table(symbol_sect);
316 build_type_table(type_sect);
318 list_for_each(file, cv8_state.source_files) {
319 nasm_free(file->fullname);
320 saa_free(file->lines);
321 free(file);
323 hash_free(&cv8_state.file_hash);
325 saa_rewind(cv8_state.symbols);
326 while ((sym = saa_rstruct(cv8_state.symbols)))
327 nasm_free(sym->name);
328 saa_free(cv8_state.symbols);
330 nasm_free(cv8_state.outfile.name);
333 /*******************************************************************************
334 * implementation
335 ******************************************************************************/
336 static void calc_md5(const char *const filename,
337 unsigned char sum[MD5_HASHBYTES])
339 int success = 0;
340 unsigned char *file_buf;
341 FILE *f;
342 MD5_CTX ctx;
344 f = pp_input_fopen(filename, NF_BINARY);
345 if (!f)
346 goto done;
348 file_buf = nasm_zalloc(BUFSIZ);
350 MD5Init(&ctx);
351 while (!feof(f)) {
352 size_t i = fread(file_buf, 1, BUFSIZ, f);
353 if (ferror(f))
354 goto done_0;
355 else if (i == 0)
356 break;
357 MD5Update(&ctx, file_buf, i);
359 MD5Final(sum, &ctx);
361 success = 1;
362 done_0:
363 nasm_free(file_buf);
364 fclose(f);
365 done:
366 if (!success) {
367 nasm_error(ERR_NONFATAL, "unable to hash file %s. "
368 "Debug information may be unavailable.\n",
369 filename);
371 return;
374 static struct source_file *register_file(const char *filename)
376 struct source_file *file;
377 void **filep;
378 char *fullpath;
379 struct hash_insert hi;
382 * The common case is that we are invoked with the same filename
383 * as we were last time. Make this a pointer comparison: this is
384 * safe because the NASM core code allocates each filename once
385 * and never frees it.
387 if (likely(cv8_state.last_filename == filename))
388 return cv8_state.last_source_file;
390 cv8_state.last_filename = filename;
392 filep = hash_find(&cv8_state.file_hash, filename, &hi);
393 if (likely(filep)) {
394 file = *filep;
395 } else {
396 /* New filename encounter */
398 fullpath = nasm_realpath(filename);
400 file = nasm_zalloc(sizeof(*file));
402 file->filename = filename;
403 file->fullname = fullpath;
404 file->fullnamelen = strlen(fullpath);
405 file->lines = saa_init(sizeof(struct linepair));
406 *cv8_state.source_files_tail = file;
407 cv8_state.source_files_tail = &file->next;
408 calc_md5(fullpath, file->md5sum);
410 hash_add(&hi, filename, file);
412 cv8_state.num_files++;
413 cv8_state.total_filename_len += file->fullnamelen + 1;
416 cv8_state.last_source_file = file;
417 return file;
420 static struct coff_Section *find_section(int32_t segto)
422 int i;
424 for (i = 0; i < coff_nsects; i++) {
425 struct coff_Section *sec;
427 sec = coff_sects[i];
428 if (segto == sec->index)
429 return sec;
431 return NULL;
434 static void register_reloc(struct coff_Section *const sect,
435 char *sym, uint32_t addr, uint16_t type)
437 struct coff_Reloc *r;
438 struct coff_Section *sec;
439 uint32_t i;
441 r = *sect->tail = nasm_malloc(sizeof(struct coff_Reloc));
442 sect->tail = &r->next;
443 r->next = NULL;
444 sect->nrelocs++;
446 r->address = addr;
447 r->symbase = SECT_SYMBOLS;
448 r->type = type;
450 r->symbol = 0;
451 for (i = 0; i < (uint32_t)coff_nsects; i++) {
452 sec = coff_sects[i];
453 if (!strcmp(sym, sec->name)) {
454 return;
456 r->symbol += 2;
459 saa_rewind(coff_syms);
460 for (i = 0; i < coff_nsyms; i++) {
461 struct coff_Symbol *s = saa_rstruct(coff_syms);
462 r->symbol++;
463 if (s->strpos == -1 && !strcmp(sym, s->name)) {
464 return;
465 } else if (s->strpos != -1) {
466 int res;
467 char *symname;
469 symname = nasm_malloc(s->namlen + 1);
470 saa_fread(coff_strs, s->strpos-4, symname, s->namlen);
471 symname[s->namlen] = '\0';
472 res = strcmp(sym, symname);
473 nasm_free(symname);
474 if (!res)
475 return;
478 nasm_panic(0, "codeview: relocation for unregistered symbol: %s", sym);
481 static inline void section_write32(struct coff_Section *sect, uint32_t val)
483 saa_write32(sect->data, val);
484 sect->len += 4;
487 static inline void section_write16(struct coff_Section *sect, uint16_t val)
489 saa_write16(sect->data, val);
490 sect->len += 2;
493 static inline void section_write8(struct coff_Section *sect, uint8_t val)
495 saa_write8(sect->data, val);
496 sect->len++;
499 static inline void section_wbytes(struct coff_Section *sect, const void *buf,
500 size_t len)
502 saa_wbytes(sect->data, buf, len);
503 sect->len += len;
506 static void write_filename_table(struct coff_Section *const sect)
508 uint32_t field_length;
509 uint32_t tbl_off = 1; /* offset starts at 1 to skip NULL entry */
510 struct source_file *file;
512 nasm_assert(cv8_state.source_files != NULL);
513 nasm_assert(cv8_state.num_files > 0);
514 nasm_assert(cv8_state.total_filename_len > 0);
516 field_length = 1 + cv8_state.total_filename_len;
518 section_write32(sect, 0x000000F3);
519 section_write32(sect, field_length);
521 section_write8(sect, 0);
523 list_for_each(file, cv8_state.source_files) {
524 section_wbytes(sect, file->fullname, file->fullnamelen + 1);
525 file->filetbl_off = tbl_off;
526 tbl_off += file->fullnamelen + 1;
530 static void write_sourcefile_table(struct coff_Section *const sect)
532 const uint32_t entry_size = 4 + 2 + MD5_HASHBYTES + 2;
534 uint32_t field_length = 0;
535 uint32_t tbl_off = 0;
536 struct source_file *file;
538 field_length = entry_size * cv8_state.num_files;
540 section_write32(sect, 0x000000F4);
541 section_write32(sect, field_length);
543 list_for_each(file, cv8_state.source_files) {
544 nasm_assert(file->filetbl_off > 0);
545 section_write32(sect, file->filetbl_off);
546 section_write16(sect, 0x0110);
547 section_wbytes(sect, file->md5sum, MD5_HASHBYTES);
548 section_write16(sect, 0);
550 file->sourcetbl_off = tbl_off;
551 tbl_off += entry_size;
555 static void write_linenumber_table(struct coff_Section *const sect)
557 const uint32_t file_field_len = 12;
558 const uint32_t line_field_len = 8;
560 int i;
561 uint32_t field_length = 0;
562 size_t field_base;
563 struct source_file *file;
564 struct coff_Section *s;
566 for (i = 0; i < coff_nsects; i++) {
567 if (!strncmp(coff_sects[i]->name, ".text", 5))
568 break;
571 if (i == coff_nsects)
572 return;
573 s = coff_sects[i];
575 field_length = 12;
576 field_length += (cv8_state.num_files * file_field_len);
577 field_length += (cv8_state.total_lines * line_field_len);
579 section_write32(sect, 0x000000F2);
580 section_write32(sect, field_length);
582 field_base = sect->len;
583 section_write32(sect, 0); /* SECREL, updated by relocation */
584 section_write16(sect, 0); /* SECTION, updated by relocation*/
585 section_write16(sect, 0); /* pad */
586 section_write32(sect, s->len);
588 register_reloc(sect, ".text", field_base,
589 win64 ? IMAGE_REL_AMD64_SECREL : IMAGE_REL_I386_SECREL);
591 register_reloc(sect, ".text", field_base + 4,
592 win64 ? IMAGE_REL_AMD64_SECTION : IMAGE_REL_I386_SECTION);
594 list_for_each(file, cv8_state.source_files) {
595 struct linepair *li;
597 /* source mapping */
598 section_write32(sect, file->sourcetbl_off);
599 section_write32(sect, file->num_lines);
600 section_write32(sect, file_field_len + (file->num_lines * line_field_len));
602 /* the pairs */
603 saa_rewind(file->lines);
604 while ((li = saa_rstruct(file->lines))) {
605 section_write32(sect, li->file_offset);
606 section_write32(sect, li->linenumber |= 0x80000000);
611 static uint16_t write_symbolinfo_obj(struct coff_Section *sect)
613 uint16_t obj_len;
615 obj_len = 2 + 4 + cv8_state.outfile.namebytes;
617 section_write16(sect, obj_len);
618 section_write16(sect, 0x1101);
619 section_write32(sect, 0); /* ASM language */
620 section_wbytes(sect, cv8_state.outfile.name, cv8_state.outfile.namebytes);
622 return obj_len;
625 static uint16_t write_symbolinfo_properties(struct coff_Section *sect,
626 const char *const creator_str)
628 /* https://github.com/Microsoft/microsoft-pdb/blob/1d60e041/include/cvinfo.h#L3313 */
629 uint16_t creator_len;
631 creator_len = 2 + 4 + 2 + 3*2 + 3*2 + strlen(creator_str)+1 + 2;
633 section_write16(sect, creator_len);
634 section_write16(sect, 0x1116);
635 section_write32(sect, 3); /* language/flags */
636 if (win64)
637 section_write16(sect, 0x00D0); /* machine */
638 else if (win32)
639 section_write16(sect, 0x0006); /* machine */
640 else
641 nasm_assert(!"neither win32 nor win64 are set!");
642 section_write16(sect, 0); /* verFEMajor */
643 section_write16(sect, 0); /* verFEMinor */
644 section_write16(sect, 0); /* verFEBuild */
646 /* BinScope/WACK insist on version >= 8.0.50727 */
647 section_write16(sect, 8); /* verMajor */
648 section_write16(sect, 0); /* verMinor */
649 section_write16(sect, 50727); /* verBuild */
651 section_wbytes(sect, creator_str, strlen(creator_str)+1); /* verSt */
653 * normally there would be key/value pairs here, but they aren't
654 * necessary. They are terminated by 2B
656 section_write16(sect, 0);
658 return creator_len;
661 static uint16_t write_symbolinfo_symbols(struct coff_Section *sect)
663 uint16_t len = 0, field_len;
664 uint32_t field_base;
665 struct cv8_symbol *sym;
667 saa_rewind(cv8_state.symbols);
668 while ((sym = saa_rstruct(cv8_state.symbols))) {
669 switch (sym->type) {
670 case SYMTYPE_LDATA:
671 case SYMTYPE_GDATA:
672 field_len = 12 + strlen(sym->name) + 1;
673 len += field_len - 2;
674 section_write16(sect, field_len);
675 if (sym->type == SYMTYPE_LDATA)
676 section_write16(sect, 0x110C);
677 else
678 section_write16(sect, 0x110D);
679 section_write32(sect, sym->symtype);
681 field_base = sect->len;
682 section_write32(sect, 0); /* SECREL */
683 section_write16(sect, 0); /* SECTION */
684 break;
685 case SYMTYPE_PROC:
686 case SYMTYPE_CODE:
687 field_len = 9 + strlen(sym->name) + 1;
688 len += field_len - 2;
689 section_write16(sect, field_len);
690 section_write16(sect, 0x1105);
692 field_base = sect->len;
693 section_write32(sect, 0); /* SECREL */
694 section_write16(sect, 0); /* SECTION */
695 section_write8(sect, 0); /* FLAG */
696 break;
697 default:
698 nasm_assert(!"unknown symbol type");
701 section_wbytes(sect, sym->name, strlen(sym->name) + 1);
703 register_reloc(sect, sym->name, field_base,
704 win64 ? IMAGE_REL_AMD64_SECREL :
705 IMAGE_REL_I386_SECREL);
706 register_reloc(sect, sym->name, field_base + 4,
707 win64 ? IMAGE_REL_AMD64_SECTION :
708 IMAGE_REL_I386_SECTION);
711 return len;
714 static void write_symbolinfo_table(struct coff_Section *const sect)
716 static const char creator_str[] = "The Netwide Assembler " NASM_VER;
717 uint16_t obj_length, creator_length, sym_length;
718 uint32_t field_length = 0, out_len;
720 nasm_assert(cv8_state.outfile.namebytes);
722 /* signature, language, outfile NULL */
723 obj_length = 2 + 4 + cv8_state.outfile.namebytes;
724 creator_length = 2 + 4 + 2 + 3*2 + 3*2 + strlen(creator_str)+1 + 2;
726 sym_length = ( cv8_state.num_syms[SYMTYPE_CODE] * 7) +
727 ( cv8_state.num_syms[SYMTYPE_PROC] * 7) +
728 ( cv8_state.num_syms[SYMTYPE_LDATA] * 10) +
729 ( cv8_state.num_syms[SYMTYPE_GDATA] * 10) +
730 cv8_state.symbol_lengths;
732 field_length = 2 + obj_length +
733 2 + creator_length +
734 (4 * cv8_state.total_syms) + sym_length;
736 section_write32(sect, 0x000000F1);
737 section_write32(sect, field_length);
739 /* for sub fields, length preceeds type */
741 out_len = write_symbolinfo_obj(sect);
742 nasm_assert(out_len == obj_length);
744 out_len = write_symbolinfo_properties(sect, creator_str);
745 nasm_assert(out_len == creator_length);
747 out_len = write_symbolinfo_symbols(sect);
748 nasm_assert(out_len == sym_length);
751 static inline void align4_table(struct coff_Section *const sect)
753 unsigned diff;
754 uint32_t zero = 0;
755 struct SAA *data = sect->data;
757 if (data->wptr % 4 == 0)
758 return;
760 diff = 4 - (data->wptr % 4);
761 if (diff)
762 section_wbytes(sect, &zero, diff);
765 static void build_symbol_table(struct coff_Section *const sect)
767 section_write32(sect, 0x00000004);
769 write_filename_table(sect);
770 align4_table(sect);
771 write_sourcefile_table(sect);
772 align4_table(sect);
773 write_linenumber_table(sect);
774 align4_table(sect);
775 write_symbolinfo_table(sect);
776 align4_table(sect);
779 static void build_type_table(struct coff_Section *const sect)
781 uint16_t field_len;
782 struct cv8_symbol *sym;
784 section_write32(sect, 0x00000004);
786 saa_rewind(cv8_state.symbols);
787 while ((sym = saa_rstruct(cv8_state.symbols))) {
788 if (sym->type != SYMTYPE_PROC)
789 continue;
791 /* proc leaf */
793 field_len = 2 + 4 + 4 + 4 + 2;
794 section_write16(sect, field_len);
795 section_write16(sect, 0x1008); /* PROC type */
797 section_write32(sect, 0x00000003); /* return type */
798 section_write32(sect, 0); /* calling convention (default) */
799 section_write32(sect, sym->typeindex);
800 section_write16(sect, 0); /* # params */
802 /* arglist */
804 field_len = 2 + 4;
805 section_write16(sect, field_len);
806 section_write16(sect, 0x1201); /* ARGLIST */
807 section_write32(sect, 0); /*num params */