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
34 #define EXCEPTION_WINE_STUB 0x80000100 /* stub entry point called */
35 #define EH_NONCONTINUABLE 0x01
40 /* check if entry point needs a relay thunk */
41 static inline int needs_relay( const ORDDEF
*odp
)
43 /* skip nonexistent entry points */
45 /* skip non-functions */
46 if ((odp
->type
!= TYPE_STDCALL
) && (odp
->type
!= TYPE_CDECL
)) return 0;
47 /* skip norelay and forward entry points */
48 if (odp
->flags
& (FLAG_NORELAY
|FLAG_FORWARD
)) return 0;
52 /* check if dll will output relay thunks */
53 int has_relays( DLLSPEC
*spec
)
57 if (target_cpu
!= CPU_x86
) return 0;
59 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
61 ORDDEF
*odp
= spec
->ordinals
[i
];
62 if (needs_relay( odp
)) return 1;
67 /*******************************************************************
70 * Generate an internal name for an entry point. Used for stubs etc.
72 static const char *make_internal_name( const ORDDEF
*odp
, DLLSPEC
*spec
, const char *prefix
)
74 static char buffer
[256];
75 if (odp
->name
|| odp
->export_name
)
78 sprintf( buffer
, "__wine_%s_%s_%s", prefix
, spec
->file_name
,
79 odp
->name
? odp
->name
: odp
->export_name
);
80 /* make sure name is a legal C identifier */
81 for (p
= buffer
; *p
; p
++) if (!isalnum(*p
) && *p
!= '_') break;
82 if (!*p
) return buffer
;
84 sprintf( buffer
, "__wine_%s_%s_%d", prefix
, make_c_identifier(spec
->file_name
), odp
->ordinal
);
89 /*******************************************************************
92 * Output entry points for relay debugging
94 static void output_relay_debug( FILE *outfile
, DLLSPEC
*spec
)
96 unsigned int i
, j
, args
, flags
;
98 /* first the table of entry point offsets */
100 fprintf( outfile
, "\t%s\n", get_asm_rodata_section() );
101 fprintf( outfile
, "\t.align %d\n", get_alignment(4) );
102 fprintf( outfile
, ".L__wine_spec_relay_entry_point_offsets:\n" );
104 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
106 ORDDEF
*odp
= spec
->ordinals
[i
];
108 if (needs_relay( odp
))
109 fprintf( outfile
, "\t.long .L__wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i
);
111 fprintf( outfile
, "\t.long 0\n" );
114 /* then the table of argument types */
116 fprintf( outfile
, "\t.align %d\n", get_alignment(4) );
117 fprintf( outfile
, ".L__wine_spec_relay_arg_types:\n" );
119 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
121 ORDDEF
*odp
= spec
->ordinals
[i
];
122 unsigned int mask
= 0;
124 if (needs_relay( odp
))
126 for (j
= 0; j
< 16 && odp
->u
.func
.arg_types
[j
]; j
++)
128 if (odp
->u
.func
.arg_types
[j
] == 't') mask
|= 1<< (j
*2);
129 if (odp
->u
.func
.arg_types
[j
] == 'W') mask
|= 2<< (j
*2);
132 fprintf( outfile
, "\t.long 0x%08x\n", mask
);
135 /* then the relay thunks */
137 fprintf( outfile
, "\t.text\n" );
138 fprintf( outfile
, "__wine_spec_relay_entry_points:\n" );
139 fprintf( outfile
, "\tnop\n" ); /* to avoid 0 offset */
141 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
143 ORDDEF
*odp
= spec
->ordinals
[i
];
145 if (!needs_relay( odp
)) continue;
147 fprintf( outfile
, "\t.align %d\n", get_alignment(4) );
148 fprintf( outfile
, ".L__wine_spec_relay_entry_point_%d:\n", i
);
150 if (odp
->flags
& FLAG_REGISTER
)
151 fprintf( outfile
, "\tpushl %%eax\n" );
153 fprintf( outfile
, "\tpushl %%esp\n" );
155 args
= strlen(odp
->u
.func
.arg_types
);
157 if (odp
->flags
& FLAG_RET64
) flags
|= 1;
158 if (odp
->type
== TYPE_STDCALL
) flags
|= 2;
159 fprintf( outfile
, "\tpushl $%u\n", (flags
<< 24) | (args
<< 16) | (i
- spec
->base
) );
163 fprintf( outfile
, "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
164 fprintf( outfile
, "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
166 else fprintf( outfile
, "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
167 fprintf( outfile
, "\tpushl %%eax\n" );
169 if (odp
->flags
& FLAG_REGISTER
)
171 fprintf( outfile
, "\tcall *8(%%eax)\n" );
175 fprintf( outfile
, "\tcall *4(%%eax)\n" );
176 if (odp
->type
== TYPE_STDCALL
)
177 fprintf( outfile
, "\tret $%u\n", args
* get_ptr_size() );
179 fprintf( outfile
, "\tret\n" );
184 /*******************************************************************
187 * Output the export table for a Win32 module.
189 static void output_exports( FILE *outfile
, DLLSPEC
*spec
)
192 int nr_exports
= spec
->base
<= spec
->limit
? spec
->limit
- spec
->base
+ 1 : 0;
194 if (!nr_exports
) return;
196 fprintf( outfile
, "\n/* export table */\n\n" );
197 fprintf( outfile
, "\t.data\n" );
198 fprintf( outfile
, "\t.align %d\n", get_alignment(4) );
199 fprintf( outfile
, ".L__wine_spec_exports:\n" );
201 /* export directory header */
203 fprintf( outfile
, "\t.long 0\n" ); /* Characteristics */
204 fprintf( outfile
, "\t.long 0\n" ); /* TimeDateStamp */
205 fprintf( outfile
, "\t.long 0\n" ); /* MajorVersion/MinorVersion */
206 fprintf( outfile
, "\t.long .L__wine_spec_exp_names-.L__wine_spec_rva_base\n" ); /* Name */
207 fprintf( outfile
, "\t.long %u\n", spec
->base
); /* Base */
208 fprintf( outfile
, "\t.long %u\n", nr_exports
); /* NumberOfFunctions */
209 fprintf( outfile
, "\t.long %u\n", spec
->nb_names
); /* NumberOfNames */
210 fprintf( outfile
, "\t.long .L__wine_spec_exports_funcs-.L__wine_spec_rva_base\n" ); /* AddressOfFunctions */
213 fprintf( outfile
, "\t.long .L__wine_spec_exp_name_ptrs-.L__wine_spec_rva_base\n" ); /* AddressOfNames */
214 fprintf( outfile
, "\t.long .L__wine_spec_exp_ordinals-.L__wine_spec_rva_base\n" ); /* AddressOfNameOrdinals */
218 fprintf( outfile
, "\t.long 0\n" ); /* AddressOfNames */
219 fprintf( outfile
, "\t.long 0\n" ); /* AddressOfNameOrdinals */
222 /* output the function pointers */
224 fprintf( outfile
, "\n.L__wine_spec_exports_funcs:\n" );
225 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
227 ORDDEF
*odp
= spec
->ordinals
[i
];
228 if (!odp
) fprintf( outfile
, "\t.long 0\n" );
229 else switch(odp
->type
)
235 if (odp
->flags
& FLAG_FORWARD
)
237 fprintf( outfile
, "\t%s .L__wine_spec_forwards+%u\n", get_asm_ptr_keyword(), fwd_size
);
238 fwd_size
+= strlen(odp
->link_name
) + 1;
240 else if (odp
->flags
& FLAG_EXT_LINK
)
242 fprintf( outfile
, "\t%s %s_%s\n",
243 get_asm_ptr_keyword(), asm_name("__wine_spec_ext_link"), odp
->link_name
);
247 fprintf( outfile
, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
251 fprintf( outfile
, "\t%s %s\n", get_asm_ptr_keyword(),
252 asm_name( get_stub_name( odp
, spec
)) );
261 /* output the function name pointers */
263 int namepos
= strlen(spec
->file_name
) + 1;
265 fprintf( outfile
, "\n.L__wine_spec_exp_name_ptrs:\n" );
266 for (i
= 0; i
< spec
->nb_names
; i
++)
268 fprintf( outfile
, "\t.long .L__wine_spec_exp_names+%u-.L__wine_spec_rva_base\n", namepos
);
269 namepos
+= strlen(spec
->names
[i
]->name
) + 1;
272 /* output the function ordinals */
274 fprintf( outfile
, "\n.L__wine_spec_exp_ordinals:\n" );
275 for (i
= 0; i
< spec
->nb_names
; i
++)
277 fprintf( outfile
, "\t%s %d\n",
278 get_asm_short_keyword(), spec
->names
[i
]->ordinal
- spec
->base
);
280 if (spec
->nb_names
% 2)
282 fprintf( outfile
, "\t%s 0\n", get_asm_short_keyword() );
286 /* output the export name strings */
288 fprintf( outfile
, "\n.L__wine_spec_exp_names:\n" );
289 fprintf( outfile
, "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
290 for (i
= 0; i
< spec
->nb_names
; i
++)
291 fprintf( outfile
, "\t%s \"%s\"\n",
292 get_asm_string_keyword(), spec
->names
[i
]->name
);
294 /* output forward strings */
298 fprintf( outfile
, "\n.L__wine_spec_forwards:\n" );
299 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
301 ORDDEF
*odp
= spec
->ordinals
[i
];
302 if (odp
&& (odp
->flags
& FLAG_FORWARD
))
303 fprintf( outfile
, "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->link_name
);
306 fprintf( outfile
, "\t.align %d\n", get_alignment(get_ptr_size()) );
307 fprintf( outfile
, ".L__wine_spec_exports_end:\n" );
311 /* we only support relay debugging on i386 */
312 if (target_cpu
!= CPU_x86
)
314 fprintf( outfile
, "\t%s 0\n", get_asm_ptr_keyword() );
318 fprintf( outfile
, ".L__wine_spec_relay_descr:\n" );
319 fprintf( outfile
, "\t%s 0xdeb90001\n", get_asm_ptr_keyword() ); /* magic */
320 fprintf( outfile
, "\t%s 0,0\n", get_asm_ptr_keyword() ); /* relay funcs */
321 fprintf( outfile
, "\t%s 0\n", get_asm_ptr_keyword() ); /* private data */
322 fprintf( outfile
, "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
323 fprintf( outfile
, "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
324 fprintf( outfile
, "\t%s .L__wine_spec_relay_arg_types\n", get_asm_ptr_keyword() );
326 output_relay_debug( outfile
, spec
);
330 /*******************************************************************
333 * Output the functions for stub entry points
335 static void output_stub_funcs( FILE *outfile
, DLLSPEC
*spec
)
340 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
342 ORDDEF
*odp
= &spec
->entry_points
[i
];
343 if (odp
->type
!= TYPE_STUB
) continue;
344 fprintf( outfile
, "#ifdef __GNUC__\n" );
345 fprintf( outfile
, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func ) __attribute__((noreturn));\n" );
346 fprintf( outfile
, "#else\n" );
347 fprintf( outfile
, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func );\n" );
348 fprintf( outfile
, "#endif\n\n" );
353 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
355 const ORDDEF
*odp
= &spec
->entry_points
[i
];
356 if (odp
->type
!= TYPE_STUB
) continue;
357 fprintf( outfile
, "void %s(void) ", make_internal_name( odp
, spec
, "stub" ) );
359 fprintf( outfile
, "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp
->name
);
360 else if (odp
->export_name
)
361 fprintf( outfile
, "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp
->export_name
);
363 fprintf( outfile
, "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%d\"); }\n", odp
->ordinal
);
368 /*******************************************************************
369 * output_asm_constructor
371 * Output code for calling a dll constructor.
373 static void output_asm_constructor( FILE *outfile
, const char *constructor
)
375 if (target_platform
== PLATFORM_APPLE
)
377 /* Mach-O doesn't have an init section */
378 fprintf( outfile
, "\n\t.mod_init_func\n" );
379 fprintf( outfile
, "\t.align %d\n", get_alignment(4) );
380 fprintf( outfile
, "\t.long %s\n", asm_name(constructor
) );
384 fprintf( outfile
, "\n\t.section \".init\",\"ax\"\n" );
389 fprintf( outfile
, "\tcall %s\n", asm_name(constructor
) );
392 fprintf( outfile
, "\tcall %s\n", asm_name(constructor
) );
393 fprintf( outfile
, "\tnop\n" );
396 fprintf( outfile
, "\tjsr $26,%s\n", asm_name(constructor
) );
399 fprintf( outfile
, "\tbl %s\n", asm_name(constructor
) );
406 /*******************************************************************
409 * Build a Win32 C file from a spec file.
411 void BuildSpec32File( FILE *outfile
, DLLSPEC
*spec
)
414 unsigned int page_size
= get_page_size();
416 resolve_imports( spec
);
417 output_standard_file_header( outfile
);
419 /* Reserve some space for the PE header */
421 fprintf( outfile
, "\t.text\n" );
422 fprintf( outfile
, "\t.align %d\n", get_alignment(page_size
) );
423 fprintf( outfile
, "__wine_spec_pe_header:\n" );
424 if (target_platform
== PLATFORM_APPLE
)
425 fprintf( outfile
, "\t.space 65536\n" );
427 fprintf( outfile
, "\t.skip 65536\n" );
429 /* Output the NT header */
431 fprintf( outfile
, "\n\t.data\n" );
432 fprintf( outfile
, "\t.align %d\n", get_alignment(get_ptr_size()) );
433 fprintf( outfile
, "%s\n", asm_globl("__wine_spec_nt_header") );
434 fprintf( outfile
, ".L__wine_spec_rva_base:\n" );
436 fprintf( outfile
, "\t.long 0x%04x\n", IMAGE_NT_SIGNATURE
); /* Signature */
439 case CPU_x86
: machine
= IMAGE_FILE_MACHINE_I386
; break;
440 case CPU_x86_64
: machine
= IMAGE_FILE_MACHINE_AMD64
; break;
441 case CPU_POWERPC
: machine
= IMAGE_FILE_MACHINE_POWERPC
; break;
442 case CPU_ALPHA
: machine
= IMAGE_FILE_MACHINE_ALPHA
; break;
443 case CPU_SPARC
: machine
= IMAGE_FILE_MACHINE_UNKNOWN
; break;
445 fprintf( outfile
, "\t%s 0x%04x\n", /* Machine */
446 get_asm_short_keyword(), machine
);
447 fprintf( outfile
, "\t%s 0\n", /* NumberOfSections */
448 get_asm_short_keyword() );
449 fprintf( outfile
, "\t.long 0\n" ); /* TimeDateStamp */
450 fprintf( outfile
, "\t.long 0\n" ); /* PointerToSymbolTable */
451 fprintf( outfile
, "\t.long 0\n" ); /* NumberOfSymbols */
452 fprintf( outfile
, "\t%s %d\n", /* SizeOfOptionalHeader */
453 get_asm_short_keyword(),
454 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
: IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
);
455 fprintf( outfile
, "\t%s 0x%04x\n", /* Characteristics */
456 get_asm_short_keyword(), spec
->characteristics
);
457 fprintf( outfile
, "\t%s 0x%04x\n", /* Magic */
458 get_asm_short_keyword(),
459 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
: IMAGE_NT_OPTIONAL_HDR32_MAGIC
);
460 fprintf( outfile
, "\t.byte 0\n" ); /* MajorLinkerVersion */
461 fprintf( outfile
, "\t.byte 0\n" ); /* MinorLinkerVersion */
462 fprintf( outfile
, "\t.long 0\n" ); /* SizeOfCode */
463 fprintf( outfile
, "\t.long 0\n" ); /* SizeOfInitializedData */
464 fprintf( outfile
, "\t.long 0\n" ); /* SizeOfUninitializedData */
465 /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
466 fprintf( outfile
, "\t%s %s\n", /* AddressOfEntryPoint */
467 get_asm_ptr_keyword(), asm_name(spec
->init_func
) );
468 if (get_ptr_size() == 4)
470 fprintf( outfile
, "\t.long 0\n" ); /* BaseOfCode */
471 fprintf( outfile
, "\t.long 0\n" ); /* BaseOfData */
473 fprintf( outfile
, "\t%s __wine_spec_pe_header\n", /* ImageBase */
474 get_asm_ptr_keyword() );
475 fprintf( outfile
, "\t.long %u\n", page_size
); /* SectionAlignment */
476 fprintf( outfile
, "\t.long %u\n", page_size
); /* FileAlignment */
477 fprintf( outfile
, "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
478 get_asm_short_keyword() );
479 fprintf( outfile
, "\t%s 0,0\n", /* Major/MinorImageVersion */
480 get_asm_short_keyword() );
481 fprintf( outfile
, "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
482 get_asm_short_keyword(), spec
->subsystem_major
, spec
->subsystem_minor
);
483 fprintf( outfile
, "\t.long 0\n" ); /* Win32VersionValue */
484 fprintf( outfile
, "\t.long %s-.L__wine_spec_rva_base\n", /* SizeOfImage */
486 fprintf( outfile
, "\t.long %u\n", page_size
); /* SizeOfHeaders */
487 fprintf( outfile
, "\t.long 0\n" ); /* CheckSum */
488 fprintf( outfile
, "\t%s 0x%04x\n", /* Subsystem */
489 get_asm_short_keyword(), spec
->subsystem
);
490 fprintf( outfile
, "\t%s 0\n", /* DllCharacteristics */
491 get_asm_short_keyword() );
492 fprintf( outfile
, "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
493 get_asm_ptr_keyword(), (spec
->stack_size
? spec
->stack_size
: 1024) * 1024, page_size
);
494 fprintf( outfile
, "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
495 get_asm_ptr_keyword(), (spec
->heap_size
? spec
->heap_size
: 1024) * 1024, page_size
);
496 fprintf( outfile
, "\t.long 0\n" ); /* LoaderFlags */
497 fprintf( outfile
, "\t.long 16\n" ); /* NumberOfRvaAndSizes */
499 if (spec
->base
<= spec
->limit
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
500 fprintf( outfile
, "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
501 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
503 fprintf( outfile
, "\t.long 0,0\n" );
505 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
506 fprintf( outfile
, "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
507 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
509 fprintf( outfile
, "\t.long 0,0\n" );
511 if (spec
->nb_resources
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
512 fprintf( outfile
, "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
513 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
515 fprintf( outfile
, "\t.long 0,0\n" );
517 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[3] */
518 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[4] */
519 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[5] */
520 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[6] */
521 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[7] */
522 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[8] */
523 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[9] */
524 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[10] */
525 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[11] */
526 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[12] */
527 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[13] */
528 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[14] */
529 fprintf( outfile
, "\t.long 0,0\n" ); /* DataDirectory[15] */
531 fprintf( outfile
, "\n\t%s\n", get_asm_string_section() );
532 fprintf( outfile
, "%s\n", asm_globl("__wine_spec_file_name") );
533 fprintf( outfile
, ".L__wine_spec_file_name:\n" );
534 fprintf( outfile
, "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
535 if (target_platform
== PLATFORM_APPLE
)
536 fprintf( outfile
, "\t.lcomm %s,4\n", asm_name("_end") );
538 output_stubs( outfile
, spec
);
539 output_exports( outfile
, spec
);
540 output_imports( outfile
, spec
);
541 output_resources( outfile
, spec
);
542 output_asm_constructor( outfile
, "__wine_spec_init_ctor" );
546 /*******************************************************************
549 * Build a Win32 def file from a spec file.
551 void BuildDef32File( FILE *outfile
, DLLSPEC
*spec
)
557 fprintf( outfile
, "; File generated automatically from %s; do not edit!\n\n",
560 fprintf( outfile
, "; File generated automatically; do not edit!\n\n" );
562 fprintf(outfile
, "LIBRARY %s\n\n", spec
->file_name
);
564 fprintf(outfile
, "EXPORTS\n");
566 /* Output the exports and relay entry points */
568 for (i
= total
= 0; i
< spec
->nb_entry_points
; i
++)
570 const ORDDEF
*odp
= &spec
->entry_points
[i
];
575 if (odp
->name
) name
= odp
->name
;
576 else if (odp
->type
== TYPE_STUB
) name
= make_internal_name( odp
, spec
, "stub" );
577 else if (odp
->export_name
) name
= odp
->export_name
;
578 else name
= make_internal_name( odp
, spec
, "noname_export" );
580 if (!(odp
->flags
& FLAG_PRIVATE
)) total
++;
582 fprintf(outfile
, " %s", name
);
591 /* try to reduce output */
592 if(strcmp(name
, odp
->link_name
) || (odp
->flags
& FLAG_FORWARD
))
593 fprintf(outfile
, "=%s", odp
->link_name
);
597 int at_param
= strlen(odp
->u
.func
.arg_types
) * get_ptr_size();
598 if (!kill_at
) fprintf(outfile
, "@%d", at_param
);
599 if (odp
->flags
& FLAG_FORWARD
)
601 fprintf(outfile
, "=%s", odp
->link_name
);
603 else if (strcmp(name
, odp
->link_name
)) /* try to reduce output */
605 fprintf(outfile
, "=%s", odp
->link_name
);
606 if (!kill_at
) fprintf(outfile
, "@%d", at_param
);
614 const char *check
= name
+ strlen(name
);
615 while (name
!= check
&&
616 '0' <= check
[-1] && check
[-1] <= '9')
620 if (name
!= check
&& check
!= name
+ strlen(name
) &&
623 fprintf(outfile
, "%s", check
- 1);
626 if (NULL
!= odp
->name
)
628 fprintf(outfile
, "=%s", make_internal_name( odp
, spec
, "stub" ));
635 fprintf( outfile
, " @%d", odp
->ordinal
);
636 #if 0 /* MinGW binutils cannot handle this correctly */
637 if (!odp
->name
) fprintf( outfile
, " NONAME" );
639 if (!odp
->name
&& (odp
->type
== TYPE_STUB
|| odp
->export_name
)) fprintf( outfile
, " NONAME" );
641 if (is_data
) fprintf( outfile
, " DATA" );
643 /* MinGW binutils cannot handle this correctly */
644 if (odp
->flags
& FLAG_PRIVATE
) fprintf( outfile
, " PRIVATE" );
646 fprintf( outfile
, "\n" );
648 if (!total
) warning( "%s: Import library doesn't export anything\n", spec
->file_name
);
652 /*******************************************************************
655 * Build a PE DLL C file from a spec file.
657 void BuildPedllFile( FILE *outfile
, DLLSPEC
*spec
)
661 nr_exports
= spec
->base
<= spec
->limit
? spec
->limit
- spec
->base
+ 1 : 0;
662 output_standard_file_header( outfile
);
664 fprintf( outfile
, "#include <stdarg.h>\n");
665 fprintf( outfile
, "#include \"windef.h\"\n");
666 fprintf( outfile
, "#include \"winbase.h\"\n");
667 fprintf( outfile
, "#include \"wine/config.h\"\n");
668 fprintf( outfile
, "#include \"wine/exception.h\"\n\n");
670 fprintf( outfile
, "void __wine_spec_unimplemented_stub( const char *module, const char *function )\n");
671 fprintf( outfile
, "{\n");
672 fprintf( outfile
, " ULONG_PTR args[2];\n");
673 fprintf( outfile
, "\n");
674 fprintf( outfile
, " args[0] = (ULONG_PTR)module;\n");
675 fprintf( outfile
, " args[1] = (ULONG_PTR)function;\n");
676 fprintf( outfile
, " RaiseException( EXCEPTION_WINE_STUB, EH_NONCONTINUABLE, 2, args );\n");
677 fprintf( outfile
, "}\n\n");
679 fprintf( outfile
, "static const char __wine_spec_file_name[] = \"%s\";\n\n", spec
->file_name
);
683 /* Output the stub functions */
685 output_stub_funcs( outfile
, spec
);