build.h 13.2 KB
Newer Older
1 2 3 4 5 6
/*
 * Copyright 1993 Robert J. Amstadt
 * Copyright 1995 Martin von Loewis
 * Copyright 1995, 1996, 1997 Alexandre Julliard
 * Copyright 1997 Eric Youngdale
 * Copyright 1999 Ulrich Weigand
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 23 24 25
 */

#ifndef __WINE_BUILD_H
#define __WINE_BUILD_H

26 27 28
#ifndef __WINE_CONFIG_H
# error You must include config.h to use this header
#endif
29

30 31
#include <stdio.h>
#include <stdlib.h>
32
#include <string.h>
33

34 35 36 37 38 39 40
#ifndef max
#define max(a,b)   (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b)   (((a) < (b)) ? (a) : (b))
#endif

41 42
typedef enum
{
43
    TYPE_VARIABLE,     /* variable */
44
    TYPE_PASCAL,       /* pascal function (Win16) */
45 46 47 48 49
    TYPE_ABS,          /* absolute value (Win16) */
    TYPE_STUB,         /* unimplemented stub */
    TYPE_STDCALL,      /* stdcall function (Win32) */
    TYPE_CDECL,        /* cdecl function (Win32) */
    TYPE_VARARGS,      /* varargs function (Win32) */
50
    TYPE_THISCALL,     /* thiscall function (Win32 on i386) */
51 52 53 54 55 56 57 58 59 60
    TYPE_EXTERN,       /* external symbol (Win32) */
    TYPE_NBTYPES
} ORD_TYPE;

typedef enum
{
    SPEC_WIN16,
    SPEC_WIN32
} SPEC_TYPE;

61 62 63 64 65 66 67 68 69 70
enum arg_type
{
    ARG_WORD,     /* 16-bit word */
    ARG_SWORD,    /* 16-bit signed word */
    ARG_SEGPTR,   /* segmented pointer */
    ARG_SEGSTR,   /* segmented pointer to Ansi string */
    ARG_LONG,     /* long */
    ARG_PTR,      /* pointer */
    ARG_STR,      /* pointer to Ansi string */
    ARG_WSTR,     /* pointer to Unicode string */
71 72 73 74
    ARG_INT64,    /* 64-bit integer */
    ARG_INT128,   /* 128-bit integer */
    ARG_FLOAT,    /* 32-bit float */
    ARG_DOUBLE,   /* 64-bit float */
75 76 77 78 79
    ARG_MAXARG = ARG_DOUBLE
};

#define MAX_ARGUMENTS 32

80 81 82 83 84 85 86 87
typedef struct
{
    int n_values;
    int *values;
} ORD_VARIABLE;

typedef struct
{
88
    int           nb_args;
89
    enum arg_type args[MAX_ARGUMENTS];
90 91 92 93
} ORD_FUNCTION;

typedef struct
{
94
    unsigned short value;
95 96 97 98 99 100
} ORD_ABS;

typedef struct
{
    ORD_TYPE    type;
    int         ordinal;
101 102
    int         lineno;
    int         flags;
103 104 105
    char       *name;         /* public name of this function */
    char       *link_name;    /* name of the C symbol to link to */
    char       *export_name;  /* name exported under for noname exports */
106 107 108 109 110 111 112 113
    union
    {
        ORD_VARIABLE   var;
        ORD_FUNCTION   func;
        ORD_ABS        abs;
    } u;
} ORDDEF;

