build.h 15 KB

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