2 * Copyright 1993 Robert J. Amstadt
3 * Copyright 1995 Martin von Loewis
4 * Copyright 1995, 1996, 1997 Alexandre Julliard
5 * Copyright 1997 Eric Youngdale
6 * Copyright 1999 Ulrich Weigand
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifndef __WINE_BUILD_H
24 #define __WINE_BUILD_H
26 #ifndef __WINE_CONFIG_H
27 # error You must include config.h to use this header
35 #define max(a,b) (((a) > (b)) ? (a) : (b))
38 #define min(a,b) (((a) < (b)) ? (a) : (b))
41 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
45 TYPE_VARIABLE
, /* variable */
46 TYPE_PASCAL
, /* pascal function (Win16) */
47 TYPE_ABS
, /* absolute value (Win16) */
48 TYPE_STUB
, /* unimplemented stub */
49 TYPE_STDCALL
, /* stdcall function (Win32) */
50 TYPE_CDECL
, /* cdecl function (Win32) */
51 TYPE_VARARGS
, /* varargs function (Win32) */
52 TYPE_EXTERN
, /* external symbol (Win32) */
64 ARG_WORD
, /* 16-bit word */
65 ARG_SWORD
, /* 16-bit signed word */
66 ARG_SEGPTR
, /* segmented pointer */
67 ARG_SEGSTR
, /* segmented pointer to Ansi string */
69 ARG_PTR
, /* pointer */
70 ARG_STR
, /* pointer to Ansi string */
71 ARG_WSTR
, /* pointer to Unicode string */
72 ARG_INT64
, /* 64-bit integer */
73 ARG_INT128
, /* 128-bit integer */
74 ARG_FLOAT
, /* 32-bit float */
75 ARG_DOUBLE
, /* 64-bit float */
76 ARG_MAXARG
= ARG_DOUBLE
79 #define MAX_ARGUMENTS 32
91 enum arg_type args
[MAX_ARGUMENTS
];
106 char *name
; /* public name of this function */
107 char *link_name
; /* name of the C symbol to link to */
108 char *export_name
; /* name exported under for noname exports */
119 char *src_name
; /* file name of the source spec file */
120 char *file_name
; /* file name of the dll */
121 char *dll_name
; /* internal name of the dll */
122 char *c_name
; /* internal name of the dll, as a C-compatible identifier */
123 char *init_func
; /* initialization routine */
124 char *main_module
; /* main Win32 module for Win16 specs */
125 SPEC_TYPE type
; /* type of dll (Win16/Win32) */
126 int base
; /* ordinal base */
127 int limit
; /* ordinal limit */
128 int stack_size
; /* exe stack size */
129 int heap_size
; /* exe heap size */
130 int nb_entry_points
; /* number of used entry points */
131 int alloc_entry_points
; /* number of allocated entry points */
132 int nb_names
; /* number of entry points with names */
133 unsigned int nb_resources
; /* number of resources */
134 int characteristics
; /* characteristics for the PE header */
135 int dll_characteristics
;/* DLL characteristics for the PE header */
136 int subsystem
; /* subsystem id */
137 int subsystem_major
; /* subsystem version major number */
138 int subsystem_minor
; /* subsystem version minor number */
139 int unicode_app
; /* default to unicode entry point */
140 ORDDEF
*entry_points
; /* dll entry points */
141 ORDDEF
**names
; /* array of entry point names (points into entry_points) */
142 ORDDEF
**ordinals
; /* array of dll ordinals (points into entry_points) */
143 struct resource
*resources
; /* array of dll resources (format differs between Win16/Win32) */
148 CPU_x86
, CPU_x86_64
, CPU_POWERPC
, CPU_ARM
, CPU_ARM64
, CPU_LAST
= CPU_ARM64
153 PLATFORM_UNSPECIFIED
,
161 extern char *target_alias
;
162 extern enum target_cpu target_cpu
;
163 extern enum target_platform target_platform
;
165 static inline int is_pe(void)
167 return target_platform
== PLATFORM_MINGW
|| target_platform
== PLATFORM_WINDOWS
;
177 /* entry point flags */
178 #define FLAG_NORELAY 0x0001 /* don't use relay debugging for this function */
179 #define FLAG_NONAME 0x0002 /* don't export function by name */
180 #define FLAG_RET16 0x0004 /* function returns a 16-bit value */
181 #define FLAG_RET64 0x0008 /* function returns a 64-bit value */
182 #define FLAG_REGISTER 0x0010 /* use register calling convention */
183 #define FLAG_PRIVATE 0x0020 /* function is private (cannot be imported) */
184 #define FLAG_ORDINAL 0x0040 /* function should be imported by ordinal */
185 #define FLAG_THISCALL 0x0080 /* function uses thiscall calling convention */
186 #define FLAG_FASTCALL 0x0100 /* function uses fastcall calling convention */
187 #define FLAG_SYSCALL 0x0200 /* function is a system call */
188 #define FLAG_IMPORT 0x0400 /* export is imported from another module */
190 #define FLAG_FORWARD 0x1000 /* function is a forwarded name */
191 #define FLAG_EXT_LINK 0x2000 /* function links to an external symbol */
192 #define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
194 #define FLAG_CPU(cpu) (0x10000 << (cpu))
195 #define FLAG_CPU_MASK (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0))
196 #define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
197 #define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
199 #define MAX_ORDINALS 65535
201 /* some Windows constants */
203 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
204 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
205 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
206 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
207 #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
208 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
209 #define IMAGE_FILE_16BIT_MACHINE 0x0040
210 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
211 #define IMAGE_FILE_32BIT_MACHINE 0x0100
212 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
213 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
214 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
215 #define IMAGE_FILE_SYSTEM 0x1000
216 #define IMAGE_FILE_DLL 0x2000
217 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
218 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
220 #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
221 #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
223 #define IMAGE_SUBSYSTEM_NATIVE 1
224 #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
225 #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
226 #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
228 /* global functions */
231 #define __attribute__(X)
234 #ifndef DECLSPEC_NORETURN
235 # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
236 # define DECLSPEC_NORETURN __declspec(noreturn)
238 # define DECLSPEC_NORETURN __attribute__((noreturn))
242 extern void *xmalloc (size_t size
);
243 extern void *xrealloc (void *ptr
, size_t size
);
244 extern char *xstrdup( const char *str
);
245 extern char *strupper(char *s
);
246 extern int strendswith(const char* str
, const char* end
);
247 extern char *strmake(const char* fmt
, ...) __attribute__((__format__ (__printf__
, 1, 2 )));
248 extern struct strarray
strarray_fromstring( const char *str
, const char *delim
);
249 extern void strarray_add( struct strarray
*array
, ... );
250 extern void strarray_addv( struct strarray
*array
, char * const *argv
);
251 extern void strarray_addall( struct strarray
*array
, struct strarray args
);
252 extern DECLSPEC_NORETURN
void fatal_error( const char *msg
, ... )
253 __attribute__ ((__format__ (__printf__
, 1, 2)));
254 extern DECLSPEC_NORETURN
void fatal_perror( const char *msg
, ... )
255 __attribute__ ((__format__ (__printf__
, 1, 2)));
256 extern void error( const char *msg
, ... )
257 __attribute__ ((__format__ (__printf__
, 1, 2)));
258 extern void warning( const char *msg
, ... )
259 __attribute__ ((__format__ (__printf__
, 1, 2)));
260 extern int output( const char *format
, ... )
261 __attribute__ ((__format__ (__printf__
, 1, 2)));
262 extern void output_cfi( const char *format
, ... )
263 __attribute__ ((__format__ (__printf__
, 1, 2)));
264 extern void output_rva( const char *format
, ... )
265 __attribute__ ((__format__ (__printf__
, 1, 2)));
266 extern void spawn( struct strarray array
);
267 extern struct strarray
find_tool( const char *name
, const char * const *names
);
268 extern struct strarray
find_link_tool(void);
269 extern struct strarray
get_as_command(void);
270 extern struct strarray
get_ld_command(void);
271 extern const char *get_nm_command(void);
272 extern void cleanup_tmp_files(void);
273 extern char *get_temp_file_name( const char *prefix
, const char *suffix
);
274 extern void output_standard_file_header(void);
275 extern FILE *open_input_file( const char *srcdir
, const char *name
);
276 extern void close_input_file( FILE *file
);
277 extern void open_output_file(void);
278 extern void close_output_file(void);
279 extern char *open_temp_output_file( const char *suffix
);
280 extern void dump_bytes( const void *buffer
, unsigned int size
);
281 extern int remove_stdcall_decoration( char *name
);
282 extern void assemble_file( const char *src_file
, const char *obj_file
);
283 extern DLLSPEC
*alloc_dll_spec(void);
284 extern void free_dll_spec( DLLSPEC
*spec
);
285 extern char *make_c_identifier( const char *str
);
286 extern const char *get_stub_name( const ORDDEF
*odp
, const DLLSPEC
*spec
);
287 extern const char *get_link_name( const ORDDEF
*odp
);
288 extern int sort_func_list( ORDDEF
**list
, int count
, int (*compare
)(const void *, const void *) );
289 extern int get_cpu_from_name( const char *name
);
290 extern unsigned int get_alignment(unsigned int align
);
291 extern unsigned int get_page_size(void);
292 extern unsigned int get_ptr_size(void);
293 extern unsigned int get_args_size( const ORDDEF
*odp
);
294 extern const char *asm_name( const char *func
);
295 extern const char *func_declaration( const char *func
);
296 extern const char *asm_globl( const char *func
);
297 extern const char *get_asm_ptr_keyword(void);
298 extern const char *get_asm_string_keyword(void);
299 extern const char *get_asm_export_section(void);
300 extern const char *get_asm_rodata_section(void);
301 extern const char *get_asm_rsrc_section(void);
302 extern const char *get_asm_string_section(void);
303 extern const char *arm64_page( const char *sym
);
304 extern const char *arm64_pageoff( const char *sym
);
305 extern void output_function_size( const char *name
);
306 extern void output_gnu_stack_note(void);
308 extern void add_import_dll( const char *name
, const char *filename
);
309 extern void add_delayed_import( const char *name
);
310 extern void add_extra_ld_symbol( const char *name
);
311 extern void add_spec_extra_ld_symbol( const char *name
);
312 extern void read_undef_symbols( DLLSPEC
*spec
, char **argv
);
313 extern void resolve_imports( DLLSPEC
*spec
);
314 extern int is_undefined( const char *name
);
315 extern int has_imports(void);
316 extern void output_get_pc_thunk(void);
317 extern void output_module( DLLSPEC
*spec
);
318 extern void output_stubs( DLLSPEC
*spec
);
319 extern void output_syscalls( DLLSPEC
*spec
);
320 extern void output_imports( DLLSPEC
*spec
);
321 extern void output_static_lib( DLLSPEC
*spec
, char **argv
);
322 extern void output_exports( DLLSPEC
*spec
);
323 extern int load_res32_file( const char *name
, DLLSPEC
*spec
);
324 extern void output_resources( DLLSPEC
*spec
);
325 extern void output_bin_resources( DLLSPEC
*spec
, unsigned int start_rva
);
326 extern void output_spec32_file( DLLSPEC
*spec
);
327 extern void output_fake_module( DLLSPEC
*spec
);
328 extern void output_def_file( DLLSPEC
*spec
, int import_only
);
329 extern void load_res16_file( const char *name
, DLLSPEC
*spec
);
330 extern void output_res16_data( DLLSPEC
*spec
);
331 extern void output_bin_res16_data( DLLSPEC
*spec
);
332 extern void output_res16_directory( DLLSPEC
*spec
);
333 extern void output_bin_res16_directory( DLLSPEC
*spec
, unsigned int data_offset
);
334 extern void output_spec16_file( DLLSPEC
*spec
);
335 extern void output_fake_module16( DLLSPEC
*spec16
);
336 extern void output_res_o_file( DLLSPEC
*spec
);
337 extern void output_asm_relays16(void);
338 extern void make_builtin_files( char *argv
[] );
339 extern void fixup_constructors( char *argv
[] );
341 extern void add_16bit_exports( DLLSPEC
*spec32
, DLLSPEC
*spec16
);
342 extern int parse_spec_file( FILE *file
, DLLSPEC
*spec
);
343 extern int parse_def_file( FILE *file
, DLLSPEC
*spec
);
345 /* buffer management */
347 extern int byte_swapped
;
348 extern const char *input_buffer_filename
;
349 extern const unsigned char *input_buffer
;
350 extern size_t input_buffer_pos
;
351 extern size_t input_buffer_size
;
352 extern unsigned char *output_buffer
;
353 extern size_t output_buffer_pos
;
354 extern size_t output_buffer_size
;
356 extern void init_input_buffer( const char *file
);
357 extern void init_output_buffer(void);
358 extern void flush_output_buffer(void);
359 extern unsigned char get_byte(void);
360 extern unsigned short get_word(void);
361 extern unsigned int get_dword(void);
362 extern void put_data( const void *data
, size_t size
);
363 extern void put_byte( unsigned char val
);
364 extern void put_word( unsigned short val
);
365 extern void put_dword( unsigned int val
);
366 extern void put_qword( unsigned int val
);
367 extern void put_pword( unsigned int val
);
368 extern void align_output( unsigned int align
);
370 /* global variables */
372 extern int current_line
;
374 extern int nb_errors
;
375 extern int display_warnings
;
378 extern int link_ext_symbols
;
379 extern int force_pointer_size
;
380 extern int unwind_tables
;
381 extern int use_msvcrt
;
384 extern int prefer_native
;
386 extern char *input_file_name
;
387 extern char *spec_file_name
;
388 extern FILE *output_file
;
389 extern const char *output_file_name
;
391 extern struct strarray lib_path
;
392 extern struct strarray tools_path
;
393 extern struct strarray as_command
;
394 extern struct strarray cc_command
;
395 extern struct strarray ld_command
;
396 extern struct strarray nm_command
;
397 extern char *cpu_option
;
398 extern char *fpu_option
;
399 extern char *arch_option
;
400 extern const char *float_abi_option
;
401 extern int thumb_mode
;
402 extern int needs_get_pc_thunk
;
404 #endif /* __WINE_BUILD_H */