build.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. struct apiset_entry
  97. {
  98. unsigned int name_off;
  99. unsigned int name_len;
  100. unsigned int hash;
  101. unsigned int hash_len;
  102. unsigned int val_count;
  103. struct apiset_value
  104. {
  105. unsigned int name_off;
  106. unsigned int name_len;
  107. unsigned int val_off;
  108. unsigned int val_len;
  109. } values[4];
  110. };
  111. struct apiset
  112. {
  113. unsigned int count;
  114. unsigned int size;
  115. struct apiset_entry *entries;
  116. unsigned int str_pos;
  117. unsigned int str_size;
  118. char *strings;
  119. };
  120. static const unsigned int apiset_hash_factor = 31;
  121. typedef struct
  122. {
  123. char *src_name; /* file name of the source spec file */
  124. char *file_name; /* file name of the dll */
  125. char *dll_name; /* internal name of the dll */
  126. char *c_name; /* internal name of the dll, as a C-compatible identifier */
  127. char *init_func; /* initialization routine */
  128. char *main_module; /* main Win32 module for Win16 specs */
  129. SPEC_TYPE type; /* type of dll (Win16/Win32) */
  130. int base; /* ordinal base */
  131. int limit; /* ordinal limit */
  132. int stack_size; /* exe stack size */
  133. int heap_size; /* exe heap size */
  134. int nb_entry_points; /* number of used entry points */
  135. int alloc_entry_points; /* number of allocated entry points */
  136. int nb_names; /* number of entry points with names */
  137. unsigned int nb_resources; /* number of resources */
  138. int characteristics; /* characteristics for the PE header */
  139. int dll_characteristics;/* DLL characteristics for the PE header */
  140. int subsystem; /* subsystem id */
  141. int subsystem_major; /* subsystem version major number */
  142. int subsystem_minor; /* subsystem version minor number */
  143. int syscall_table; /* syscall table id */
  144. int unicode_app; /* default to unicode entry point */
  145. ORDDEF *entry_points; /* dll entry points */
  146. ORDDEF **names; /* array of entry point names (points into entry_points) */
  147. ORDDEF **ordinals; /* array of dll ordinals (points into entry_points) */
  148. struct resource *resources; /* array of dll resources (format differs between Win16/Win32) */
  149. struct apiset apiset; /* list of defined api sets */
  150. } DLLSPEC;
  151. extern char *target_alias;
  152. extern struct target target;
  153. static inline unsigned int get_ptr_size(void)
  154. {
  155. return get_target_ptr_size( target );
  156. }
  157. static inline int is_pe(void)
  158. {
  159. return target.platform == PLATFORM_MINGW || target.platform == PLATFORM_WINDOWS;
  160. }
  161. /* entry point flags */
  162. #define FLAG_NORELAY 0x0001 /* don't use relay debugging for this function */
  163. #define FLAG_NONAME 0x0002 /* don't export function by name */
  164. #define FLAG_RET16 0x0004 /* function returns a 16-bit value */
  165. #define FLAG_RET64 0x0008 /* function returns a 64-bit value */
  166. #define FLAG_REGISTER 0x0010 /* use register calling convention */
  167. #define FLAG_PRIVATE 0x0020 /* function is private (cannot be imported) */
  168. #define FLAG_ORDINAL 0x0040 /* function should be imported by ordinal */
  169. #define FLAG_THISCALL 0x0080 /* function uses thiscall calling convention */
  170. #define FLAG_FASTCALL 0x0100 /* function uses fastcall calling convention */
  171. #define FLAG_SYSCALL 0x0200 /* function is a system call */
  172. #define FLAG_IMPORT 0x0400 /* export is imported from another module */
  173. #define FLAG_FORWARD 0x1000 /* function is a forwarded name */
  174. #define FLAG_EXT_LINK 0x2000 /* function links to an external symbol */
  175. #define FLAG_EXPORT32 0x4000 /* 32-bit export in 16-bit spec file */
  176. #define FLAG_CPU(cpu) (0x10000 << (cpu))
  177. #define FLAG_CPU_MASK (FLAG_CPU_WIN32 | FLAG_CPU_WIN64)
  178. #define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64) | FLAG_CPU(CPU_ARM64))
  179. #define FLAG_CPU_WIN32 (FLAG_CPU(CPU_i386) | FLAG_CPU(CPU_ARM))
  180. #define MAX_ORDINALS 65535
  181. /* some Windows constants */
  182. #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
  183. #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
  184. #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
  185. #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
  186. #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
  187. #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
  188. #define IMAGE_FILE_16BIT_MACHINE 0x0040
  189. #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
  190. #define IMAGE_FILE_32BIT_MACHINE 0x0100
  191. #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
  192. #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
  193. #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
  194. #define IMAGE_FILE_SYSTEM 0x1000
  195. #define IMAGE_FILE_DLL 0x2000
  196. #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
  197. #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
  198. #define IMAGE_DLLCHARACTERISTICS_PREFER_NATIVE 0x0010 /* Wine extension */
  199. #define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
  200. #define IMAGE_SUBSYSTEM_NATIVE 1
  201. #define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
  202. #define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
  203. #define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
  204. /* global functions */
  205. #ifndef DECLSPEC_NORETURN
  206. # if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
  207. # define DECLSPEC_NORETURN __declspec(noreturn)
  208. # else
  209. # define DECLSPEC_NORETURN __attribute__((noreturn))
  210. # endif
  211. #endif
  212. extern char *strupper(char *s);
  213. extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
  214. __attribute__ ((__format__ (__printf__, 1, 2)));
  215. extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
  216. __attribute__ ((__format__ (__printf__, 1, 2)));
  217. extern void error( const char *msg, ... )
  218. __attribute__ ((__format__ (__printf__, 1, 2)));
  219. extern void warning( const char *msg, ... )
  220. __attribute__ ((__format__ (__printf__, 1, 2)));
  221. extern int output( const char *format, ... )
  222. __attribute__ ((__format__ (__printf__, 1, 2)));
  223. extern void output_cfi( const char *format, ... )
  224. __attribute__ ((__format__ (__printf__, 1, 2)));
  225. extern void output_rva( const char *format, ... )
  226. __attribute__ ((__format__ (__printf__, 1, 2)));
  227. extern void spawn( struct strarray array );
  228. extern struct strarray find_tool( const char *name, const char * const *names );
  229. extern struct strarray find_link_tool(void);
  230. extern struct strarray get_as_command(void);
  231. extern struct strarray get_ld_command(void);
  232. extern const char *get_nm_command(void);
  233. extern void cleanup_tmp_files(void);
  234. extern char *get_temp_file_name( const char *prefix, const char *suffix );
  235. extern void output_standard_file_header(void);
  236. extern FILE *open_input_file( const char *srcdir, const char *name );
  237. extern void close_input_file( FILE *file );
  238. extern void open_output_file(void);
  239. extern void close_output_file(void);
  240. extern char *open_temp_output_file( const char *suffix );
  241. extern void dump_bytes( const void *buffer, unsigned int size );
  242. extern int remove_stdcall_decoration( char *name );
  243. extern void assemble_file( const char *src_file, const char *obj_file );
  244. extern DLLSPEC *alloc_dll_spec(void);
  245. extern void free_dll_spec( DLLSPEC *spec );
  246. extern char *make_c_identifier( const char *str );
  247. extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
  248. extern const char *get_link_name( const ORDDEF *odp );
  249. extern int sort_func_list( ORDDEF **list, int count, int (*compare)(const void *, const void *) );
  250. extern unsigned int get_alignment(unsigned int align);
  251. extern unsigned int get_page_size(void);
  252. extern unsigned int get_args_size( const ORDDEF *odp );
  253. extern const char *asm_name( const char *func );
  254. extern const char *func_declaration( const char *func );
  255. extern const char *asm_globl( const char *func );
  256. extern const char *get_asm_ptr_keyword(void);
  257. extern const char *get_asm_string_keyword(void);
  258. extern const char *get_asm_export_section(void);
  259. extern const char *get_asm_rodata_section(void);
  260. extern const char *get_asm_rsrc_section(void);
  261. extern const char *get_asm_string_section(void);
  262. extern const char *arm64_page( const char *sym );
  263. extern const char *arm64_pageoff( const char *sym );
  264. extern void output_function_size( const char *name );
  265. extern void output_gnu_stack_note(void);
  266. extern void add_import_dll( const char *name, const char *filename );
  267. extern void add_delayed_import( const char *name );
  268. extern void add_extra_ld_symbol( const char *name );
  269. extern void add_spec_extra_ld_symbol( const char *name );
  270. extern void read_undef_symbols( DLLSPEC *spec, struct strarray files );
  271. extern void resolve_imports( DLLSPEC *spec );
  272. extern int is_undefined( const char *name );
  273. extern int has_imports(void);
  274. extern void output_get_pc_thunk(void);
  275. extern void output_module( DLLSPEC *spec );
  276. extern void output_stubs( DLLSPEC *spec );
  277. extern void output_syscalls( DLLSPEC *spec );
  278. extern void output_imports( DLLSPEC *spec );
  279. extern void output_static_lib( DLLSPEC *spec, struct strarray files );
  280. extern void output_exports( DLLSPEC *spec );
  281. extern int load_res32_file( const char *name, DLLSPEC *spec );
  282. extern void output_resources( DLLSPEC *spec );
  283. extern void output_bin_resources( DLLSPEC *spec, unsigned int start_rva );
  284. extern void output_spec32_file( DLLSPEC *spec );
  285. extern void output_fake_module( DLLSPEC *spec );
  286. extern void output_data_module( DLLSPEC *spec );
  287. extern void output_def_file( DLLSPEC *spec, int import_only );
  288. extern void output_apiset_lib( DLLSPEC *spec, const struct apiset *apiset );
  289. extern void load_res16_file( const char *name, DLLSPEC *spec );
  290. extern void output_res16_data( DLLSPEC *spec );
  291. extern void output_bin_res16_data( DLLSPEC *spec );
  292. extern void output_res16_directory( DLLSPEC *spec );
  293. extern void output_bin_res16_directory( DLLSPEC *spec, unsigned int data_offset );
  294. extern void output_spec16_file( DLLSPEC *spec );
  295. extern void output_fake_module16( DLLSPEC *spec16 );
  296. extern void output_res_o_file( DLLSPEC *spec );
  297. extern void output_asm_relays16(void);
  298. extern void make_builtin_files( struct strarray files );
  299. extern void fixup_constructors( struct strarray files );
  300. extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
  301. extern int parse_spec_file( FILE *file, DLLSPEC *spec );
  302. extern int parse_def_file( FILE *file, DLLSPEC *spec );
  303. /* buffer management */
  304. extern int byte_swapped;
  305. extern const char *input_buffer_filename;
  306. extern const unsigned char *input_buffer;
  307. extern size_t input_buffer_pos;
  308. extern size_t input_buffer_size;
  309. extern void init_input_buffer( const char *file );
  310. extern unsigned char get_byte(void);
  311. extern unsigned short get_word(void);
  312. extern unsigned int get_dword(void);
  313. extern void put_pword( unsigned int val );
  314. /* global variables */
  315. extern int current_line;
  316. extern int UsePIC;
  317. extern int nb_errors;
  318. extern int display_warnings;
  319. extern int kill_at;
  320. extern int verbose;
  321. extern int link_ext_symbols;
  322. extern int force_pointer_size;
  323. extern int unwind_tables;
  324. extern int use_msvcrt;
  325. extern int unix_lib;
  326. extern int safe_seh;
  327. extern int prefer_native;
  328. extern int data_only;
  329. extern char *input_file_name;
  330. extern char *spec_file_name;
  331. extern FILE *output_file;
  332. extern const char *output_file_name;
  333. extern struct strarray lib_path;
  334. extern struct strarray tools_path;
  335. extern struct strarray as_command;
  336. extern struct strarray cc_command;
  337. extern struct strarray ld_command;
  338. extern struct strarray nm_command;
  339. extern char *cpu_option;
  340. extern char *fpu_option;
  341. extern char *arch_option;
  342. extern const char *float_abi_option;
  343. extern int thumb_mode;
  344. extern int needs_get_pc_thunk;
  345. #endif /* __WINE_BUILD_H */