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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
34 //#include "wine/exception.h"
38 /* check if entry point needs a relay thunk */
39 static inline int needs_relay( const ORDDEF
*odp
)
41 /* skip nonexistent entry points */
43 /* skip non-functions */
44 if ((odp
->type
!= TYPE_STDCALL
) && (odp
->type
!= TYPE_CDECL
)) return 0;
45 if ((odp
->type
== TYPE_CDECL
) && (target_cpu
== CPU_x86_64
)) return 0;
46 /* skip norelay and forward entry points */
47 if (odp
->flags
& (FLAG_NORELAY
|FLAG_FORWARD
)) return 0;
51 /* check if dll will output relay thunks */
52 int has_relays( DLLSPEC
*spec
)
56 if (target_cpu
!= CPU_x86
&& target_cpu
!= CPU_x86_64
) return 0;
58 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
60 ORDDEF
*odp
= spec
->ordinals
[i
];
61 if (needs_relay( odp
)) return 1;
66 /*******************************************************************
69 * Generate an internal name for an entry point. Used for stubs etc.
71 static const char *make_internal_name( const ORDDEF
*odp
, DLLSPEC
*spec
, const char *prefix
)
73 static char buffer
[256];
74 if (odp
->name
|| odp
->export_name
)
77 sprintf( buffer
, "__wine_%s_%s_%s", prefix
, spec
->file_name
,
78 odp
->name
? odp
->name
: odp
->export_name
);
79 /* make sure name is a legal C identifier */
80 for (p
= buffer
; *p
; p
++) if (!isalnum(*p
) && *p
!= '_') break;
81 if (!*p
) return buffer
;
83 sprintf( buffer
, "__wine_%s_%s_%d", prefix
, make_c_identifier(spec
->file_name
), odp
->ordinal
);
87 static void output_relay_debug_x86(DLLSPEC
*spec
, int i
)
89 unsigned int args
, flags
;
90 ORDDEF
*odp
= spec
->ordinals
[i
];
92 output( "\t.align %d\n", get_alignment(4) );
93 output( ".L__wine_spec_relay_entry_point_%d:\n", i
);
95 if (odp
->flags
& FLAG_REGISTER
)
96 output( "\tpushl %%eax\n" );
98 output( "\tpushl %%esp\n" );
100 args
= strlen(odp
->u
.func
.arg_types
);
102 if (odp
->flags
& FLAG_RET64
) flags
|= 1;
103 if (odp
->type
== TYPE_STDCALL
) flags
|= 2;
104 output( "\tpushl $%u\n", (flags
<< 24) | (args
<< 16) | (i
- spec
->base
) );
108 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
109 output( "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
111 else output( "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
112 output( "\tpushl %%eax\n" );
114 if (odp
->flags
& FLAG_REGISTER
)
116 output( "\tcall *8(%%eax)\n" );
120 output( "\tcall *4(%%eax)\n" );
121 if (odp
->type
== TYPE_STDCALL
)
122 output( "\tret $%u\n", args
* get_ptr_size() );
129 static void output_relay_debug_amd64(DLLSPEC
*spec
, int i
)
131 unsigned int args
, flags
;
132 ORDDEF
*odp
= spec
->ordinals
[i
];
134 output( "\t.align %d\n", get_alignment(8) );
135 output( ".type __wine_spec_relay_entry_point_%d,@function\n", i
);
136 output( "__wine_spec_relay_entry_point_%d:\n", i
);
138 /* Save the original registers on the stack, so +relay can use them */
139 /* This makes the stack layout a bit weird:
140 * [ 4 longs reserved by abi ]
141 * [ rcx, rdx, r8, r9 ]
142 * [ fixed alignment ]
144 * [ 4 longs reserved by abi ]
145 * [ possibly additonal args ]
147 output( "\tpushq %%rbp\n" );
148 output( "\tmovq %%rsp, %%rbp\n" );
149 output( "\tsubq $0x40, %%rsp\n" );
150 output( "\tmovq %%rcx, 0x20(%%rsp)\n" );
151 output( "\tmovq %%rdx, 0x28(%%rsp)\n" );
152 output( "\tmovq %%r8, 0x30(%%rsp)\n" );
153 output( "\tmovq %%r9, 0x38(%%rsp)\n" );
157 output( "\tleaq .L__wine_spec_relay_descr(%%rip),%%rcx\n" );
159 else output( "\tmovq $.L__wine_spec_relay_descr,%%rcx\n" );
161 args
= strlen(odp
->u
.func
.arg_types
);
162 flags
= 0; /* For later use */
163 output( "\tmovq $%u, %%rdx\n", (flags
<< 24) | (args
<< 16) | (i
- spec
->base
) );
165 output( "\tmovq %%rsp, %%r8\n" );
167 output( "\tcall *8(%%rcx)\n" );
168 output( "\tmovq 0x20(%%rsp), %%rcx\n" );
169 output( "\tmovq 0x28(%%rsp), %%rdx\n" );
170 output( "\tmovq 0x30(%%rsp), %%r8\n" );
171 output( "\tmovq 0x38(%%rsp), %%r9\n" );
172 output( "\taddq $0x40, %%rsp\n" );
173 output( "\tleaveq\n" );
177 /*******************************************************************
180 * Output entry points for relay debugging
182 static void output_relay_debug( DLLSPEC
*spec
)
187 /* first the table of entry point offsets */
189 output( "\t%s\n", get_asm_rodata_section() );
190 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
191 output( ".L__wine_spec_relay_entry_point_offsets:\n" );
193 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
195 ORDDEF
*odp
= spec
->ordinals
[i
];
197 if (needs_relay( odp
))
198 output( "\t.long __wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i
);
200 output( "\t.long 0\n" );
203 /* then the table of argument types */
205 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
206 output( ".L__wine_spec_relay_arg_types:\n" );
208 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
210 ORDDEF
*odp
= spec
->ordinals
[i
];
211 unsigned int mask
= 0;
213 if (needs_relay( odp
))
215 for (j
= 0; j
< 16 && odp
->u
.func
.arg_types
[j
]; j
++)
217 if (odp
->u
.func
.arg_types
[j
] == 't') mask
|= 1<< (j
*2);
218 if (odp
->u
.func
.arg_types
[j
] == 'W') mask
|= 2<< (j
*2);
221 output( "\t.long 0x%08x\n", mask
);
224 /* then the relay thunks */
226 output( "\t.text\n" );
227 output( "__wine_spec_relay_entry_points:\n" );
228 output( "\tnop\n" ); /* to avoid 0 offset */
230 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
232 ORDDEF
*odp
= spec
->ordinals
[i
];
234 if (!needs_relay( odp
)) continue;
236 if (target_cpu
== CPU_x86
)
237 output_relay_debug_x86( spec
, i
);
238 else if (target_cpu
== CPU_x86_64
)
239 output_relay_debug_amd64( spec
, i
);
245 /*******************************************************************
248 * Output the export table for a Win32 module.
250 static void output_exports( DLLSPEC
*spec
)
253 int nr_exports
= spec
->base
<= spec
->limit
? spec
->limit
- spec
->base
+ 1 : 0;
255 if (!nr_exports
) return;
257 output( "\n/* export table */\n\n" );
258 output( "\t.data\n" );
259 output( "\t.align %d\n", get_alignment(4) );
260 output( ".L__wine_spec_exports:\n" );
262 /* export directory header */
264 output( "\t.long 0\n" ); /* Characteristics */
265 output( "\t.long 0\n" ); /* TimeDateStamp */
266 output( "\t.long 0\n" ); /* MajorVersion/MinorVersion */
267 output( "\t.long .L__wine_spec_exp_names-.L__wine_spec_rva_base\n" ); /* Name */
268 output( "\t.long %u\n", spec
->base
); /* Base */
269 output( "\t.long %u\n", nr_exports
); /* NumberOfFunctions */
270 output( "\t.long %u\n", spec
->nb_names
); /* NumberOfNames */
271 output( "\t.long .L__wine_spec_exports_funcs-.L__wine_spec_rva_base\n" ); /* AddressOfFunctions */
274 output( "\t.long .L__wine_spec_exp_name_ptrs-.L__wine_spec_rva_base\n" ); /* AddressOfNames */
275 output( "\t.long .L__wine_spec_exp_ordinals-.L__wine_spec_rva_base\n" ); /* AddressOfNameOrdinals */
279 output( "\t.long 0\n" ); /* AddressOfNames */
280 output( "\t.long 0\n" ); /* AddressOfNameOrdinals */
283 /* output the function pointers */
285 output( "\n.L__wine_spec_exports_funcs:\n" );
286 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
288 ORDDEF
*odp
= spec
->ordinals
[i
];
289 if (!odp
) output( "\t%s 0\n", get_asm_ptr_keyword() );
290 else switch(odp
->type
)
296 if (odp
->flags
& FLAG_FORWARD
)
298 output( "\t%s .L__wine_spec_forwards+%u\n", get_asm_ptr_keyword(), fwd_size
);
299 fwd_size
+= strlen(odp
->link_name
) + 1;
301 else if (odp
->flags
& FLAG_EXT_LINK
)
303 output( "\t%s %s_%s\n",
304 get_asm_ptr_keyword(), asm_name("__wine_spec_ext_link"), odp
->link_name
);
308 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
312 output( "\t%s %s\n", get_asm_ptr_keyword(),
313 asm_name( get_stub_name( odp
, spec
)) );
322 /* output the function name pointers */
324 int namepos
= strlen(spec
->file_name
) + 1;
326 output( "\n.L__wine_spec_exp_name_ptrs:\n" );
327 for (i
= 0; i
< spec
->nb_names
; i
++)
329 output( "\t.long .L__wine_spec_exp_names+%u-.L__wine_spec_rva_base\n", namepos
);
330 namepos
+= strlen(spec
->names
[i
]->name
) + 1;
333 /* output the function ordinals */
335 output( "\n.L__wine_spec_exp_ordinals:\n" );
336 for (i
= 0; i
< spec
->nb_names
; i
++)
339 get_asm_short_keyword(), spec
->names
[i
]->ordinal
- spec
->base
);
341 if (spec
->nb_names
% 2)
343 output( "\t%s 0\n", get_asm_short_keyword() );
347 /* output the export name strings */
349 output( "\n.L__wine_spec_exp_names:\n" );
350 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
351 for (i
= 0; i
< spec
->nb_names
; i
++)
352 output( "\t%s \"%s\"\n",
353 get_asm_string_keyword(), spec
->names
[i
]->name
);
355 /* output forward strings */
359 output( "\n.L__wine_spec_forwards:\n" );
360 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
362 ORDDEF
*odp
= spec
->ordinals
[i
];
363 if (odp
&& (odp
->flags
& FLAG_FORWARD
))
364 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->link_name
);
367 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
368 output( ".L__wine_spec_exports_end:\n" );
372 /* we only support relay debugging on i386 and amd64 */
373 if (target_cpu
!= CPU_x86
&& target_cpu
!= CPU_x86_64
)
375 output( "\t%s 0\n", get_asm_ptr_keyword() );
379 output( ".L__wine_spec_relay_descr:\n" );
380 output( "\t%s 0xdeb90001\n", get_asm_ptr_keyword() ); /* magic */
381 output( "\t%s 0,0\n", get_asm_ptr_keyword() ); /* relay funcs */
382 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* private data */
383 output( "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
384 output( "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
385 output( "\t%s .L__wine_spec_relay_arg_types\n", get_asm_ptr_keyword() );
387 output_relay_debug( spec
);
391 /*******************************************************************
394 * Output the functions for stub entry points
396 static void output_stub_funcs( DLLSPEC
*spec
)
401 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
403 ORDDEF
*odp
= &spec
->entry_points
[i
];
404 if (odp
->type
!= TYPE_STUB
) continue;
405 fprintf( outfile
, "#ifdef __GNUC__\n" );
406 fprintf( outfile
, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func ) __attribute__((noreturn));\n" );
407 fprintf( outfile
, "#else\n" );
408 fprintf( outfile
, "extern void __wine_spec_unimplemented_stub( const char *module, const char *func );\n" );
409 fprintf( outfile
, "#endif\n\n" );
414 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
416 const ORDDEF
*odp
= &spec
->entry_points
[i
];
417 if (odp
->type
!= TYPE_STUB
) continue;
418 output( "void %s(void) ", make_internal_name( odp
, spec
, "stub" ) );
420 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp
->name
);
421 else if (odp
->export_name
)
422 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%s\"); }\n", odp
->export_name
);
424 output( "{ __wine_spec_unimplemented_stub(__wine_spec_file_name, \"%d\"); }\n", odp
->ordinal
);
429 /*******************************************************************
430 * output_asm_constructor
432 * Output code for calling a dll constructor.
434 static void output_asm_constructor( const char *constructor
)
436 if (target_platform
== PLATFORM_APPLE
)
438 /* Mach-O doesn't have an init section */
439 output( "\n\t.mod_init_func\n" );
440 output( "\t.align %d\n", get_alignment(4) );
441 output( "\t.long %s\n", asm_name(constructor
) );
445 output( "\n\t.section \".init\",\"ax\"\n" );
450 output( "\tcall %s\n", asm_name(constructor
) );
453 output( "\tcall %s\n", asm_name(constructor
) );
457 output( "\tjsr $26,%s\n", asm_name(constructor
) );
460 output( "\tbl %s\n", asm_name(constructor
) );
467 /*******************************************************************
470 * Build a Win32 C file from a spec file.
472 void BuildSpec32File( DLLSPEC
*spec
)
475 unsigned int page_size
= get_page_size();
477 resolve_imports( spec
);
478 output_standard_file_header();
480 /* Reserve some space for the PE header */
482 switch (target_platform
)
485 output( "\t.text\n" );
486 output( "\t.align %d\n", get_alignment(page_size
) );
487 output( "__wine_spec_pe_header:\n" );
488 output( "\t.space 65536\n" );
490 case PLATFORM_SOLARIS
:
491 output( "\n\t.section \".text\",\"ax\"\n" );
492 output( "__wine_spec_pe_header:\n" );
493 output( "\t.skip %u\n", 65536 + page_size
);
496 output( "\n\t.section \".init\",\"ax\"\n" );
503 output( "\tjmp 1f\n" );
506 output( "\tb 1f\n" );
509 output( "__wine_spec_pe_header:\n" );
510 output( "\t.skip %u\n", 65536 + page_size
);
515 /* Output the NT header */
517 output( "\n\t.data\n" );
518 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
519 output( "%s\n", asm_globl("__wine_spec_nt_header") );
520 output( ".L__wine_spec_rva_base:\n" );
522 output( "\t.long 0x%04x\n", IMAGE_NT_SIGNATURE
); /* Signature */
525 case CPU_x86
: machine
= IMAGE_FILE_MACHINE_I386
; break;
526 case CPU_x86_64
: machine
= IMAGE_FILE_MACHINE_AMD64
; break;
527 case CPU_POWERPC
: machine
= IMAGE_FILE_MACHINE_POWERPC
; break;
528 case CPU_ALPHA
: machine
= IMAGE_FILE_MACHINE_ALPHA
; break;
529 case CPU_SPARC
: machine
= IMAGE_FILE_MACHINE_UNKNOWN
; break;
531 output( "\t%s 0x%04x\n", /* Machine */
532 get_asm_short_keyword(), machine
);
533 output( "\t%s 0\n", /* NumberOfSections */
534 get_asm_short_keyword() );
535 output( "\t.long 0\n" ); /* TimeDateStamp */
536 output( "\t.long 0\n" ); /* PointerToSymbolTable */
537 output( "\t.long 0\n" ); /* NumberOfSymbols */
538 output( "\t%s %d\n", /* SizeOfOptionalHeader */
539 get_asm_short_keyword(),
540 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
: IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
);
541 output( "\t%s 0x%04x\n", /* Characteristics */
542 get_asm_short_keyword(), spec
->characteristics
);
543 output( "\t%s 0x%04x\n", /* Magic */
544 get_asm_short_keyword(),
545 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
: IMAGE_NT_OPTIONAL_HDR32_MAGIC
);
546 output( "\t.byte 0\n" ); /* MajorLinkerVersion */
547 output( "\t.byte 0\n" ); /* MinorLinkerVersion */
548 output( "\t.long 0\n" ); /* SizeOfCode */
549 output( "\t.long 0\n" ); /* SizeOfInitializedData */
550 output( "\t.long 0\n" ); /* SizeOfUninitializedData */
551 /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
552 output( "\t%s %s\n", /* AddressOfEntryPoint */
553 get_asm_ptr_keyword(), asm_name(spec
->init_func
) );
554 if (get_ptr_size() == 4)
556 output( "\t.long 0\n" ); /* BaseOfCode */
557 output( "\t.long 0\n" ); /* BaseOfData */
559 output( "\t%s __wine_spec_pe_header\n", /* ImageBase */
560 get_asm_ptr_keyword() );
561 output( "\t.long %u\n", page_size
); /* SectionAlignment */
562 output( "\t.long %u\n", page_size
); /* FileAlignment */
563 output( "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
564 get_asm_short_keyword() );
565 output( "\t%s 0,0\n", /* Major/MinorImageVersion */
566 get_asm_short_keyword() );
567 output( "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
568 get_asm_short_keyword(), spec
->subsystem_major
, spec
->subsystem_minor
);
569 output( "\t.long 0\n" ); /* Win32VersionValue */
570 output( "\t.long %s-.L__wine_spec_rva_base\n", /* SizeOfImage */
572 output( "\t.long %u\n", page_size
); /* SizeOfHeaders */
573 output( "\t.long 0\n" ); /* CheckSum */
574 output( "\t%s 0x%04x\n", /* Subsystem */
575 get_asm_short_keyword(), spec
->subsystem
);
576 output( "\t%s 0x%04x\n", /* DllCharacteristics */
577 get_asm_short_keyword(), spec
->dll_characteristics
);
578 output( "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
579 get_asm_ptr_keyword(), (spec
->stack_size
? spec
->stack_size
: 1024) * 1024, page_size
);
580 output( "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
581 get_asm_ptr_keyword(), (spec
->heap_size
? spec
->heap_size
: 1024) * 1024, page_size
);
582 output( "\t.long 0\n" ); /* LoaderFlags */
583 output( "\t.long 16\n" ); /* NumberOfRvaAndSizes */
585 if (spec
->base
<= spec
->limit
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
586 output( "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
587 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
589 output( "\t.long 0,0\n" );
591 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
592 output( "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
593 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
595 output( "\t.long 0,0\n" );
597 if (spec
->nb_resources
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
598 output( "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
599 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
601 output( "\t.long 0,0\n" );
603 output( "\t.long 0,0\n" ); /* DataDirectory[3] */
604 output( "\t.long 0,0\n" ); /* DataDirectory[4] */
605 output( "\t.long 0,0\n" ); /* DataDirectory[5] */
606 output( "\t.long 0,0\n" ); /* DataDirectory[6] */
607 output( "\t.long 0,0\n" ); /* DataDirectory[7] */
608 output( "\t.long 0,0\n" ); /* DataDirectory[8] */
609 output( "\t.long 0,0\n" ); /* DataDirectory[9] */
610 output( "\t.long 0,0\n" ); /* DataDirectory[10] */
611 output( "\t.long 0,0\n" ); /* DataDirectory[11] */
612 output( "\t.long 0,0\n" ); /* DataDirectory[12] */
613 output( "\t.long 0,0\n" ); /* DataDirectory[13] */
614 output( "\t.long 0,0\n" ); /* DataDirectory[14] */
615 output( "\t.long 0,0\n" ); /* DataDirectory[15] */
617 output( "\n\t%s\n", get_asm_string_section() );
618 output( "%s\n", asm_globl("__wine_spec_file_name") );
619 output( ".L__wine_spec_file_name:\n" );
620 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
621 if (target_platform
== PLATFORM_APPLE
)
622 output( "\t.lcomm %s,4\n", asm_name("_end") );
624 output_stubs( spec
);
625 output_exports( spec
);
626 output_imports( spec
);
627 output_resources( spec
);
628 output_asm_constructor( "__wine_spec_init_ctor" );
629 output_gnu_stack_note();
633 /*******************************************************************
636 * Build a Win32 def file from a spec file.
638 void BuildDef32File( DLLSPEC
*spec
)
644 output( "; File generated automatically from %s; do not edit!\n\n",
647 output( "; File generated automatically; do not edit!\n\n" );
649 output( "LIBRARY %s\n\n", spec
->file_name
);
650 output( "EXPORTS\n");
652 /* Output the exports and relay entry points */
654 for (i
= total
= 0; i
< spec
->nb_entry_points
; i
++)
656 const ORDDEF
*odp
= &spec
->entry_points
[i
];
661 if (odp
->name
) name
= odp
->name
;
662 else if (odp
->export_name
) name
= odp
->export_name
;
665 if (!(odp
->flags
& FLAG_PRIVATE
)) total
++;
670 output( " %s", name
);
672 if(strcmp(name
, odp
->link_name
) || (odp
->flags
& FLAG_FORWARD
))
673 output( "=%s", odp
->link_name
);
677 /* try to reduce output */
678 output( " %s", name
);
679 if(strcmp(name
, odp
->link_name
) || (odp
->flags
& FLAG_FORWARD
))
680 output( "=%s", odp
->link_name
);
684 int at_param
= strlen(odp
->u
.func
.arg_types
) * get_ptr_size();
685 output( " %s", name
);
686 if (!kill_at
) output( "@%d", at_param
);
687 if (odp
->flags
& FLAG_FORWARD
)
689 output( "=%s", odp
->link_name
);
691 else if (strcmp(name
, odp
->link_name
)) /* try to reduce output */
693 output( "=%s", odp
->link_name
);
694 if (!kill_at
) output( "@%d", at_param
);
700 int at_param
= strlen(odp
->u
.func
.arg_types
) * get_ptr_size();
702 if (!kill_at
) output( "@" );
703 output( "%s", name
);
704 if (!kill_at
) output( "@%d", at_param
);
705 if (odp
->flags
& FLAG_FORWARD
)
708 if (!kill_at
) output( "@" );
709 output( "%s", odp
->link_name
);
711 else if (strcmp(name
, odp
->link_name
)) /* try to reduce output */
714 if (!kill_at
) output( "@" );
715 output( "%s", odp
->link_name
);
716 if (!kill_at
) output( "@%d", at_param
);
722 output( " %s", name
);
725 const char *check
= name
+ strlen(name
);
726 while (name
!= check
&&
727 '0' <= check
[-1] && check
[-1] <= '9')
731 if (name
!= check
&& check
!= name
+ strlen(name
) &&
734 output("%s", check
- 1);
737 if (odp
->name
|| odp
->export_name
)
739 output("=%s", make_internal_name( odp
, spec
, "stub" ));
746 output( " @%d", odp
->ordinal
);
747 if (!odp
->name
|| (odp
->flags
& FLAG_ORDINAL
)) output( " NONAME" );
748 if (is_data
) output( " DATA" );
749 if (odp
->flags
& FLAG_PRIVATE
) output( " PRIVATE" );
752 if (!total
) warning( "%s: Import library doesn't export anything\n", spec
->file_name
);
756 /*******************************************************************
759 * Build a PE DLL C file from a spec file.
761 void BuildPedllFile( DLLSPEC
*spec
)
763 int i
, has_stubs
= 0;
765 output_standard_file_header();
767 for (i
= 0; i
< spec
->nb_entry_points
; i
++)
769 const ORDDEF
*odp
= &spec
->entry_points
[i
];
770 if (odp
->type
== TYPE_STUB
)
779 output( "/* This file is intentionally left blank */\n");
783 output( "#include <windows.h>\n");
784 output( "#include <reactos/debug.h>\n");
786 output( "void __stdcall __wine_spec_unimplemented_stub( const char *module, const char *function )\n");
788 output( " DPRINT1(\"%%s hit stub for %%s\\n\",module,function);\n");
789 output( " SetLastError(ERROR_CALL_NOT_IMPLEMENTED);\n");
792 output( "static const char __wine_spec_file_name[] = \"%s\";\n\n", spec
->file_name
);
794 /* Output the stub functions */
795 output_stub_funcs( spec
);