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, "/* export table */\n" );
111 fprintf( outfile, "asm(\".data\\n\"\n" );
112 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
113 fprintf( outfile, " \".L__wine_spec_exports:\\n\"\n" );
115 /* export directory header */
117 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* Characteristics */
118 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* TimeDateStamp */
119 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* MajorVersion/MinorVersion */
120 fprintf( outfile, " \"\\t.long .L__wine_spec_exp_names\\n\"\n" ); /* Name */
121 fprintf( outfile, " \"\\t.long %d\\n\"\n", spec->base ); /* Base */
122 fprintf( outfile, " \"\\t.long %d\\n\"\n", nr_exports ); /* NumberOfFunctions */
123 fprintf( outfile, " \"\\t.long %d\\n\"\n", spec->nb_names ); /* NumberOfNames */
124 fprintf( outfile, " \"\\t.long .L__wine_spec_exports_funcs\\n\"\n" ); /* AddressOfFunctions */
127 fprintf( outfile, " \"\\t.long .L__wine_spec_exp_name_ptrs\\n\"\n" ); /* AddressOfNames */
128 fprintf( outfile, " \"\\t.long .L__wine_spec_exp_ordinals\\n\"\n" ); /* AddressOfNameOrdinals */
132 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNames */
133 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* AddressOfNameOrdinals */
136 /* output the function pointers */
138 fprintf( outfile, " \".L__wine_spec_exports_funcs:\\n\"\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\"\n" );
143 else switch(odp->type)
149 if (!(odp->flags & FLAG_FORWARD))
151 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name(odp->link_name) );
155 fprintf( outfile, " \"\\t.long .L__wine_spec_forwards+%d\\n\"\n", fwd_size );
156 fwd_size += strlen(odp->link_name) + 1;
160 fprintf( outfile, " \"\\t.long %s\\n\"\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, " \".L__wine_spec_exp_name_ptrs:\\n\"\n" );
175 for (i = 0; i < spec->nb_names; i++)
177 fprintf( outfile, " \"\\t.long .L__wine_spec_exp_names+%d\\n\"\n", namepos );
178 namepos += strlen(spec->names[i]->name) + 1;
181 /* output the function ordinals */
183 fprintf( outfile, " \".L__wine_spec_exp_ordinals:\\n\"\n" );
184 for (i = 0; i < spec->nb_names; i++)
186 fprintf( outfile, " \"\\t%s %d\\n\"\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\"\n", get_asm_short_keyword() );
195 /* output the export name strings */
197 fprintf( outfile, " \".L__wine_spec_exp_names:\\n\"\n" );
198 fprintf( outfile, " \"\\t%s \\\"%s\\\"\\n\"\n", get_asm_string_keyword(), spec->file_name );
199 for (i = 0; i < spec->nb_names; i++)
200 fprintf( outfile, " \"\\t%s \\\"%s\\\"\\n\"\n",
201 get_asm_string_keyword(), spec->names[i]->name );
203 /* output forward strings */
207 fprintf( outfile, " \".L__wine_spec_forwards:\\n\"\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\"\n", get_asm_string_keyword(), odp->link_name );
215 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
216 fprintf( outfile, " \".L__wine_spec_exports_end:\\n\"\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\"\n", asm_name(odp->link_name) );
248 fprintf( outfile, " \"\\tret $%d\\n\"\n", args );
249 fprintf( outfile, " \"\\t.long %s,0x%08x\\n\"\n", asm_name(odp->link_name), mask );
252 fprintf( outfile, " \"\\tjmp %s\\n\"\n", asm_name(odp->link_name) );
253 fprintf( outfile, " \"\\tret\\n\"\n" );
254 fprintf( outfile, " \"\\t%s %d\\n\"\n", get_asm_short_keyword(), args );
255 fprintf( outfile, " \"\\t.long %s,0x%08x\\n\"\n", asm_name(odp->link_name), mask );
263 fprintf( outfile, " \"\\t.long 0,0,0,0\\n\"\n" );
266 else fprintf( outfile, " \"\\t.long 0\\n\"\n" );
268 fprintf( outfile, ");\n" );
272 /*******************************************************************
275 * Output the functions for stub entry points
277 static void output_stubs( FILE *outfile, DLLSPEC *spec )
279 const char *name, *exp_name;
282 if (!has_stubs( spec )) return;
284 fprintf( outfile, "asm(\".text\\n\"\n" );
286 for (i = pos = 0; i < spec->nb_entry_points; i++)
288 ORDDEF *odp = &spec->entry_points[i];
289 if (odp->type != TYPE_STUB) continue;
291 name = make_internal_name( odp, spec, "stub" );
292 exp_name = odp->name ? odp->name : odp->export_name;
293 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(4) );
294 fprintf( outfile, " \"\\t%s\\n\"\n", func_declaration(name) );
295 fprintf( outfile, " \"%s:\\n\"\n", asm_name(name) );
296 fprintf( outfile, " \"\\tcall .L__wine_stub_getpc_%d\\n\"\n", i );
297 fprintf( outfile, " \".L__wine_stub_getpc_%d:\\n\"\n", i );
298 fprintf( outfile, " \"\\tpopl %%eax\\n\"\n" );
301 fprintf( outfile, " \"\\tleal .L__wine_stub_strings+%d-.L__wine_stub_getpc_%d(%%eax),%%ecx\\n\"\n",
303 fprintf( outfile, " \"\\tpushl %%ecx\\n\"\n" );
304 pos += strlen(exp_name) + 1;
307 fprintf( outfile, " \"\\tpushl $%d\\n\"\n", odp->ordinal );
308 fprintf( outfile, " \"\\tleal %s-.L__wine_stub_getpc_%d(%%eax),%%ecx\\n\"\n",
309 asm_name("__wine_spec_file_name"), i );
310 fprintf( outfile, " \"\\tpushl %%ecx\\n\"\n" );
311 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name("__wine_spec_unimplemented_stub") );
312 fprintf( outfile, " \"\\t%s\\n\"\n", func_size(name) );
317 fprintf( outfile, " \"\\t%s\\n\"\n", get_asm_string_section() );
318 fprintf( outfile, " \".L__wine_stub_strings:\\n\"\n" );
319 for (i = 0; i < spec->nb_entry_points; i++)
321 ORDDEF *odp = &spec->entry_points[i];
322 if (odp->type != TYPE_STUB) continue;
323 exp_name = odp->name ? odp->name : odp->export_name;
325 fprintf( outfile, " \"\\t%s \\\"%s\\\"\\n\"\n", get_asm_string_keyword(), exp_name );
329 fprintf( outfile, ");\n" );
333 /*******************************************************************
336 * Output code for calling a dll constructor and destructor.
338 void output_dll_init( FILE *outfile, const char *constructor, const char *destructor )
340 if (target_platform == PLATFORM_APPLE)
342 /* Mach-O doesn't have an init section */
345 fprintf( outfile, "asm(\"\\t.mod_init_func\\n\"\n" );
346 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
347 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name(constructor) );
348 fprintf( outfile, " \"\\t.text\\n\");\n" );
352 fprintf( outfile, "asm(\"\\t.mod_term_func\\n\"\n" );
353 fprintf( outfile, " \"\\t.align 2\\n\"\n" );
354 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name(destructor) );
355 fprintf( outfile, " \"\\t.text\\n\");\n" );
358 else switch(target_cpu)
364 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
365 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(constructor) );
366 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
370 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
371 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(destructor) );
372 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
378 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
379 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(constructor) );
380 fprintf( outfile, " \"\\tnop\\n\"\n" );
381 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
385 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
386 fprintf( outfile, " \"\\tcall %s\\n\"\n", asm_name(destructor) );
387 fprintf( outfile, " \"\\tnop\\n\"\n" );
388 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
394 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
395 fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n", asm_name(constructor) );
396 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
400 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
401 fprintf( outfile, " \"\\tjsr $26,%s\\n\"\n", asm_name(destructor) );
402 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
408 fprintf( outfile, "asm(\"\\t.section\\t\\\".init\\\" ,\\\"ax\\\"\\n\"\n" );
409 fprintf( outfile, " \"\\tbl %s\\n\"\n", asm_name(constructor) );
410 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
414 fprintf( outfile, "asm(\"\\t.section\\t\\\".fini\\\" ,\\\"ax\\\"\\n\"\n" );
415 fprintf( outfile, " \"\\tbl %s\\n\"\n", asm_name(destructor) );
416 fprintf( outfile, " \"\\t.section\\t\\\".text\\\"\\n\");\n" );
423 /*******************************************************************
426 * Build a Win32 C file from a spec file.
428 void BuildSpec32File( FILE *outfile, DLLSPEC *spec )
431 unsigned int page_size = get_page_size();
433 resolve_imports( spec );
434 output_standard_file_header( outfile );
436 /* Reserve some space for the PE header */
438 fprintf( outfile, "#ifndef __GNUC__\n" );
439 fprintf( outfile, "static void __asm__dummy(void) {\n" );
440 fprintf( outfile, "#endif\n" );
442 fprintf( outfile, "asm(\".text\\n\\t\"\n" );
443 fprintf( outfile, " \".align %d\\n\"\n", get_alignment(page_size) );
444 fprintf( outfile, " \"__wine_spec_pe_header:\\t\"\n" );
445 if (target_platform == PLATFORM_APPLE)
446 fprintf( outfile, " \".space 65536\\n\\t\"\n" );
448 fprintf( outfile, " \".skip 65536\\n\\t\"\n" );
450 /* Output the NT header */
452 fprintf( outfile, " \"\\t.data\\n\\t\"\n" );
453 fprintf( outfile, " \"\\t.align %d\\n\"\n", get_alignment(get_ptr_size()) );
454 fprintf( outfile, " \"\\t.globl %s\\n\"\n", asm_name("__wine_spec_nt_header") );
455 fprintf( outfile, " \"%s:\\n\"\n", asm_name("__wine_spec_nt_header"));
457 fprintf( outfile, " \"\\t.long 0x%04x\\n\"\n", IMAGE_NT_SIGNATURE ); /* Signature */
460 case CPU_x86: machine = IMAGE_FILE_MACHINE_I386; break;
461 case CPU_x86_64: machine = IMAGE_FILE_MACHINE_AMD64; break;
462 case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
463 case CPU_ALPHA: machine = IMAGE_FILE_MACHINE_ALPHA; break;
464 case CPU_SPARC: machine = IMAGE_FILE_MACHINE_UNKNOWN; break;
466 fprintf( outfile, " \"\\t%s 0x%04x\\n\"\n", /* Machine */
467 get_asm_short_keyword(), machine );
468 fprintf( outfile, " \"\\t%s 0\\n\"\n", /* NumberOfSections */
469 get_asm_short_keyword() );
470 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* TimeDateStamp */
471 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* PointerToSymbolTable */
472 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* NumberOfSymbols */
473 fprintf( outfile, " \"\\t%s %d\\n\"\n", /* SizeOfOptionalHeader */
474 get_asm_short_keyword(),
475 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
476 fprintf( outfile, " \"\\t%s 0x%04x\\n\"\n", /* Characteristics */
477 get_asm_short_keyword(), spec->characteristics );
478 fprintf( outfile, " \"\\t%s 0x%04x\\n\"\n", /* Magic */
479 get_asm_short_keyword(),
480 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
481 fprintf( outfile, " \"\\t.byte 0\\n\"\n" ); /* MajorLinkerVersion */
482 fprintf( outfile, " \"\\t.byte 0\\n\"\n" ); /* MinorLinkerVersion */
483 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* SizeOfCode */
484 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* SizeOfInitializedData */
485 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* SizeOfUninitializedData */
486 fprintf( outfile, " \"\\t.long %s\\n\"\n", /* AddressOfEntryPoint */
487 asm_name(spec->init_func) );
488 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* BaseOfCode */
489 if (get_ptr_size() == 4)
490 fprintf( outfile, " \"\\t.long %s\\n\"\n", asm_name("__wine_spec_nt_header") ); /* BaseOfData */
491 fprintf( outfile, " \"\\t%s __wine_spec_pe_header\\n\"\n", /* ImageBase */
492 get_asm_ptr_keyword() );
493 fprintf( outfile, " \"\\t.long %u\\n\"\n", page_size ); /* SectionAlignment */
494 fprintf( outfile, " \"\\t.long %u\\n\"\n", page_size ); /* FileAlignment */
495 fprintf( outfile, " \"\\t%s 1,0\\n\"\n", /* Major/MinorOperatingSystemVersion */
496 get_asm_short_keyword() );
497 fprintf( outfile, " \"\\t%s 0,0\\n\"\n", /* Major/MinorImageVersion */
498 get_asm_short_keyword() );
499 fprintf( outfile, " \"\\t%s %u,%u\\n\"\n", /* Major/MinorSubsystemVersion */
500 get_asm_short_keyword(), spec->subsystem_major, spec->subsystem_minor );
501 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* Win32VersionValue */
502 fprintf( outfile, " \"\\t.long %s\\n\"\n", /* SizeOfImage */
504 fprintf( outfile, " \"\\t.long %u\\n\"\n", page_size ); /* SizeOfHeaders */
505 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* CheckSum */
506 fprintf( outfile, " \"\\t%s 0x%04x\\n\"\n", /* Subsystem */
507 get_asm_short_keyword(), spec->subsystem );
508 fprintf( outfile, " \"\\t%s 0\\n\"\n", /* DllCharacteristics */
509 get_asm_short_keyword() );
510 fprintf( outfile, " \"\\t%s %u,%u\\n\"\n", /* SizeOfStackReserve/Commit */
511 get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
512 fprintf( outfile, " \"\\t%s %u,%u\\n\"\n", /* SizeOfHeapReserve/Commit */
513 get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
514 fprintf( outfile, " \"\\t.long 0\\n\"\n" ); /* LoaderFlags */
515 fprintf( outfile, " \"\\t.long 16\\n\"\n" ); /* NumberOfRvaAndSizes */
517 if (spec->base <= spec->limit) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
518 fprintf( outfile, " \"\\t.long .L__wine_spec_exports, .L__wine_spec_exports_end-.L__wine_spec_exports\\n\"\n" );
520 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" );
522 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
523 fprintf( outfile, " \"\\t.long .L__wine_spec_imports, .L__wine_spec_imports_end-.L__wine_spec_imports\\n\"\n" );
525 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" );
527 if (spec->nb_resources) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
528 fprintf( outfile, " \"\\t.long .L__wine_spec_resources, .L__wine_spec_resources_end-.L__wine_spec_resources\\n\"\n" );
530 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" );
532 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[3] */
533 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[4] */
534 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[5] */
535 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[6] */
536 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[7] */
537 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[8] */
538 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[9] */
539 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[10] */
540 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[11] */
541 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[12] */
542 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[13] */
543 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[14] */
544 fprintf( outfile, " \"\\t.long 0,0\\n\"\n" ); /* DataDirectory[15] */
545 fprintf( outfile, ");\n" );
547 fprintf( outfile, "asm(\"%s\\n\"\n", get_asm_string_section() );
548 fprintf( outfile, " \"\\t.globl %s\\n\"\n", asm_name("__wine_spec_file_name") );
549 fprintf( outfile, " \"%s:\\n\"\n", asm_name("__wine_spec_file_name"));
550 fprintf( outfile, " \"\\t%s \\\"%s\\\"\\n\"\n", get_asm_string_keyword(), spec->file_name );
551 if (target_platform == PLATFORM_APPLE)
552 fprintf( outfile, " \"\\t.comm %s,4\\n\"\n", asm_name("_end") );
554 fprintf( outfile, ");\n" );
556 output_stubs( outfile, spec );
557 output_exports( outfile, spec );
558 output_imports( outfile, spec );
559 output_resources( outfile, spec );
560 output_dll_init( outfile, "__wine_spec_init_ctor", NULL );
562 fprintf( outfile, "#ifndef __GNUC__\n" );
563 fprintf( outfile, "}\n" );
564 fprintf( outfile, "#endif\n" );
568 /*******************************************************************
571 * Build a Win32 def file from a spec file.
573 void BuildDef32File( FILE *outfile, DLLSPEC *spec )
579 fprintf( outfile, "; File generated automatically from %s; do not edit!\n\n",
582 fprintf( outfile, "; File generated automatically; do not edit!\n\n" );
584 fprintf(outfile, "LIBRARY %s\n\n", spec->file_name);
586 fprintf(outfile, "EXPORTS\n");
588 /* Output the exports and relay entry points */
590 for (i = total = 0; i < spec->nb_entry_points; i++)
592 const ORDDEF *odp = &spec->entry_points[i];
597 if (odp->name) name = odp->name;
598 else if (odp->export_name) name = odp->export_name;
601 if (!(odp->flags & FLAG_PRIVATE)) total++;
603 if (odp->type == TYPE_STUB) continue;
605 fprintf(outfile, " %s", name);
614 /* try to reduce output */
615 if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
616 fprintf(outfile, "=%s", odp->link_name);
620 int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
621 if (!kill_at) fprintf(outfile, "@%d", at_param);
622 if (odp->flags & FLAG_FORWARD)
624 fprintf(outfile, "=%s", odp->link_name);
626 else if (strcmp(name, odp->link_name)) /* try to reduce output */
628 fprintf(outfile, "=%s", odp->link_name);
629 if (!kill_at) fprintf(outfile, "@%d", at_param);
636 fprintf( outfile, " @%d", odp->ordinal );
637 if (!odp->name) fprintf( outfile, " NONAME" );
638 if (is_data) fprintf( outfile, " DATA" );
639 if (odp->flags & FLAG_PRIVATE) fprintf( outfile, " PRIVATE" );
640 fprintf( outfile, "\n" );
642 if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
646 /*******************************************************************
649 * Build the debugging channels source file.
651 void BuildDebugFile( FILE *outfile, const char *srcdir, char **argv )
654 char *prefix, *p, *constructor, *destructor;
658 if (!parse_debug_channels( srcdir, *argv++ )) exit(1);
661 output_standard_file_header( outfile );
662 nr_debug = output_debug( outfile );
665 fprintf( outfile, "/* no debug channels found for this module */\n" );
669 if (output_file_name)
671 if ((p = strrchr( output_file_name, '/' ))) p++;
672 prefix = xstrdup( p ? p : output_file_name );
673 if ((p = strchr( prefix, '.' ))) *p = 0;
674 strcpy( p, make_c_identifier(p) );
676 else prefix = xstrdup( "_" );
678 /* Output the DLL constructor */
680 constructor = xmalloc( strlen(prefix) + 17 );
681 destructor = xmalloc( strlen(prefix) + 17 );
682 sprintf( constructor, "__wine_dbg_%s_init", prefix );
683 sprintf( destructor, "__wine_dbg_%s_fini", prefix );
686 "void %s(void) __attribute__((constructor));\n"
687 "void %s(void) __attribute__((destructor));\n"
689 "static void __asm__dummy_dll_init(void) {\n",
690 constructor, destructor );
691 output_dll_init( outfile, constructor, destructor );
692 fprintf( outfile, "}\n#endif /* defined(__GNUC__) */\n\n" );
697 " extern void *__wine_dbg_register( char * const *, int );\n"
698 " if (!debug_registration) debug_registration = __wine_dbg_register( debug_channels, %d );\n"
699 "}\n\n", constructor, nr_debug );
703 " extern void __wine_dbg_unregister( void* );\n"
704 " __wine_dbg_unregister( debug_registration );\n"