Reduce the number of warnings about missing initializers.
[wine] / tools / winebuild / spec32.c
1 /*
2  * 32-bit spec files
3  *
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
9  */
10
11 #include <assert.h>
12 #include <unistd.h>
13
14 #include "winbase.h"
15 #include "build.h"
16
17
18 static int name_compare( const void *name1, const void *name2 )
19 {
20     ORDDEF *odp1 = *(ORDDEF **)name1;
21     ORDDEF *odp2 = *(ORDDEF **)name2;
22     return strcmp( odp1->name, odp2->name );
23 }
24
25 /*******************************************************************
26  *         AssignOrdinals
27  *
28  * Assign ordinals to all entry points.
29  */
30 static void AssignOrdinals(void)
31 {
32     int i, ordinal;
33
34     if ( !nb_names ) return;
35
36     /* sort the list of names */
37     qsort( Names, nb_names, sizeof(Names[0]), name_compare );
38
39     /* check for duplicate names */
40     for (i = 0; i < nb_names - 1; i++)
41     {
42         if (!strcmp( Names[i]->name, Names[i+1]->name ))
43         {
44             current_line = max( Names[i]->lineno, Names[i+1]->lineno );
45             fatal_error( "'%s' redefined (previous definition at line %d)\n",
46                          Names[i]->name, min( Names[i]->lineno, Names[i+1]->lineno ) );
47         }
48     }
49
50     /* start assigning from Base, or from 1 if no ordinal defined yet */
51     if (Base == MAX_ORDINALS) Base = 1;
52     for (i = 0, ordinal = Base; i < nb_names; i++)
53     {
54         if (Names[i]->ordinal != -1) continue;  /* already has an ordinal */
55         while (Ordinals[ordinal]) ordinal++;
56         if (ordinal >= MAX_ORDINALS)
57         {
58             current_line = Names[i]->lineno;
59             fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
60         }
61         Names[i]->ordinal = ordinal;
62         Ordinals[ordinal] = Names[i];
63     }
64     if (ordinal > Limit) Limit = ordinal;
65 }
66
67
68 /*******************************************************************
69  *         output_exports
70  *
71  * Output the export table for a Win32 module.
72  */
73 static void output_exports( FILE *outfile, int nr_exports, int nr_names, int fwd_size )
74 {
75     int i, fwd_pos = 0;
76
77     if (!nr_exports) return;
78
79     fprintf( outfile, "\n\n/* exports */\n\n" );
80     fprintf( outfile, "typedef void (*func_ptr)();\n" );
81     fprintf( outfile, "static struct {\n" );
82     fprintf( outfile, "  struct {\n" );
83     fprintf( outfile, "    unsigned int    Characteristics;\n" );
84     fprintf( outfile, "    unsigned int    TimeDateStamp;\n" );
85     fprintf( outfile, "    unsigned short  MajorVersion;\n" );
86     fprintf( outfile, "    unsigned short  MinorVersion;\n" );
87     fprintf( outfile, "    const char     *Name;\n" );
88     fprintf( outfile, "    unsigned int    Base;\n" );
89     fprintf( outfile, "    unsigned int    NumberOfFunctions;\n" );
90     fprintf( outfile, "    unsigned int    NumberOfNames;\n" );
91     fprintf( outfile, "    func_ptr       *AddressOfFunctions;\n" );
92     fprintf( outfile, "    const char    **AddressOfNames;\n" );
93     fprintf( outfile, "    unsigned short *AddressOfNameOrdinals;\n" );
94     fprintf( outfile, "    func_ptr        functions[%d];\n", nr_exports );
95     if (nb_names)
96     {
97         fprintf( outfile, "    const char     *names[%d];\n", nb_names );
98         fprintf( outfile, "    unsigned short  ordinals[%d];\n", nb_names );
99         if (nb_names % 2) fprintf( outfile, "    unsigned short  pad1;\n" );
100     }
101     if (fwd_size)
102     {
103         fprintf( outfile, "    char            forwards[%d];\n", (fwd_size + 3) & ~3 );
104     }
105     fprintf( outfile, "  } exp;\n" );
106
107 #ifdef __i386__
108     fprintf( outfile, "  struct {\n" );
109     fprintf( outfile, "    unsigned char  jmp;\n" );
110     fprintf( outfile, "    unsigned char  addr[4];\n" );
111     fprintf( outfile, "    unsigned char  ret;\n" );
112     fprintf( outfile, "    unsigned short args;\n" );
113     fprintf( outfile, "    func_ptr       orig;\n" );
114     fprintf( outfile, "    unsigned int   argtypes;\n" );
115     fprintf( outfile, "  } relay[%d];\n", nr_exports );
116 #endif  /* __i386__ */
117
118     fprintf( outfile, "} exports = {\n  {\n" );
119     fprintf( outfile, "    0,\n" );                 /* Characteristics */
120     fprintf( outfile, "    0,\n" );                 /* TimeDateStamp */
121     fprintf( outfile, "    0,\n" );                 /* MajorVersion */
122     fprintf( outfile, "    0,\n" );                 /* MinorVersion */
123     fprintf( outfile, "    dllname,\n" );           /* Name */
124     fprintf( outfile, "    %d,\n", Base );          /* Base */
125     fprintf( outfile, "    %d,\n", nr_exports );    /* NumberOfFunctions */
126     fprintf( outfile, "    %d,\n", nb_names );      /* NumberOfNames */
127     fprintf( outfile, "    exports.exp.functions,\n" ); /* AddressOfFunctions */
128     if (nb_names)
129     {
130         fprintf( outfile, "    exports.exp.names,\n" );     /* AddressOfNames */
131         fprintf( outfile, "    exports.exp.ordinals,\n" );  /* AddressOfNameOrdinals */
132     }
133     else
134     {
135         fprintf( outfile, "    0,\n" );  /* AddressOfNames */
136         fprintf( outfile, "    0,\n" );  /* AddressOfNameOrdinals */
137     }
138
139     /* output the function addresses */
140
141     fprintf( outfile, "    {\n      " );
142     for (i = Base; i <= Limit; i++)
143     {
144         ORDDEF *odp = Ordinals[i];
145         if (!odp) fprintf( outfile, "0" );
146         else switch(odp->type)
147         {
148         case TYPE_EXTERN:
149             fprintf( outfile, "%s", odp->u.ext.link_name );
150             break;
151         case TYPE_STDCALL:
152         case TYPE_STDCALL64:
153         case TYPE_VARARGS:
154         case TYPE_CDECL:
155             fprintf( outfile, "%s", odp->u.func.link_name);
156             break;
157         case TYPE_STUB:
158             fprintf( outfile, "__stub_%d", i );
159             break;
160         case TYPE_REGISTER:
161             fprintf( outfile, "__regs_%d", i );
162             break;
163         case TYPE_FORWARD:
164             fprintf( outfile, "(func_ptr)&exports.exp.forwards[%d] /* %s */",
165                      fwd_pos, odp->u.fwd.link_name );
166             fwd_pos += strlen(odp->u.fwd.link_name) + 1;
167             break;
168         default:
169             assert(0);
170         }
171         if (i < Limit) fprintf( outfile, ",\n      " );
172         else fprintf( outfile, "\n    },\n" );
173     }
174
175     if (nb_names)
176     {
177         /* output the function names */
178
179         fprintf( outfile, "    {\n" );
180         for (i = 0; i < nb_names; i++)
181         {
182             if (i) fprintf( outfile, ",\n" );
183             fprintf( outfile, "      \"%s\"", Names[i]->name );
184         }
185         fprintf( outfile, "\n    },\n" );
186
187         /* output the function ordinals */
188
189         fprintf( outfile, "    {\n     " );
190         for (i = 0; i < nb_names; i++)
191         {
192             fprintf( outfile, "%4d", Names[i]->ordinal - Base );
193             if (i < nb_names-1)
194             {
195                 fputc( ',', outfile );
196                 if ((i % 8) == 7) fprintf( outfile, "\n     " );
197             }
198         }
199         fprintf( outfile, "\n    },\n" );
200         if (nb_names % 2) fprintf( outfile, "    0,\n" );
201     }
202
203     /* output forwards */
204
205     if (fwd_size)
206     {
207         for (i = Base; i <= Limit; i++)
208         {
209             ORDDEF *odp = Ordinals[i];
210             if (odp && odp->type == TYPE_FORWARD)
211                 fprintf( outfile, "    \"%s\\0\"\n", odp->u.fwd.link_name );
212         }
213     }
214
215     /* output relays */
216
217 #ifdef __i386__
218     fprintf( outfile, "  },\n  {\n" );
219     for (i = Base; i <= Limit; i++)
220     {
221         ORDDEF *odp = Ordinals[i];
222
223         if (odp && ((odp->type == TYPE_STDCALL) ||
224                     (odp->type == TYPE_STDCALL64) ||
225                     (odp->type == TYPE_CDECL) ||
226                     (odp->type == TYPE_REGISTER)))
227         {
228             unsigned int j, mask = 0;
229             for (j = 0; odp->u.func.arg_types[j]; j++)
230             {
231                 if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
232                 if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
233             }
234
235             switch(odp->type)
236             {
237             case TYPE_STDCALL64:
238                 if (j < 16) mask |= 0x80000000;
239                 /* fall through */
240             case TYPE_STDCALL:
241                 fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc2, 0x%04x, %s, 0x%08x }",
242                          strlen(odp->u.func.arg_types) * sizeof(int),
243                          odp->u.func.link_name, mask );
244                 break;
245             case TYPE_CDECL:
246                 fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, %s, 0x%08x }",
247                          strlen(odp->u.func.arg_types) * sizeof(int),
248                          odp->u.func.link_name, mask );
249                 break;
250             case TYPE_REGISTER:
251                 fprintf( outfile, "    { 0xe9, { 0,0,0,0 }, 0xc3, 0x%04x, __regs_%d, 0x%08x }",
252                          0x8000 | (strlen(odp->u.func.arg_types) * sizeof(int)), i, mask );
253                 break;
254             default:
255                 assert(0);
256             }
257         }
258         else fprintf( outfile, "    { 0, { 0,0,0,0 }, 0, 0, 0, 0 }" );
259
260         if (i < Limit) fprintf( outfile, ",\n" );
261     }
262 #endif  /* __i386__ */
263
264     fprintf( outfile, "  }\n};\n" );
265 }
266
267
268 /*******************************************************************
269  *         BuildSpec32File
270  *
271  * Build a Win32 C file from a spec file.
272  */
273 void BuildSpec32File( FILE *outfile )
274 {
275     ORDDEF *odp;
276     int i, fwd_size = 0, have_regs = FALSE;
277     int nr_exports, nr_imports;
278     int characteristics, subsystem;
279     const char *init_func;
280     DWORD page_size;
281
282 #ifdef HAVE_GETPAGESIZE
283     page_size = getpagesize();
284 #else
285 # ifdef __svr4__
286     page_size = sysconf(_SC_PAGESIZE);
287 # else
288 #   error Cannot get the page size on this platform
289 # endif
290 #endif
291
292     AssignOrdinals();
293     nr_exports = Base <= Limit ? Limit - Base + 1 : 0;
294
295     fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
296              input_file_name );
297     fprintf( outfile, "extern void BUILTIN32_Unimplemented( const char *dllname, const char *funcname );\n\n" );
298
299     /* Reserve some space for the PE header */
300
301     fprintf( outfile, "extern char pe_header[];\n" );
302     fprintf( outfile, "asm(\".section .text\\n\\t\"\n" );
303     fprintf( outfile, "    \".align %ld\\n\"\n", page_size );
304     fprintf( outfile, "    \"pe_header:\\t.fill %ld,1,0\\n\\t\");\n", page_size );
305
306     fprintf( outfile, "static const char dllname[] = \"%s\";\n", DLLName );
307
308     /* Output the DLL functions prototypes */
309
310     for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
311     {
312         switch(odp->type)
313         {
314         case TYPE_EXTERN:
315             fprintf( outfile, "extern void %s();\n", odp->u.ext.link_name );
316             break;
317         case TYPE_STDCALL:
318         case TYPE_STDCALL64:
319         case TYPE_VARARGS:
320         case TYPE_CDECL:
321             fprintf( outfile, "extern void %s();\n", odp->u.func.link_name );
322             break;
323         case TYPE_FORWARD:
324             fwd_size += strlen(odp->u.fwd.link_name) + 1;
325             break;
326         case TYPE_REGISTER:
327             fprintf( outfile, "extern void __regs_%d();\n", odp->ordinal );
328             have_regs = TRUE;
329             break;
330         case TYPE_STUB:
331             if (odp->name[0])
332                 fprintf( outfile,
333                          "static void __stub_%d() { BUILTIN32_Unimplemented(dllname,\"%s\"); }\n",
334                          odp->ordinal, odp->name );
335             else
336                 fprintf( outfile,
337                          "static void __stub_%d() { BUILTIN32_Unimplemented(dllname,\"%d\"); }\n",
338                          odp->ordinal, odp->ordinal );
339             
340             break;
341         default:
342             fprintf(stderr,"build: function type %d not available for Win32\n",
343                     odp->type);
344             exit(1);
345         }
346     }
347
348     /* Output code for all register functions */
349
350     if ( have_regs )
351     { 
352         fprintf( outfile, "#ifndef __GNUC__\n" );
353         fprintf( outfile, "static void __asm__dummy(void) {\n" );
354         fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
355         for (i = 0, odp = EntryPoints; i < nb_entry_points; i++, odp++)
356         {
357             if (odp->type != TYPE_REGISTER) continue;
358             fprintf( outfile,
359                      "asm(\".align 4\\n\\t\"\n"
360                      "    \".type " PREFIX "__regs_%d,@function\\n\\t\"\n"
361                      "    \"" PREFIX "__regs_%d:\\n\\t\"\n"
362                      "    \"call " PREFIX "CALL32_Regs\\n\\t\"\n"
363                      "    \".long " PREFIX "%s\\n\\t\"\n"
364                      "    \".byte %d,%d\");\n",
365                      odp->ordinal, odp->ordinal, odp->u.func.link_name,
366                      4 * strlen(odp->u.func.arg_types),
367                      4 * strlen(odp->u.func.arg_types) );
368         }
369         fprintf( outfile, "#ifndef __GNUC__\n" );
370         fprintf( outfile, "}\n" );
371         fprintf( outfile, "#endif /* !defined(__GNUC__) */\n" );
372     }
373
374     /* Output the exports and relay entry points */
375
376     output_exports( outfile, nr_exports, nb_names, fwd_size );
377
378     /* Output the DLL imports */
379
380     nr_imports = output_imports( outfile );
381
382     /* Output LibMain function */
383
384     init_func = DLLInitFunc[0] ? DLLInitFunc : NULL;
385     characteristics = subsystem = 0;
386     switch(SpecMode)
387     {
388     case SPEC_MODE_DLL:
389         if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
390         characteristics = IMAGE_FILE_DLL;
391         break;
392     case SPEC_MODE_GUIEXE:
393         if (!init_func) init_func = "WinMain";
394         fprintf( outfile,
395                  "\n#include <winbase.h>\n"
396                  "static void exe_main(void)\n"
397                  "{\n"
398                  "    extern int PASCAL %s(HINSTANCE,HINSTANCE,LPSTR,INT);\n"
399                  "    STARTUPINFOA info;\n"
400                  "    LPSTR cmdline = GetCommandLineA();\n"
401                  "    while (*cmdline && *cmdline != ' ') cmdline++;\n"
402                  "    if (*cmdline) cmdline++;\n"
403                  "    GetStartupInfoA( &info );\n"
404                  "    if (!(info.dwFlags & STARTF_USESHOWWINDOW)) info.wShowWindow = 1;\n"
405                  "    ExitProcess( %s( GetModuleHandleA(0), 0, cmdline, info.wShowWindow ) );\n"
406                  "}\n\n", init_func, init_func );
407         fprintf( outfile,
408                  "int main( int argc, char *argv[] )\n"
409                  "{\n"
410                  "    extern void PROCESS_InitWinelib( int, char ** );\n"
411                  "    PROCESS_InitWinelib( argc, argv );\n"
412                  "    return 1;\n"
413                  "}\n\n" );
414         init_func = "exe_main";
415         subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
416         break;
417     case SPEC_MODE_CUIEXE:
418         if (!init_func) init_func = "wine_main";
419         fprintf( outfile,
420                  "\n#include <winbase.h>\n"
421                  "static void exe_main(void)\n"
422                  "{\n"
423                  "    extern int %s( int argc, char *argv[] );\n"
424                  "    extern int _ARGC;\n"
425                  "    extern char **_ARGV;\n"
426                  "    ExitProcess( %s( _ARGC, _ARGV ) );\n"
427                  "}\n\n", init_func, init_func );
428         fprintf( outfile,
429                  "int main( int argc, char *argv[] )\n"
430                  "{\n"
431                  "    extern void PROCESS_InitWinelib( int, char ** );\n"
432                  "    PROCESS_InitWinelib( argc, argv );\n"
433                  "    return 1;\n"
434                  "}\n\n" );
435         init_func = "exe_main";
436         subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
437         break;
438     case SPEC_MODE_GUIEXE_NO_MAIN:
439         if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
440         subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI;
441         break;
442     case SPEC_MODE_CUIEXE_NO_MAIN:
443         if (init_func) fprintf( outfile, "extern void %s();\n", init_func );
444         subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
445         break;
446     }
447
448     /* Output the DLL descriptor */
449
450     if (rsrc_name[0]) fprintf( outfile, "extern char %s[];\n\n", rsrc_name );
451
452     /* Output the NT header */
453
454     /* this is the IMAGE_NT_HEADERS structure, but we cannot include winnt.h here */
455     fprintf( outfile, "static const struct image_nt_headers\n{\n" );
456     fprintf( outfile, "  int Signature;\n" );
457     fprintf( outfile, "  struct file_header {\n" );
458     fprintf( outfile, "    short Machine;\n" );
459     fprintf( outfile, "    short NumberOfSections;\n" );
460     fprintf( outfile, "    int   TimeDateStamp;\n" );
461     fprintf( outfile, "    void *PointerToSymbolTable;\n" );
462     fprintf( outfile, "    int   NumberOfSymbols;\n" );
463     fprintf( outfile, "    short SizeOfOptionalHeader;\n" );
464     fprintf( outfile, "    short Characteristics;\n" );
465     fprintf( outfile, "  } FileHeader;\n" );
466     fprintf( outfile, "  struct opt_header {\n" );
467     fprintf( outfile, "    short Magic;\n" );
468     fprintf( outfile, "    char  MajorLinkerVersion, MinorLinkerVersion;\n" );
469     fprintf( outfile, "    int   SizeOfCode;\n" );
470     fprintf( outfile, "    int   SizeOfInitializedData;\n" );
471     fprintf( outfile, "    int   SizeOfUninitializedData;\n" );
472     fprintf( outfile, "    void *AddressOfEntryPoint;\n" );
473     fprintf( outfile, "    void *BaseOfCode;\n" );
474     fprintf( outfile, "    void *BaseOfData;\n" );
475     fprintf( outfile, "    void *ImageBase;\n" );
476     fprintf( outfile, "    int   SectionAlignment;\n" );
477     fprintf( outfile, "    int   FileAlignment;\n" );
478     fprintf( outfile, "    short MajorOperatingSystemVersion;\n" );
479     fprintf( outfile, "    short MinorOperatingSystemVersion;\n" );
480     fprintf( outfile, "    short MajorImageVersion;\n" );
481     fprintf( outfile, "    short MinorImageVersion;\n" );
482     fprintf( outfile, "    short MajorSubsystemVersion;\n" );
483     fprintf( outfile, "    short MinorSubsystemVersion;\n" );
484     fprintf( outfile, "    int   Win32VersionValue;\n" );
485     fprintf( outfile, "    int   SizeOfImage;\n" );
486     fprintf( outfile, "    int   SizeOfHeaders;\n" );
487     fprintf( outfile, "    int   CheckSum;\n" );
488     fprintf( outfile, "    short Subsystem;\n" );
489     fprintf( outfile, "    short DllCharacteristics;\n" );
490     fprintf( outfile, "    int   SizeOfStackReserve;\n" );
491     fprintf( outfile, "    int   SizeOfStackCommit;\n" );
492     fprintf( outfile, "    int   SizeOfHeapReserve;\n" );
493     fprintf( outfile, "    int   SizeOfHeapCommit;\n" );
494     fprintf( outfile, "    int   LoaderFlags;\n" );
495     fprintf( outfile, "    int   NumberOfRvaAndSizes;\n" );
496     fprintf( outfile, "    struct { void *VirtualAddress; int Size; } DataDirectory[%d];\n",
497              IMAGE_NUMBEROF_DIRECTORY_ENTRIES );
498     fprintf( outfile, "  } OptionalHeader;\n" );
499     fprintf( outfile, "} nt_header = {\n" );
500     fprintf( outfile, "  0x%04x,\n", IMAGE_NT_SIGNATURE );   /* Signature */
501
502     fprintf( outfile, "  { 0x%04x,\n", IMAGE_FILE_MACHINE_I386 );  /* Machine */
503     fprintf( outfile, "    0, 0, 0, 0,\n" );
504     fprintf( outfile, "    sizeof(nt_header.OptionalHeader),\n" ); /* SizeOfOptionalHeader */
505     fprintf( outfile, "    0x%04x },\n", characteristics );        /* Characteristics */
506
507     fprintf( outfile, "  { 0x%04x,\n", IMAGE_NT_OPTIONAL_HDR_MAGIC );  /* Magic */
508     fprintf( outfile, "    0, 0,\n" );                   /* Major/MinorLinkerVersion */
509     fprintf( outfile, "    0, 0, 0,\n" );                /* SizeOfCode/Data */
510     fprintf( outfile, "    %s,\n", init_func ? init_func : "0" );  /* AddressOfEntryPoint */
511     fprintf( outfile, "    0, 0,\n" );                   /* BaseOfCode/Data */
512     fprintf( outfile, "    pe_header,\n" );              /* ImageBase */
513     fprintf( outfile, "    %ld,\n", page_size );         /* SectionAlignment */
514     fprintf( outfile, "    %ld,\n", page_size );         /* FileAlignment */
515     fprintf( outfile, "    1, 0,\n" );                   /* Major/MinorOperatingSystemVersion */
516     fprintf( outfile, "    0, 0,\n" );                   /* Major/MinorImageVersion */
517     fprintf( outfile, "    4, 0,\n" );                   /* Major/MinorSubsystemVersion */
518     fprintf( outfile, "    0,\n" );                      /* Win32VersionValue */
519     fprintf( outfile, "    %ld,\n", page_size );         /* SizeOfImage */
520     fprintf( outfile, "    %ld,\n", page_size );         /* SizeOfHeaders */
521     fprintf( outfile, "    0,\n" );                      /* CheckSum */
522     fprintf( outfile, "    0x%04x,\n", subsystem );      /* Subsystem */
523     fprintf( outfile, "    0, 0, 0, 0, 0, 0,\n" );
524     fprintf( outfile, "    %d,\n", IMAGE_NUMBEROF_DIRECTORY_ENTRIES );  /* NumberOfRvaAndSizes */
525     fprintf( outfile, "    {\n" );
526     fprintf( outfile, "      { %s, %s },\n",  /* IMAGE_DIRECTORY_ENTRY_EXPORT */
527              nr_exports ? "&exports" : "0", nr_exports ? "sizeof(exports.exp)" : "0" );
528     fprintf( outfile, "      { %s, %s },\n",  /* IMAGE_DIRECTORY_ENTRY_IMPORT */
529              nr_imports ? "&imports" : "0", nr_imports ? "sizeof(imports)" : "0" );
530     fprintf( outfile, "      { %s, 0 },\n",   /* IMAGE_DIRECTORY_ENTRY_RESOURCE */
531              rsrc_name[0] ? rsrc_name : "0" );
532     fprintf( outfile, "    }\n  }\n};\n\n" );
533
534     /* Output the DLL constructor */
535
536     fprintf( outfile, "#ifdef __GNUC__\n" );
537     fprintf( outfile, "static void %s_init(void) __attribute__((constructor));\n", DLLName );
538     fprintf( outfile, "#else /* defined(__GNUC__) */\n" );
539     fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
540     fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
541     fprintf( outfile, "    \"\\tcall %s_init\\n\"\n", DLLName );
542     fprintf( outfile, "    \"\\t.previous\\n\");\n" );
543     fprintf( outfile, "}\n" );
544     fprintf( outfile, "#endif /* defined(__GNUC__) */\n" );
545     fprintf( outfile, "static void %s_init(void)\n{\n", DLLName );
546     fprintf( outfile, "    extern void BUILTIN32_RegisterDLL( const struct image_nt_headers *, const char * );\n" );
547     fprintf( outfile, "    BUILTIN32_RegisterDLL( &nt_header, \"%s\" );\n}\n", DLLFileName );
548 }