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"
35 #define IMAGE_FILE_MACHINE_UNKNOWN 0
36 #define IMAGE_FILE_MACHINE_I386 0x014c
37 #define IMAGE_FILE_MACHINE_ALPHA 0x0184
38 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
39 #define IMAGE_FILE_MACHINE_AMD64 0x8664
40 #define IMAGE_FILE_MACHINE_ARM 0x01C0
42 #define IMAGE_SIZEOF_NT_OPTIONAL32_HEADER 224
43 #define IMAGE_SIZEOF_NT_OPTIONAL64_HEADER 240
45 #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
46 #define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b
47 #define IMAGE_ROM_OPTIONAL_HDR_MAGIC 0x107
49 /* check if entry point needs a relay thunk */
50 static inline int needs_relay( const ORDDEF
*odp
)
52 /* skip nonexistent entry points */
54 /* skip non-functions */
55 if (odp
->type
!= TYPE_STDCALL
&& odp
->type
!= TYPE_CDECL
&& odp
->type
!= TYPE_THISCALL
) return 0;
56 /* skip norelay and forward entry points */
57 if (odp
->flags
& (FLAG_NORELAY
|FLAG_FORWARD
)) return 0;
61 /* check if dll will output relay thunks */
62 int has_relays( DLLSPEC
*spec
)
66 if (target_cpu
!= CPU_x86
&& target_cpu
!= CPU_x86_64
) return 0;
68 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
70 ORDDEF
*odp
= spec
->ordinals
[i
];
71 if (needs_relay( odp
)) return 1;
76 /*******************************************************************
79 * Output entry points for relay debugging
81 static void output_relay_debug( DLLSPEC
*spec
)
84 unsigned int j
, args
, flags
;
86 /* first the table of entry point offsets */
88 output( "\t%s\n", get_asm_rodata_section() );
89 output( "\t.align %d\n", get_alignment(4) );
90 output( ".L__wine_spec_relay_entry_point_offsets:\n" );
92 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
94 ORDDEF
*odp
= spec
->ordinals
[i
];
96 if (needs_relay( odp
))
97 output( "\t.long .L__wine_spec_relay_entry_point_%d-__wine_spec_relay_entry_points\n", i
);
99 output( "\t.long 0\n" );
102 /* then the table of argument types */
104 output( "\t.align %d\n", get_alignment(4) );
105 output( ".L__wine_spec_relay_arg_types:\n" );
107 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
109 ORDDEF
*odp
= spec
->ordinals
[i
];
110 unsigned int mask
= 0;
112 if (needs_relay( odp
))
114 for (j
= 0; j
< 16 && odp
->u
.func
.arg_types
[j
]; j
++)
116 if (odp
->u
.func
.arg_types
[j
] == 't') mask
|= 1<< (j
*2);
117 if (odp
->u
.func
.arg_types
[j
] == 'W') mask
|= 2<< (j
*2);
120 output( "\t.long 0x%08x\n", mask
);
123 /* then the relay thunks */
125 output( "\t.text\n" );
126 output( "__wine_spec_relay_entry_points:\n" );
127 output( "\tnop\n" ); /* to avoid 0 offset */
129 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
131 ORDDEF
*odp
= spec
->ordinals
[i
];
133 if (!needs_relay( odp
)) continue;
135 output( "\t.align %d\n", get_alignment(4) );
136 output( ".L__wine_spec_relay_entry_point_%d:\n", i
);
138 args
= strlen(odp
->u
.func
.arg_types
);
144 if (odp
->type
== TYPE_THISCALL
) /* add the this pointer */
146 output( "\tpopl %%eax\n" );
147 output( "\tpushl %%ecx\n" );
148 output( "\tpushl %%eax\n" );
151 if (odp
->flags
& FLAG_REGISTER
)
152 output( "\tpushl %%eax\n" );
154 output( "\tpushl %%esp\n" );
156 if (odp
->flags
& FLAG_RET64
) flags
|= 1;
157 output( "\tpushl $%u\n", (flags
<< 24) | (args
<< 16) | (i
- spec
->base
) );
161 output( "\tcall %s\n", asm_name("__wine_spec_get_pc_thunk_eax") );
162 output( "1:\tleal .L__wine_spec_relay_descr-1b(%%eax),%%eax\n" );
164 else output( "\tmovl $.L__wine_spec_relay_descr,%%eax\n" );
165 output( "\tpushl %%eax\n" );
167 if (odp
->flags
& FLAG_REGISTER
)
169 output( "\tcall *8(%%eax)\n" );
173 output( "\tcall *4(%%eax)\n" );
174 if (odp
->type
== TYPE_STDCALL
|| odp
->type
== TYPE_THISCALL
)
175 output( "\tret $%u\n", args
* get_ptr_size() );
182 output( "\t.cfi_startproc\n" );
183 output( "\tsubq $40,%%rsp\n" );
184 output( "\t.cfi_adjust_cfa_offset 40\n" );
185 output( "\tmovq %%rcx,48(%%rsp)\n" );
186 output( "\tmovq %%rdx,56(%%rsp)\n" );
187 output( "\tmovq %%r8,64(%%rsp)\n" );
188 output( "\tmovq %%r9,72(%%rsp)\n" );
189 output( "\tleaq 40(%%rsp),%%r8\n" );
190 output( "\tmovq $%u,%%rdx\n", (flags
<< 24) | (args
<< 16) | (i
- spec
->base
) );
191 output( "\tleaq .L__wine_spec_relay_descr(%%rip),%%rcx\n" );
192 output( "\tcallq *%u(%%rcx)\n", (odp
->flags
& FLAG_REGISTER
) ? 16 : 8 );
193 output( "\taddq $40,%%rsp\n" );
194 output( "\t.cfi_adjust_cfa_offset -40\n" );
196 output( "\t.cfi_endproc\n" );
205 /*******************************************************************
208 * Output the export table for a Win32 module.
210 void output_exports( DLLSPEC
*spec
)
213 int nr_exports
= spec
->base
<= spec
->limit
? spec
->limit
- spec
->base
+ 1 : 0;
215 if (!nr_exports
) return;
217 output( "\n/* export table */\n\n" );
218 output( "\t.data\n" );
219 output( "\t.align %d\n", get_alignment(4) );
220 output( ".L__wine_spec_exports:\n" );
222 /* export directory header */
224 output( "\t.long 0\n" ); /* Characteristics */
225 output( "\t.long 0\n" ); /* TimeDateStamp */
226 output( "\t.long 0\n" ); /* MajorVersion/MinorVersion */
227 output( "\t.long .L__wine_spec_exp_names-.L__wine_spec_rva_base\n" ); /* Name */
228 output( "\t.long %u\n", spec
->base
); /* Base */
229 output( "\t.long %u\n", nr_exports
); /* NumberOfFunctions */
230 output( "\t.long %u\n", spec
->nb_names
); /* NumberOfNames */
231 output( "\t.long .L__wine_spec_exports_funcs-.L__wine_spec_rva_base\n" ); /* AddressOfFunctions */
234 output( "\t.long .L__wine_spec_exp_name_ptrs-.L__wine_spec_rva_base\n" ); /* AddressOfNames */
235 output( "\t.long .L__wine_spec_exp_ordinals-.L__wine_spec_rva_base\n" ); /* AddressOfNameOrdinals */
239 output( "\t.long 0\n" ); /* AddressOfNames */
240 output( "\t.long 0\n" ); /* AddressOfNameOrdinals */
243 /* output the function pointers */
245 output( "\n.L__wine_spec_exports_funcs:\n" );
246 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
248 ORDDEF
*odp
= spec
->ordinals
[i
];
249 if (!odp
) output( "\t%s 0\n", get_asm_ptr_keyword() );
250 else switch(odp
->type
)
257 if (odp
->flags
& FLAG_FORWARD
)
259 output( "\t%s .L__wine_spec_forwards+%u\n", get_asm_ptr_keyword(), fwd_size
);
260 fwd_size
+= strlen(odp
->link_name
) + 1;
262 else if (odp
->flags
& FLAG_EXT_LINK
)
264 output( "\t%s %s_%s\n",
265 get_asm_ptr_keyword(), asm_name("__wine_spec_ext_link"), odp
->link_name
);
269 output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp
->link_name
) );
273 output( "\t%s %s\n", get_asm_ptr_keyword(),
274 asm_name( get_stub_name( odp
, spec
)) );
283 /* output the function name pointers */
285 int namepos
= strlen(spec
->file_name
) + 1;
287 output( "\n.L__wine_spec_exp_name_ptrs:\n" );
288 for (i
= 0; i
< spec
->nb_names
; i
++)
290 output( "\t.long .L__wine_spec_exp_names+%u-.L__wine_spec_rva_base\n", namepos
);
291 namepos
+= strlen(spec
->names
[i
]->name
) + 1;
294 /* output the function ordinals */
296 output( "\n.L__wine_spec_exp_ordinals:\n" );
297 for (i
= 0; i
< spec
->nb_names
; i
++)
300 get_asm_short_keyword(), spec
->names
[i
]->ordinal
- spec
->base
);
302 if (spec
->nb_names
% 2)
304 output( "\t%s 0\n", get_asm_short_keyword() );
308 /* output the export name strings */
310 output( "\n.L__wine_spec_exp_names:\n" );
311 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
312 for (i
= 0; i
< spec
->nb_names
; i
++)
313 output( "\t%s \"%s\"\n",
314 get_asm_string_keyword(), spec
->names
[i
]->name
);
316 /* output forward strings */
320 output( "\n.L__wine_spec_forwards:\n" );
321 for (i
= spec
->base
; i
<= spec
->limit
; i
++)
323 ORDDEF
*odp
= spec
->ordinals
[i
];
324 if (odp
&& (odp
->flags
& FLAG_FORWARD
))
325 output( "\t%s \"%s\"\n", get_asm_string_keyword(), odp
->link_name
);
328 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
329 output( ".L__wine_spec_exports_end:\n" );
333 if (!has_relays( spec
))
335 output( "\t%s 0\n", get_asm_ptr_keyword() );
339 output( ".L__wine_spec_relay_descr:\n" );
340 output( "\t%s 0xdeb90001\n", get_asm_ptr_keyword() ); /* magic */
341 output( "\t%s 0,0\n", get_asm_ptr_keyword() ); /* relay funcs */
342 output( "\t%s 0\n", get_asm_ptr_keyword() ); /* private data */
343 output( "\t%s __wine_spec_relay_entry_points\n", get_asm_ptr_keyword() );
344 output( "\t%s .L__wine_spec_relay_entry_point_offsets\n", get_asm_ptr_keyword() );
345 output( "\t%s .L__wine_spec_relay_arg_types\n", get_asm_ptr_keyword() );
347 output_relay_debug( spec
);
351 /*******************************************************************
352 * output_asm_constructor
354 * Output code for calling a dll constructor.
356 static void output_asm_constructor( const char *constructor
)
358 if (target_platform
== PLATFORM_APPLE
)
360 /* Mach-O doesn't have an init section */
361 output( "\n\t.mod_init_func\n" );
362 output( "\t.align %d\n", get_alignment(4) );
363 output( "\t.long %s\n", asm_name(constructor
) );
367 output( "\n\t.section \".init\",\"ax\"\n" );
372 output( "\tcall %s\n", asm_name(constructor
) );
375 output( "\tcall %s\n", asm_name(constructor
) );
379 output( "\tjsr $26,%s\n", asm_name(constructor
) );
382 output( "\tblx %s\n", asm_name(constructor
) );
385 output( "\tbl %s\n", asm_name(constructor
) );
392 /*******************************************************************
395 * Output the module data.
397 void output_module( DLLSPEC
*spec
)
400 unsigned int page_size
= get_page_size();
402 /* Reserve some space for the PE header */
404 switch (target_platform
)
407 output( "\t.text\n" );
408 output( "\t.align %d\n", get_alignment(page_size
) );
409 output( "__wine_spec_pe_header:\n" );
410 output( "\t.space 65536\n" );
412 case PLATFORM_SOLARIS
:
413 output( "\n\t.section \".text\",\"ax\"\n" );
414 output( "__wine_spec_pe_header:\n" );
415 output( "\t.skip %u\n", 65536 + page_size
);
418 output( "\n\t.section \".init\",\"ax\"\n" );
425 output( "\tjmp 1f\n" );
429 output( "\tb 1f\n" );
432 output( "__wine_spec_pe_header:\n" );
433 output( "\t.skip %u\n", 65536 + page_size
);
438 /* Output the NT header */
440 output( "\n\t.data\n" );
441 output( "\t.align %d\n", get_alignment(get_ptr_size()) );
442 output( "%s\n", asm_globl("__wine_spec_nt_header") );
443 output( ".L__wine_spec_rva_base:\n" );
445 output( "\t.long 0x4550\n" ); /* Signature */
448 case CPU_x86
: machine
= IMAGE_FILE_MACHINE_I386
; break;
449 case CPU_x86_64
: machine
= IMAGE_FILE_MACHINE_AMD64
; break;
450 case CPU_ARM
: machine
= IMAGE_FILE_MACHINE_ARM
; break;
451 case CPU_POWERPC
: machine
= IMAGE_FILE_MACHINE_POWERPC
; break;
452 case CPU_ALPHA
: machine
= IMAGE_FILE_MACHINE_ALPHA
; break;
453 case CPU_SPARC
: machine
= IMAGE_FILE_MACHINE_UNKNOWN
; break;
455 output( "\t%s 0x%04x\n", /* Machine */
456 get_asm_short_keyword(), machine
);
457 output( "\t%s 0\n", /* NumberOfSections */
458 get_asm_short_keyword() );
459 output( "\t.long 0\n" ); /* TimeDateStamp */
460 output( "\t.long 0\n" ); /* PointerToSymbolTable */
461 output( "\t.long 0\n" ); /* NumberOfSymbols */
462 output( "\t%s %d\n", /* SizeOfOptionalHeader */
463 get_asm_short_keyword(),
464 get_ptr_size() == 8 ? IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
: IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
);
465 output( "\t%s 0x%04x\n", /* Characteristics */
466 get_asm_short_keyword(), spec
->characteristics
);
467 output( "\t%s 0x%04x\n", /* Magic */
468 get_asm_short_keyword(),
469 get_ptr_size() == 8 ? IMAGE_NT_OPTIONAL_HDR64_MAGIC
: IMAGE_NT_OPTIONAL_HDR32_MAGIC
);
470 output( "\t.byte 0\n" ); /* MajorLinkerVersion */
471 output( "\t.byte 0\n" ); /* MinorLinkerVersion */
472 output( "\t.long 0\n" ); /* SizeOfCode */
473 output( "\t.long 0\n" ); /* SizeOfInitializedData */
474 output( "\t.long 0\n" ); /* SizeOfUninitializedData */
475 /* note: we expand the AddressOfEntryPoint field on 64-bit by overwriting the BaseOfCode field */
476 output( "\t%s %s\n", /* AddressOfEntryPoint */
477 get_asm_ptr_keyword(), spec
->init_func
? asm_name(spec
->init_func
) : "0" );
478 if (get_ptr_size() == 4)
480 output( "\t.long 0\n" ); /* BaseOfCode */
481 output( "\t.long 0\n" ); /* BaseOfData */
483 output( "\t%s __wine_spec_pe_header\n", /* ImageBase */
484 get_asm_ptr_keyword() );
485 output( "\t.long %u\n", page_size
); /* SectionAlignment */
486 output( "\t.long %u\n", page_size
); /* FileAlignment */
487 output( "\t%s 1,0\n", /* Major/MinorOperatingSystemVersion */
488 get_asm_short_keyword() );
489 output( "\t%s 0,0\n", /* Major/MinorImageVersion */
490 get_asm_short_keyword() );
491 output( "\t%s %u,%u\n", /* Major/MinorSubsystemVersion */
492 get_asm_short_keyword(), spec
->subsystem_major
, spec
->subsystem_minor
);
493 output( "\t.long 0\n" ); /* Win32VersionValue */
494 output( "\t.long %s-.L__wine_spec_rva_base\n", /* SizeOfImage */
496 output( "\t.long %u\n", page_size
); /* SizeOfHeaders */
497 output( "\t.long 0\n" ); /* CheckSum */
498 output( "\t%s 0x%04x\n", /* Subsystem */
499 get_asm_short_keyword(), spec
->subsystem
);
500 output( "\t%s 0x%04x\n", /* DllCharacteristics */
501 get_asm_short_keyword(), spec
->dll_characteristics
);
502 output( "\t%s %u,%u\n", /* SizeOfStackReserve/Commit */
503 get_asm_ptr_keyword(), (spec
->stack_size
? spec
->stack_size
: 1024) * 1024, page_size
);
504 output( "\t%s %u,%u\n", /* SizeOfHeapReserve/Commit */
505 get_asm_ptr_keyword(), (spec
->heap_size
? spec
->heap_size
: 1024) * 1024, page_size
);
506 output( "\t.long 0\n" ); /* LoaderFlags */
507 output( "\t.long 16\n" ); /* NumberOfRvaAndSizes */
509 if (spec
->base
<= spec
->limit
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
510 output( "\t.long .L__wine_spec_exports-.L__wine_spec_rva_base,"
511 ".L__wine_spec_exports_end-.L__wine_spec_exports\n" );
513 output( "\t.long 0,0\n" );
515 if (has_imports()) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
516 output( "\t.long .L__wine_spec_imports-.L__wine_spec_rva_base,"
517 ".L__wine_spec_imports_end-.L__wine_spec_imports\n" );
519 output( "\t.long 0,0\n" );
521 if (spec
->nb_resources
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
522 output( "\t.long .L__wine_spec_resources-.L__wine_spec_rva_base,"
523 ".L__wine_spec_resources_end-.L__wine_spec_resources\n" );
525 output( "\t.long 0,0\n" );
527 output( "\t.long 0,0\n" ); /* DataDirectory[3] */
528 output( "\t.long 0,0\n" ); /* DataDirectory[4] */
529 output( "\t.long 0,0\n" ); /* DataDirectory[5] */
530 output( "\t.long 0,0\n" ); /* DataDirectory[6] */
531 output( "\t.long 0,0\n" ); /* DataDirectory[7] */
532 output( "\t.long 0,0\n" ); /* DataDirectory[8] */
533 output( "\t.long 0,0\n" ); /* DataDirectory[9] */
534 output( "\t.long 0,0\n" ); /* DataDirectory[10] */
535 output( "\t.long 0,0\n" ); /* DataDirectory[11] */
536 output( "\t.long 0,0\n" ); /* DataDirectory[12] */
537 output( "\t.long 0,0\n" ); /* DataDirectory[13] */
538 output( "\t.long 0,0\n" ); /* DataDirectory[14] */
539 output( "\t.long 0,0\n" ); /* DataDirectory[15] */
541 output( "\n\t%s\n", get_asm_string_section() );
542 output( "%s\n", asm_globl("__wine_spec_file_name") );
543 output( ".L__wine_spec_file_name:\n" );
544 output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec
->file_name
);
545 if (target_platform
== PLATFORM_APPLE
)
546 output( "\t.lcomm %s,4\n", asm_name("_end") );
548 output_asm_constructor( "__wine_spec_init_ctor" );
552 /*******************************************************************
555 * Build a Win32 C file from a spec file.
557 void BuildSpec32File( DLLSPEC
*spec
)
559 resolve_imports( spec
);
560 output_standard_file_header();
561 output_module( spec
);
562 output_stubs( spec
);
563 output_exports( spec
);
564 output_imports( spec
);
565 if (is_undefined( "__wine_call_from_regs" )) output_asm_relays();
566 output_resources( spec
);
567 output_gnu_stack_note();
571 /*******************************************************************
574 * Build a fake binary module from a spec file.
576 void output_fake_module( DLLSPEC
*spec
)
578 static const unsigned char dll_code_section
[] = { 0x31, 0xc0, /* xor %eax,%eax */
579 0xc2, 0x0c, 0x00 }; /* ret $12 */
581 static const unsigned char exe_code_section
[] = { 0xb8, 0x01, 0x00, 0x00, 0x00, /* movl $1,%eax */
582 0xc2, 0x04, 0x00 }; /* ret $4 */
584 static const char fakedll_signature
[] = "Wine placeholder DLL";
585 const unsigned int page_size
= get_page_size();
586 const unsigned int section_align
= page_size
;
587 const unsigned int file_align
= 0x200;
588 const unsigned int reloc_size
= 8;
589 const unsigned int lfanew
= (0x40 + sizeof(fakedll_signature
) + 15) & ~15;
590 const unsigned int nb_sections
= 2 + (spec
->nb_resources
!= 0);
591 const unsigned int text_size
= (spec
->characteristics
& IMAGE_FILE_DLL
) ?
592 sizeof(dll_code_section
) : sizeof(exe_code_section
);
593 unsigned char *resources
;
594 unsigned int resources_size
;
595 unsigned int image_size
= 3 * section_align
;
597 resolve_imports( spec
);
598 output_bin_resources( spec
, 3 * section_align
);
599 resources
= output_buffer
;
600 resources_size
= output_buffer_pos
;
601 if (resources_size
) image_size
+= (resources_size
+ section_align
- 1) & ~(section_align
- 1);
603 init_output_buffer();
605 put_word( 0x5a4d ); /* e_magic */
606 put_word( 0x40 ); /* e_cblp */
607 put_word( 0x01 ); /* e_cp */
608 put_word( 0 ); /* e_crlc */
609 put_word( lfanew
/ 16 ); /* e_cparhdr */
610 put_word( 0x0000 ); /* e_minalloc */
611 put_word( 0xffff ); /* e_maxalloc */
612 put_word( 0x0000 ); /* e_ss */
613 put_word( 0x00b8 ); /* e_sp */
614 put_word( 0 ); /* e_csum */
615 put_word( 0 ); /* e_ip */
616 put_word( 0 ); /* e_cs */
617 put_word( lfanew
); /* e_lfarlc */
618 put_word( 0 ); /* e_ovno */
619 put_dword( 0 ); /* e_res */
621 put_word( 0 ); /* e_oemid */
622 put_word( 0 ); /* e_oeminfo */
623 put_dword( 0 ); /* e_res2 */
630 put_data( fakedll_signature
, sizeof(fakedll_signature
) );
633 put_dword( 0x4550 ); /* Signature */
636 case CPU_x86
: put_word( IMAGE_FILE_MACHINE_I386
); break;
637 case CPU_x86_64
: put_word( IMAGE_FILE_MACHINE_AMD64
); break;
638 case CPU_POWERPC
: put_word( IMAGE_FILE_MACHINE_POWERPC
); break;
639 case CPU_ALPHA
: put_word( IMAGE_FILE_MACHINE_ALPHA
); break;
640 case CPU_SPARC
: put_word( IMAGE_FILE_MACHINE_UNKNOWN
); break;
641 case CPU_ARM
: put_word( IMAGE_FILE_MACHINE_ARM
); break;
643 put_word( nb_sections
); /* NumberOfSections */
644 put_dword( 0 ); /* TimeDateStamp */
645 put_dword( 0 ); /* PointerToSymbolTable */
646 put_dword( 0 ); /* NumberOfSymbols */
647 put_word( get_ptr_size() == 8 ?
648 IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
:
649 IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
); /* SizeOfOptionalHeader */
650 put_word( spec
->characteristics
); /* Characteristics */
651 put_word( get_ptr_size() == 8 ?
652 IMAGE_NT_OPTIONAL_HDR64_MAGIC
:
653 IMAGE_NT_OPTIONAL_HDR32_MAGIC
); /* Magic */
654 put_byte( 0 ); /* MajorLinkerVersion */
655 put_byte( 0 ); /* MinorLinkerVersion */
656 put_dword( text_size
); /* SizeOfCode */
657 put_dword( 0 ); /* SizeOfInitializedData */
658 put_dword( 0 ); /* SizeOfUninitializedData */
659 put_dword( section_align
); /* AddressOfEntryPoint */
660 put_dword( section_align
); /* BaseOfCode */
661 if (get_ptr_size() == 4) put_dword( 0 ); /* BaseOfData */
662 put_pword( 0x10000000 ); /* ImageBase */
663 put_dword( section_align
); /* SectionAlignment */
664 put_dword( file_align
); /* FileAlignment */
665 put_word( 1 ); /* MajorOperatingSystemVersion */
666 put_word( 0 ); /* MinorOperatingSystemVersion */
667 put_word( 0 ); /* MajorImageVersion */
668 put_word( 0 ); /* MinorImageVersion */
669 put_word( spec
->subsystem_major
); /* MajorSubsystemVersion */
670 put_word( spec
->subsystem_minor
); /* MinorSubsystemVersion */
671 put_dword( 0 ); /* Win32VersionValue */
672 put_dword( image_size
); /* SizeOfImage */
673 put_dword( file_align
); /* SizeOfHeaders */
674 put_dword( 0 ); /* CheckSum */
675 put_word( spec
->subsystem
); /* Subsystem */
676 put_word( spec
->dll_characteristics
); /* DllCharacteristics */
677 put_pword( (spec
->stack_size
? spec
->stack_size
: 1024) * 1024 ); /* SizeOfStackReserve */
678 put_pword( page_size
); /* SizeOfStackCommit */
679 put_pword( (spec
->heap_size
? spec
->heap_size
: 1024) * 1024 ); /* SizeOfHeapReserve */
680 put_pword( page_size
); /* SizeOfHeapCommit */
681 put_dword( 0 ); /* LoaderFlags */
682 put_dword( 16 ); /* NumberOfRvaAndSizes */
684 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT] */
685 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT] */
686 if (resources_size
) /* DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE] */
688 put_dword( 3 * section_align
);
689 put_dword( resources_size
);
697 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_EXCEPTION] */
698 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY] */
699 put_dword( 2 * section_align
); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC] */
700 put_dword( reloc_size
);
701 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG] */
702 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COPYRIGHT] */
703 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_GLOBALPTR] */
704 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS] */
705 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG] */
706 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT] */
707 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT] */
708 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT] */
709 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR] */
710 put_dword( 0 ); put_dword( 0 ); /* DataDirectory[15] */
713 put_data( ".text\0\0", 8 ); /* Name */
714 put_dword( section_align
); /* VirtualSize */
715 put_dword( section_align
); /* VirtualAddress */
716 put_dword( text_size
); /* SizeOfRawData */
717 put_dword( file_align
); /* PointerToRawData */
718 put_dword( 0 ); /* PointerToRelocations */
719 put_dword( 0 ); /* PointerToLinenumbers */
720 put_word( 0 ); /* NumberOfRelocations */
721 put_word( 0 ); /* NumberOfLinenumbers */
722 put_dword( 0x60000020 /* CNT_CODE|MEM_EXECUTE|MEM_READ */ ); /* Characteristics */
725 put_data( ".reloc\0", 8 ); /* Name */
726 put_dword( section_align
); /* VirtualSize */
727 put_dword( 2 * section_align
);/* VirtualAddress */
728 put_dword( reloc_size
); /* SizeOfRawData */
729 put_dword( 2 * file_align
); /* PointerToRawData */
730 put_dword( 0 ); /* PointerToRelocations */
731 put_dword( 0 ); /* PointerToLinenumbers */
732 put_word( 0 ); /* NumberOfRelocations */
733 put_word( 0 ); /* NumberOfLinenumbers */
734 put_dword( 0x42000040 /* CNT_INITIALIZED_DATA|MEM_DISCARDABLE|MEM_READ */ ); /* Characteristics */
739 put_data( ".rsrc\0\0", 8 ); /* Name */
740 put_dword( (resources_size
+ section_align
- 1) & ~(section_align
- 1) ); /* VirtualSize */
741 put_dword( 3 * section_align
);/* VirtualAddress */
742 put_dword( resources_size
); /* SizeOfRawData */
743 put_dword( 3 * file_align
); /* PointerToRawData */
744 put_dword( 0 ); /* PointerToRelocations */
745 put_dword( 0 ); /* PointerToLinenumbers */
746 put_word( 0 ); /* NumberOfRelocations */
747 put_word( 0 ); /* NumberOfLinenumbers */
748 put_dword( 0x40000040 /* CNT_INITIALIZED_DATA|MEM_READ */ ); /* Characteristics */
752 align_output( file_align
);
753 if (spec
->characteristics
& IMAGE_FILE_DLL
)
754 put_data( dll_code_section
, sizeof(dll_code_section
) );
756 put_data( exe_code_section
, sizeof(exe_code_section
) );
758 /* .reloc contents */
759 align_output( file_align
);
760 put_dword( 0 ); /* VirtualAddress */
761 put_dword( 0 ); /* SizeOfBlock */
766 align_output( file_align
);
767 put_data( resources
, resources_size
);
769 flush_output_buffer();
773 /*******************************************************************
776 * Build a Win32 def file from a spec file.
778 void output_def_file( DLLSPEC
*spec
, int include_private
)
780 DLLSPEC
*spec32
= NULL
;
784 if (spec
->type
== SPEC_WIN16
)
786 spec32
= alloc_dll_spec();
787 add_16bit_exports( spec32
, spec
);
792 output( "; File generated automatically from %s; do not edit!\n\n",
795 output( "; File generated automatically; do not edit!\n\n" );
797 output( "LIBRARY %s\n\n", spec
->file_name
);
798 output( "EXPORTS\n");
800 /* Output the exports and relay entry points */
802 for (i
= total
= 0; i
< spec
->nb_entry_points
; i
++)
804 const ORDDEF
*odp
= &spec
->entry_points
[i
];
809 if (odp
->name
) name
= odp
->name
;
810 else if (odp
->export_name
) name
= odp
->export_name
;
813 if (!(odp
->flags
& FLAG_PRIVATE
)) total
++;
814 else if (!include_private
) continue;
816 if (odp
->type
== TYPE_STUB
) continue;
818 output( " %s", name
);
828 /* try to reduce output */
829 if(strcmp(name
, odp
->link_name
) || (odp
->flags
& FLAG_FORWARD
))
830 output( "=%s", odp
->link_name
);
834 int at_param
= strlen(odp
->u
.func
.arg_types
) * get_ptr_size();
835 if (!kill_at
&& target_cpu
== CPU_x86
) output( "@%d", at_param
);
836 if (odp
->flags
& FLAG_FORWARD
)
838 output( "=%s", odp
->link_name
);
840 else if (strcmp(name
, odp
->link_name
)) /* try to reduce output */
842 output( "=%s", odp
->link_name
);
843 if (!kill_at
&& target_cpu
== CPU_x86
) output( "@%d", at_param
);
850 output( " @%d", odp
->ordinal
);
851 if (!odp
->name
|| (odp
->flags
& FLAG_ORDINAL
)) output( " NONAME" );
852 if (is_data
) output( " DATA" );
853 if (odp
->flags
& FLAG_PRIVATE
) output( " PRIVATE" );
856 if (!total
) warning( "%s: Import library doesn't export anything\n", spec
->file_name
);
857 if (spec32
) free_dll_spec( spec32
);