build.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  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
  7. *
  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.
  12. *
  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.
  17. *
  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
  21. */
  22. #ifndef __WINE_BUILD_H
  23. #define __WINE_BUILD_H
  24. #ifndef __WINE_CONFIG_H
  25. # error You must include config.h to use this header
  26. #endif
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include "../tools.h"
  30. typedef enum
  31. {
  32. TYPE_VARIABLE, /* variable */
  33. TYPE_PASCAL, /* pascal function (Win16) */
  34. TYPE_ABS, /* absolute value (Win16) */
  35. TYPE_STUB, /* unimplemented stub */
  36. TYPE_STDCALL, /* stdcall function (Win32) */
  37. TYPE_CDECL, /* cdecl function (Win32) */
  38. TYPE_VARARGS, /* varargs function (Win32) */
  39. TYPE_EXTERN, /* external symbol (Win32) */
  40. TYPE_NBTYPES
  41. } ORD_TYPE;
  42. typedef enum
  43. {
  44. SPEC_WIN16,
  45. SPEC_WIN32
  46. } SPEC_TYPE;
  47. enum arg_type
  48. {
  49. ARG_WORD, /* 16-bit word */
  50. ARG_SWORD, /* 16-bit signed word */
  51. ARG_SEGPTR, /* segmented pointer */
  52. ARG_SEGSTR, /* segmented pointer to Ansi string */
  53. ARG_LONG, /* long */
  54. ARG_PTR, /* pointer */
  55. ARG_STR, /* pointer to Ansi string */
  56. ARG_WSTR, /* pointer to Unicode string */
  57. ARG_INT64, /* 64-bit integer */
  58. ARG_INT128, /* 128-bit integer */
  59. ARG_FLOAT, /* 32-bit float */
  60. ARG_DOUBLE, /* 64-bit float */
  61. ARG_MAXARG = ARG_DOUBLE
  62. };
  63. #define MAX_ARGUMENTS 32
  64. typedef struct
  65. {
  66. int n_values;
  67. unsigned int *values;
  68. } ORD_VARIABLE;
  69. typedef struct
  70. {
  71. int nb_args;
  72. int args_str_offset;
  73. enum arg_type args[MAX_ARGUMENTS];
  74. } ORD_FUNCTION;
  75. typedef struct
  76. {
  77. unsigned short value;
  78. } ORD_ABS;
  79. typedef struct
  80. {
  81. ORD_TYPE type;
  82. int ordinal;
  83. int hint;
  84. int lineno;
  85. int flags;
  86. char *name; /* public name of this function */
  87. char *link_name; /* name of the C symbol to link to */
  88. char *export_name; /* name exported under for noname exports */
  89. union
  90. {
  91. ORD_VARIABLE var;
  92. ORD_FUNCTION func;
  93. ORD_ABS abs;
  94. } u;
  95. } ORDDEF;
  96. typedef struct
  97. {
  98. char *src_name; /* file name of the source spec file */
  99. char *file_name; /* file name of the dll */
  100. char *dll_name; /* internal name of the dll */
  101. char *c_name; /* internal name of the dll, as a C-compatible identifier */
  102. char *init_func; /* initialization routine */
  103. char *main_module; /* main Win32 module for Win16 specs */
  104. SPEC_TYPE type; /* type of dll (Win16/Win32) */
  105. int base; /* ordinal base */
  106. int limit; /* ordinal limit */
  107. int stack_size; /* exe stack size */
  108. int heap_size; /* exe heap size */
  109. int nb_entry_points; /* number of used entry points */
  110. int alloc_entry_points; /* number of allocated entry points */
  111. int nb_names; /* number of entry points with names */
  112. unsigned int nb_resources; /* number of resources */
  113. int characteristics; /* characteristics for the PE header */
  114. int dll_characteristics;/* DLL characteristics for the PE header */
  115. int subsystem; /* subsystem id */
  116. int subsystem_major; /* subsystem version major number */
  117. int subsystem_minor; /* subsystem version minor number */
  118. int syscall_table; /* syscall table id */
  119. int unicode_app; /* default to unicode entry point */
  120. ORDDEF *entry_points; /* dll entry points */
  121. ORDDEF **names; /* array of entry point names (points into entry_points) */
  122. ORDDEF **ordinals; /* array of dll ordinals (points into entry_points) */
  123. struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
  124. } DLLSPEC;
  125. extern char *target_alias;
  126. extern struct target target;
  127. static inline unsigned int get_ptr_size(void)
  128. {
  129. return get_target_ptr_size( target );
  130. }
  131. static inline int is_pe(void)
  132. {
  133. return target.platform == PLATFORM_MINGW || target.platform == PLATFORM_WINDOWS;
  134. }
  135. /* entry point flags */
  136. #define FLAG_NORELAY 0x0001 /* don't use relay debugging for this function */
  137. #define FLAG_NONAME 0x0002 /* don't export function by name */
  138. #define FLAG_RET16 0x0004 /* function returns a 16-bit value */
  139. #define FLAG_RET64 0x0008 /* function returns a 64-bit value */
  140. #define FLAG_REGISTER 0x0010 /* use register calling convention */
  141. #define FLAG_PRIVATE 0x0020 /* function is private (cannot be imported) */
  142. #define FLAG_ORDINAL 0x0040 /* function should be imported by ordinal */
  143. #define FLAG_THISCALL 0x0080 /* function uses thiscall calling convention */
  144. #define FLAG_FASTCALL 0x0100 /* function uses fastcall calling convention */
  145. #define FLAG_SYSCALL 0x0200 /* function is a system call */
  146. #define FLAG_IMPORT 0x0400 /* export is imported from another module */
  147. #define FLAG_FORWARD 0x1000 /* function is a forwarded name */
  148. #define FLAG_EXT_LINK 0x2000 /* function links to an external symbol */
  149. #define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
  150. #define FLAG_CPU(cpu) (0x10000 << (cpu))
  151. #define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
  152. #define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
  153. #define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
  154. #define MAX_ORDINALS 65535
  155. /* some Windows constants */
  156. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
  157. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
  158. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
  159. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
  160. #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
  161. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
  162. #define IMAGE_FILE_16BIT_MACHINE 0x0040
  163. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
  164. #define IMAGE_FILE_32BIT_MACHINE 0x0100
  165. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
  166. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
  167. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
  168. #define IMAGE_FILE_SYSTEM 0x1000
  169. #define IMAGE_FILE_DLL 0x2000
  170. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
  171. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
  172. #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
  173. #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
  174. #define IMAGE_SUBSYSTEM_NATIVE 1
  175. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
  176. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
  177. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
  178. /* global functions */
  179. #ifndef DECLSPEC_NORETURN
  180. # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  181. # define DECLSPEC_NORETURN __declspec(noreturn)
  182. # else
  183. # define DECLSPEC_NORETURN __attribute__((noreturn))
  184. # endif
  185. #endif
  186. extern char *strupper(char *s);
  187. extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
  188. __attribute__ ((__format__ (__printf__, 1, 2)));
  189. extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
  190. __attribute__ ((__format__ (__printf__, 1, 2)));
  191. extern void error( const char *msg, ... )
  192. __attribute__ ((__format__ (__printf__, 1, 2)));
  193. extern void warning( const char *msg, ... )
  194. __attribute__ ((__format__ (__printf__, 1, 2)));
  195. extern int output( const char *format, ... )
  196. __attribute__ ((__format__ (__printf__, 1, 2)));
  197. extern void output_cfi( const char *format, ... )
  198. __attribute__ ((__format__ (__printf__, 1, 2)));
  199. extern void output_rva( const char *format, ... )
  200. __attribute__ ((__format__ (__printf__, 1, 2)));
  201. extern void spawn( struct strarray array );
  202. extern struct strarray find_tool( const char *name, const char * const *names );
  203. extern struct strarray find_link_tool(void);
  204. extern struct strarray get_as_command(void);
  205. extern struct strarray get_ld_command(void);
  206. extern const char *get_nm_command(void);
  207. extern void cleanup_tmp_files(void);
  208. extern char *get_temp_file_name( const char *prefix, const char *suffix );
  209. extern void output_standard_file_header(void);
  210. extern FILE *open_input_file( const char *srcdir, const char *name );
  211. extern void close_input_file( FILE *file );
  212. extern void open_output_file(void);
  213. extern void close_output_file(void);
  214. extern char *open_temp_output_file( const char *suffix );
  215. extern void dump_bytes( const void *buffer, unsigned int size );
  216. extern int remove_stdcall_decoration( char *name );
  217. extern void assemble_file( const char *src_file, const char *obj_file );
  218. extern DLLSPEC *alloc_dll_spec(void);
  219. extern void free_dll_spec( DLLSPEC *spec );
  220. extern char *make_c_identifier( const char *str );
  221. extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
  222. extern const char *get_link_name( const ORDDEF *odp );
  223. extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
  224. extern unsigned int get_alignment(unsigned int align);
  225. extern unsigned int get_page_size(void);
  226. extern unsigned int get_args_size( const ORDDEF *odp );
  227. extern const char *asm_name( const char *func );
  228. extern const char *func_declaration( const char *func );
  229. extern const char *asm_globl( const char *func );
  230. extern const char *get_asm_ptr_keyword(void);
  231. extern const char *get_asm_string_keyword(void);
  232. extern const char *get_asm_export_section(void);
  233. extern const char *get_asm_rodata_section(void);
  234. extern const char *get_asm_rsrc_section(void);
  235. extern const char *get_asm_string_section(void);
  236. extern const char *arm64_page( const char *sym );
  237. extern const char *arm64_pageoff( const char *sym );
  238. extern void output_function_size( const char *name );
  239. extern void output_gnu_stack_note(void);
  240. extern void add_import_dll( const char *name, const char *filename );
  241. extern void add_delayed_import( const char *name );
  242. extern void add_extra_ld_symbol( const char *name );
  243. extern void add_spec_extra_ld_symbol( const char *name );
  244. extern void read_undef_symbols( DLLSPEC *spec, struct strarray files );
  245. extern void resolve_imports( DLLSPEC *spec );
  246. extern int is_undefined( const char *name );
  247. extern int has_imports(void);
  248. extern void output_get_pc_thunk(void);
  249. extern void output_module( DLLSPEC *spec );
  250. extern void output_stubs( DLLSPEC *spec );
  251. extern void output_syscalls( DLLSPEC *spec );
  252. extern void output_imports( DLLSPEC *spec );
  253. extern void output_static_lib( DLLSPEC *spec, struct strarray files );
  254. extern void output_exports( DLLSPEC *spec );
  255. extern int load_res32_file( const char *name, DLLSPEC *spec );
  256. extern void output_resources( DLLSPEC *spec );
  257. extern void output_bin_resources( DLLSPEC *spec, unsigned int start_rva );
  258. extern void output_spec32_file( DLLSPEC *spec );
  259. extern void output_fake_module( DLLSPEC *spec );
  260. extern void output_def_file( DLLSPEC *spec, int import_only );
  261. extern void load_res16_file( const char *name, DLLSPEC *spec );
  262. extern void output_res16_data( DLLSPEC *spec );
  263. extern void output_bin_res16_data( DLLSPEC *spec );
  264. extern void output_res16_directory( DLLSPEC *spec );
  265. extern void output_bin_res16_directory( DLLSPEC *spec, unsigned int data_offset );
  266. extern void output_spec16_file( DLLSPEC *spec );
  267. extern void output_fake_module16( DLLSPEC *spec16 );
  268. extern void output_res_o_file( DLLSPEC *spec );
  269. extern void output_asm_relays16(void);
  270. extern void make_builtin_files( struct strarray files );
  271. extern void fixup_constructors( struct strarray files );
  272. extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
  273. extern int parse_spec_file( FILE *file, DLLSPEC *spec );
  274. extern int parse_def_file( FILE *file, DLLSPEC *spec );
  275. /* buffer management */
  276. extern int byte_swapped;
  277. extern const char *input_buffer_filename;
  278. extern const unsigned char *input_buffer;
  279. extern size_t input_buffer_pos;
  280. extern size_t input_buffer_size;
  281. extern void init_input_buffer( const char *file );
  282. extern unsigned char get_byte(void);
  283. extern unsigned short get_word(void);
  284. extern unsigned int get_dword(void);
  285. extern void put_pword( unsigned int val );
  286. /* global variables */
  287. extern int current_line;
  288. extern int UsePIC;
  289. extern int nb_errors;
  290. extern int display_warnings;
  291. extern int kill_at;
  292. extern int verbose;
  293. extern int link_ext_symbols;
  294. extern int force_pointer_size;
  295. extern int unwind_tables;
  296. extern int use_msvcrt;
  297. extern int unix_lib;
  298. extern int safe_seh;
  299. extern int prefer_native;
  300. extern char *input_file_name;
  301. extern char *spec_file_name;
  302. extern FILE *output_file;
  303. extern const char *output_file_name;
  304. extern struct strarray lib_path;
  305. extern struct strarray tools_path;
  306. extern struct strarray as_command;
  307. extern struct strarray cc_command;
  308. extern struct strarray ld_command;
  309. extern struct strarray nm_command;
  310. extern char *cpu_option;
  311. extern char *fpu_option;
  312. extern char *arch_option;
  313. extern const char *float_abi_option;
  314. extern int thumb_mode;
  315. extern int needs_get_pc_thunk;
  316. #endif /* __WINE_BUILD_H */