spec32.c 21.5 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * 32-bit spec files
 *
 * Copyright 1993 Robert J. Amstadt
 * Copyright 1995 Martin von Loewis
 * Copyright 1995, 1996, 1997 Alexandre Julliard
 * Copyright 1997 Eric Youngdale
 * Copyright 1999 Ulrich Weigand
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
23 24
 */

25
#include "config.h"
26
#include "wine/port.h"
27

28
#include <assert.h>
29
#include <ctype.h>
30
#include <stdarg.h>
31
#include <string.h>
32 33 34

#include "build.h"

35 36 37 38 39 40 41 42 43 44 45 46
#define IMAGE_FILE_MACHINE_UNKNOWN 0
#define IMAGE_FILE_MACHINE_I386    0x014c
#define IMAGE_FILE_MACHINE_ALPHA   0x0184
#define IMAGE_FILE_MACHINE_POWERPC 0x01f0
#define IMAGE_FILE_MACHINE_AMD64   0x8664

#define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
#define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240

#define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
#define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
#define IMAGE_ROM_OPTIONAL_HDR_MAGIC  0x107
47

48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/* check if entry point needs a relay thunk */
static inline int needs_relay( const ORDDEF *odp )
{
    /* skip nonexistent entry points */
    if (!odp) return 0;
    /* skip non-functions */
    if ((odp->type != TYPE_STDCALL) && (odp->type != TYPE_CDECL)) return 0;
    /* skip norelay and forward entry points */
    if (odp->flags & (FLAG_NORELAY|FLAG_FORWARD)) return 0;
    return 1;
}

/* check if dll will output relay thunks */
int has_relays( DLLSPEC *spec )
{
63
    int i;
64

65
    if (target_cpu != CPU_x86 && target_cpu != CPU_x86_64) return 0;
66 67 68 69 70 71 72 73 74 75 76 77 78 79

    for (i = spec->base; i <= spec->limit; i++)
    {
        ORDDEF *odp = spec->ordinals[i];
        if (needs_relay( odp )) return 1;
    }
    return 0;
}

/*******************************************************************
 *         output_relay_debug
 *
 * Output entry points for relay debugging
 */