114 115
typedef struct
{
116
    char            *src_name;           /* file name of the source spec file */
117 118 119
    char            *file_name;          /* file name of the dll */
    char            *dll_name;           /* internal name of the dll */
    char            *init_func;          /* initialization routine */
120
    char            *main_module;        /* main Win32 module for Win16 specs */
121 122 123 124 125 126 127 128
    SPEC_TYPE        type;               /* type of dll (Win16/Win32) */
    int              base;               /* ordinal base */
    int              limit;              /* ordinal limit */
    int              stack_size;         /* exe stack size */
    int              heap_size;          /* exe heap size */
    int              nb_entry_points;    /* number of used entry points */
    int              alloc_entry_points; /* number of allocated entry points */
    int              nb_names;           /* number of entry points with names */
Jon Griffiths's avatar
Jon Griffiths committed
129
    unsigned int     nb_resources;       /* number of resources */
130
    int              characteristics;    /* characteristics for the PE header */
131
    int              dll_characteristics;/* DLL characteristics for the PE header */
132 133 134
    int              subsystem;          /* subsystem id */
    int              subsystem_major;    /* subsystem version major number */
    int              subsystem_minor;    /* subsystem version minor number */
135 136 137 138 139 140
    ORDDEF          *entry_points;       /* dll entry points */
    ORDDEF         **names;              /* array of entry point names (points into entry_points) */
    ORDDEF         **ordinals;           /* array of dll ordinals (points into entry_points) */
    struct resource *resources;          /* array of dll resources (format differs between Win16/Win32) */
} DLLSPEC;

141 142
enum target_cpu
{
143
    CPU_x86, CPU_x86_64, CPU_SPARC, CPU_POWERPC, CPU_ARM, CPU_LAST = CPU_ARM
144 145 146 147
};

enum target_platform
{
148 149 150 151 152
    PLATFORM_UNSPECIFIED,
    PLATFORM_APPLE,
    PLATFORM_FREEBSD,
    PLATFORM_SOLARIS,
    PLATFORM_WINDOWS
153 154
};

155
extern char *target_alias;
156 157 158
extern enum target_cpu target_cpu;
extern enum target_platform target_platform;

159 160 161 162 163 164 165
struct strarray
{
    const char **str;
    unsigned int count;
    unsigned int max;
};

166
/* entry point flags */
167
#define FLAG_NORELAY   0x01  /* don't use relay debugging for this function */
168
#define FLAG_NONAME    0x02  /* don't export function by name */
169 170
#define FLAG_RET16     0x04  /* function returns a 16-bit value */
#define FLAG_RET64     0x08  /* function returns a 64-bit value */
171 172 173
#define FLAG_REGISTER  0x10  /* use register calling convention */
#define FLAG_PRIVATE   0x20  /* function is private (cannot be imported) */
#define FLAG_ORDINAL   0x40  /* function should be imported by ordinal */
174

175 176
#define FLAG_FORWARD   0x100  /* function is a forwarded name */
#define FLAG_EXT_LINK  0x200  /* function links to an external symbol */
177
#define FLAG_EXPORT32  0x400  /* 32-bit export in 16-bit spec file */
178

179
#define FLAG_CPU(cpu)  (0x01000 << (cpu))
180
#define FLAG_CPU_MASK  (FLAG_CPU(CPU_LAST + 1) - FLAG_CPU(0))
181 182
#define FLAG_CPU_WIN64 (FLAG_CPU(CPU_x86_64))
#define FLAG_CPU_WIN32 (FLAG_CPU_MASK & ~FLAG_CPU_WIN64)
183

184
#define MAX_ORDINALS  65535
185

186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
/* some Windows constants */

#define IMAGE_FILE_RELOCS_STRIPPED	   0x0001 /* No relocation info */
#define IMAGE_FILE_EXECUTABLE_IMAGE	   0x0002
#define IMAGE_FILE_LINE_NUMS_STRIPPED      0x0004
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED     0x0008
#define IMAGE_FILE_AGGRESIVE_WS_TRIM	   0x0010
#define IMAGE_FILE_LARGE_ADDRESS_AWARE	   0x0020
#define IMAGE_FILE_16BIT_MACHINE	   0x0040
#define IMAGE_FILE_BYTES_REVERSED_LO	   0x0080
#define IMAGE_FILE_32BIT_MACHINE	   0x0100
#define IMAGE_FILE_DEBUG_STRIPPED	   0x0200
#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
#define IMAGE_FILE_NET_RUN_FROM_SWAP	   0x0800
#define IMAGE_FILE_SYSTEM		   0x1000
#define IMAGE_FILE_DLL			   0x2000
#define IMAGE_FILE_UP_SYSTEM_ONLY	   0x4000
#define IMAGE_FILE_BYTES_REVERSED_HI	   0x8000

