Fix invalid size with GNU designated initializers
[tinycc.git] / tcc.h
blob640f2edf9c2800174ac6ccea34468376dad461f6
1 /*
2 * TCC - Tiny C Compiler
4 * Copyright (c) 2001-2004 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef _TCC_H
22 #define _TCC_H
24 #define _GNU_SOURCE
25 #include "config.h"
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <math.h>
33 #include <fcntl.h>
34 #include <setjmp.h>
35 #include <time.h>
37 #ifndef _WIN32
38 # include <unistd.h>
39 # include <sys/time.h>
40 # ifndef CONFIG_TCC_STATIC
41 # include <dlfcn.h>
42 # endif
43 /* XXX: need to define this to use them in non ISOC99 context */
44 extern float strtof (const char *__nptr, char **__endptr);
45 extern long double strtold (const char *__nptr, char **__endptr);
46 #endif
48 #ifdef _WIN32
49 # include <windows.h>
50 # include <io.h> /* open, close etc. */
51 # include <direct.h> /* getcwd */
52 # ifdef __GNUC__
53 # include <stdint.h>
54 # endif
55 # define inline __inline
56 # define snprintf _snprintf
57 # define vsnprintf _vsnprintf
58 # ifndef __GNUC__
59 # define strtold (long double)strtod
60 # define strtof (float)strtod
61 # define strtoll _strtoi64
62 # define strtoull _strtoui64
63 # endif
64 # ifdef LIBTCC_AS_DLL
65 # define LIBTCCAPI __declspec(dllexport)
66 # define PUB_FUNC LIBTCCAPI
67 # endif
68 # define inp next_inp /* inp is an intrinsic on msvc/mingw */
69 # ifdef _MSC_VER
70 # pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
71 # pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
72 # pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
73 # pragma warning (disable : 4018) // signed/unsigned mismatch
74 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
75 # define ssize_t intptr_t
76 # ifdef _X86_
77 # define __i386__ 1
78 # endif
79 # ifdef _AMD64_
80 # define __x86_64__ 1
81 # endif
82 # endif
83 # undef CONFIG_TCC_STATIC
84 #endif
86 #ifndef O_BINARY
87 # define O_BINARY 0
88 #endif
90 #ifndef offsetof
91 #define offsetof(type, field) ((size_t) &((type *)0)->field)
92 #endif
94 #ifndef countof
95 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
96 #endif
98 #ifdef _MSC_VER
99 # define NORETURN __declspec(noreturn)
100 # define ALIGNED(x) __declspec(align(x))
101 #else
102 # define NORETURN __attribute__((noreturn))
103 # define ALIGNED(x) __attribute__((aligned(x)))
104 #endif
106 /* gnu headers use to #define __attribute__ to empty for non-gcc compilers */
107 #ifdef __TINYC__
108 # undef __attribute__
109 #endif
111 #ifdef _WIN32
112 # define IS_DIRSEP(c) (c == '/' || c == '\\')
113 # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
114 # define PATHCMP stricmp
115 # define PATHSEP ";"
116 #else
117 # define IS_DIRSEP(c) (c == '/')
118 # define IS_ABSPATH(p) IS_DIRSEP(p[0])
119 # define PATHCMP strcmp
120 # define PATHSEP ":"
121 #endif
123 /* -------------------------------------------- */
125 /* parser debug */
126 /* #define PARSE_DEBUG */
127 /* preprocessor debug */
128 /* #define PP_DEBUG */
129 /* include file debug */
130 /* #define INC_DEBUG */
131 /* memory leak debug */
132 /* #define MEM_DEBUG */
133 /* assembler debug */
134 /* #define ASM_DEBUG */
136 /* target selection */
137 /* #define TCC_TARGET_I386 *//* i386 code generator */
138 /* #define TCC_TARGET_X86_64 *//* x86-64 code generator */
139 /* #define TCC_TARGET_ARM *//* ARMv4 code generator */
140 /* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */
141 /* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */
143 /* default target is I386 */
144 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
145 !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
146 !defined(TCC_TARGET_X86_64)
147 # if defined __x86_64__
148 # define TCC_TARGET_X86_64
149 # elif defined __arm__
150 # define TCC_TARGET_ARM
151 # define TCC_ARM_EABI
152 # define TCC_ARM_HARDFLOAT
153 # elif defined __aarch64__
154 # define TCC_TARGET_ARM64
155 # else
156 # define TCC_TARGET_I386
157 # endif
158 # ifdef _WIN32
159 # define TCC_TARGET_PE 1
160 # endif
161 #endif
163 /* only native compiler supports -run */
164 #if defined _WIN32 == defined TCC_TARGET_PE
165 # if defined __i386__ && defined TCC_TARGET_I386
166 # define TCC_IS_NATIVE
167 # elif defined __x86_64__ && defined TCC_TARGET_X86_64
168 # define TCC_IS_NATIVE
169 # elif defined __arm__ && defined TCC_TARGET_ARM
170 # define TCC_IS_NATIVE
171 # elif defined __aarch64__ && defined TCC_TARGET_ARM64
172 # define TCC_IS_NATIVE
173 # endif
174 #endif
176 #if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
177 # define CONFIG_TCC_BACKTRACE
178 # if (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64) \
179 && !defined TCC_UCLIBC && !defined TCC_MUSL
180 # define CONFIG_TCC_BCHECK /* enable bound checking code */
181 # endif
182 #endif
184 /* ------------ path configuration ------------ */
186 #ifndef CONFIG_SYSROOT
187 # define CONFIG_SYSROOT ""
188 #endif
189 #ifndef CONFIG_TCCDIR
190 # define CONFIG_TCCDIR "/usr/local/lib/tcc"
191 #endif
192 #ifndef CONFIG_LDDIR
193 # define CONFIG_LDDIR "lib"
194 #endif
195 #ifdef CONFIG_TRIPLET
196 # define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
197 # define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
198 #else
199 # define USE_TRIPLET(s) s
200 # define ALSO_TRIPLET(s) s
201 #endif
203 /* path to find crt1.o, crti.o and crtn.o */
204 #ifndef CONFIG_TCC_CRTPREFIX
205 # define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
206 #endif
208 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
210 /* system include paths */
211 #ifndef CONFIG_TCC_SYSINCLUDEPATHS
212 # ifdef TCC_TARGET_PE
213 # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi"
214 # else
215 # define CONFIG_TCC_SYSINCLUDEPATHS \
216 "{B}/include" \
217 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
218 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
219 # endif
220 #endif
222 /* library search paths */
223 #ifndef CONFIG_TCC_LIBPATHS
224 # ifdef TCC_TARGET_PE
225 # define CONFIG_TCC_LIBPATHS "{B}/lib"
226 # else
227 # define CONFIG_TCC_LIBPATHS \
228 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
229 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
230 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
231 # endif
232 #endif
234 /* name of ELF interpreter */
235 #ifndef CONFIG_TCC_ELFINTERP
236 # if defined __FreeBSD__
237 # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
238 # elif defined __FreeBSD_kernel__
239 # if defined(TCC_TARGET_X86_64)
240 # define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
241 # else
242 # define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
243 # endif
244 # elif defined __DragonFly__
245 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
246 # elif defined __NetBSD__
247 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
248 # elif defined __GNU__
249 # define CONFIG_TCC_ELFINTERP "/lib/ld.so"
250 # elif defined(TCC_TARGET_PE)
251 # define CONFIG_TCC_ELFINTERP "-"
252 # elif defined(TCC_UCLIBC)
253 # define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
254 # elif defined TCC_TARGET_ARM64
255 # if defined(TCC_MUSL)
256 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
257 # else
258 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
259 # endif
260 # elif defined(TCC_TARGET_X86_64)
261 # if defined(TCC_MUSL)
262 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
263 # else
264 # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
265 # endif
266 # elif !defined(TCC_ARM_EABI)
267 # if defined(TCC_MUSL)
268 # if defined(TCC_TARGET_I386)
269 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-i386.so.1"
270 # else
271 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
272 # endif
273 # else
274 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
275 # endif
276 # endif
277 #endif
279 /* var elf_interp dans *-gen.c */
280 #ifdef CONFIG_TCC_ELFINTERP
281 # define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
282 #else
283 # define DEFAULT_ELFINTERP(s) default_elfinterp(s)
284 #endif
286 /* (target specific) libtcc1.a */
287 #ifndef TCC_LIBTCC1
288 # define TCC_LIBTCC1 "libtcc1.a"
289 #endif
291 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
292 #if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
293 #define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
294 #endif
296 /* -------------------------------------------- */
298 #include "libtcc.h"
299 #include "elf.h"
300 #include "stab.h"
302 /* -------------------------------------------- */
304 #ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
305 # define PUB_FUNC
306 #endif
308 #ifndef ONE_SOURCE
309 # define ONE_SOURCE 1
310 #endif
312 #if ONE_SOURCE
313 #define ST_INLN static inline
314 #define ST_FUNC static
315 #define ST_DATA static
316 #else
317 #define ST_INLN
318 #define ST_FUNC
319 #define ST_DATA extern
320 #endif
322 #ifdef TCC_PROFILE /* profile all functions */
323 # define static
324 #endif
326 /* -------------------------------------------- */
327 /* include the target specific definitions */
329 #define TARGET_DEFS_ONLY
330 #ifdef TCC_TARGET_I386
331 # include "i386-gen.c"
332 # include "i386-link.c"
333 #endif
334 #ifdef TCC_TARGET_X86_64
335 # include "x86_64-gen.c"
336 # include "x86_64-link.c"
337 #endif
338 #ifdef TCC_TARGET_ARM
339 # include "arm-gen.c"
340 # include "arm-link.c"
341 # include "arm-asm.c"
342 #endif
343 #ifdef TCC_TARGET_ARM64
344 # include "arm64-gen.c"
345 # include "arm64-link.c"
346 #endif
347 #ifdef TCC_TARGET_C67
348 # define TCC_TARGET_COFF
349 # include "coff.h"
350 # include "c67-gen.c"
351 # include "c67-link.c"
352 #endif
353 #undef TARGET_DEFS_ONLY
355 /* -------------------------------------------- */
357 #if PTR_SIZE == 8
358 # define ELFCLASSW ELFCLASS64
359 # define ElfW(type) Elf##64##_##type
360 # define ELFW(type) ELF##64##_##type
361 # define ElfW_Rel ElfW(Rela)
362 # define SHT_RELX SHT_RELA
363 # define REL_SECTION_FMT ".rela%s"
364 #else
365 # define ELFCLASSW ELFCLASS32
366 # define ElfW(type) Elf##32##_##type
367 # define ELFW(type) ELF##32##_##type
368 # define ElfW_Rel ElfW(Rel)
369 # define SHT_RELX SHT_REL
370 # define REL_SECTION_FMT ".rel%s"
371 #endif
372 /* target address type */
373 #define addr_t ElfW(Addr)
374 #define ElfSym ElfW(Sym)
376 #if PTR_SIZE == 8 && !defined TCC_TARGET_PE
377 # define LONG_SIZE 8
378 #else
379 # define LONG_SIZE 4
380 #endif
382 /* -------------------------------------------- */
384 #define INCLUDE_STACK_SIZE 32
385 #define IFDEF_STACK_SIZE 64
386 #define VSTACK_SIZE 256
387 #define STRING_MAX_SIZE 1024
388 #define TOKSTR_MAX_SIZE 256
389 #define PACK_STACK_SIZE 8
391 #define TOK_HASH_SIZE 16384 /* must be a power of two */
392 #define TOK_ALLOC_INCR 512 /* must be a power of two */
393 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
395 /* token symbol management */
396 typedef struct TokenSym {
397 struct TokenSym *hash_next;
398 struct Sym *sym_define; /* direct pointer to define */
399 struct Sym *sym_label; /* direct pointer to label */
400 struct Sym *sym_struct; /* direct pointer to structure */
401 struct Sym *sym_identifier; /* direct pointer to identifier */
402 int tok; /* token number */
403 int len;
404 char str[1];
405 } TokenSym;
407 #ifdef TCC_TARGET_PE
408 typedef unsigned short nwchar_t;
409 #else
410 typedef int nwchar_t;
411 #endif
413 typedef struct CString {
414 int size; /* size in bytes */
415 void *data; /* either 'char *' or 'nwchar_t *' */
416 int size_allocated;
417 } CString;
419 /* type definition */
420 typedef struct CType {
421 int t;
422 struct Sym *ref;
423 } CType;
425 /* constant value */
426 typedef union CValue {
427 long double ld;
428 double d;
429 float f;
430 uint64_t i;
431 struct {
432 int size;
433 const void *data;
434 } str;
435 int tab[LDOUBLE_SIZE/4];
436 } CValue;
438 /* value on stack */
439 typedef struct SValue {
440 CType type; /* type */
441 unsigned short r; /* register + flags */
442 unsigned short r2; /* second register, used for 'long long'
443 type. If not used, set to VT_CONST */
444 union {
445 struct { int jtrue, jfalse; }; /* forward jmps */
446 CValue c; /* constant, if VT_CONST */
448 union {
449 struct { unsigned short cmp_op, cmp_r; }; /* VT_CMP operation */
450 struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if */
451 }; /* result of unary() for an identifier. */
453 } SValue;
455 /* symbol attributes */
456 struct SymAttr {
457 unsigned short
458 aligned : 5, /* alignment as log2+1 (0 == unspecified) */
459 packed : 1,
460 weak : 1,
461 visibility : 2,
462 dllexport : 1,
463 nodecorate : 1,
464 dllimport : 1,
465 unused : 4;
468 /* function attributes or temporary attributes for parsing */
469 struct FuncAttr {
470 unsigned
471 func_call : 3, /* calling convention (0..5), see below */
472 func_type : 2, /* FUNC_OLD/NEW/ELLIPSIS */
473 func_noreturn : 1, /* attribute((noreturn)) */
474 xxxx : 2,
475 func_args : 8; /* PE __stdcall args */
478 /* symbol management */
479 typedef struct Sym {
480 int v; /* symbol token */
481 unsigned short r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
482 struct SymAttr a; /* symbol attributes */
483 union {
484 struct {
485 int c; /* associated number or Elf symbol index */
486 union {
487 int sym_scope; /* scope level for locals */
488 int jnext; /* next jump label */
489 struct FuncAttr f; /* function attributes */
490 int auxtype; /* bitfield access type */
493 long long enum_val; /* enum constant if IS_ENUM_VAL */
494 int *d; /* define token stream */
495 struct Sym *ncl; /* next cleanup */
497 CType type; /* associated type */
498 union {
499 struct Sym *next; /* next related symbol (for fields and anoms) */
500 struct Sym *cleanupstate; /* in defined labels */
501 int asm_label; /* associated asm label */
503 struct Sym *prev; /* prev symbol in stack */
504 struct Sym *prev_tok; /* previous symbol for this token */
505 } Sym;
507 /* section definition */
508 typedef struct Section {
509 unsigned long data_offset; /* current data offset */
510 unsigned char *data; /* section data */
511 unsigned long data_allocated; /* used for realloc() handling */
512 int sh_name; /* elf section name (only used during output) */
513 int sh_num; /* elf section number */
514 int sh_type; /* elf section type */
515 int sh_flags; /* elf section flags */
516 int sh_info; /* elf section info */
517 int sh_addralign; /* elf section alignment */
518 int sh_entsize; /* elf entry size */
519 unsigned long sh_size; /* section size (only used during output) */
520 addr_t sh_addr; /* address at which the section is relocated */
521 unsigned long sh_offset; /* file offset */
522 int nb_hashed_syms; /* used to resize the hash table */
523 struct Section *link; /* link to another section */
524 struct Section *reloc; /* corresponding section for relocation, if any */
525 struct Section *hash; /* hash table for symbols */
526 struct Section *prev; /* previous section on section stack */
527 char name[1]; /* section name */
528 } Section;
530 typedef struct DLLReference {
531 int level;
532 void *handle;
533 char name[1];
534 } DLLReference;
536 /* -------------------------------------------------- */
538 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
539 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
540 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
542 /* stored in 'Sym->f.func_type' field */
543 #define FUNC_NEW 1 /* ansi function prototype */
544 #define FUNC_OLD 2 /* old function prototype */
545 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
547 /* stored in 'Sym->f.func_call' field */
548 #define FUNC_CDECL 0 /* standard c call */
549 #define FUNC_STDCALL 1 /* pascal c call */
550 #define FUNC_FASTCALL1 2 /* first param in %eax */
551 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
552 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
553 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
555 /* field 'Sym.t' for macros */
556 #define MACRO_OBJ 0 /* object like macro */
557 #define MACRO_FUNC 1 /* function like macro */
559 /* field 'Sym.r' for C labels */
560 #define LABEL_DEFINED 0 /* label is defined */
561 #define LABEL_FORWARD 1 /* label is forward defined */
562 #define LABEL_DECLARED 2 /* label is declared but never used */
564 /* type_decl() types */
565 #define TYPE_ABSTRACT 1 /* type without variable */
566 #define TYPE_DIRECT 2 /* type with variable */
568 #define IO_BUF_SIZE 8192
570 typedef struct BufferedFile {
571 uint8_t *buf_ptr;
572 uint8_t *buf_end;
573 int fd;
574 struct BufferedFile *prev;
575 int line_num; /* current line number - here to simplify code */
576 int line_ref; /* tcc -E: last printed line */
577 int ifndef_macro; /* #ifndef macro / #endif search */
578 int ifndef_macro_saved; /* saved ifndef_macro */
579 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
580 int include_next_index; /* next search path */
581 char filename[1024]; /* filename */
582 char *true_filename; /* filename not modified by # line directive */
583 unsigned char unget[4];
584 unsigned char buffer[1]; /* extra size for CH_EOB char */
585 } BufferedFile;
587 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
588 #define CH_EOF (-1) /* end of file */
590 /* used to record tokens */
591 typedef struct TokenString {
592 int *str;
593 int len;
594 int lastlen;
595 int allocated_len;
596 int last_line_num;
597 int save_line_num;
598 /* used to chain token-strings with begin/end_macro() */
599 struct TokenString *prev;
600 const int *prev_ptr;
601 char alloc;
602 } TokenString;
604 /* GNUC attribute definition */
605 typedef struct AttributeDef {
606 struct SymAttr a;
607 struct FuncAttr f;
608 struct Section *section;
609 Sym *cleanup_func;
610 int alias_target; /* token */
611 int asm_label; /* associated asm label */
612 char attr_mode; /* __attribute__((__mode__(...))) */
613 } AttributeDef;
615 /* inline functions */
616 typedef struct InlineFunc {
617 TokenString *func_str;
618 Sym *sym;
619 char filename[1];
620 } InlineFunc;
622 /* include file cache, used to find files faster and also to eliminate
623 inclusion if the include file is protected by #ifndef ... #endif */
624 typedef struct CachedInclude {
625 int ifndef_macro;
626 int once;
627 int hash_next; /* -1 if none */
628 char filename[1]; /* path specified in #include */
629 } CachedInclude;
631 #define CACHED_INCLUDES_HASH_SIZE 32
633 #ifdef CONFIG_TCC_ASM
634 typedef struct ExprValue {
635 uint64_t v;
636 Sym *sym;
637 int pcrel;
638 } ExprValue;
640 #define MAX_ASM_OPERANDS 30
641 typedef struct ASMOperand {
642 int id; /* GCC 3 optional identifier (0 if number only supported */
643 char *constraint;
644 char asm_str[16]; /* computed asm string for operand */
645 SValue *vt; /* C value of the expression */
646 int ref_index; /* if >= 0, gives reference to a output constraint */
647 int input_index; /* if >= 0, gives reference to an input constraint */
648 int priority; /* priority, used to assign registers */
649 int reg; /* if >= 0, register number used for this operand */
650 int is_llong; /* true if double register value */
651 int is_memory; /* true if memory operand */
652 int is_rw; /* for '+' modifier */
653 } ASMOperand;
654 #endif
656 /* extra symbol attributes (not in symbol table) */
657 struct sym_attr {
658 unsigned got_offset;
659 unsigned plt_offset;
660 int plt_sym;
661 int dyn_index;
662 #ifdef TCC_TARGET_ARM
663 unsigned char plt_thumb_stub:1;
664 #endif
667 struct TCCState {
668 int verbose; /* if true, display some information during compilation */
669 int nostdinc; /* if true, no standard headers are added */
670 int nostdlib; /* if true, no standard libraries are added */
671 int nocommon; /* if true, do not use common symbols for .bss data */
672 int static_link; /* if true, static linking is performed */
673 int rdynamic; /* if true, all symbols are exported */
674 int symbolic; /* if true, resolve symbols in the current module first */
675 int filetype; /* file type for compilation (NONE,C,ASM) */
676 int cversion; /* supported C ISO version, 199901 (the default), 201112, ... */
678 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
679 char *soname; /* as specified on the command line (-soname) */
680 char *rpath; /* as specified on the command line (-Wl,-rpath=) */
681 int enable_new_dtags; /* ditto, (-Wl,--enable-new-dtags) */
683 /* output type, see TCC_OUTPUT_XXX */
684 int output_type;
685 /* output format, see TCC_OUTPUT_FORMAT_xxx */
686 int output_format;
688 /* C language options */
689 int char_is_unsigned;
690 int leading_underscore;
691 int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
692 int dollars_in_identifiers; /* allows '$' char in identifiers */
693 int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
695 /* warning switches */
696 int warn_write_strings;
697 int warn_unsupported;
698 int warn_error;
699 int warn_none;
700 int warn_implicit_function_declaration;
701 int warn_gcc_compat;
703 /* compile with debug symbol (and use them if error during execution) */
704 int do_debug;
705 #ifdef CONFIG_TCC_BCHECK
706 /* compile with built-in memory and bounds checker */
707 int do_bounds_check;
708 #endif
709 #ifdef TCC_TARGET_ARM
710 enum float_abi float_abi; /* float ABI of the generated code*/
711 #endif
712 int run_test; /* nth test to run with -dt -run */
714 addr_t text_addr; /* address of text section */
715 int has_text_addr;
717 unsigned section_align; /* section alignment */
719 char *init_symbol; /* symbols to call at load-time (not used currently) */
720 char *fini_symbol; /* symbols to call at unload-time (not used currently) */
722 #ifdef TCC_TARGET_I386
723 int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */
724 #endif
725 #ifdef TCC_TARGET_X86_64
726 int nosse; /* For -mno-sse support. */
727 #endif
729 /* array of all loaded dlls (including those referenced by loaded dlls) */
730 DLLReference **loaded_dlls;
731 int nb_loaded_dlls;
733 /* include paths */
734 char **include_paths;
735 int nb_include_paths;
737 char **sysinclude_paths;
738 int nb_sysinclude_paths;
740 /* library paths */
741 char **library_paths;
742 int nb_library_paths;
744 /* crt?.o object path */
745 char **crt_paths;
746 int nb_crt_paths;
748 /* -include files */
749 char **cmd_include_files;
750 int nb_cmd_include_files;
752 /* error handling */
753 void *error_opaque;
754 void (*error_func)(void *opaque, const char *msg);
755 int error_set_jmp_enabled;
756 jmp_buf error_jmp_buf;
757 int nb_errors;
759 /* output file for preprocessing (-E) */
760 FILE *ppfp;
761 enum {
762 LINE_MACRO_OUTPUT_FORMAT_GCC,
763 LINE_MACRO_OUTPUT_FORMAT_NONE,
764 LINE_MACRO_OUTPUT_FORMAT_STD,
765 LINE_MACRO_OUTPUT_FORMAT_P10 = 11
766 } Pflag; /* -P switch */
767 char dflag; /* -dX value */
769 /* for -MD/-MF: collected dependencies for this compilation */
770 char **target_deps;
771 int nb_target_deps;
773 /* compilation */
774 BufferedFile *include_stack[INCLUDE_STACK_SIZE];
775 BufferedFile **include_stack_ptr;
777 int ifdef_stack[IFDEF_STACK_SIZE];
778 int *ifdef_stack_ptr;
780 /* included files enclosed with #ifndef MACRO */
781 int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
782 CachedInclude **cached_includes;
783 int nb_cached_includes;
785 /* #pragma pack stack */
786 int pack_stack[PACK_STACK_SIZE];
787 int *pack_stack_ptr;
788 char **pragma_libs;
789 int nb_pragma_libs;
791 /* inline functions are stored as token lists and compiled last
792 only if referenced */
793 struct InlineFunc **inline_fns;
794 int nb_inline_fns;
796 /* sections */
797 Section **sections;
798 int nb_sections; /* number of sections, including first dummy section */
800 Section **priv_sections;
801 int nb_priv_sections; /* number of private sections */
803 /* got & plt handling */
804 Section *got;
805 Section *plt;
807 /* temporary dynamic symbol sections (for dll loading) */
808 Section *dynsymtab_section;
809 /* exported dynamic symbol section */
810 Section *dynsym;
811 /* copy of the global symtab_section variable */
812 Section *symtab;
813 /* extra attributes (eg. GOT/PLT value) for symtab symbols */
814 struct sym_attr *sym_attrs;
815 int nb_sym_attrs;
817 #ifdef TCC_TARGET_PE
818 /* PE info */
819 int pe_subsystem;
820 unsigned pe_characteristics;
821 unsigned pe_file_align;
822 unsigned pe_stack_size;
823 addr_t pe_imagebase;
824 # ifdef TCC_TARGET_X86_64
825 Section *uw_pdata;
826 int uw_sym;
827 unsigned uw_offs;
828 # endif
829 #endif
831 #ifdef TCC_IS_NATIVE
832 const char *runtime_main;
833 void **runtime_mem;
834 int nb_runtime_mem;
835 #endif
837 /* used by main and tcc_parse_args only */
838 struct filespec **files; /* files seen on command line */
839 int nb_files; /* number thereof */
840 int nb_libraries; /* number of libs thereof */
841 char *outfile; /* output filename */
842 int option_r; /* option -r */
843 int do_bench; /* option -bench */
844 int gen_deps; /* option -MD */
845 char *deps_outfile; /* option -MF */
846 int option_pthread; /* -pthread option */
847 int argc;
848 char **argv;
851 struct filespec {
852 char type;
853 char name[1];
856 /* The current value can be: */
857 #define VT_VALMASK 0x003f /* mask for value location, register or: */
858 #define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
859 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
860 #define VT_LOCAL 0x0032 /* offset on stack */
861 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
862 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
863 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
864 #define VT_LVAL 0x0100 /* var is an lvalue */
865 #define VT_SYM 0x0200 /* a symbol value is added */
866 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
867 char/short stored in integer registers) */
868 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
869 dereferencing value */
870 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
871 bounding function call point is in vc */
872 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
873 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
874 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
875 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
877 /* types */
878 #define VT_BTYPE 0x000f /* mask for basic type */
879 #define VT_VOID 0 /* void type */
880 #define VT_BYTE 1 /* signed byte type */
881 #define VT_SHORT 2 /* short type */
882 #define VT_INT 3 /* integer type */
883 #define VT_LLONG 4 /* 64 bit integer */
884 #define VT_PTR 5 /* pointer */
885 #define VT_FUNC 6 /* function type */
886 #define VT_STRUCT 7 /* struct/union definition */
887 #define VT_FLOAT 8 /* IEEE float */
888 #define VT_DOUBLE 9 /* IEEE double */
889 #define VT_LDOUBLE 10 /* IEEE long double */
890 #define VT_BOOL 11 /* ISOC99 boolean type */
891 #define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */
892 #define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */
894 #define VT_UNSIGNED 0x0010 /* unsigned type */
895 #define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */
896 #define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */
897 #define VT_BITFIELD 0x0080 /* bitfield modifier */
898 #define VT_CONSTANT 0x0100 /* const modifier */
899 #define VT_VOLATILE 0x0200 /* volatile modifier */
900 #define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
901 #define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */
903 /* storage */
904 #define VT_EXTERN 0x00001000 /* extern definition */
905 #define VT_STATIC 0x00002000 /* static variable */
906 #define VT_TYPEDEF 0x00004000 /* typedef definition */
907 #define VT_INLINE 0x00008000 /* inline definition */
908 /* currently unused: 0x000[1248]0000 */
910 #define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
911 #define VT_STRUCT_MASK (((1U << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)
912 #define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f)
913 #define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f)
915 #define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
916 #define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
917 #define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
919 #define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
920 #define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
921 #define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION)
923 /* type mask (except storage) */
924 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
925 #define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
927 /* symbol was created by tccasm.c first */
928 #define VT_ASM (VT_VOID | VT_UNSIGNED)
929 #define IS_ASM_SYM(sym) (((sym)->type.t & (VT_BTYPE | VT_ASM)) == VT_ASM)
931 /* token values */
933 /* warning: the following compare tokens depend on i386 asm code */
934 #define TOK_ULT 0x92
935 #define TOK_UGE 0x93
936 #define TOK_EQ 0x94
937 #define TOK_NE 0x95
938 #define TOK_ULE 0x96
939 #define TOK_UGT 0x97
940 #define TOK_Nset 0x98
941 #define TOK_Nclear 0x99
942 #define TOK_LT 0x9c
943 #define TOK_GE 0x9d
944 #define TOK_LE 0x9e
945 #define TOK_GT 0x9f
947 #define TOK_LAND 0xa0
948 #define TOK_LOR 0xa1
949 #define TOK_DEC 0xa2
950 #define TOK_MID 0xa3 /* inc/dec, to void constant */
951 #define TOK_INC 0xa4
952 #define TOK_UDIV 0xb0 /* unsigned division */
953 #define TOK_UMOD 0xb1 /* unsigned modulo */
954 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
956 /* tokens that carry values (in additional token string space / tokc) --> */
957 #define TOK_CCHAR 0xb3 /* char constant in tokc */
958 #define TOK_LCHAR 0xb4
959 #define TOK_CINT 0xb5 /* number in tokc */
960 #define TOK_CUINT 0xb6 /* unsigned int constant */
961 #define TOK_CLLONG 0xb7 /* long long constant */
962 #define TOK_CULLONG 0xb8 /* unsigned long long constant */
963 #define TOK_STR 0xb9 /* pointer to string in tokc */
964 #define TOK_LSTR 0xba
965 #define TOK_CFLOAT 0xbb /* float constant */
966 #define TOK_CDOUBLE 0xbc /* double constant */
967 #define TOK_CLDOUBLE 0xbd /* long double constant */
968 #define TOK_PPNUM 0xbe /* preprocessor number */
969 #define TOK_PPSTR 0xbf /* preprocessor string */
970 #define TOK_LINENUM 0xc0 /* line number info */
971 #define TOK_TWODOTS 0xa8 /* C++ token ? */
972 /* <-- */
974 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
975 #define TOK_ADDC1 0xc3 /* add with carry generation */
976 #define TOK_ADDC2 0xc4 /* add with carry use */
977 #define TOK_SUBC1 0xc5 /* add with carry generation */
978 #define TOK_SUBC2 0xc6 /* add with carry use */
979 #define TOK_ARROW 0xc7
980 #define TOK_DOTS 0xc8 /* three dots */
981 #define TOK_SHR 0xc9 /* unsigned shift right */
982 #define TOK_TWOSHARPS 0xca /* ## preprocessing token */
983 #define TOK_PLCHLDR 0xcb /* placeholder token as defined in C99 */
984 #define TOK_NOSUBST 0xcc /* means following token has already been pp'd */
985 #define TOK_PPJOIN 0xcd /* A '##' in the right position to mean pasting */
986 #define TOK_CLONG 0xce /* long constant */
987 #define TOK_CULONG 0xcf /* unsigned long constant */
989 #define TOK_SHL 0x01 /* shift left */
990 #define TOK_SAR 0x02 /* signed shift right */
992 /* assignment operators : normal operator or 0x80 */
993 #define TOK_A_MOD 0xa5
994 #define TOK_A_AND 0xa6
995 #define TOK_A_MUL 0xaa
996 #define TOK_A_ADD 0xab
997 #define TOK_A_SUB 0xad
998 #define TOK_A_DIV 0xaf
999 #define TOK_A_XOR 0xde
1000 #define TOK_A_OR 0xfc
1001 #define TOK_A_SHL 0x81
1002 #define TOK_A_SAR 0x82
1004 #define TOK_EOF (-1) /* end of file */
1005 #define TOK_LINEFEED 10 /* line feed */
1007 /* all identifiers and strings have token above that */
1008 #define TOK_IDENT 256
1010 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
1011 #define TOK_ASM_int TOK_INT
1012 #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
1013 #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
1014 #define TOK_ASMDIR_LAST TOK_ASMDIR_section
1016 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1017 /* only used for i386 asm opcodes definitions */
1018 #define DEF_BWL(x) \
1019 DEF(TOK_ASM_ ## x ## b, #x "b") \
1020 DEF(TOK_ASM_ ## x ## w, #x "w") \
1021 DEF(TOK_ASM_ ## x ## l, #x "l") \
1022 DEF(TOK_ASM_ ## x, #x)
1023 #define DEF_WL(x) \
1024 DEF(TOK_ASM_ ## x ## w, #x "w") \
1025 DEF(TOK_ASM_ ## x ## l, #x "l") \
1026 DEF(TOK_ASM_ ## x, #x)
1027 #ifdef TCC_TARGET_X86_64
1028 # define DEF_BWLQ(x) \
1029 DEF(TOK_ASM_ ## x ## b, #x "b") \
1030 DEF(TOK_ASM_ ## x ## w, #x "w") \
1031 DEF(TOK_ASM_ ## x ## l, #x "l") \
1032 DEF(TOK_ASM_ ## x ## q, #x "q") \
1033 DEF(TOK_ASM_ ## x, #x)
1034 # define DEF_WLQ(x) \
1035 DEF(TOK_ASM_ ## x ## w, #x "w") \
1036 DEF(TOK_ASM_ ## x ## l, #x "l") \
1037 DEF(TOK_ASM_ ## x ## q, #x "q") \
1038 DEF(TOK_ASM_ ## x, #x)
1039 # define DEF_BWLX DEF_BWLQ
1040 # define DEF_WLX DEF_WLQ
1041 /* number of sizes + 1 */
1042 # define NBWLX 5
1043 #else
1044 # define DEF_BWLX DEF_BWL
1045 # define DEF_WLX DEF_WL
1046 /* number of sizes + 1 */
1047 # define NBWLX 4
1048 #endif
1050 #define DEF_FP1(x) \
1051 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
1052 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
1053 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
1054 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
1056 #define DEF_FP(x) \
1057 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
1058 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
1059 DEF_FP1(x)
1061 #define DEF_ASMTEST(x,suffix) \
1062 DEF_ASM(x ## o ## suffix) \
1063 DEF_ASM(x ## no ## suffix) \
1064 DEF_ASM(x ## b ## suffix) \
1065 DEF_ASM(x ## c ## suffix) \
1066 DEF_ASM(x ## nae ## suffix) \
1067 DEF_ASM(x ## nb ## suffix) \
1068 DEF_ASM(x ## nc ## suffix) \
1069 DEF_ASM(x ## ae ## suffix) \
1070 DEF_ASM(x ## e ## suffix) \
1071 DEF_ASM(x ## z ## suffix) \
1072 DEF_ASM(x ## ne ## suffix) \
1073 DEF_ASM(x ## nz ## suffix) \
1074 DEF_ASM(x ## be ## suffix) \
1075 DEF_ASM(x ## na ## suffix) \
1076 DEF_ASM(x ## nbe ## suffix) \
1077 DEF_ASM(x ## a ## suffix) \
1078 DEF_ASM(x ## s ## suffix) \
1079 DEF_ASM(x ## ns ## suffix) \
1080 DEF_ASM(x ## p ## suffix) \
1081 DEF_ASM(x ## pe ## suffix) \
1082 DEF_ASM(x ## np ## suffix) \
1083 DEF_ASM(x ## po ## suffix) \
1084 DEF_ASM(x ## l ## suffix) \
1085 DEF_ASM(x ## nge ## suffix) \
1086 DEF_ASM(x ## nl ## suffix) \
1087 DEF_ASM(x ## ge ## suffix) \
1088 DEF_ASM(x ## le ## suffix) \
1089 DEF_ASM(x ## ng ## suffix) \
1090 DEF_ASM(x ## nle ## suffix) \
1091 DEF_ASM(x ## g ## suffix)
1093 #endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */
1095 enum tcc_token {
1096 TOK_LAST = TOK_IDENT - 1
1097 #define DEF(id, str) ,id
1098 #include "tcctok.h"
1099 #undef DEF
1102 /* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
1103 #define TOK_UIDENT TOK_DEFINE
1105 /* ------------ libtcc.c ------------ */
1107 /* use GNU C extensions */
1108 ST_DATA int gnu_ext;
1109 /* use Tiny C extensions */
1110 ST_DATA int tcc_ext;
1111 /* XXX: get rid of this ASAP */
1112 ST_DATA struct TCCState *tcc_state;
1114 /* public functions currently used by the tcc main function */
1115 ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
1116 ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
1117 ST_FUNC char *pstrncpy(char *out, const char *in, size_t num);
1118 PUB_FUNC char *tcc_basename(const char *name);
1119 PUB_FUNC char *tcc_fileextension (const char *name);
1121 #ifndef MEM_DEBUG
1122 PUB_FUNC void tcc_free(void *ptr);
1123 PUB_FUNC void *tcc_malloc(unsigned long size);
1124 PUB_FUNC void *tcc_mallocz(unsigned long size);
1125 PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
1126 PUB_FUNC char *tcc_strdup(const char *str);
1127 #else
1128 #define tcc_free(ptr) tcc_free_debug(ptr)
1129 #define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
1130 #define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
1131 #define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
1132 #define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
1133 PUB_FUNC void tcc_free_debug(void *ptr);
1134 PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
1135 PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
1136 PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
1137 PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
1138 #endif
1140 #define free(p) use_tcc_free(p)
1141 #define malloc(s) use_tcc_malloc(s)
1142 #define realloc(p, s) use_tcc_realloc(p, s)
1143 #undef strdup
1144 #define strdup(s) use_tcc_strdup(s)
1145 PUB_FUNC void tcc_memcheck(void);
1146 PUB_FUNC void tcc_error_noabort(const char *fmt, ...);
1147 PUB_FUNC NORETURN void tcc_error(const char *fmt, ...);
1148 PUB_FUNC void tcc_warning(const char *fmt, ...);
1150 /* other utilities */
1151 ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
1152 ST_FUNC void dynarray_reset(void *pp, int *n);
1153 ST_INLN void cstr_ccat(CString *cstr, int ch);
1154 ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
1155 ST_FUNC void cstr_wccat(CString *cstr, int ch);
1156 ST_FUNC void cstr_new(CString *cstr);
1157 ST_FUNC void cstr_free(CString *cstr);
1158 ST_FUNC void cstr_reset(CString *cstr);
1160 ST_INLN void sym_free(Sym *sym);
1161 ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, int c);
1162 ST_FUNC Sym *sym_find2(Sym *s, int v);
1163 ST_FUNC Sym *sym_push(int v, CType *type, int r, int c);
1164 ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
1165 ST_INLN Sym *struct_find(int v);
1166 ST_INLN Sym *sym_find(int v);
1167 ST_FUNC Sym *global_identifier_push(int v, int t, int c);
1169 ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
1170 ST_FUNC int tcc_open(TCCState *s1, const char *filename);
1171 ST_FUNC void tcc_close(void);
1173 ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
1174 /* flags: */
1175 #define AFF_PRINT_ERROR 0x10 /* print error if file not found */
1176 #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
1177 #define AFF_TYPE_BIN 0x40 /* file to add is binary */
1178 #define AFF_WHOLE_ARCHIVE 0x80 /* load all objects from archive */
1179 /* s->filetype: */
1180 #define AFF_TYPE_NONE 0
1181 #define AFF_TYPE_C 1
1182 #define AFF_TYPE_ASM 2
1183 #define AFF_TYPE_ASMPP 4
1184 #define AFF_TYPE_LIB 8
1185 #define AFF_TYPE_MASK (15 | AFF_TYPE_BIN)
1186 /* values from tcc_object_type(...) */
1187 #define AFF_BINTYPE_REL 1
1188 #define AFF_BINTYPE_DYN 2
1189 #define AFF_BINTYPE_AR 3
1190 #define AFF_BINTYPE_C67 4
1193 #ifndef TCC_TARGET_PE
1194 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
1195 #endif
1196 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
1197 ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
1198 PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
1199 PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
1200 PUB_FUNC int tcc_parse_args(TCCState *s, int *argc, char ***argv, int optind);
1201 #ifdef _WIN32
1202 ST_FUNC char *normalize_slashes(char *path);
1203 #endif
1205 /* tcc_parse_args return codes: */
1206 #define OPT_HELP 1
1207 #define OPT_HELP2 2
1208 #define OPT_V 3
1209 #define OPT_PRINT_DIRS 4
1210 #define OPT_AR 5
1211 #define OPT_IMPDEF 6
1212 #define OPT_M32 32
1213 #define OPT_M64 64
1215 /* ------------ tccpp.c ------------ */
1217 ST_DATA struct BufferedFile *file;
1218 ST_DATA int ch, tok;
1219 ST_DATA CValue tokc;
1220 ST_DATA const int *macro_ptr;
1221 ST_DATA int parse_flags;
1222 ST_DATA int tok_flags;
1223 ST_DATA CString tokcstr; /* current parsed string, if any */
1225 /* display benchmark infos */
1226 ST_DATA int total_lines;
1227 ST_DATA int total_bytes;
1228 ST_DATA int tok_ident;
1229 ST_DATA TokenSym **table_ident;
1231 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1232 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1233 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1234 #define TOK_FLAG_EOF 0x0008 /* end of file */
1236 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1237 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1238 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1239 token. line feed is also
1240 returned at eof */
1241 #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
1242 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1243 #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
1244 #define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
1246 /* isidnum_table flags: */
1247 #define IS_SPC 1
1248 #define IS_ID 2
1249 #define IS_NUM 4
1251 ST_FUNC TokenSym *tok_alloc(const char *str, int len);
1252 ST_FUNC const char *get_tok_str(int v, CValue *cv);
1253 ST_FUNC void begin_macro(TokenString *str, int alloc);
1254 ST_FUNC void end_macro(void);
1255 ST_FUNC int set_idnum(int c, int val);
1256 ST_INLN void tok_str_new(TokenString *s);
1257 ST_FUNC TokenString *tok_str_alloc(void);
1258 ST_FUNC void tok_str_free(TokenString *s);
1259 ST_FUNC void tok_str_free_str(int *str);
1260 ST_FUNC void tok_str_add(TokenString *s, int t);
1261 ST_FUNC void tok_str_add_tok(TokenString *s);
1262 ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
1263 ST_FUNC void define_undef(Sym *s);
1264 ST_INLN Sym *define_find(int v);
1265 ST_FUNC void free_defines(Sym *b);
1266 ST_FUNC Sym *label_find(int v);
1267 ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
1268 ST_FUNC void label_pop(Sym **ptop, Sym *slast, int keep);
1269 ST_FUNC void parse_define(void);
1270 ST_FUNC void preprocess(int is_bof);
1271 ST_FUNC void next_nomacro(void);
1272 ST_FUNC void next(void);
1273 ST_INLN void unget_tok(int last_tok);
1274 ST_FUNC void preprocess_start(TCCState *s1, int is_asm);
1275 ST_FUNC void preprocess_end(TCCState *s1);
1276 ST_FUNC void tccpp_new(TCCState *s);
1277 ST_FUNC void tccpp_delete(TCCState *s);
1278 ST_FUNC int tcc_preprocess(TCCState *s1);
1279 ST_FUNC void skip(int c);
1280 ST_FUNC NORETURN void expect(const char *msg);
1282 /* space excluding newline */
1283 static inline int is_space(int ch) {
1284 return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
1286 static inline int isid(int c) {
1287 return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
1289 static inline int isnum(int c) {
1290 return c >= '0' && c <= '9';
1292 static inline int isoct(int c) {
1293 return c >= '0' && c <= '7';
1295 static inline int toup(int c) {
1296 return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
1299 /* ------------ tccgen.c ------------ */
1301 #define SYM_POOL_NB (8192 / sizeof(Sym))
1302 ST_DATA Sym *sym_free_first;
1303 ST_DATA void **sym_pools;
1304 ST_DATA int nb_sym_pools;
1306 ST_DATA Sym *global_stack;
1307 ST_DATA Sym *local_stack;
1308 ST_DATA Sym *local_label_stack;
1309 ST_DATA Sym *global_label_stack;
1310 ST_DATA Sym *define_stack;
1311 ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;
1312 ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop, *pvtop;
1313 #define vstack (__vstack + 1)
1314 ST_DATA int rsym, anon_sym, ind, loc;
1316 ST_DATA int const_wanted; /* true if constant wanted */
1317 ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
1318 ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
1319 ST_DATA CType func_vt; /* current function return type (used by return instruction) */
1320 ST_DATA int func_var; /* true if current function is variadic */
1321 ST_DATA int func_vc;
1322 ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
1323 ST_DATA const char *funcname;
1324 ST_DATA int g_debug;
1326 ST_FUNC void tcc_debug_start(TCCState *s1);
1327 ST_FUNC void tcc_debug_end(TCCState *s1);
1328 ST_FUNC void tcc_debug_funcstart(TCCState *s1, Sym *sym);
1329 ST_FUNC void tcc_debug_funcend(TCCState *s1, int size);
1330 ST_FUNC void tcc_debug_line(TCCState *s1);
1332 ST_FUNC int tccgen_compile(TCCState *s1);
1333 ST_FUNC void free_inline_functions(TCCState *s);
1334 ST_FUNC void check_vstack(void);
1336 ST_INLN int is_float(int t);
1337 ST_FUNC int ieee_finite(double d);
1338 ST_FUNC void test_lvalue(void);
1339 ST_FUNC void vpushi(int v);
1340 ST_FUNC ElfSym *elfsym(Sym *);
1341 ST_FUNC void update_storage(Sym *sym);
1342 ST_FUNC Sym *external_global_sym(int v, CType *type);
1343 ST_FUNC void vset(CType *type, int r, int v);
1344 ST_FUNC void vset_VT_CMP(int op);
1345 ST_FUNC void vswap(void);
1346 ST_FUNC void vpush_global_sym(CType *type, int v);
1347 ST_FUNC void vrote(SValue *e, int n);
1348 ST_FUNC void vrott(int n);
1349 ST_FUNC void vrotb(int n);
1350 #if PTR_SIZE == 4
1351 ST_FUNC void lexpand(void);
1352 #endif
1353 #ifdef TCC_TARGET_ARM
1354 ST_FUNC int get_reg_ex(int rc, int rc2);
1355 #endif
1356 ST_FUNC void vpushv(SValue *v);
1357 ST_FUNC void save_reg(int r);
1358 ST_FUNC void save_reg_upstack(int r, int n);
1359 ST_FUNC int get_reg(int rc);
1360 ST_FUNC void save_regs(int n);
1361 ST_FUNC void gaddrof(void);
1362 ST_FUNC int gv(int rc);
1363 ST_FUNC void gv2(int rc1, int rc2);
1364 ST_FUNC void vpop(void);
1365 ST_FUNC void gen_op(int op);
1366 ST_FUNC int type_size(CType *type, int *a);
1367 ST_FUNC void mk_pointer(CType *type);
1368 ST_FUNC void vstore(void);
1369 ST_FUNC void inc(int post, int c);
1370 ST_FUNC void parse_mult_str (CString *astr, const char *msg);
1371 ST_FUNC void parse_asm_str(CString *astr);
1372 ST_FUNC int lvalue_type(int t);
1373 ST_FUNC void indir(void);
1374 ST_FUNC void unary(void);
1375 ST_FUNC void expr_prod(void);
1376 ST_FUNC void expr_sum(void);
1377 ST_FUNC void gexpr(void);
1378 ST_FUNC int expr_const(void);
1379 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1380 ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
1381 #endif
1382 #if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
1383 ST_FUNC int classify_x86_64_va_arg(CType *ty);
1384 #endif
1386 /* ------------ tccelf.c ------------ */
1388 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
1389 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
1390 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
1392 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1394 typedef struct {
1395 unsigned int n_strx; /* index into string table of name */
1396 unsigned char n_type; /* type of symbol */
1397 unsigned char n_other; /* misc info (usually empty) */
1398 unsigned short n_desc; /* description field */
1399 unsigned int n_value; /* value of symbol */
1400 } Stab_Sym;
1402 ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
1403 ST_DATA Section *common_section;
1404 ST_DATA Section *cur_text_section; /* current section where function code is generated */
1405 #ifdef CONFIG_TCC_ASM
1406 ST_DATA Section *last_text_section; /* to handle .previous asm directive */
1407 #endif
1408 #ifdef CONFIG_TCC_BCHECK
1409 /* bound check related sections */
1410 ST_DATA Section *bounds_section; /* contains global data bound description */
1411 ST_DATA Section *lbounds_section; /* contains local data bound description */
1412 ST_FUNC void tccelf_bounds_new(TCCState *s);
1413 #endif
1414 /* symbol sections */
1415 ST_DATA Section *symtab_section;
1416 /* debug sections */
1417 ST_DATA Section *stab_section, *stabstr_section;
1419 ST_FUNC void tccelf_new(TCCState *s);
1420 ST_FUNC void tccelf_delete(TCCState *s);
1421 ST_FUNC void tccelf_stab_new(TCCState *s);
1422 ST_FUNC void tccelf_begin_file(TCCState *s1);
1423 ST_FUNC void tccelf_end_file(TCCState *s1);
1425 ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
1426 ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
1427 ST_FUNC size_t section_add(Section *sec, addr_t size, int align);
1428 ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
1429 ST_FUNC void section_reserve(Section *sec, unsigned long size);
1430 ST_FUNC Section *find_section(TCCState *s1, const char *name);
1431 ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
1433 ST_FUNC void put_extern_sym2(Sym *sym, int sh_num, addr_t value, unsigned long size, int can_add_underscore);
1434 ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
1435 #if PTR_SIZE == 4
1436 ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
1437 #endif
1438 ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
1440 ST_FUNC int put_elf_str(Section *s, const char *sym);
1441 ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1442 ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
1443 ST_FUNC int find_elf_sym(Section *s, const char *name);
1444 ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
1445 ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
1447 ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
1448 ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
1449 ST_FUNC void put_stabn(int type, int other, int desc, int value);
1450 ST_FUNC void put_stabd(int type, int other, int desc);
1452 ST_FUNC void resolve_common_syms(TCCState *s1);
1453 ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
1454 ST_FUNC void relocate_section(TCCState *s1, Section *s);
1456 ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
1457 ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
1458 ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
1459 ST_FUNC void tcc_add_bcheck(TCCState *s1);
1460 ST_FUNC void tcc_add_runtime(TCCState *s1);
1462 ST_FUNC void build_got_entries(TCCState *s1);
1463 ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
1464 ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
1466 ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
1467 #if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
1468 ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
1469 #endif
1471 #ifndef TCC_TARGET_PE
1472 ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
1473 ST_FUNC int tcc_load_ldscript(TCCState *s1);
1474 ST_FUNC uint8_t *parse_comment(uint8_t *p);
1475 ST_FUNC void minp(void);
1476 ST_INLN void inp(void);
1477 ST_FUNC int handle_eob(void);
1478 #endif
1480 /* ------------ xxx-link.c ------------ */
1482 /* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
1483 that unknown relocation don't create a GOT or PLT entry */
1484 enum gotplt_entry {
1485 NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
1486 BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */
1487 AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
1488 ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
1491 ST_FUNC int code_reloc (int reloc_type);
1492 ST_FUNC int gotplt_entry_type (int reloc_type);
1493 ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
1494 ST_FUNC void relocate_init(Section *sr);
1495 ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
1496 ST_FUNC void relocate_plt(TCCState *s1);
1498 /* ------------ xxx-gen.c ------------ */
1500 ST_DATA const int reg_classes[NB_REGS];
1502 ST_FUNC void gsym_addr(int t, int a);
1503 ST_FUNC void gsym(int t);
1504 ST_FUNC void load(int r, SValue *sv);
1505 ST_FUNC void store(int r, SValue *v);
1506 ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
1507 ST_FUNC void gfunc_call(int nb_args);
1508 ST_FUNC void gfunc_prolog(CType *func_type);
1509 ST_FUNC void gfunc_epilog(void);
1510 ST_FUNC void gen_fill_nops(int);
1511 ST_FUNC int gjmp(int t);
1512 ST_FUNC void gjmp_addr(int a);
1513 ST_FUNC int gjmp_cond(int op, int t);
1514 ST_FUNC int gjmp_append(int n, int t);
1515 ST_FUNC void gen_opi(int op);
1516 ST_FUNC void gen_opf(int op);
1517 ST_FUNC void gen_cvt_ftoi(int t);
1518 ST_FUNC void gen_cvt_ftof(int t);
1519 ST_FUNC void ggoto(void);
1520 #ifndef TCC_TARGET_C67
1521 ST_FUNC void o(unsigned int c);
1522 #endif
1523 #ifndef TCC_TARGET_ARM
1524 ST_FUNC void gen_cvt_itof(int t);
1525 #endif
1526 ST_FUNC void gen_vla_sp_save(int addr);
1527 ST_FUNC void gen_vla_sp_restore(int addr);
1528 ST_FUNC void gen_vla_alloc(CType *type, int align);
1530 static inline uint16_t read16le(unsigned char *p) {
1531 return p[0] | (uint16_t)p[1] << 8;
1533 static inline void write16le(unsigned char *p, uint16_t x) {
1534 p[0] = x & 255; p[1] = x >> 8 & 255;
1536 static inline uint32_t read32le(unsigned char *p) {
1537 return read16le(p) | (uint32_t)read16le(p + 2) << 16;
1539 static inline void write32le(unsigned char *p, uint32_t x) {
1540 write16le(p, x); write16le(p + 2, x >> 16);
1542 static inline void add32le(unsigned char *p, int32_t x) {
1543 write32le(p, read32le(p) + x);
1545 static inline uint64_t read64le(unsigned char *p) {
1546 return read32le(p) | (uint64_t)read32le(p + 4) << 32;
1548 static inline void write64le(unsigned char *p, uint64_t x) {
1549 write32le(p, x); write32le(p + 4, x >> 32);
1551 static inline void add64le(unsigned char *p, int64_t x) {
1552 write64le(p, read64le(p) + x);
1555 /* ------------ i386-gen.c ------------ */
1556 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1557 ST_FUNC void g(int c);
1558 ST_FUNC void gen_le16(int c);
1559 ST_FUNC void gen_le32(int c);
1560 ST_FUNC void gen_addr32(int r, Sym *sym, int c);
1561 ST_FUNC void gen_addrpc32(int r, Sym *sym, int c);
1562 #endif
1564 #ifdef CONFIG_TCC_BCHECK
1565 ST_FUNC void gen_bounded_ptr_add(void);
1566 ST_FUNC void gen_bounded_ptr_deref(void);
1567 #endif
1569 /* ------------ x86_64-gen.c ------------ */
1570 #ifdef TCC_TARGET_X86_64
1571 ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
1572 ST_FUNC void gen_opl(int op);
1573 #ifdef TCC_TARGET_PE
1574 ST_FUNC void gen_vla_result(int addr);
1575 #endif
1576 #endif
1578 /* ------------ arm-gen.c ------------ */
1579 #ifdef TCC_TARGET_ARM
1580 #if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
1581 PUB_FUNC const char *default_elfinterp(struct TCCState *s);
1582 #endif
1583 ST_FUNC void arm_init(struct TCCState *s);
1584 ST_FUNC void gen_cvt_itof1(int t);
1585 #endif
1587 /* ------------ arm64-gen.c ------------ */
1588 #ifdef TCC_TARGET_ARM64
1589 ST_FUNC void gen_cvt_sxtw(void);
1590 ST_FUNC void gen_opl(int op);
1591 ST_FUNC void gfunc_return(CType *func_type);
1592 ST_FUNC void gen_va_start(void);
1593 ST_FUNC void gen_va_arg(CType *t);
1594 ST_FUNC void gen_clear_cache(void);
1595 #endif
1597 /* ------------ c67-gen.c ------------ */
1598 #ifdef TCC_TARGET_C67
1599 #endif
1601 /* ------------ tcccoff.c ------------ */
1603 #ifdef TCC_TARGET_COFF
1604 ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
1605 ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
1606 #endif
1608 /* ------------ tccasm.c ------------ */
1609 ST_FUNC void asm_instr(void);
1610 ST_FUNC void asm_global_instr(void);
1611 #ifdef CONFIG_TCC_ASM
1612 ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
1613 ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
1614 ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
1615 ST_FUNC int asm_int_expr(TCCState *s1);
1616 ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
1617 /* ------------ i386-asm.c ------------ */
1618 ST_FUNC void gen_expr32(ExprValue *pe);
1619 #ifdef TCC_TARGET_X86_64
1620 ST_FUNC void gen_expr64(ExprValue *pe);
1621 #endif
1622 ST_FUNC void asm_opcode(TCCState *s1, int opcode);
1623 ST_FUNC int asm_parse_regvar(int t);
1624 ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
1625 ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
1626 ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
1627 ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
1628 #endif
1630 /* ------------ tccpe.c -------------- */
1631 #ifdef TCC_TARGET_PE
1632 ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
1633 ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
1634 ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
1635 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1636 ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
1637 #endif
1638 #ifdef TCC_TARGET_X86_64
1639 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
1640 #endif
1641 PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp);
1642 /* symbol properties stored in Elf32_Sym->st_other */
1643 # define ST_PE_EXPORT 0x10
1644 # define ST_PE_IMPORT 0x20
1645 # define ST_PE_STDCALL 0x40
1646 #endif
1647 #define ST_ASM_SET 0x04
1649 /* ------------ tccrun.c ----------------- */
1650 #ifdef TCC_IS_NATIVE
1651 #ifdef CONFIG_TCC_STATIC
1652 #define RTLD_LAZY 0x001
1653 #define RTLD_NOW 0x002
1654 #define RTLD_GLOBAL 0x100
1655 #define RTLD_DEFAULT NULL
1656 /* dummy function for profiling */
1657 ST_FUNC void *dlopen(const char *filename, int flag);
1658 ST_FUNC void dlclose(void *p);
1659 ST_FUNC const char *dlerror(void);
1660 ST_FUNC void *dlsym(void *handle, const char *symbol);
1661 #endif
1662 #ifdef CONFIG_TCC_BACKTRACE
1663 ST_DATA int rt_num_callers;
1664 ST_DATA const char **rt_bound_error_msg;
1665 ST_DATA void *rt_prog_main;
1666 ST_FUNC void tcc_set_num_callers(int n);
1667 #endif
1668 ST_FUNC void tcc_run_free(TCCState *s1);
1669 #endif
1671 /* ------------ tcctools.c ----------------- */
1672 #if 0 /* included in tcc.c */
1673 ST_FUNC int tcc_tool_ar(TCCState *s, int argc, char **argv);
1674 #ifdef TCC_TARGET_PE
1675 ST_FUNC int tcc_tool_impdef(TCCState *s, int argc, char **argv);
1676 #endif
1677 ST_FUNC void tcc_tool_cross(TCCState *s, char **argv, int option);
1678 ST_FUNC void gen_makedeps(TCCState *s, const char *target, const char *filename);
1679 #endif
1681 /********************************************************/
1682 #undef ST_DATA
1683 #if ONE_SOURCE
1684 #define ST_DATA static
1685 #else
1686 #define ST_DATA
1687 #endif
1688 /********************************************************/
1689 #endif /* _TCC_H */