80
static void output_relay_debug( DLLSPEC *spec )
81
{
82 83
    int i;
    unsigned int j, args, flags;
84 85 86

    /* first the table of entry point offsets */

87 88 89
    output( "\t%s\n", get_asm_rodata_section() );
    output( "\t.align %d\n", get_alignment(4) );
    output( ".L__wine_spec_relay_entry_point_offsets:\n" );
90 91 92 93 94 95

    for (i = spec->base; i <= spec->limit; i++)
    {
        ORDDEF *odp = spec->ordinals[i];

        if (needs_relay( odp ))
96
            output( "\t.long .L__wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i );
97
        else
98
            output( "\t.long 0\n" );
99 100 101 102
    }

    /* then the table of argument types */

103 104
    output( "\t.align %d\n", get_alignment(4) );
    output( ".L__wine_spec_relay_arg_types:\n" );
105 106 107 108 109 110 111 112 113 114 115 116 117 118

    for (i = spec->base; i <= spec->limit; i++)
    {
        ORDDEF *odp = spec->ordinals[i];
        unsigned int mask = 0;

        if (needs_relay( odp ))
        {
            for (j = 0; j < 16 && odp->u.func.arg_types[j]; j++)
            {
                if (odp->u.func.arg_types[j] == 't') mask |= 1<< (j*2);
                if (odp->u.func.arg_types[j] == 'W') mask |= 2<< (j*2);
            }
        }
119
        output( "\t.long 0x%08x\n", mask );
120 121 122 123
    }

    /* then the relay thunks */

124 125 126
    output( "\t.text\n" );
    output( "__wine_spec_relay_entry_points:\n" );
    output( "\tnop\n" );  /* to avoid 0 offset */
127 128 129 130 131 132 133

    for (i = spec->base; i <= spec->limit; i++)
    {
        ORDDEF *odp = spec->ordinals[i];

        if (!needs_relay( odp )) continue;

134 135
        output( "\t.align %d\n", get_alignment(4) );
        output( ".L__wine_spec_relay_entry_point_%d:\n", i );
136 137 138 139

        args = strlen(odp->u.func.arg_types);
        flags = 0;

140
        switch (target_cpu)
141
        {
142 143 144 145 146
        case CPU_x86:
            if (odp->flags & FLAG_REGISTER)
                output( "\tpushl %%eax\n" );
            else
                output( "\tpushl %%esp\n" );
147

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
            if (odp->flags & FLAG_RET64) flags |= 1;
            output( "\tpushl $%u\n", (flags << 24) | (args << 16) | (i - spec->base) );

            if (UsePIC)
            {
                output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
                output( "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
            }
            else output( "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
            output( "\tpushl %%eax\n" );

            if (odp->flags & FLAG_REGISTER)
            {
                output( "\tcall *8(%%eax)\n" );
            }
163
            else
164 165 166 167 168 169 170 171 172 173
            {
                output( "\tcall *4(%%eax)\n" );
                if (odp->type == TYPE_STDCALL)
                    output( "\tret $%u\n", args * get_ptr_size() );
                else
                    output( "\tret\n" );
            }
            break;

        case CPU_x86_64:
174 175 176 177 178 179 180 181
            output( "\t.cfi_startproc\n" );
            output( "\tsubq $40,%%rsp\n" );
            output( "\t.cfi_adjust_cfa_offset 40\n" );
            output( "\tmovq %%rcx,48(%%rsp)\n" );
            output( "\tmovq %%rdx,56(%%rsp)\n" );
            output( "\tmovq %%r8,64(%%rsp)\n" );
            output( "\tmovq %%r9,72(%%rsp)\n" );
            output( "\tleaq 40(%%rsp),%%r8\n" );
182 183
            output( "\tmovq $%u,%%rdx\n", (flags << 24) | (args << 16) | (i - spec->base) );
            output( "\tleaq .L__wine_spec_relay_descr(%%rip),%%rcx\n" );
184
            output( "\tcallq *%u(%%rcx)\n", (odp->flags & FLAG_REGISTER) ? 16 : 8 );
185
            output( "\taddq $40,%%rsp\n" );
186
            output( "\t.cfi_adjust_cfa_offset -40\n" );
187
            output( "\tret\n" );
188
            output( "\t.cfi_endproc\n" );
189 190 191 192
            break;

        default:
            assert(0);
193 194 195 196
        }
    }
}

197 198 199 200 201
/*******************************************************************
 *         output_exports
 *
 * Output the export table for a Win32 module.
 */
202
void output_exports( DLLSPEC *spec )
203
{
204 205
    int i, fwd_size = 0;
    int nr_exports = spec->base <= spec->limit ? spec->limit - spec->base + 1 : 0;
206

207
    if (!nr_exports) return;
208

209 210 211 212
    output( "\n/* export table */\n\n" );
    output( "\t.data\n" );
    output( "\t.align %d\n", get_alignment(4) );
    output( ".L__wine_spec_exports:\n" );
213 214

    /* export directory header */
215

216 217 218 219 220 221 222 223
    output( "\t.long 0\n" );                       /* Characteristics */
    output( "\t.long 0\n" );                       /* TimeDateStamp */
    output( "\t.long 0\n" );                       /* MajorVersion/MinorVersion */
    output( "\t.long .L__wine_spec_exp_names-.L__wine_spec_rva_base\n" ); /* Name */
    output( "\t.long %u\n", spec->base );          /* Base */
    output( "\t.long %u\n", nr_exports );          /* NumberOfFunctions */
    output( "\t.long %u\n", spec->nb_names );      /* NumberOfNames */
    output( "\t.long .L__wine_spec_exports_funcs-.L__wine_spec_rva_base\n" ); /* AddressOfFunctions */
224
    if (spec->nb_names)
225
    {
226 227
        output( "\t.long .L__wine_spec_exp_name_ptrs-.L__wine_spec_rva_base\n" ); /* AddressOfNames */
        output( "\t.long .L__wine_spec_exp_ordinals-.L__wine_spec_rva_base\n" );  /* AddressOfNameOrdinals */
228 229 230
    }
    else
    {
231 232
        output( "\t.long 0\n" );  /* AddressOfNames */
        output( "\t.long 0\n" );  /* AddressOfNameOrdinals */
233 234
    }

235
    /* output the function pointers */
236

237
    output( "\n.L__wine_spec_exports_funcs:\n" );
238
    for (i = spec->base; i <= spec->limit; i++)
239
    {
240
        ORDDEF *odp = spec->ordinals[i];
241
        if (!odp) output( "\t%s 0\n", get_asm_ptr_keyword() );
242 243 244 245 246 247
        else switch(odp->type)
        {
        case TYPE_EXTERN:
        case TYPE_STDCALL:
        case TYPE_VARARGS:
        case TYPE_CDECL:
248
            if (odp->flags & FLAG_FORWARD)
249
            {
250
                output( "\t%s .L__wine_spec_forwards+%u\n", get_asm_ptr_keyword(), fwd_size );
251 252 253 254
                fwd_size += strlen(odp->link_name) + 1;
            }
            else if (odp->flags & FLAG_EXT_LINK)
            {
255
                output( "\t%s %s_%s\n",
256
                         get_asm_ptr_keyword(), asm_name("__wine_spec_ext_link"), odp->link_name );
257
            }
258 259
            else
            {
260
                output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
261
            }
262 263
            break;
        case TYPE_STUB:
264
            output( "\t%s %s\n", get_asm_ptr_keyword(),
265
                     asm_name( get_stub_name( odp, spec )) );
266 267 268 269 270 271
            break;
        default:
            assert(0);
        }
    }

272
    if (spec->nb_names)
273
    {
274
        /* output the function name pointers */
275

276
        int namepos = strlen(spec->file_name) + 1;
277

278
        output( "\n.L__wine_spec_exp_name_ptrs:\n" );
279
        for (i = 0; i < spec->nb_names; i++)
280
        {
281
            output( "\t.long .L__wine_spec_exp_names+%u-.L__wine_spec_rva_base\n", namepos );
282
            namepos += strlen(spec->names[i]->name) + 1;
283
        }
284

285 286
        /* output the function ordinals */

287
        output( "\n.L__wine_spec_exp_ordinals:\n" );
288
        for (i = 0; i < spec->nb_names; i++)
289
        {
290
            output( "\t%s %d\n",
291
                     get_asm_short_keyword(), spec->names[i]->ordinal - spec->base );
292
        }
293
        if (spec->nb_names % 2)
294
        {
295
            output( "\t%s 0\n", get_asm_short_keyword() );
296 297 298
        }
    }

299 300
    /* output the export name strings */

301 302
    output( "\n.L__wine_spec_exp_names:\n" );
    output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
303
    for (i = 0; i < spec->nb_names; i++)
304
        output( "\t%s \"%s\"\n",
305 306
                 get_asm_string_keyword(), spec->names[i]->name );

307
    /* output forward strings */
308 309 310

    if (fwd_size)
    {
311
        output( "\n.L__wine_spec_forwards:\n" );
312
        for (i = spec->base; i <= spec->limit; i++)
313
        {
314
            ORDDEF *odp = spec->ordinals[i];
315
            if (odp && (odp->flags & FLAG_FORWARD))
316
                output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp->link_name );
317 318
        }
    }
319 320
    output( "\t.align %d\n", get_alignment(get_ptr_size()) );
    output( ".L__wine_spec_exports_end:\n" );
321 322 323

    /* output relays */

324
    if (!has_relays( spec ))
325
    {
326
        output( "\t%s 0\n", get_asm_ptr_keyword() );
327 328
        return;
    }
329

330 331 332 333 334 335 336
    output( ".L__wine_spec_relay_descr:\n" );
    output( "\t%s 0xdeb90001\n", get_asm_ptr_keyword() );  /* magic */
    output( "\t%s 0,0\n", get_asm_ptr_keyword() );         /* relay funcs */
    output( "\t%s 0\n", get_asm_ptr_keyword() );           /* private data */
    output( "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
    output( "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
    output( "\t%s .L__wine_spec_relay_arg_types\n", get_asm_ptr_keyword() );
337

338
    output_relay_debug( spec );
339 340 341
}


342 343 344 345 346
/*******************************************************************
 *         output_asm_constructor
 *
 * Output code for calling a dll constructor.
 */
347
static void output_asm_constructor( const char *constructor )
348 349 350 351
{
    if (target_platform == PLATFORM_APPLE)
    {
        /* Mach-O doesn't have an init section */
352 353 354
        output( "\n\t.mod_init_func\n" );
        output( "\t.align %d\n", get_alignment(4) );
        output( "\t.long %s\n", asm_name(constructor) );
355 356 357
    }
    else
    {
358
        output( "\n\t.section \".init\",\"ax\"\n" );
359 360 361 362
        switch(target_cpu)
        {
        case CPU_x86:
        case CPU_x86_64:
363
            output( "\tcall %s\n", asm_name(constructor) );
364 365
            break;
        case CPU_SPARC:
366 367
            output( "\tcall %s\n", asm_name(constructor) );
            output( "\tnop\n" );
368 369
            break;
        case CPU_ALPHA:
370
            output( "\tjsr $26,%s\n", asm_name(constructor) );
371 372
            break;
        case CPU_POWERPC:
373
            output( "\tbl %s\n", asm_name(constructor) );
374 375 376 377 378 379
            break;
        }
    }
}


380
/*******************************************************************
381
 *         output_module
382
 *
383
 * Output the module data.
384
 */
385
void output_module( DLLSPEC *spec )
386
{
387
    int machine = 0;
388
    unsigned int page_size = get_page_size();
389 390 391

    /* Reserve some space for the PE header */

392
    switch (target_platform)
393
    {
394
    case PLATFORM_APPLE:
395 396 397 398
        output( "\t.text\n" );
        output( "\t.align %d\n", get_alignment(page_size) );
        output( "__wine_spec_pe_header:\n" );
        output( "\t.space 65536\n" );
399 400 401 402 403 404 405
        break;
    case PLATFORM_SOLARIS:
        output( "\n\t.section \".text\",\"ax\"\n" );
        output( "__wine_spec_pe_header:\n" );
        output( "\t.skip %u\n", 65536 + page_size );
        break;
    default:
406
        output( "\n\t.section \".init\",\"ax\"\n" );
407 408 409 410 411 412 413 414 415 416 417 418
        switch(target_cpu)
        {
        case CPU_x86:
        case CPU_x86_64:
        case CPU_ALPHA:
        case CPU_SPARC:
            output( "\tjmp 1f\n" );
            break;
        case CPU_POWERPC:
            output( "\tb 1f\n" );
            break;
        }
419
        output( "__wine_spec_pe_header:\n" );
420
        output( "\t.skip %u\n", 65536 + page_size );
421
        output( "1:\n" );
422
        break;
423
    }
424

425 426
    /* Output the NT header */

427 428 429 430
    output( "\n\t.data\n" );
    output( "\t.align %d\n", get_alignment(get_ptr_size()) );
    output( "%s\n", asm_globl("__wine_spec_nt_header") );
    output( ".L__wine_spec_rva_base:\n" );
431

432
    output( "\t.long 0x4550\n" );         /* Signature */
433 434
    switch(target_cpu)
    {
435
    case CPU_x86:     machine = IMAGE_FILE_MACHINE_I386; break;
436
    case CPU_x86_64:  machine = IMAGE_FILE_MACHINE_AMD64; break;
437 438 439
    case CPU_POWERPC: machine = IMAGE_FILE_MACHINE_POWERPC; break;
    case CPU_ALPHA:   machine = IMAGE_FILE_MACHINE_ALPHA; break;
    case CPU_SPARC:   machine = IMAGE_FILE_MACHINE_UNKNOWN; break;
440
    }
441
    output( "\t%s 0x%04x\n",              /* Machine */
442
             get_asm_short_keyword(), machine );
443
    output( "\t%s 0\n",                   /* NumberOfSections */
444
             get_asm_short_keyword() );
445 446 447 448
    output( "\t.long 0\n" );              /* TimeDateStamp */
    output( "\t.long 0\n" );              /* PointerToSymbolTable */
    output( "\t.long 0\n" );              /* NumberOfSymbols */
    output( "\t%s %d\n",                  /* SizeOfOptionalHeader */
449 450
             get_asm_short_keyword(),
             get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER : IMAGE_SIZEOF_NT_OPTIONAL32_HEADER );
451
    output( "\t%s 0x%04x\n",              /* Characteristics */
452
             get_asm_short_keyword(), spec->characteristics );
453
    output( "\t%s 0x%04x\n",              /* Magic */
454 455
             get_asm_short_keyword(),
             get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC : IMAGE_NT_OPTIONAL_HDR32_MAGIC );
456 457 458 459 460
    output( "\t.byte 0\n" );              /* MajorLinkerVersion */
    output( "\t.byte 0\n" );              /* MinorLinkerVersion */
    output( "\t.long 0\n" );              /* SizeOfCode */
    output( "\t.long 0\n" );              /* SizeOfInitializedData */
    output( "\t.long 0\n" );              /* SizeOfUninitializedData */
461
    /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
462
    output( "\t%s %s\n",                  /* AddressOfEntryPoint */
463
            get_asm_ptr_keyword(), spec->init_func ? asm_name(spec->init_func) : "0" );
464
    if (get_ptr_size() == 4)
465
    {
466 467
        output( "\t.long 0\n" );          /* BaseOfCode */
        output( "\t.long 0\n" );          /* BaseOfData */
468
    }
469
    output( "\t%s __wine_spec_pe_header\n",         /* ImageBase */
470
             get_asm_ptr_keyword() );
471 472 473
    output( "\t.long %u\n", page_size );  /* SectionAlignment */
    output( "\t.long %u\n", page_size );  /* FileAlignment */
    output( "\t%s 1,0\n",                 /* Major/MinorOperatingSystemVersion */
474
             get_asm_short_keyword() );
475
    output( "\t%s 0,0\n",                 /* Major/MinorImageVersion */
476
             get_asm_short_keyword() );
477
    output( "\t%s %u,%u\n",               /* Major/MinorSubsystemVersion */
478
             get_asm_short_keyword(), spec->subsystem_major, spec->subsystem_minor );
479 480
    output( "\t.long 0\n" );                          /* Win32VersionValue */
    output( "\t.long %s-.L__wine_spec_rva_base\n",    /* SizeOfImage */
481
             asm_name("_end") );
482 483 484
    output( "\t.long %u\n", page_size );  /* SizeOfHeaders */
    output( "\t.long 0\n" );              /* CheckSum */
    output( "\t%s 0x%04x\n",              /* Subsystem */
485
             get_asm_short_keyword(), spec->subsystem );
486 487
    output( "\t%s 0x%04x\n",              /* DllCharacteristics */
            get_asm_short_keyword(), spec->dll_characteristics );
488
    output( "\t%s %u,%u\n",               /* SizeOfStackReserve/Commit */
489
             get_asm_ptr_keyword(), (spec->stack_size ? spec->stack_size : 1024) * 1024, page_size );
490
    output( "\t%s %u,%u\n",               /* SizeOfHeapReserve/Commit */
491
             get_asm_ptr_keyword(), (spec->heap_size ? spec->heap_size : 1024) * 1024, page_size );
492 493
    output( "\t.long 0\n" );              /* LoaderFlags */
    output( "\t.long 16\n" );             /* NumberOfRvaAndSizes */
494

495
    if (spec->base <= spec->limit)   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
496
        output( "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
497
                 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
498
    else
499
        output( "\t.long 0,0\n" );
500

501
    if (has_imports())   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
502
        output( "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
503
                 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
504
    else
505
        output( "\t.long 0,0\n" );
506

507
    if (spec->nb_resources)   /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
508
        output( "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
509
                 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
510
    else
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
        output( "\t.long 0,0\n" );

    output( "\t.long 0,0\n" );  /* DataDirectory[3] */
    output( "\t.long 0,0\n" );  /* DataDirectory[4] */
    output( "\t.long 0,0\n" );  /* DataDirectory[5] */
    output( "\t.long 0,0\n" );  /* DataDirectory[6] */
    output( "\t.long 0,0\n" );  /* DataDirectory[7] */
    output( "\t.long 0,0\n" );  /* DataDirectory[8] */
    output( "\t.long 0,0\n" );  /* DataDirectory[9] */
    output( "\t.long 0,0\n" );  /* DataDirectory[10] */
    output( "\t.long 0,0\n" );  /* DataDirectory[11] */
    output( "\t.long 0,0\n" );  /* DataDirectory[12] */
    output( "\t.long 0,0\n" );  /* DataDirectory[13] */
    output( "\t.long 0,0\n" );  /* DataDirectory[14] */
    output( "\t.long 0,0\n" );  /* DataDirectory[15] */

    output( "\n\t%s\n", get_asm_string_section() );
    output( "%s\n", asm_globl("__wine_spec_file_name") );
    output( ".L__wine_spec_file_name:\n" );
    output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec->file_name );
531
    if (target_platform == PLATFORM_APPLE)
532 533
        output( "\t.lcomm %s,4\n", asm_name("_end") );

534 535 536 537 538 539 540 541 542 543 544 545 546 547
    output_asm_constructor( "__wine_spec_init_ctor" );
}


/*******************************************************************
 *         BuildSpec32File
 *
 * Build a Win32 C file from a spec file.
 */
void BuildSpec32File( DLLSPEC *spec )
{
    resolve_imports( spec );
    output_standard_file_header();
    output_module( spec );
548 549 550 551 552
    output_stubs( spec );
    output_exports( spec );
    output_imports( spec );
    output_resources( spec );
    output_gnu_stack_note();
553
}
554 555 556 557 558 559 560


/*******************************************************************
 *         BuildDef32File
 *
 * Build a Win32 def file from a spec file.
 */
561
void BuildDef32File( DLLSPEC *spec )
562
{
563
    const char *name;
564
    int i, total;
565

566
    if (spec_file_name)
567
        output( "; File generated automatically from %s; do not edit!\n\n",
568 569
                 spec_file_name );
    else
570
        output( "; File generated automatically; do not edit!\n\n" );
571

572 573
    output( "LIBRARY %s\n\n", spec->file_name);
    output( "EXPORTS\n");
574 575 576

    /* Output the exports and relay entry points */

577
    for (i = total = 0; i < spec->nb_entry_points; i++)
578
    {
579
        const ORDDEF *odp = &spec->entry_points[i];
580
        int is_data = 0;
581 582

        if (!odp) continue;
583

584 585 586 587
        if (odp->name) name = odp->name;
        else if (odp->export_name) name = odp->export_name;
        else continue;

588 589 590 591
        if (!(odp->flags & FLAG_PRIVATE)) total++;

        if (odp->type == TYPE_STUB) continue;

592
        output( "  %s", name );
593 594 595 596

        switch(odp->type)
        {
        case TYPE_EXTERN:
597 598
            is_data = 1;
            /* fall through */
599 600 601
        case TYPE_VARARGS:
        case TYPE_CDECL:
            /* try to reduce output */
602
            if(strcmp(name, odp->link_name) || (odp->flags & FLAG_FORWARD))
603
                output( "=%s", odp->link_name );
604 605 606
            break;
        case TYPE_STDCALL:
        {
607
            int at_param = strlen(odp->u.func.arg_types) * get_ptr_size();
608
            if (!kill_at && target_cpu == CPU_x86) output( "@%d", at_param );
609 610
            if  (odp->flags & FLAG_FORWARD)
            {
611
                output( "=%s", odp->link_name );
612 613
            }
            else if (strcmp(name, odp->link_name)) /* try to reduce output */
614
            {
615
                output( "=%s", odp->link_name );
616
                if (!kill_at && target_cpu == CPU_x86) output( "@%d", at_param );
617 618 619 620 621 622
            }
            break;
        }
        default:
            assert(0);
        }
623
        output( " @%d", odp->ordinal );
624
        if (!odp->name || (odp->flags & FLAG_ORDINAL)) output( " NONAME" );
625 626 627
        if (is_data) output( " DATA" );
        if (odp->flags & FLAG_PRIVATE) output( " PRIVATE" );
        output( "\n" );
628
    }
629
    if (!total) warning( "%s: Import library doesn't export anything\n", spec->file_name );
630
}