#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100

#define	IMAGE_SUBSYSTEM_NATIVE      1
#define	IMAGE_SUBSYSTEM_WINDOWS_GUI 2
#define	IMAGE_SUBSYSTEM_WINDOWS_CUI 3
210
#define	IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
211

212 213
/* global functions */

214 215 216 217
#ifndef __GNUC__
#define __attribute__(X)
#endif

218 219 220 221 222 223 224 225
#ifndef DECLSPEC_NORETURN
# if defined(_MSC_VER) && (_MSC_VER >= 1200) && !defined(MIDL_PASS)
#  define DECLSPEC_NORETURN __declspec(noreturn)
# else
#  define DECLSPEC_NORETURN __attribute__((noreturn))
# endif
#endif

226 227 228 229
extern void *xmalloc (size_t size);
extern void *xrealloc (void *ptr, size_t size);
extern char *xstrdup( const char *str );
extern char *strupper(char *s);
230
extern int strendswith(const char* str, const char* end);
231
extern char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
232 233 234 235
extern struct strarray *strarray_init(void);
extern void strarray_add( struct strarray *array, ... );
extern void strarray_addv( struct strarray *array, char * const *argv );
extern void strarray_free( struct strarray *array );
236
extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
237
   __attribute__ ((__format__ (__printf__, 1, 2)));
238
extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
239 240 241 242 243
   __attribute__ ((__format__ (__printf__, 1, 2)));
extern void error( const char *msg, ... )
   __attribute__ ((__format__ (__printf__, 1, 2)));
extern void warning( const char *msg, ... )
   __attribute__ ((__format__ (__printf__, 1, 2)));
244 245
extern int output( const char *format, ... )
   __attribute__ ((__format__ (__printf__, 1, 2)));
246 247
extern void output_cfi( const char *format, ... )
   __attribute__ ((__format__ (__printf__, 1, 2)));
248
extern void spawn( struct strarray *array );
249
extern char *find_tool( const char *name, const char * const *names );
250 251
extern struct strarray *get_as_command(void);
extern struct strarray *get_ld_command(void);
252
extern const char *get_nm_command(void);
253
extern char *get_temp_file_name( const char *prefix, const char *suffix );
254
extern void output_standard_file_header(void);
255 256
extern FILE *open_input_file( const char *srcdir, const char *name );
extern void close_input_file( FILE *file );
257
extern void dump_bytes( const void *buffer, unsigned int size );
258
extern int remove_stdcall_decoration( char *name );
259
extern void assemble_file( const char *src_file, const char *obj_file );
260 261
extern DLLSPEC *alloc_dll_spec(void);
extern void free_dll_spec( DLLSPEC *spec );
262
extern const char *make_c_identifier( const char *str );
263
extern const char *get_stub_name( const ORDDEF *odp, const DLLSPEC *spec );
264
extern enum target_cpu get_cpu_from_name( const char *name );
265 266
extern unsigned int get_alignment(unsigned int align);
extern unsigned int get_page_size(void);
267
extern unsigned int get_ptr_size(void);
268
extern unsigned int get_args_size( const ORDDEF *odp );
269
extern const char *asm_name( const char *func );
270
extern const char *func_declaration( const char *func );
271
extern const char *asm_globl( const char *func );
272
extern const char *get_asm_ptr_keyword(void);
273 274
extern const char *get_asm_string_keyword(void);
extern const char *get_asm_short_keyword(void);
275
extern const char *get_asm_rodata_section(void);
276
extern const char *get_asm_string_section(void);
277 278
extern void output_function_size( const char *name );
extern void output_gnu_stack_note(void);
279

