4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
35 #include "wine/exception.h"
39 static int string_compare( const void *ptr1, const void *ptr2 )
41 const char * const *str1 = ptr1;
42 const char * const *str2 = ptr2;
43 return strcmp( *str1, *str2 );
47 /*******************************************************************
50 * Generate an internal name for an entry point. Used for stubs etc.
52 static const char *make_internal_name( const ORDDEF *odp, DLLSPEC *spec, const char *prefix )
54 static char buffer[256];
55 if (odp->name || odp->export_name)
58 sprintf( buffer, "__wine_%s_%s_%s", prefix, spec->file_name,
59 odp->name ? odp->name : odp->export_name );
60 /* make sure name is a legal C identifier */
61 for (p = buffer; *p; p++) if (!isalnum(*p) && *p != '_') break;
62 if (!*p) return buffer;
64 sprintf( buffer, "__wine_%s_%s_%d", prefix, make_c_identifier(spec->file_name), odp->ordinal );
69 /*******************************************************************
72 * Output the debug channels.
74 static int output_debug( FILE *outfile )
78 if (!nb_debug_channels) return 0;
79 qsort( debug_channels, nb_debug_channels, sizeof(debug_channels[0]), string_compare );
81 for (i = 0; i < nb_debug_channels; i++)
82 fprintf( outfile, "char __wine_dbch_%s[] = \"\\003%s\";\n",
83 debug_channels[i], debug_channels[i] );
85 fprintf( outfile, "\nstatic char * const debug_channels[%d] =\n{\n", nb_debug_channels );
86 for (i = 0; i < nb_debug_channels; i++)
88 fprintf( outfile, " __wine_dbch_%s", debug_channels[i] );
89 if (i < nb_debug_channels - 1) fprintf( outfile, ",\n" );
91 fprintf( outfile, "\n};\n\n" );
92 fprintf( outfile, "static void *debug_registration;\n\n" );
94 return nb_debug_channels;
98 /*******************************************************************
101 * Output the export table for a Win32 module.
103 static void output_exports( FILE *outfile, DLLSPEC *spec )
106 int nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
108 if (!nr_exports) return;
110 fprintf( outfile, "\n/* export table */\n\n" );
111 fprintf( outfile, "\t.data\n" );
112 fprintf( outfile, "\t.align %d\n", get_alignment(4) );
113 fprintf( outfile, ".L__wine_spec_exports:\n" );
115 /* export directory header */
117 fprintf( outfile, "\t.long 0\n" ); /* Characteristics */
118 fprintf( outfile, "\t.long 0\n" ); /* TimeDateStamp */
119 fprintf( outfile, "\t.long 0\n" ); /* MajorVersion/MinorVersion */
120 fprintf( outfile, "\t.long .L__wine_spec_exp_names\n" ); /* Name */
121 fprintf( outfile, "\t.long %d\n", spec->base ); /* Base */
122 fprintf( outfile, "\t.long %d\n", nr_exports ); /* NumberOfFunctions */
123 fprintf( outfile, "\t.long %d\n", spec->nb_names ); /* NumberOfNames */
124 fprintf( outfile, "\t.long .L__wine_spec_exports_funcs\n" ); /* AddressOfFunctions */
127 fprintf( outfile, "\t.long .L__wine_spec_exp_name_ptrs\n" ); /* AddressOfNames */
128 fprintf( outfile, "\t.long .L__wine_spec_exp_ordinals\n" ); /* AddressOfNameOrdinals */
132 fprintf( outfile, "\t.long 0\n" ); /* AddressOfNames */
133 fprintf( outfile, "\t.long 0\n" ); /* AddressOfNameOrdinals */
136 /* output the function pointers */
138 fprintf( outfile, "\n.L__wine_spec_exports_funcs:\n" );
139 for (i = spec->base; i <= spec->limit; i++)
141 ORDDEF *odp = spec->ordinals[i];
142 if (!odp) fprintf( outfile, "\t.long 0\n" );
143 else switch(odp->type)
149 if (!(odp->flags & FLAG_FORWARD))
151 fprintf( outfile, "\t.long %s\n", asm_name(odp->link_name) );
155 fprintf( outfile, "\t.long .L__wine_spec_forwards+%d\n", fwd_size );
156 fwd_size += strlen(odp->link_name) + 1;
160 fprintf( outfile, "\t.long %s\n",
161 asm_name( make_internal_name( odp, spec, "stub" )) );
170 /* output the function name pointers */
172 int namepos = strlen(spec->file_name) + 1;
174 fprintf( outfile, "\n.L__wine_spec_exp_name_ptrs:\n" );
175 for (i = 0; i < spec->nb_names; i++)
177 fprintf( outfile, "\t.long .L__wine_spec_exp_names+%d\n", namepos );
178 namepos += strlen(spec->names[i]->name) + 1;
181 /* output the function ordinals */
183 fprintf( outfile, "\n.L__wine_spec_exp_ordinals:\n" );
184 for (i = 0; i < spec->nb_names; i++)
186 fprintf( outfile, "\t%s %d\n",
187 get_asm_short_keyword(), spec->names[i]->ordinal - spec->base );
189 if (spec->nb_names % 2)
191 fprintf( outfile, "\t%s 0\n", get_asm_short_keyword() );
195 /* output the export name strings */
197 fprintf( outfile, "\n.L__wine_spec_exp_names:\n" );
198 fprintf( outfile, "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
199 for (i = 0; i < spec->nb_names; i++)
200 fprintf( outfile, "\t%s \"%s\"\n",
201 get_asm_string_keyword(), spec->names[i]->name );
203 /* output forward strings */
207 fprintf( outfile, "\n.L__wine_spec_forwards:\n" );
208 for (i = spec->base; i <= spec->limit; i++)
210 ORDDEF *odp = spec->ordinals[i];
211 if (odp && (odp->flags & FLAG_FORWARD))
212 fprintf( outfile, "\t%s \"%s\"\n", get_asm_string_keyword(), odp->link_name );
215 fprintf( outfile, "\t.align %d\n", get_alignment(4) );
216 fprintf( outfile, ".L__wine_spec_exports_end:\n" );
220 /* we only support relay debugging on i386 */
221 if (target_cpu == CPU_x86)
223 for (i = spec->base; i <= spec->limit; i++)
225 ORDDEF *odp = spec->ordinals[i];
226 unsigned int j, args, mask = 0;
228 /* skip nonexistent entry points */
229 if (!odp) goto ignore;
230 /* skip non-functions */
231 if ((odp->type != TYPE_STDCALL) && (odp->type != TYPE_CDECL)) goto ignore;
232 /* skip norelay and forward entry points */
233 if (odp->flags & (FLAG_NORELAY|FLAG_FORWARD)) goto ignore;
235 for (j = 0; odp->u.func.arg_types[j]; j++)
237 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
238 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
240 if ((odp->flags & FLAG_RET64) && (j < 16)) mask |= 0x80000000;
242 args = strlen(odp->u.func.arg_types) * get_ptr_size();
247 fprintf( outfile, "\tjmp %s\n", asm_name(odp->link_name) );
248 fprintf( outfile, "\tret $%d\n", args );
249 fprintf( outfile, "\t.long %s,0x%08x\n", asm_name(odp->link_name), mask );
252 fprintf( outfile, "\tjmp %s\n", asm_name(odp->link_name) );
253 fprintf( outfile, "\tret\n" );
254 fprintf( outfile, "\t%s %d\n", get_asm_short_keyword(), args );
255 fprintf( outfile, "\t.long %s,0x%08x\n", asm_name(odp->link_name), mask );
263 fprintf( outfile, "\t.long 0,0,0,0\n" );
266 else fprintf( outfile, "\t.long 0\n" );
270 /*******************************************************************
273 * Output the functions for stub entry points
275 static void output_stubs( FILE *outfile, DLLSPEC *spec )
277 const char *name, *exp_name;
280 if (!has_stubs( spec )) return;
282 fprintf( outfile, "\n/* stub functions */\n\n" );
283 fprintf( outfile, "\t.text\n" );
285 for (i = pos = 0; i < spec->nb_entry_points; i++)
287 ORDDEF *odp = &spec->entry_points[i];
288 if (odp->type != TYPE_STUB) continue;
290 name = make_internal_name( odp, spec, "stub" );
291 exp_name = odp->name ? odp->name : odp->export_name;
292 fprintf( outfile, "\t.align %d\n", get_alignment(4) );
293 fprintf( outfile, "\t%s\n", func_declaration(name) );
294 fprintf( outfile, "%s:\n", asm_name(name) );
295 fprintf( outfile, "\tcall .L__wine_stub_getpc_%d\n", i );
296 fprintf( outfile, ".L__wine_stub_getpc_%d:\n", i );
297 fprintf( outfile, "\tpopl %%eax\n" );
300 fprintf( outfile, "\tleal .L__wine_stub_strings+%d-.L__wine_stub_getpc_%d(%%eax),%%ecx\n",
302 fprintf( outfile, "\tpushl %%ecx\n" );
303 pos += strlen(exp_name) + 1;
306 fprintf( outfile, "\tpushl $%d\n", odp->ordinal );
307 fprintf( outfile, "\tleal %s-.L__wine_stub_getpc_%d(%%eax),%%ecx\n",
308 asm_name("__wine_spec_file_name"), i );
309 fprintf( outfile, "\tpushl %%ecx\n" );
310 fprintf( outfile, "\tcall %s\n", asm_name("__wine_spec_unimplemented_stub") );
311 fprintf( outfile, "\t%s\n", func_size(name) );
316 fprintf( outfile, "\t%s\n", get_asm_string_section() );
317 fprintf( outfile, ".L__wine_stub_strings:\n" );
318 for (i = 0; i < spec->nb_entry_points; i++)
320 ORDDEF *odp = &spec->entry_points[i];
321 if (odp->type != TYPE_STUB) continue;
322 exp_name = odp->name ? odp->name : odp->export_name;
324 fprintf( outfile, "\t%s \"%s\"\n", get_asm_string_keyword(), exp_name );
330 /*******************************************************************
333 * Output code for calling a dll constructor and destructor.
335 void output_dll_init( FILE *outfile, const char *constructor, const char *destructor )
337 if (target_platform == PLATFORM_APPLE)
339 /* Mach-O doesn't have an init section */
342 fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
343 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
344 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name(constructor) );
345 fprintf( outfile, " \"\\t.text\\n\");\n" );
349 fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
350 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
351 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name(destructor) );
352 fprintf( outfile, " \"\\t.text\\n\");\n" );
355 else switch(target_cpu)
361 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
362 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(constructor) );
363 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
367 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
368 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(destructor) );
369 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
375 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
376 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(constructor) );
377 fprintf( outfile, " \"\\tnop\\n\"\n" );
378 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
382 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
383 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(destructor) );
384 fprintf( outfile, " \"\\tnop\\n\"\n" );
385 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
391 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
392 fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n", asm_name(constructor) );
393 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
397 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
398 fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n", asm_name(destructor) );
399 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
405 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
406 fprintf( outfile, " \"\\tbl %s\\n\"\n", asm_name(constructor) );
407 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
411 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
412 fprintf( outfile, " \"\\tbl %s\\n\"\n", asm_name(destructor) );
413 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
420 /*******************************************************************
421 * output_asm_constructor
423 * Output code for calling a dll constructor.
425 static void output_asm_constructor( FILE *outfile, const char *constructor )
427 if (target_platform == PLATFORM_APPLE)
429 /* Mach-O doesn't have an init section */
430 fprintf( outfile, "\n\t.mod_init_func\n" );
431 fprintf( outfile, "\t.align %d\n", get_alignment(4) );
432 fprintf( outfile, "\t.long %s\n", asm_name(constructor) );
436 fprintf( outfile, "\n\t.section \".init\",\"ax\"\n" );
441 fprintf( outfile, "\tcall %s\n", asm_name(constructor) );
444 fprintf( outfile, "\tcall %s\n", asm_name(constructor) );
445 fprintf( outfile, "\tnop\n" );
448 fprintf( outfile, "\tjsr $26,%s\n", asm_name(constructor) );
451 fprintf( outfile, "\tbl %s\n", asm_name(constructor) );
458 /*******************************************************************
461 * Build a Win32 C file from a spec file.
463 void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
466 unsigned int page_size = get_page_size();
468 resolve_imports( spec );
469 output_standard_file_header( outfile );
471 /* Reserve some space for the PE header */
473 fprintf( outfile, "\t.text\n" );
474 fprintf( outfile, "\t.align %d\n", get_alignment(page_size) );
475 fprintf( outfile, "__wine_spec_pe_header:\n" );
476 if (target_platform == PLATFORM_APPLE)
477 fprintf( outfile, "\t.space 65536\n" );
479 fprintf( outfile, "\t.skip 65536\n" );
481 /* Output the NT header */
483 fprintf( outfile, "\n\t.data\n" );
484 fprintf( outfile, "\t.align %d\n", get_alignment(get_ptr_size()) );
485 fprintf( outfile, "%s\n", asm_globl("__wine_spec_nt_header") );
487 fprintf( outfile, "\t.long 0x%04x\n", IMAGE_NT_SIGNATURE ); /* Signature */
490 case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
491 case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
492 case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
493 case CPU_ALPHA: machine = IMAGE_FILE_MACHINE_ALPHA; break;
494 case CPU_SPARC: machine = IMAGE_FILE_MACHINE_UNKNOWN; break;
496 fprintf( outfile, "\t%s 0x%04x\n", /* Machine */
497 get_asm_short_keyword(), machine );
498 fprintf( outfile, "\t%s 0\n", /* NumberOfSections */
499 get_asm_short_keyword() );
500 fprintf( outfile, "\t.long 0\n" ); /* TimeDateStamp */
501 fprintf( outfile, "\t.long 0\n" ); /* PointerToSymbolTable */
502 fprintf( outfile, "\t.long 0\n" ); /* NumberOfSymbols */
503 fprintf( outfile, "\t%s %d\n", /* SizeOfOptionalHeader */
504 get_asm_short_keyword(),
505 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
506 fprintf( outfile, "\t%s 0x%04x\n", /* Characteristics */
507 get_asm_short_keyword(), spec->characteristics );
508 fprintf( outfile, "\t%s 0x%04x\n", /* Magic */
509 get_asm_short_keyword(),
510 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
511 fprintf( outfile, "\t.byte 0\n" ); /* MajorLinkerVersion */
512 fprintf( outfile, "\t.byte 0\n" ); /* MinorLinkerVersion */
513 fprintf( outfile, "\t.long 0\n" ); /* SizeOfCode */
514 fprintf( outfile, "\t.long 0\n" ); /* SizeOfInitializedData */
515 fprintf( outfile, "\t.long 0\n" ); /* SizeOfUninitializedData */
516 fprintf( outfile, "\t.long %s\n", /* AddressOfEntryPoint */
517 asm_name(spec->init_func) );
518 fprintf( outfile, "\t.long 0\n" ); /* BaseOfCode */
519 if (get_ptr_size() == 4)
520 fprintf( outfile, "\t.long %s\n", asm_name("__wine_spec_nt_header") ); /* BaseOfData */
521 fprintf( outfile, "\t%s __wine_spec_pe_header\n", /* ImageBase */
522 get_asm_ptr_keyword() );
523 fprintf( outfile, "\t.long %u\n", page_size ); /* SectionAlignment */
524 fprintf( outfile, "\t.long %u\n", page_size ); /* FileAlignment */
525 fprintf( outfile, "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
526 get_asm_short_keyword() );
527 fprintf( outfile, "\t%s 0,0\n", /* Major/MinorImageVersion */
528 get_asm_short_keyword() );
529 fprintf( outfile, "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
530 get_asm_short_keyword(), spec->subsystem_major, spec->subsystem_minor );
531 fprintf( outfile, "\t.long 0\n" ); /* Win32VersionValue */
532 fprintf( outfile, "\t.long %s\n", /* SizeOfImage */
534 fprintf( outfile, "\t.long %u\n", page_size ); /* SizeOfHeaders */
535 fprintf( outfile, "\t.long 0\n" ); /* CheckSum */
536 fprintf( outfile, "\t%s 0x%04x\n", /* Subsystem */
537 get_asm_short_keyword(), spec->subsystem );
538 fprintf( outfile, "\t%s 0\n", /* DllCharacteristics */
539 get_asm_short_keyword() );
540 fprintf( outfile, "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
541 get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
542 fprintf( outfile, "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
543 get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
544 fprintf( outfile, "\t.long 0\n" ); /* LoaderFlags */
545 fprintf( outfile, "\t.long 16\n" ); /* NumberOfRvaAndSizes */
547 if (spec->base <= spec->limit) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
548 fprintf( outfile, "\t.long .L__wine_spec_exports, .L__wine_spec_exports_end-.L__wine_spec_exports\n" );
550 fprintf( outfile, "\t.long 0,0\n" );
552 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
553 fprintf( outfile, "\t.long .L__wine_spec_imports, .L__wine_spec_imports_end-.L__wine_spec_imports\n" );
555 fprintf( outfile, "\t.long 0,0\n" );
557 if (spec->nb_resources) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
558 fprintf( outfile, "\t.long .L__wine_spec_resources, .L__wine_spec_resources_end-.L__wine_spec_resources\n" );
560 fprintf( outfile, "\t.long 0,0\n" );
562 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[3] */
563 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[4] */
564 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[5] */
565 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[6] */
566 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[7] */
567 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[8] */
568 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[9] */
569 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[10] */
570 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[11] */
571 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[12] */
572 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[13] */
573 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[14] */
574 fprintf( outfile, "\t.long 0,0\n" ); /* DataDirectory[15] */
576 fprintf( outfile, "\n\t%s\n", get_asm_string_section() );
577 fprintf( outfile, "%s\n", asm_globl("__wine_spec_file_name") );
578 fprintf( outfile, "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
579 if (target_platform == PLATFORM_APPLE)
580 fprintf( outfile, "\t.comm %s,4\n", asm_name("_end") );
582 output_stubs( outfile, spec );
583 output_exports( outfile, spec );
584 output_imports( outfile, spec );
585 output_resources( outfile, spec );
586 output_asm_constructor( outfile, "__wine_spec_init_ctor" );
590 /*******************************************************************
593 * Build a Win32 def file from a spec file.
595 void BuildDef32File( FILE *outfile, DLLSPEC *spec )
601 fprintf( outfile, "; File generated automatically from %s; do not edit!\n\n",
604 fprintf( outfile, "; File generated automatically; do not edit!\n\n" );
606 fprintf(outfile, "LIBRARY %s\n\n", spec->file_name);
608 fprintf(outfile, "EXPORTS\n");
610 /* Output the exports and relay entry points */
612 for (i = total = 0; i < spec->nb_entry_points; i++)
614 const ORDDEF *odp = &spec->entry_points[i];
619 if (odp->name) name = odp->name;
620 else if (odp->export_name) name = odp->export_name;
623 if (!(odp->flags & FLAG_PRIVATE)) total++;
625 if (odp->type == TYPE_STUB) continue;
627 fprintf(outfile, " %s", name);
636 /* try to reduce output */
637 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
638 fprintf(outfile, "=%s", odp->link_name);
642 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
643 if (!kill_at) fprintf(outfile, "@%d", at_param);
644 if (odp->flags & FLAG_FORWARD)
646 fprintf(outfile, "=%s", odp->link_name);
648 else if (strcmp(name, odp->link_name)) /* try to reduce output */
650 fprintf(outfile, "=%s", odp->link_name);
651 if (!kill_at) fprintf(outfile, "@%d", at_param);
658 fprintf( outfile, " @%d", odp->ordinal );
659 if (!odp->name) fprintf( outfile, " NONAME" );
660 if (is_data) fprintf( outfile, " DATA" );
661 if (odp->flags & FLAG_PRIVATE) fprintf( outfile, " PRIVATE" );
662 fprintf( outfile, "\n" );
664 if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
668 /*******************************************************************
671 * Build the debugging channels source file.
673 void BuildDebugFile( FILE *outfile, const char *srcdir, char **argv )
676 char *prefix, *p, *constructor, *destructor;
680 if (!parse_debug_channels( srcdir, *argv++ )) exit(1);
683 output_standard_file_header( outfile );
684 nr_debug = output_debug( outfile );
687 fprintf( outfile, "/* no debug channels found for this module */\n" );
691 if (output_file_name)
693 if ((p = strrchr( output_file_name, '/' ))) p++;
694 prefix = xstrdup( p ? p : output_file_name );
695 if ((p = strchr( prefix, '.' ))) *p = 0;
696 strcpy( p, make_c_identifier(p) );
698 else prefix = xstrdup( "_" );
700 /* Output the DLL constructor */
702 constructor = xmalloc( strlen(prefix) + 17 );
703 destructor = xmalloc( strlen(prefix) + 17 );
704 sprintf( constructor, "__wine_dbg_%s_init", prefix );
705 sprintf( destructor, "__wine_dbg_%s_fini", prefix );
708 "void %s(void) __attribute__((constructor));\n"
709 "void %s(void) __attribute__((destructor));\n"
711 "static void __asm__dummy_dll_init(void) {\n",
712 constructor, destructor );
713 output_dll_init( outfile, constructor, destructor );
714 fprintf( outfile, "}\n#endif /* defined(__GNUC__) */\n\n" );
719 " extern void *__wine_dbg_register( char * const *, int );\n"
720 " if (!debug_registration) debug_registration = __wine_dbg_register( debug_channels, %d );\n"
721 "}\n\n", constructor, nr_debug );
725 " extern void __wine_dbg_unregister( void* );\n"
726 " __wine_dbg_unregister( debug_registration );\n"