280 281
extern void add_import_dll( const char *name, const char *filename );
extern void add_delayed_import( const char *name );
282
extern void add_extra_ld_symbol( const char *name );
283
extern void read_undef_symbols( DLLSPEC *spec, char **argv );
284 285
extern void resolve_imports( DLLSPEC *spec );
extern int is_undefined( const char *name );
286
extern int has_imports(void);
287
extern int has_relays( DLLSPEC *spec );
288
extern void output_get_pc_thunk(void);
289
extern void output_module( DLLSPEC *spec );
290 291
extern void output_stubs( DLLSPEC *spec );
extern void output_imports( DLLSPEC *spec );
292
extern void output_import_lib( DLLSPEC *spec, char **argv );
293
extern void output_exports( DLLSPEC *spec );
294
extern int load_res32_file( const char *name, DLLSPEC *spec );
295
extern void output_resources( DLLSPEC *spec );
296 297
extern void output_bin_resources( DLLSPEC *spec, unsigned int start_rva );
extern void output_fake_module( DLLSPEC *spec );
298
extern void output_def_file( DLLSPEC *spec, int include_private );
299
extern void load_res16_file( const char *name, DLLSPEC *spec );
300
extern void output_res16_data( DLLSPEC *spec );
301
extern void output_bin_res16_data( DLLSPEC *spec );
302
extern void output_res16_directory( DLLSPEC *spec );
303
extern void output_bin_res16_directory( DLLSPEC *spec, unsigned int data_offset );
304
extern void output_spec16_file( DLLSPEC *spec );
305
extern void output_fake_module16( DLLSPEC *spec16 );
306
extern void output_res_o_file( DLLSPEC *spec );
307
extern void output_asm_relays(void);
308
extern void output_asm_relays16(void);
309

310
extern void BuildSpec32File( DLLSPEC *spec );
311

312
extern void add_16bit_exports( DLLSPEC *spec32, DLLSPEC *spec16 );
313 314
extern int parse_spec_file( FILE *file, DLLSPEC *spec );
extern int parse_def_file( FILE *file, DLLSPEC *spec );
315

316 317 318 319 320 321 322
/* buffer management */

extern int byte_swapped;
extern const char *input_buffer_filename;
extern const unsigned char *input_buffer;
extern size_t input_buffer_pos;
extern size_t input_buffer_size;
323 324 325
extern unsigned char *output_buffer;
extern size_t output_buffer_pos;
extern size_t output_buffer_size;
326 327

extern void init_input_buffer( const char *file );
328 329
extern void init_output_buffer(void);
extern void flush_output_buffer(void);
330 331 332
extern unsigned char get_byte(void);
extern unsigned short get_word(void);
extern unsigned int get_dword(void);
333 334 335 336 337 338 339
extern void put_data( const void *data, size_t size );
extern void put_byte( unsigned char val );
extern void put_word( unsigned short val );
extern void put_dword( unsigned int val );
extern void put_qword( unsigned int val );
extern void put_pword( unsigned int val );
extern void align_output( unsigned int align );
340

341 342 343 344
/* global variables */

extern int current_line;
extern int UsePIC;
345
extern int nb_lib_paths;
346
extern int nb_errors;
347
extern int display_warnings;
348
extern int kill_at;
349 350
extern int verbose;
extern int save_temps;
351
extern int link_ext_symbols;
352
extern int force_pointer_size;
353
extern int unwind_tables;
354

355
extern char *input_file_name;
356
extern char *spec_file_name;
357
extern FILE *output_file;
358
extern const char *output_file_name;
359
extern char **lib_path;
360

361
extern char *as_command;
362 363
extern char *ld_command;
extern char *nm_command;
364
extern char *cpu_option;
365

366
#endif  /* __WINE_BUILD_H */