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
25 #define _DARWIN_C_SOURCE
39 # define WIN32_LEAN_AND_MEAN 1
41 # include <sys/time.h>
42 # ifndef CONFIG_TCC_STATIC
45 /* XXX: need to define this to use them in non ISOC99 context */
46 extern float strtof (const char *__nptr
, char **__endptr
);
47 extern long double strtold (const char *__nptr
, char **__endptr
);
48 # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
49 extern char **environ
;
54 # define WIN32_LEAN_AND_MEAN
56 # include <io.h> /* open, close etc. */
57 # include <direct.h> /* getcwd */
61 # define inline __inline
62 # define snprintf _snprintf
63 # define vsnprintf _vsnprintf
65 # define strtold (long double)strtod
66 # define strtof (float)strtod
67 # define strtoll _strtoi64
68 # define strtoull _strtoui64
71 # define LIBTCCAPI __declspec(dllexport)
72 # define PUB_FUNC LIBTCCAPI
74 # define inp next_inp /* inp is an intrinsic on msvc/mingw */
76 # pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
77 # pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
78 # pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
79 # pragma warning (disable : 4018) // signed/unsigned mismatch
80 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
81 # define ssize_t intptr_t
89 # undef CONFIG_TCC_STATIC
97 #define offsetof(type, field) ((size_t) &((type *)0)->field)
101 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
105 # define NORETURN __declspec(noreturn)
106 # define ALIGNED(x) __declspec(align(x))
107 # define PRINTF_LIKE(x,y)
109 # define NORETURN __attribute__((noreturn))
110 # define ALIGNED(x) __attribute__((aligned(x)))
111 # define PRINTF_LIKE(x,y) __attribute__ ((format (printf, (x), (y))))
114 /* gnu headers use to #define __attribute__ to empty for non-gcc compilers */
116 # undef __attribute__
120 # define IS_DIRSEP(c) (c == '/' || c == '\\')
121 # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
122 # define PATHCMP stricmp
125 # define IS_DIRSEP(c) (c == '/')
126 # define IS_ABSPATH(p) IS_DIRSEP(p[0])
127 # define PATHCMP strcmp
131 /* -------------------------------------------- */
134 /* #define PARSE_DEBUG */
135 /* preprocessor debug */
136 /* #define PP_DEBUG */
137 /* include file debug */
138 /* #define INC_DEBUG */
139 /* memory leak debug (only for single threaded usage) */
140 /* #define MEM_DEBUG */
141 /* assembler debug */
142 /* #define ASM_DEBUG */
144 /* target selection */
145 /* #define TCC_TARGET_I386 *//* i386 code generator */
146 /* #define TCC_TARGET_X86_64 *//* x86-64 code generator */
147 /* #define TCC_TARGET_ARM *//* ARMv4 code generator */
148 /* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */
149 /* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */
150 /* #define TCC_TARGET_RISCV64 *//* risc-v code generator */
152 /* default target is I386 */
153 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
154 !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
155 !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_RISCV64)
156 # if defined __x86_64__
157 # define TCC_TARGET_X86_64
158 # elif defined __arm__
159 # define TCC_TARGET_ARM
160 # define TCC_ARM_EABI
162 # define TCC_ARM_HARDFLOAT
163 # elif defined __aarch64__
164 # define TCC_TARGET_ARM64
165 # elif defined __riscv
166 # define TCC_TARGET_RISCV64
168 # define TCC_TARGET_I386
171 # define TCC_TARGET_PE 1
175 /* only native compiler supports -run */
176 #if defined _WIN32 == defined TCC_TARGET_PE
177 # if defined __i386__ && defined TCC_TARGET_I386
178 # define TCC_IS_NATIVE
179 # elif defined __x86_64__ && defined TCC_TARGET_X86_64
180 # define TCC_IS_NATIVE
181 # elif defined __arm__ && defined TCC_TARGET_ARM
182 # define TCC_IS_NATIVE
183 # elif defined __aarch64__ && defined TCC_TARGET_ARM64
184 # define TCC_IS_NATIVE
185 # elif defined __riscv && defined __LP64__ && defined TCC_TARGET_RISCV64
186 # define TCC_IS_NATIVE
190 #if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
191 # define CONFIG_TCC_BACKTRACE
192 # if (defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 || \
193 defined TCC_TARGET_ARM || defined TCC_TARGET_ARM64 || \
194 defined TCC_TARGET_RISCV64) \
195 && !defined TCC_UCLIBC && !defined TCC_MUSL
196 # define CONFIG_TCC_BCHECK /* enable bound checking code */
200 #if defined TCC_TARGET_PE || defined TCC_TARGET_MACHO
201 # define ELF_OBJ_ONLY /* create elf .o but native executables */
204 /* ------------ path configuration ------------ */
206 #ifndef CONFIG_SYSROOT
207 # define CONFIG_SYSROOT ""
209 #ifndef CONFIG_TCCDIR
210 # define CONFIG_TCCDIR "/usr/local/lib/tcc"
213 # define CONFIG_LDDIR "lib"
215 #ifdef CONFIG_TRIPLET
216 # define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
217 # define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
219 # define USE_TRIPLET(s) s
220 # define ALSO_TRIPLET(s) s
223 /* path to find crt1.o, crti.o and crtn.o */
224 #ifndef CONFIG_TCC_CRTPREFIX
225 # define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
228 #ifndef CONFIG_USR_INCLUDE
229 # define CONFIG_USR_INCLUDE "/usr/include"
232 /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
234 /* system include paths */
235 #ifndef CONFIG_TCC_SYSINCLUDEPATHS
236 # if defined TCC_TARGET_PE || defined _WIN32
237 # define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi"
239 # define CONFIG_TCC_SYSINCLUDEPATHS \
241 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
242 ":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE)
246 /* library search paths */
247 #ifndef CONFIG_TCC_LIBPATHS
248 # ifdef TCC_TARGET_PE
249 # define CONFIG_TCC_LIBPATHS "{B}/lib"
251 # define CONFIG_TCC_LIBPATHS \
252 ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
253 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
254 ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
258 /* name of ELF interpreter */
259 #ifndef CONFIG_TCC_ELFINTERP
260 # if defined __FreeBSD__
261 # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
262 # elif defined __FreeBSD_kernel__
263 # if defined(TCC_TARGET_X86_64)
264 # define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
266 # define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
268 # elif defined __DragonFly__
269 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
270 # elif defined __NetBSD__
271 # define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
272 # elif defined __GNU__
273 # define CONFIG_TCC_ELFINTERP "/lib/ld.so"
274 # elif defined(TCC_TARGET_PE)
275 # define CONFIG_TCC_ELFINTERP "-"
276 # elif defined(TCC_UCLIBC)
277 # define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
278 # elif defined TCC_TARGET_ARM64
279 # if defined(TCC_MUSL)
280 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-aarch64.so.1"
282 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
284 # elif defined(TCC_TARGET_X86_64)
285 # if defined(TCC_MUSL)
286 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-x86_64.so.1"
288 # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
290 # elif defined(TCC_TARGET_RISCV64)
291 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-riscv64-lp64d.so.1"
292 # elif !defined(TCC_ARM_EABI)
293 # if defined(TCC_MUSL)
294 # if defined(TCC_TARGET_I386)
295 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-i386.so.1"
297 # define CONFIG_TCC_ELFINTERP "/lib/ld-musl-arm.so.1"
300 # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
305 /* var elf_interp dans *-gen.c */
306 #ifdef CONFIG_TCC_ELFINTERP
307 # define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
309 # define DEFAULT_ELFINTERP(s) default_elfinterp(s)
312 /* (target specific) libtcc1.a */
314 # define TCC_LIBTCC1 "libtcc1.a"
317 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
318 #if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
319 #define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
322 /* -------------------------------------------- */
328 /* -------------------------------------------- */
330 #ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
335 # define ONE_SOURCE 1
338 /* support using libtcc from threads */
339 #define CONFIG_TCC_SEMLOCK
342 #define ST_INLN static inline
343 #define ST_FUNC static
344 #define ST_DATA static
348 #define ST_DATA extern
351 #ifdef TCC_PROFILE /* profile all functions */
355 /* -------------------------------------------- */
356 /* include the target specific definitions */
358 #define TARGET_DEFS_ONLY
359 #ifdef TCC_TARGET_I386
360 # include "i386-gen.c"
361 # include "i386-link.c"
362 #elif defined TCC_TARGET_X86_64
363 # include "x86_64-gen.c"
364 # include "x86_64-link.c"
365 #elif defined TCC_TARGET_ARM
366 # include "arm-gen.c"
367 # include "arm-link.c"
368 # include "arm-asm.c"
369 #elif defined TCC_TARGET_ARM64
370 # include "arm64-gen.c"
371 # include "arm64-link.c"
372 # include "arm-asm.c"
373 #elif defined TCC_TARGET_C67
374 # define TCC_TARGET_COFF
376 # include "c67-gen.c"
377 # include "c67-link.c"
378 #elif defined(TCC_TARGET_RISCV64)
379 # include "riscv64-gen.c"
380 # include "riscv64-link.c"
381 # include "riscv64-asm.c"
383 #error unknown target
385 #undef TARGET_DEFS_ONLY
387 /* -------------------------------------------- */
390 # define ELFCLASSW ELFCLASS64
391 # define ElfW(type) Elf##64##_##type
392 # define ELFW(type) ELF##64##_##type
393 # define ElfW_Rel ElfW(Rela)
394 # define SHT_RELX SHT_RELA
395 # define REL_SECTION_FMT ".rela%s"
397 # define ELFCLASSW ELFCLASS32
398 # define ElfW(type) Elf##32##_##type
399 # define ELFW(type) ELF##32##_##type
400 # define ElfW_Rel ElfW(Rel)
401 # define SHT_RELX SHT_REL
402 # define REL_SECTION_FMT ".rel%s"
404 /* target address type */
405 #define addr_t ElfW(Addr)
406 #define ElfSym ElfW(Sym)
408 #if PTR_SIZE == 8 && !defined TCC_TARGET_PE
414 /* -------------------------------------------- */
416 #define INCLUDE_STACK_SIZE 32
417 #define IFDEF_STACK_SIZE 64
418 #define VSTACK_SIZE 256
419 #define STRING_MAX_SIZE 1024
420 #define TOKSTR_MAX_SIZE 256
421 #define PACK_STACK_SIZE 8
423 #define TOK_HASH_SIZE 16384 /* must be a power of two */
424 #define TOK_ALLOC_INCR 512 /* must be a power of two */
425 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
427 /* token symbol management */
428 typedef struct TokenSym
{
429 struct TokenSym
*hash_next
;
430 struct Sym
*sym_define
; /* direct pointer to define */
431 struct Sym
*sym_label
; /* direct pointer to label */
432 struct Sym
*sym_struct
; /* direct pointer to structure */
433 struct Sym
*sym_identifier
; /* direct pointer to identifier */
434 int tok
; /* token number */
441 typedef unsigned short nwchar_t
;
443 typedef int nwchar_t
;
446 typedef struct CString
{
447 int size
; /* size in bytes */
448 void *data
; /* either 'char *' or 'nwchar_t *' */
452 /* type definition */
453 typedef struct CType
{
459 typedef union CValue
{
468 int tab
[LDOUBLE_SIZE
/4];
472 typedef struct SValue
{
473 CType type
; /* type */
474 unsigned short r
; /* register + flags */
475 unsigned short r2
; /* second register, used for 'long long'
476 type. If not used, set to VT_CONST */
478 struct { int jtrue
, jfalse
; }; /* forward jmps */
479 CValue c
; /* constant, if VT_CONST */
482 struct { unsigned short cmp_op
, cmp_r
; }; /* VT_CMP operation */
483 struct Sym
*sym
; /* symbol, if (VT_SYM | VT_CONST), or if */
484 }; /* result of unary() for an identifier. */
488 /* symbol attributes */
491 aligned
: 5, /* alignment as log2+1 (0 == unspecified) */
499 xxxx
: 3; /* not used */
502 /* function attributes or temporary attributes for parsing */
505 func_call
: 3, /* calling convention (0..5), see below */
506 func_type
: 2, /* FUNC_OLD/NEW/ELLIPSIS */
507 func_noreturn
: 1, /* attribute((noreturn)) */
508 func_ctor
: 1, /* attribute((constructor)) */
509 func_dtor
: 1, /* attribute((destructor)) */
510 func_args
: 8, /* PE __stdcall args */
511 func_alwinl
: 1, /* always_inline */
515 /* symbol management */
517 int v
; /* symbol token */
518 unsigned short r
; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
519 struct SymAttr a
; /* symbol attributes */
522 int c
; /* associated number or Elf symbol index */
524 int sym_scope
; /* scope level for locals */
525 int jnext
; /* next jump label */
526 struct FuncAttr f
; /* function attributes */
527 int auxtype
; /* bitfield access type */
530 long long enum_val
; /* enum constant if IS_ENUM_VAL */
531 int *d
; /* define token stream */
532 struct Sym
*ncl
; /* next cleanup */
534 CType type
; /* associated type */
536 struct Sym
*next
; /* next related symbol (for fields and anoms) */
537 struct Sym
*cleanupstate
; /* in defined labels */
538 int asm_label
; /* associated asm label */
540 struct Sym
*prev
; /* prev symbol in stack */
541 struct Sym
*prev_tok
; /* previous symbol for this token */
544 /* section definition */
545 typedef struct Section
{
546 unsigned long data_offset
; /* current data offset */
547 unsigned char *data
; /* section data */
548 unsigned long data_allocated
; /* used for realloc() handling */
550 int sh_name
; /* elf section name (only used during output) */
551 int sh_num
; /* elf section number */
552 int sh_type
; /* elf section type */
553 int sh_flags
; /* elf section flags */
554 int sh_info
; /* elf section info */
555 int sh_addralign
; /* elf section alignment */
556 int sh_entsize
; /* elf entry size */
557 unsigned long sh_size
; /* section size (only used during output) */
558 addr_t sh_addr
; /* address at which the section is relocated */
559 unsigned long sh_offset
; /* file offset */
560 int nb_hashed_syms
; /* used to resize the hash table */
561 struct Section
*link
; /* link to another section */
562 struct Section
*reloc
; /* corresponding section for relocation, if any */
563 struct Section
*hash
; /* hash table for symbols */
564 struct Section
*prev
; /* previous section on section stack */
565 char name
[1]; /* section name */
568 typedef struct DLLReference
{
574 /* -------------------------------------------------- */
576 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
577 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
578 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
580 /* stored in 'Sym->f.func_type' field */
581 #define FUNC_NEW 1 /* ansi function prototype */
582 #define FUNC_OLD 2 /* old function prototype */
583 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
585 /* stored in 'Sym->f.func_call' field */
586 #define FUNC_CDECL 0 /* standard c call */
587 #define FUNC_STDCALL 1 /* pascal c call */
588 #define FUNC_FASTCALL1 2 /* first param in %eax */
589 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
590 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
591 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
593 /* field 'Sym.t' for macros */
594 #define MACRO_OBJ 0 /* object like macro */
595 #define MACRO_FUNC 1 /* function like macro */
597 /* field 'Sym.r' for C labels */
598 #define LABEL_DEFINED 0 /* label is defined */
599 #define LABEL_FORWARD 1 /* label is forward defined */
600 #define LABEL_DECLARED 2 /* label is declared but never used */
601 #define LABEL_GONE 3 /* label isn't in scope, but not yet popped
602 from local_label_stack (stmt exprs) */
604 /* type_decl() types */
605 #define TYPE_ABSTRACT 1 /* type without variable */
606 #define TYPE_DIRECT 2 /* type with variable */
608 #define IO_BUF_SIZE 8192
610 typedef struct BufferedFile
{
614 struct BufferedFile
*prev
;
615 int line_num
; /* current line number - here to simplify code */
616 int line_ref
; /* tcc -E: last printed line */
617 int ifndef_macro
; /* #ifndef macro / #endif search */
618 int ifndef_macro_saved
; /* saved ifndef_macro */
619 int *ifdef_stack_ptr
; /* ifdef_stack value at the start of the file */
620 int include_next_index
; /* next search path */
621 char filename
[1024]; /* filename */
622 char *true_filename
; /* filename not modified by # line directive */
623 unsigned char unget
[4];
624 unsigned char buffer
[1]; /* extra size for CH_EOB char */
627 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
628 #define CH_EOF (-1) /* end of file */
630 /* used to record tokens */
631 typedef struct TokenString
{
638 /* used to chain token-strings with begin/end_macro() */
639 struct TokenString
*prev
;
644 /* GNUC attribute definition */
645 typedef struct AttributeDef
{
648 struct Section
*section
;
650 int alias_target
; /* token */
651 int asm_label
; /* associated asm label */
652 char attr_mode
; /* __attribute__((__mode__(...))) */
655 /* inline functions */
656 typedef struct InlineFunc
{
657 TokenString
*func_str
;
662 /* include file cache, used to find files faster and also to eliminate
663 inclusion if the include file is protected by #ifndef ... #endif */
664 typedef struct CachedInclude
{
667 int hash_next
; /* -1 if none */
668 char filename
[1]; /* path specified in #include */
671 #define CACHED_INCLUDES_HASH_SIZE 32
673 #ifdef CONFIG_TCC_ASM
674 typedef struct ExprValue
{
680 #define MAX_ASM_OPERANDS 30
681 typedef struct ASMOperand
{
682 int id
; /* GCC 3 optional identifier (0 if number only supported */
684 char asm_str
[16]; /* computed asm string for operand */
685 SValue
*vt
; /* C value of the expression */
686 int ref_index
; /* if >= 0, gives reference to a output constraint */
687 int input_index
; /* if >= 0, gives reference to an input constraint */
688 int priority
; /* priority, used to assign registers */
689 int reg
; /* if >= 0, register number used for this operand */
690 int is_llong
; /* true if double register value */
691 int is_memory
; /* true if memory operand */
692 int is_rw
; /* for '+' modifier */
696 /* extra symbol attributes (not in symbol table) */
702 #ifdef TCC_TARGET_ARM
703 unsigned char plt_thumb_stub
:1;
708 unsigned char verbose
; /* if true, display some information during compilation */
709 unsigned char nostdinc
; /* if true, no standard headers are added */
710 unsigned char nostdlib
; /* if true, no standard libraries are added */
711 unsigned char nocommon
; /* if true, do not use common symbols for .bss data */
712 unsigned char static_link
; /* if true, static linking is performed */
713 unsigned char rdynamic
; /* if true, all symbols are exported */
714 unsigned char symbolic
; /* if true, resolve symbols in the current module first */
715 unsigned char filetype
; /* file type for compilation (NONE,C,ASM) */
716 unsigned char optimize
; /* only to #define __OPTIMIZE__ */
717 unsigned char option_pthread
; /* -pthread option */
718 unsigned char enable_new_dtags
; /* -Wl,--enable-new-dtags */
719 unsigned int cversion
; /* supported C ISO version, 199901 (the default), 201112, ... */
721 char *tcc_lib_path
; /* CONFIG_TCCDIR or -B option */
722 char *soname
; /* as specified on the command line (-soname) */
723 char *rpath
; /* as specified on the command line (-Wl,-rpath=) */
725 /* output type, see TCC_OUTPUT_XXX */
727 /* output format, see TCC_OUTPUT_FORMAT_xxx */
730 /* C language options */
731 unsigned char char_is_unsigned
;
732 unsigned char leading_underscore
;
733 unsigned char ms_extensions
; /* allow nested named struct w/o identifier behave like unnamed */
734 unsigned char dollars_in_identifiers
; /* allows '$' char in identifiers */
735 unsigned char ms_bitfields
; /* if true, emulate MS algorithm for aligning bitfields */
737 /* warning switches */
738 unsigned char warn_write_strings
;
739 unsigned char warn_unsupported
;
740 unsigned char warn_error
;
741 unsigned char warn_none
;
742 unsigned char warn_implicit_function_declaration
;
743 unsigned char warn_gcc_compat
;
745 /* compile with debug symbol (and use them if error during execution) */
746 unsigned char do_debug
;
747 unsigned char do_backtrace
;
748 #ifdef CONFIG_TCC_BCHECK
749 /* compile with built-in memory and bounds checker */
750 unsigned char do_bounds_check
;
752 #ifdef TCC_TARGET_ARM
753 enum float_abi float_abi
; /* float ABI of the generated code*/
755 int run_test
; /* nth test to run with -dt -run */
757 addr_t text_addr
; /* address of text section */
758 unsigned char has_text_addr
;
760 unsigned section_align
; /* section alignment */
762 /* use GNU C extensions */
763 unsigned char gnu_ext
;
764 /* use TinyCC extensions */
765 unsigned char tcc_ext
;
767 char *init_symbol
; /* symbols to call at load-time (not used currently) */
768 char *fini_symbol
; /* symbols to call at unload-time (not used currently) */
770 #ifdef TCC_TARGET_I386
771 int seg_size
; /* 32. Can be 16 with i386 assembler (.code16) */
773 #ifdef TCC_TARGET_X86_64
774 unsigned char nosse
; /* For -mno-sse support. */
777 /* array of all loaded dlls (including those referenced by loaded dlls) */
778 DLLReference
**loaded_dlls
;
782 char **include_paths
;
783 int nb_include_paths
;
785 char **sysinclude_paths
;
786 int nb_sysinclude_paths
;
789 char **library_paths
;
790 int nb_library_paths
;
792 /* crt?.o object path */
796 /* -D / -U options */
797 CString cmdline_defs
;
798 /* -include options */
799 CString cmdline_incl
;
803 void (*error_func
)(void *opaque
, const char *msg
);
804 int error_set_jmp_enabled
;
805 jmp_buf error_jmp_buf
;
808 /* output file for preprocessing (-E) */
811 LINE_MACRO_OUTPUT_FORMAT_GCC
,
812 LINE_MACRO_OUTPUT_FORMAT_NONE
,
813 LINE_MACRO_OUTPUT_FORMAT_STD
,
814 LINE_MACRO_OUTPUT_FORMAT_P10
= 11
815 } Pflag
; /* -P switch */
816 char dflag
; /* -dX value */
818 /* for -MD/-MF: collected dependencies for this compilation */
823 BufferedFile
*include_stack
[INCLUDE_STACK_SIZE
];
824 BufferedFile
**include_stack_ptr
;
826 int ifdef_stack
[IFDEF_STACK_SIZE
];
827 int *ifdef_stack_ptr
;
829 /* included files enclosed with #ifndef MACRO */
830 int cached_includes_hash
[CACHED_INCLUDES_HASH_SIZE
];
831 CachedInclude
**cached_includes
;
832 int nb_cached_includes
;
834 /* #pragma pack stack */
835 int pack_stack
[PACK_STACK_SIZE
];
840 /* inline functions are stored as token lists and compiled last
841 only if referenced */
842 struct InlineFunc
**inline_fns
;
847 int nb_sections
; /* number of sections, including first dummy section */
849 Section
**priv_sections
;
850 int nb_priv_sections
; /* number of private sections */
852 /* got & plt handling */
856 /* predefined sections */
857 Section
*text_section
, *data_section
, *bss_section
;
858 Section
*common_section
;
859 Section
*cur_text_section
; /* current section where function code is generated */
860 #ifdef CONFIG_TCC_BCHECK
861 /* bound check related sections */
862 Section
*bounds_section
; /* contains global data bound description */
863 Section
*lbounds_section
; /* contains local data bound description */
865 /* symbol sections */
866 Section
*symtab_section
;
868 Section
*stab_section
;
869 /* Is there a new undefined sym since last new_undef_sym() */
872 /* temporary dynamic symbol sections (for dll loading) */
873 Section
*dynsymtab_section
;
874 /* exported dynamic symbol section */
876 /* copy of the global symtab_section variable */
878 /* extra attributes (eg. GOT/PLT value) for symtab symbols */
879 struct sym_attr
*sym_attrs
;
881 /* ptr to next reloc entry reused */
883 # define qrel s1->qrel
888 unsigned pe_characteristics
;
889 unsigned pe_file_align
;
890 unsigned pe_stack_size
;
892 # ifdef TCC_TARGET_X86_64
901 struct sym_version
*sym_versions
;
902 int nb_sym_to_version
;
905 Section
*versym_section
;
906 Section
*verneed_section
;
910 const char *runtime_main
;
915 #ifdef CONFIG_TCC_BACKTRACE
919 int fd
, cc
; /* used by tcc_load_ldscript */
927 /* option -dnum (for general development purposes) */
930 /* for warnings/errors for object files*/
931 const char *current_filename
;
933 /* used by main and tcc_parse_args only */
934 struct filespec
**files
; /* files seen on command line */
935 int nb_files
; /* number thereof */
936 int nb_libraries
; /* number of libs thereof */
937 char *outfile
; /* output filename */
938 unsigned char option_r
; /* option -r */
939 unsigned char do_bench
; /* option -bench */
940 int gen_deps
; /* option -MD */
941 char *deps_outfile
; /* option -MF */
951 /* The current value can be: */
952 #define VT_VALMASK 0x003f /* mask for value location, register or: */
953 #define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
954 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
955 #define VT_LOCAL 0x0032 /* offset on stack */
956 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
957 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
958 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
959 #define VT_LVAL 0x0100 /* var is an lvalue */
960 #define VT_SYM 0x0200 /* a symbol value is added */
961 #define VT_MUSTCAST 0x0C00 /* value must be casted to be correct (used for
962 char/short stored in integer registers) */
963 #define VT_MUSTBOUND 0x4000 /* bound checking must be done before
964 dereferencing value */
965 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
966 bounding function call point is in vc */
968 #define VT_BTYPE 0x000f /* mask for basic type */
969 #define VT_VOID 0 /* void type */
970 #define VT_BYTE 1 /* signed byte type */
971 #define VT_SHORT 2 /* short type */
972 #define VT_INT 3 /* integer type */
973 #define VT_LLONG 4 /* 64 bit integer */
974 #define VT_PTR 5 /* pointer */
975 #define VT_FUNC 6 /* function type */
976 #define VT_STRUCT 7 /* struct/union definition */
977 #define VT_FLOAT 8 /* IEEE float */
978 #define VT_DOUBLE 9 /* IEEE double */
979 #define VT_LDOUBLE 10 /* IEEE long double */
980 #define VT_BOOL 11 /* ISOC99 boolean type */
981 #define VT_QLONG 13 /* 128-bit integer. Only used for x86-64 ABI */
982 #define VT_QFLOAT 14 /* 128-bit float. Only used for x86-64 ABI */
984 #define VT_UNSIGNED 0x0010 /* unsigned type */
985 #define VT_DEFSIGN 0x0020 /* explicitly signed or unsigned */
986 #define VT_ARRAY 0x0040 /* array type (also has VT_PTR) */
987 #define VT_BITFIELD 0x0080 /* bitfield modifier */
988 #define VT_CONSTANT 0x0100 /* const modifier */
989 #define VT_VOLATILE 0x0200 /* volatile modifier */
990 #define VT_VLA 0x0400 /* VLA type (also has VT_PTR and VT_ARRAY) */
991 #define VT_LONG 0x0800 /* long type (also has VT_INT rsp. VT_LLONG) */
994 #define VT_EXTERN 0x00001000 /* extern definition */
995 #define VT_STATIC 0x00002000 /* static variable */
996 #define VT_TYPEDEF 0x00004000 /* typedef definition */
997 #define VT_INLINE 0x00008000 /* inline definition */
998 /* currently unused: 0x000[1248]0000 */
1000 #define VT_STRUCT_SHIFT 20 /* shift for bitfield shift values (32 - 2*6) */
1001 #define VT_STRUCT_MASK (((1U << (6+6)) - 1) << VT_STRUCT_SHIFT | VT_BITFIELD)
1002 #define BIT_POS(t) (((t) >> VT_STRUCT_SHIFT) & 0x3f)
1003 #define BIT_SIZE(t) (((t) >> (VT_STRUCT_SHIFT + 6)) & 0x3f)
1005 #define VT_UNION (1 << VT_STRUCT_SHIFT | VT_STRUCT)
1006 #define VT_ENUM (2 << VT_STRUCT_SHIFT) /* integral type is an enum really */
1007 #define VT_ENUM_VAL (3 << VT_STRUCT_SHIFT) /* integral type is an enum constant really */
1009 #define IS_ENUM(t) ((t & VT_STRUCT_MASK) == VT_ENUM)
1010 #define IS_ENUM_VAL(t) ((t & VT_STRUCT_MASK) == VT_ENUM_VAL)
1011 #define IS_UNION(t) ((t & (VT_STRUCT_MASK|VT_BTYPE)) == VT_UNION)
1013 /* type mask (except storage) */
1014 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE)
1015 #define VT_TYPE (~(VT_STORAGE|VT_STRUCT_MASK))
1017 /* symbol was created by tccasm.c first */
1018 #define VT_ASM (VT_VOID | 1 << VT_STRUCT_SHIFT)
1019 #define VT_ASM_FUNC (VT_ASM | 2 << VT_STRUCT_SHIFT)
1020 #define IS_ASM_SYM(sym) (((sym)->type.t & (VT_BTYPE | VT_ASM)) == VT_ASM)
1022 /* general: set/get the pseudo-bitfield value for bit-mask M */
1023 #define BFVAL(M,N) ((unsigned)((M) & ~((M) << 1)) * (N))
1024 #define BFGET(X,M) (((X) & (M)) / BFVAL(M,1))
1025 #define BFSET(X,M,N) ((X) = ((X) & ~(M)) | BFVAL(M,N))
1029 /* conditional ops */
1030 #define TOK_LAND 0x90
1031 #define TOK_LOR 0x91
1032 /* warning: the following compare tokens depend on i386 asm code */
1033 #define TOK_ULT 0x92
1034 #define TOK_UGE 0x93
1037 #define TOK_ULE 0x96
1038 #define TOK_UGT 0x97
1039 #define TOK_Nset 0x98
1040 #define TOK_Nclear 0x99
1046 #define TOK_ISCOND(t) (t >= TOK_LAND && t <= TOK_GT)
1048 #define TOK_DEC 0x80 /* -- */
1049 #define TOK_MID 0x81 /* inc/dec, to void constant */
1050 #define TOK_INC 0x82 /* ++ */
1051 #define TOK_UDIV 0x83 /* unsigned division */
1052 #define TOK_UMOD 0x84 /* unsigned modulo */
1053 #define TOK_PDIV 0x85 /* fast division with undefined rounding for pointers */
1054 #define TOK_UMULL 0x86 /* unsigned 32x32 -> 64 mul */
1055 #define TOK_ADDC1 0x87 /* add with carry generation */
1056 #define TOK_ADDC2 0x88 /* add with carry use */
1057 #define TOK_SUBC1 0x89 /* add with carry generation */
1058 #define TOK_SUBC2 0x8a /* add with carry use */
1059 #define TOK_SHL '<' /* shift left */
1060 #define TOK_SAR '>' /* signed shift right */
1061 #define TOK_SHR 0x8b /* unsigned shift right */
1063 #define TOK_ARROW 0xa0 /* -> */
1064 #define TOK_DOTS 0xa1 /* three dots */
1065 #define TOK_TWODOTS 0xa2 /* C++ token ? */
1066 #define TOK_TWOSHARPS 0xa3 /* ## preprocessing token */
1067 #define TOK_PLCHLDR 0xa4 /* placeholder token as defined in C99 */
1068 #define TOK_NOSUBST 0xa5 /* means following token has already been pp'd */
1069 #define TOK_PPJOIN 0xa6 /* A '##' in the right position to mean pasting */
1071 /* assignment operators */
1072 #define TOK_A_ADD 0xb0
1073 #define TOK_A_SUB 0xb1
1074 #define TOK_A_MUL 0xb2
1075 #define TOK_A_DIV 0xb3
1076 #define TOK_A_MOD 0xb4
1077 #define TOK_A_AND 0xb5
1078 #define TOK_A_OR 0xb6
1079 #define TOK_A_XOR 0xb7
1080 #define TOK_A_SHL 0xb8
1081 #define TOK_A_SAR 0xb9
1083 #define TOK_ASSIGN(t) (t >= TOK_A_ADD && t <= TOK_A_SAR)
1084 #define TOK_ASSIGN_OP(t) ("+-*/%&|^<>"[t - TOK_A_ADD])
1086 /* tokens that carry values (in additional token string space / tokc) --> */
1087 #define TOK_CCHAR 0xc0 /* char constant in tokc */
1088 #define TOK_LCHAR 0xc1
1089 #define TOK_CINT 0xc2 /* number in tokc */
1090 #define TOK_CUINT 0xc3 /* unsigned int constant */
1091 #define TOK_CLLONG 0xc4 /* long long constant */
1092 #define TOK_CULLONG 0xc5 /* unsigned long long constant */
1093 #define TOK_CLONG 0xc6 /* long constant */
1094 #define TOK_CULONG 0xc7 /* unsigned long constant */
1095 #define TOK_STR 0xc8 /* pointer to string in tokc */
1096 #define TOK_LSTR 0xc9
1097 #define TOK_CFLOAT 0xca /* float constant */
1098 #define TOK_CDOUBLE 0xcb /* double constant */
1099 #define TOK_CLDOUBLE 0xcc /* long double constant */
1100 #define TOK_PPNUM 0xcd /* preprocessor number */
1101 #define TOK_PPSTR 0xce /* preprocessor string */
1102 #define TOK_LINENUM 0xcf /* line number info */
1104 #define TOK_HAS_VALUE(t) (t >= TOK_CCHAR && t <= TOK_LINENUM)
1106 #define TOK_EOF (-1) /* end of file */
1107 #define TOK_LINEFEED 10 /* line feed */
1109 /* all identifiers and strings have token above that */
1110 #define TOK_IDENT 256
1112 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
1113 #define TOK_ASM_int TOK_INT
1114 #define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
1115 #define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
1116 #define TOK_ASMDIR_LAST TOK_ASMDIR_section
1118 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1119 /* only used for i386 asm opcodes definitions */
1120 #define DEF_BWL(x) \
1121 DEF(TOK_ASM_ ## x ## b, #x "b") \
1122 DEF(TOK_ASM_ ## x ## w, #x "w") \
1123 DEF(TOK_ASM_ ## x ## l, #x "l") \
1124 DEF(TOK_ASM_ ## x, #x)
1126 DEF(TOK_ASM_ ## x ## w, #x "w") \
1127 DEF(TOK_ASM_ ## x ## l, #x "l") \
1128 DEF(TOK_ASM_ ## x, #x)
1129 #ifdef TCC_TARGET_X86_64
1130 # define DEF_BWLQ(x) \
1131 DEF(TOK_ASM_ ## x ## b, #x "b") \
1132 DEF(TOK_ASM_ ## x ## w, #x "w") \
1133 DEF(TOK_ASM_ ## x ## l, #x "l") \
1134 DEF(TOK_ASM_ ## x ## q, #x "q") \
1135 DEF(TOK_ASM_ ## x, #x)
1136 # define DEF_WLQ(x) \
1137 DEF(TOK_ASM_ ## x ## w, #x "w") \
1138 DEF(TOK_ASM_ ## x ## l, #x "l") \
1139 DEF(TOK_ASM_ ## x ## q, #x "q") \
1140 DEF(TOK_ASM_ ## x, #x)
1141 # define DEF_BWLX DEF_BWLQ
1142 # define DEF_WLX DEF_WLQ
1143 /* number of sizes + 1 */
1146 # define DEF_BWLX DEF_BWL
1147 # define DEF_WLX DEF_WL
1148 /* number of sizes + 1 */
1152 #define DEF_FP1(x) \
1153 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
1154 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
1155 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
1156 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
1159 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
1160 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
1163 #define DEF_ASMTEST(x,suffix) \
1164 DEF_ASM(x ## o ## suffix) \
1165 DEF_ASM(x ## no ## suffix) \
1166 DEF_ASM(x ## b ## suffix) \
1167 DEF_ASM(x ## c ## suffix) \
1168 DEF_ASM(x ## nae ## suffix) \
1169 DEF_ASM(x ## nb ## suffix) \
1170 DEF_ASM(x ## nc ## suffix) \
1171 DEF_ASM(x ## ae ## suffix) \
1172 DEF_ASM(x ## e ## suffix) \
1173 DEF_ASM(x ## z ## suffix) \
1174 DEF_ASM(x ## ne ## suffix) \
1175 DEF_ASM(x ## nz ## suffix) \
1176 DEF_ASM(x ## be ## suffix) \
1177 DEF_ASM(x ## na ## suffix) \
1178 DEF_ASM(x ## nbe ## suffix) \
1179 DEF_ASM(x ## a ## suffix) \
1180 DEF_ASM(x ## s ## suffix) \
1181 DEF_ASM(x ## ns ## suffix) \
1182 DEF_ASM(x ## p ## suffix) \
1183 DEF_ASM(x ## pe ## suffix) \
1184 DEF_ASM(x ## np ## suffix) \
1185 DEF_ASM(x ## po ## suffix) \
1186 DEF_ASM(x ## l ## suffix) \
1187 DEF_ASM(x ## nge ## suffix) \
1188 DEF_ASM(x ## nl ## suffix) \
1189 DEF_ASM(x ## ge ## suffix) \
1190 DEF_ASM(x ## le ## suffix) \
1191 DEF_ASM(x ## ng ## suffix) \
1192 DEF_ASM(x ## nle ## suffix) \
1193 DEF_ASM(x ## g ## suffix)
1195 #endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */
1198 TOK_LAST
= TOK_IDENT
- 1
1199 #define DEF(id, str) ,id
1204 /* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
1205 #define TOK_UIDENT TOK_DEFINE
1207 /* ------------ libtcc.c ------------ */
1209 ST_DATA
struct TCCState
*tcc_state
;
1211 /* public functions currently used by the tcc main function */
1212 ST_FUNC
char *pstrcpy(char *buf
, size_t buf_size
, const char *s
);
1213 ST_FUNC
char *pstrcat(char *buf
, size_t buf_size
, const char *s
);
1214 ST_FUNC
char *pstrncpy(char *out
, const char *in
, size_t num
);
1215 PUB_FUNC
char *tcc_basename(const char *name
);
1216 PUB_FUNC
char *tcc_fileextension (const char *name
);
1219 PUB_FUNC
void tcc_free(void *ptr
);
1220 PUB_FUNC
void *tcc_malloc(unsigned long size
);
1221 PUB_FUNC
void *tcc_mallocz(unsigned long size
);
1222 PUB_FUNC
void *tcc_realloc(void *ptr
, unsigned long size
);
1223 PUB_FUNC
char *tcc_strdup(const char *str
);
1225 #define tcc_free(ptr) tcc_free_debug(ptr)
1226 #define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
1227 #define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
1228 #define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
1229 #define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
1230 PUB_FUNC
void tcc_free_debug(void *ptr
);
1231 PUB_FUNC
void *tcc_malloc_debug(unsigned long size
, const char *file
, int line
);
1232 PUB_FUNC
void *tcc_mallocz_debug(unsigned long size
, const char *file
, int line
);
1233 PUB_FUNC
void *tcc_realloc_debug(void *ptr
, unsigned long size
, const char *file
, int line
);
1234 PUB_FUNC
char *tcc_strdup_debug(const char *str
, const char *file
, int line
);
1237 #define free(p) use_tcc_free(p)
1238 #define malloc(s) use_tcc_malloc(s)
1239 #define realloc(p, s) use_tcc_realloc(p, s)
1241 #define strdup(s) use_tcc_strdup(s)
1242 PUB_FUNC
void _tcc_error_noabort(const char *fmt
, ...) PRINTF_LIKE(1,2);
1243 PUB_FUNC NORETURN
void _tcc_error(const char *fmt
, ...) PRINTF_LIKE(1,2);
1244 PUB_FUNC
void _tcc_warning(const char *fmt
, ...) PRINTF_LIKE(1,2);
1245 #define tcc_internal_error(msg) tcc_error("internal compiler error\n"\
1246 "%s:%d: in %s(): " msg, __FILE__,__LINE__,__FUNCTION__)
1248 /* other utilities */
1249 ST_FUNC
void dynarray_add(void *ptab
, int *nb_ptr
, void *data
);
1250 ST_FUNC
void dynarray_reset(void *pp
, int *n
);
1251 ST_INLN
void cstr_ccat(CString
*cstr
, int ch
);
1252 ST_FUNC
void cstr_cat(CString
*cstr
, const char *str
, int len
);
1253 ST_FUNC
void cstr_wccat(CString
*cstr
, int ch
);
1254 ST_FUNC
void cstr_new(CString
*cstr
);
1255 ST_FUNC
void cstr_free(CString
*cstr
);
1256 ST_FUNC
int cstr_printf(CString
*cs
, const char *fmt
, ...) PRINTF_LIKE(2,3);
1257 ST_FUNC
void cstr_reset(CString
*cstr
);
1259 ST_FUNC
void tcc_open_bf(TCCState
*s1
, const char *filename
, int initlen
);
1260 ST_FUNC
int tcc_open(TCCState
*s1
, const char *filename
);
1261 ST_FUNC
void tcc_close(void);
1263 ST_FUNC
int tcc_add_file_internal(TCCState
*s1
, const char *filename
, int flags
);
1265 #define AFF_PRINT_ERROR 0x10 /* print error if file not found */
1266 #define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
1267 #define AFF_TYPE_BIN 0x40 /* file to add is binary */
1268 #define AFF_WHOLE_ARCHIVE 0x80 /* load all objects from archive */
1270 #define AFF_TYPE_NONE 0
1271 #define AFF_TYPE_C 1
1272 #define AFF_TYPE_ASM 2
1273 #define AFF_TYPE_ASMPP 4
1274 #define AFF_TYPE_LIB 8
1275 #define AFF_TYPE_MASK (15 | AFF_TYPE_BIN)
1276 /* values from tcc_object_type(...) */
1277 #define AFF_BINTYPE_REL 1
1278 #define AFF_BINTYPE_DYN 2
1279 #define AFF_BINTYPE_AR 3
1280 #define AFF_BINTYPE_C67 4
1282 #ifndef ELF_OBJ_ONLY
1283 ST_FUNC
int tcc_add_crt(TCCState
*s
, const char *filename
);
1285 #ifndef TCC_TARGET_MACHO
1286 ST_FUNC
int tcc_add_dll(TCCState
*s
, const char *filename
, int flags
);
1288 #ifdef CONFIG_TCC_BCHECK
1289 ST_FUNC
void tcc_add_bcheck(TCCState
*s1
);
1291 #ifdef CONFIG_TCC_BACKTRACE
1292 ST_FUNC
void tcc_add_btstub(TCCState
*s1
);
1294 ST_FUNC
void tcc_add_pragma_libs(TCCState
*s1
);
1295 PUB_FUNC
int tcc_add_library_err(TCCState
*s
, const char *f
);
1296 PUB_FUNC
void tcc_print_stats(TCCState
*s
, unsigned total_time
);
1297 PUB_FUNC
int tcc_parse_args(TCCState
*s
, int *argc
, char ***argv
, int optind
);
1299 ST_FUNC
char *normalize_slashes(char *path
);
1302 /* tcc_parse_args return codes: */
1306 #define OPT_PRINT_DIRS 4
1308 #define OPT_IMPDEF 6
1312 /* ------------ tccpp.c ------------ */
1314 ST_DATA
struct BufferedFile
*file
;
1315 ST_DATA
int ch
, tok
;
1316 ST_DATA CValue tokc
;
1317 ST_DATA
const int *macro_ptr
;
1318 ST_DATA
int parse_flags
;
1319 ST_DATA
int tok_flags
;
1320 ST_DATA CString tokcstr
; /* current parsed string, if any */
1322 /* display benchmark infos */
1323 ST_DATA
int tok_ident
;
1324 ST_DATA TokenSym
**table_ident
;
1326 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1327 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1328 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1329 #define TOK_FLAG_EOF 0x0008 /* end of file */
1331 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1332 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1333 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1334 token. line feed is also
1336 #define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
1337 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1338 #define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
1339 #define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
1341 /* isidnum_table flags: */
1346 ST_FUNC TokenSym
*tok_alloc(const char *str
, int len
);
1347 ST_FUNC
const char *get_tok_str(int v
, CValue
*cv
);
1348 ST_FUNC
void begin_macro(TokenString
*str
, int alloc
);
1349 ST_FUNC
void end_macro(void);
1350 ST_FUNC
int set_idnum(int c
, int val
);
1351 ST_INLN
void tok_str_new(TokenString
*s
);
1352 ST_FUNC TokenString
*tok_str_alloc(void);
1353 ST_FUNC
void tok_str_free(TokenString
*s
);
1354 ST_FUNC
void tok_str_free_str(int *str
);
1355 ST_FUNC
void tok_str_add(TokenString
*s
, int t
);
1356 ST_FUNC
void tok_str_add_tok(TokenString
*s
);
1357 ST_INLN
void define_push(int v
, int macro_type
, int *str
, Sym
*first_arg
);
1358 ST_FUNC
void define_undef(Sym
*s
);
1359 ST_INLN Sym
*define_find(int v
);
1360 ST_FUNC
void free_defines(Sym
*b
);
1361 ST_FUNC Sym
*label_find(int v
);
1362 ST_FUNC Sym
*label_push(Sym
**ptop
, int v
, int flags
);
1363 ST_FUNC
void label_pop(Sym
**ptop
, Sym
*slast
, int keep
);
1364 ST_FUNC
void parse_define(void);
1365 ST_FUNC
void preprocess(int is_bof
);
1366 ST_FUNC
void next(void);
1367 ST_INLN
void unget_tok(int last_tok
);
1368 ST_FUNC
void preprocess_start(TCCState
*s1
, int filetype
);
1369 ST_FUNC
void preprocess_end(TCCState
*s1
);
1370 ST_FUNC
void tccpp_new(TCCState
*s
);
1371 ST_FUNC
void tccpp_delete(TCCState
*s
);
1372 ST_FUNC
int tcc_preprocess(TCCState
*s1
);
1373 ST_FUNC
void skip(int c
);
1374 ST_FUNC NORETURN
void expect(const char *msg
);
1376 /* space excluding newline */
1377 static inline int is_space(int ch
) {
1378 return ch
== ' ' || ch
== '\t' || ch
== '\v' || ch
== '\f' || ch
== '\r';
1380 static inline int isid(int c
) {
1381 return (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z') || c
== '_';
1383 static inline int isnum(int c
) {
1384 return c
>= '0' && c
<= '9';
1386 static inline int isoct(int c
) {
1387 return c
>= '0' && c
<= '7';
1389 static inline int toup(int c
) {
1390 return (c
>= 'a' && c
<= 'z') ? c
- 'a' + 'A' : c
;
1393 /* ------------ tccgen.c ------------ */
1395 #define SYM_POOL_NB (8192 / sizeof(Sym))
1397 ST_DATA Sym
*global_stack
;
1398 ST_DATA Sym
*local_stack
;
1399 ST_DATA Sym
*local_label_stack
;
1400 ST_DATA Sym
*global_label_stack
;
1401 ST_DATA Sym
*define_stack
;
1402 ST_DATA CType int_type
, func_old_type
, char_pointer_type
;
1403 ST_DATA SValue
*vtop
;
1404 ST_DATA
int rsym
, anon_sym
, ind
, loc
;
1406 ST_DATA
int const_wanted
; /* true if constant wanted */
1407 ST_DATA
int nocode_wanted
; /* true if no code generation wanted for an expression */
1408 ST_DATA
int global_expr
; /* true if compound literals must be allocated globally (used during initializers parsing */
1409 ST_DATA CType func_vt
; /* current function return type (used by return instruction) */
1410 ST_DATA
int func_var
; /* true if current function is variadic */
1411 ST_DATA
int func_vc
;
1412 ST_DATA
const char *funcname
;
1414 ST_FUNC
void tcc_debug_start(TCCState
*s1
);
1415 ST_FUNC
void tcc_debug_end(TCCState
*s1
);
1416 ST_FUNC
void tcc_debug_bincl(TCCState
*s1
);
1417 ST_FUNC
void tcc_debug_eincl(TCCState
*s1
);
1418 ST_FUNC
void tcc_debug_putfile(TCCState
*s1
, const char *filename
);
1419 ST_FUNC
void tcc_debug_funcstart(TCCState
*s1
, Sym
*sym
);
1420 ST_FUNC
void tcc_debug_funcend(TCCState
*s1
, int size
);
1421 ST_FUNC
void tcc_debug_line(TCCState
*s1
);
1423 ST_FUNC
void tccgen_init(TCCState
*s1
);
1424 ST_FUNC
int tccgen_compile(TCCState
*s1
);
1425 ST_FUNC
void tccgen_finish(TCCState
*s1
);
1426 ST_FUNC
void check_vstack(void);
1428 ST_INLN
int is_float(int t
);
1429 ST_FUNC
int ieee_finite(double d
);
1430 ST_FUNC
int exact_log2p1(int i
);
1431 ST_FUNC
void test_lvalue(void);
1433 ST_FUNC ElfSym
*elfsym(Sym
*);
1434 ST_FUNC
void update_storage(Sym
*sym
);
1435 ST_FUNC
void put_extern_sym2(Sym
*sym
, int sh_num
, addr_t value
, unsigned long size
, int can_add_underscore
);
1436 ST_FUNC
void put_extern_sym(Sym
*sym
, Section
*section
, addr_t value
, unsigned long size
);
1438 ST_FUNC
void greloc(Section
*s
, Sym
*sym
, unsigned long offset
, int type
);
1440 ST_FUNC
void greloca(Section
*s
, Sym
*sym
, unsigned long offset
, int type
, addr_t addend
);
1442 ST_INLN
void sym_free(Sym
*sym
);
1443 ST_FUNC Sym
*sym_push(int v
, CType
*type
, int r
, int c
);
1444 ST_FUNC
void sym_pop(Sym
**ptop
, Sym
*b
, int keep
);
1445 ST_FUNC Sym
*sym_push2(Sym
**ps
, int v
, int t
, int c
);
1446 ST_FUNC Sym
*sym_find2(Sym
*s
, int v
);
1447 ST_INLN Sym
*sym_find(int v
);
1448 ST_INLN Sym
*struct_find(int v
);
1450 ST_FUNC Sym
*global_identifier_push(int v
, int t
, int c
);
1451 ST_FUNC Sym
*external_global_sym(int v
, CType
*type
);
1452 ST_FUNC Sym
*external_helper_sym(int v
);
1453 ST_FUNC
void vpush_helper_func(int v
);
1454 ST_FUNC
void vset(CType
*type
, int r
, int v
);
1455 ST_FUNC
void vset_VT_CMP(int op
);
1456 ST_FUNC
void vpushi(int v
);
1457 ST_FUNC
void vpushv(SValue
*v
);
1458 ST_FUNC
void vpushsym(CType
*type
, Sym
*sym
);
1459 ST_FUNC
void vswap(void);
1460 ST_FUNC
void vrote(SValue
*e
, int n
);
1461 ST_FUNC
void vrott(int n
);
1462 ST_FUNC
void vrotb(int n
);
1463 ST_FUNC
void vpop(void);
1465 ST_FUNC
void lexpand(void);
1467 #ifdef TCC_TARGET_ARM
1468 ST_FUNC
int get_reg_ex(int rc
, int rc2
);
1470 ST_FUNC
void save_reg(int r
);
1471 ST_FUNC
void save_reg_upstack(int r
, int n
);
1472 ST_FUNC
int get_reg(int rc
);
1473 ST_FUNC
void save_regs(int n
);
1474 ST_FUNC
void gaddrof(void);
1475 ST_FUNC
int gv(int rc
);
1476 ST_FUNC
void gv2(int rc1
, int rc2
);
1477 ST_FUNC
void gen_op(int op
);
1478 ST_FUNC
int type_size(CType
*type
, int *a
);
1479 ST_FUNC
void mk_pointer(CType
*type
);
1480 ST_FUNC
void vstore(void);
1481 ST_FUNC
void inc(int post
, int c
);
1482 ST_FUNC
void parse_mult_str (CString
*astr
, const char *msg
);
1483 ST_FUNC
void parse_asm_str(CString
*astr
);
1484 ST_FUNC
void indir(void);
1485 ST_FUNC
void unary(void);
1486 ST_FUNC
void gexpr(void);
1487 ST_FUNC
int expr_const(void);
1488 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1489 ST_FUNC Sym
*get_sym_ref(CType
*type
, Section
*sec
, unsigned long offset
, unsigned long size
);
1491 #if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
1492 ST_FUNC
int classify_x86_64_va_arg(CType
*ty
);
1494 #ifdef CONFIG_TCC_BCHECK
1495 ST_FUNC
void gbound_args(int nb_args
);
1496 ST_DATA
int func_bound_add_epilog
;
1499 /* ------------ tccelf.c ------------ */
1501 #define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
1502 #define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
1503 #define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
1505 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1508 unsigned int n_strx
; /* index into string table of name */
1509 unsigned char n_type
; /* type of symbol */
1510 unsigned char n_other
; /* misc info (usually empty) */
1511 unsigned short n_desc
; /* description field */
1512 unsigned int n_value
; /* value of symbol */
1515 ST_FUNC
void tccelf_new(TCCState
*s
);
1516 ST_FUNC
void tccelf_delete(TCCState
*s
);
1517 ST_FUNC
void tccelf_stab_new(TCCState
*s
);
1518 ST_FUNC
void tccelf_begin_file(TCCState
*s1
);
1519 ST_FUNC
void tccelf_end_file(TCCState
*s1
);
1520 #ifdef CONFIG_TCC_BCHECK
1521 ST_FUNC
void tccelf_bounds_new(TCCState
*s
);
1523 ST_FUNC Section
*new_section(TCCState
*s1
, const char *name
, int sh_type
, int sh_flags
);
1524 ST_FUNC
void section_realloc(Section
*sec
, unsigned long new_size
);
1525 ST_FUNC
size_t section_add(Section
*sec
, addr_t size
, int align
);
1526 ST_FUNC
void *section_ptr_add(Section
*sec
, addr_t size
);
1527 ST_FUNC Section
*find_section(TCCState
*s1
, const char *name
);
1528 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
);
1530 ST_FUNC
int put_elf_str(Section
*s
, const char *sym
);
1531 ST_FUNC
int put_elf_sym(Section
*s
, addr_t value
, unsigned long size
, int info
, int other
, int shndx
, const char *name
);
1532 ST_FUNC
int set_elf_sym(Section
*s
, addr_t value
, unsigned long size
, int info
, int other
, int shndx
, const char *name
);
1533 ST_FUNC
int find_elf_sym(Section
*s
, const char *name
);
1534 ST_FUNC
void put_elf_reloc(Section
*symtab
, Section
*s
, unsigned long offset
, int type
, int symbol
);
1535 ST_FUNC
void put_elf_reloca(Section
*symtab
, Section
*s
, unsigned long offset
, int type
, int symbol
, addr_t addend
);
1537 ST_FUNC
void put_stabs(TCCState
*s1
, const char *str
, int type
, int other
, int desc
, unsigned long value
);
1538 ST_FUNC
void put_stabs_r(TCCState
*s1
, const char *str
, int type
, int other
, int desc
, unsigned long value
, Section
*sec
, int sym_index
);
1539 ST_FUNC
void put_stabn(TCCState
*s1
, int type
, int other
, int desc
, int value
);
1541 ST_FUNC
void resolve_common_syms(TCCState
*s1
);
1542 ST_FUNC
void relocate_syms(TCCState
*s1
, Section
*symtab
, int do_resolve
);
1543 ST_FUNC
void relocate_section(TCCState
*s1
, Section
*s
);
1545 ST_FUNC ssize_t
full_read(int fd
, void *buf
, size_t count
);
1546 ST_FUNC
void *load_data(int fd
, unsigned long file_offset
, unsigned long size
);
1547 ST_FUNC
int tcc_object_type(int fd
, ElfW(Ehdr
) *h
);
1548 ST_FUNC
int tcc_load_object_file(TCCState
*s1
, int fd
, unsigned long file_offset
);
1549 ST_FUNC
int tcc_load_archive(TCCState
*s1
, int fd
, int alacarte
);
1550 ST_FUNC
void add_array(TCCState
*s1
, const char *sec
, int c
);
1552 #if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE)
1553 ST_FUNC
void build_got_entries(TCCState
*s1
);
1555 ST_FUNC
struct sym_attr
*get_sym_attr(TCCState
*s1
, int index
, int alloc
);
1556 ST_FUNC addr_t
get_sym_addr(TCCState
*s
, const char *name
, int err
, int forc
);
1557 ST_FUNC
void list_elf_symbols(TCCState
*s
, void *ctx
,
1558 void (*symbol_cb
)(void *ctx
, const char *name
, const void *val
));
1559 ST_FUNC
int set_global_sym(TCCState
*s1
, const char *name
, Section
*sec
, addr_t offs
);
1561 /* Browse each elem of type <type> in section <sec> starting at elem <startoff>
1562 using variable <elem> */
1563 #define for_each_elem(sec, startoff, elem, type) \
1564 for (elem = (type *) sec->data + startoff; \
1565 elem < (type *) (sec->data + sec->data_offset); elem++)
1567 #ifndef ELF_OBJ_ONLY
1568 ST_FUNC
int tcc_load_dll(TCCState
*s1
, int fd
, const char *filename
, int level
);
1569 ST_FUNC
int tcc_load_ldscript(TCCState
*s1
, int fd
);
1571 #ifndef TCC_TARGET_PE
1572 ST_FUNC
void tcc_add_runtime(TCCState
*s1
);
1575 /* ------------ xxx-link.c ------------ */
1577 /* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
1578 that unknown relocation don't create a GOT or PLT entry */
1580 NO_GOTPLT_ENTRY
, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
1581 BUILD_GOT_ONLY
, /* only build GOT (eg. TPOFF relocs) */
1582 AUTO_GOTPLT_ENTRY
, /* generate if sym is UNDEF */
1583 ALWAYS_GOTPLT_ENTRY
/* always generate (eg. PLTOFF relocs) */
1586 #if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO)
1587 ST_FUNC
int code_reloc (int reloc_type
);
1588 ST_FUNC
int gotplt_entry_type (int reloc_type
);
1589 #if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE
1590 ST_FUNC
unsigned create_plt_entry(TCCState
*s1
, unsigned got_offset
, struct sym_attr
*attr
);
1591 ST_FUNC
void relocate_plt(TCCState
*s1
);
1594 ST_FUNC
void relocate(TCCState
*s1
, ElfW_Rel
*rel
, int type
, unsigned char *ptr
, addr_t addr
, addr_t val
);
1596 /* ------------ xxx-gen.c ------------ */
1598 ST_DATA
const int reg_classes
[NB_REGS
];
1600 ST_FUNC
void gsym_addr(int t
, int a
);
1601 ST_FUNC
void gsym(int t
);
1602 ST_FUNC
void load(int r
, SValue
*sv
);
1603 ST_FUNC
void store(int r
, SValue
*v
);
1604 ST_FUNC
int gfunc_sret(CType
*vt
, int variadic
, CType
*ret
, int *align
, int *regsize
);
1605 ST_FUNC
void gfunc_call(int nb_args
);
1606 ST_FUNC
void gfunc_prolog(Sym
*func_sym
);
1607 ST_FUNC
void gfunc_epilog(void);
1608 ST_FUNC
void gen_fill_nops(int);
1609 ST_FUNC
int gjmp(int t
);
1610 ST_FUNC
void gjmp_addr(int a
);
1611 ST_FUNC
int gjmp_cond(int op
, int t
);
1612 ST_FUNC
int gjmp_append(int n
, int t
);
1613 ST_FUNC
void gen_opi(int op
);
1614 ST_FUNC
void gen_opf(int op
);
1615 ST_FUNC
void gen_cvt_ftoi(int t
);
1616 ST_FUNC
void gen_cvt_itof(int t
);
1617 ST_FUNC
void gen_cvt_ftof(int t
);
1618 ST_FUNC
void ggoto(void);
1619 #ifndef TCC_TARGET_C67
1620 ST_FUNC
void o(unsigned int c
);
1622 ST_FUNC
void gen_vla_sp_save(int addr
);
1623 ST_FUNC
void gen_vla_sp_restore(int addr
);
1624 ST_FUNC
void gen_vla_alloc(CType
*type
, int align
);
1626 static inline uint16_t read16le(unsigned char *p
) {
1627 return p
[0] | (uint16_t)p
[1] << 8;
1629 static inline void write16le(unsigned char *p
, uint16_t x
) {
1630 p
[0] = x
& 255; p
[1] = x
>> 8 & 255;
1632 static inline uint32_t read32le(unsigned char *p
) {
1633 return read16le(p
) | (uint32_t)read16le(p
+ 2) << 16;
1635 static inline void write32le(unsigned char *p
, uint32_t x
) {
1636 write16le(p
, x
); write16le(p
+ 2, x
>> 16);
1638 static inline void add32le(unsigned char *p
, int32_t x
) {
1639 write32le(p
, read32le(p
) + x
);
1641 static inline uint64_t read64le(unsigned char *p
) {
1642 return read32le(p
) | (uint64_t)read32le(p
+ 4) << 32;
1644 static inline void write64le(unsigned char *p
, uint64_t x
) {
1645 write32le(p
, x
); write32le(p
+ 4, x
>> 32);
1647 static inline void add64le(unsigned char *p
, int64_t x
) {
1648 write64le(p
, read64le(p
) + x
);
1651 /* ------------ i386-gen.c ------------ */
1652 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1653 ST_FUNC
void g(int c
);
1654 ST_FUNC
void gen_le16(int c
);
1655 ST_FUNC
void gen_le32(int c
);
1656 ST_FUNC
void gen_addr32(int r
, Sym
*sym
, int c
);
1657 ST_FUNC
void gen_addrpc32(int r
, Sym
*sym
, int c
);
1658 ST_FUNC
void gen_cvt_csti(int t
);
1661 /* ------------ x86_64-gen.c ------------ */
1662 #ifdef TCC_TARGET_X86_64
1663 ST_FUNC
void gen_addr64(int r
, Sym
*sym
, int64_t c
);
1664 ST_FUNC
void gen_opl(int op
);
1665 #ifdef TCC_TARGET_PE
1666 ST_FUNC
void gen_vla_result(int addr
);
1668 ST_FUNC
void gen_cvt_sxtw(void);
1669 ST_FUNC
void gen_cvt_csti(int t
);
1672 /* ------------ arm-gen.c ------------ */
1673 #ifdef TCC_TARGET_ARM
1674 #if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
1675 PUB_FUNC
const char *default_elfinterp(struct TCCState
*s
);
1677 ST_FUNC
void arm_init(struct TCCState
*s
);
1680 /* ------------ arm64-gen.c ------------ */
1681 #ifdef TCC_TARGET_ARM64
1682 ST_FUNC
void gen_opl(int op
);
1683 ST_FUNC
void gfunc_return(CType
*func_type
);
1684 ST_FUNC
void gen_va_start(void);
1685 ST_FUNC
void gen_va_arg(CType
*t
);
1686 ST_FUNC
void gen_clear_cache(void);
1687 ST_FUNC
void gen_cvt_sxtw(void);
1688 ST_FUNC
void gen_cvt_csti(int t
);
1691 /* ------------ riscv64-gen.c ------------ */
1692 #ifdef TCC_TARGET_RISCV64
1693 ST_FUNC
void gen_opl(int op
);
1694 //ST_FUNC void gfunc_return(CType *func_type);
1695 ST_FUNC
void gen_va_start(void);
1696 ST_FUNC
void arch_transfer_ret_regs(int);
1697 ST_FUNC
void gen_cvt_sxtw(void);
1700 /* ------------ c67-gen.c ------------ */
1701 #ifdef TCC_TARGET_C67
1704 /* ------------ tcccoff.c ------------ */
1706 #ifdef TCC_TARGET_COFF
1707 ST_FUNC
int tcc_output_coff(TCCState
*s1
, FILE *f
);
1708 ST_FUNC
int tcc_load_coff(TCCState
* s1
, int fd
);
1711 /* ------------ tccasm.c ------------ */
1712 ST_FUNC
void asm_instr(void);
1713 ST_FUNC
void asm_global_instr(void);
1714 #ifdef CONFIG_TCC_ASM
1715 ST_FUNC
int find_constraint(ASMOperand
*operands
, int nb_operands
, const char *name
, const char **pp
);
1716 ST_FUNC Sym
* get_asm_sym(int name
, Sym
*csym
);
1717 ST_FUNC
void asm_expr(TCCState
*s1
, ExprValue
*pe
);
1718 ST_FUNC
int asm_int_expr(TCCState
*s1
);
1719 ST_FUNC
int tcc_assemble(TCCState
*s1
, int do_preprocess
);
1720 /* ------------ i386-asm.c ------------ */
1721 ST_FUNC
void gen_expr32(ExprValue
*pe
);
1722 #ifdef TCC_TARGET_X86_64
1723 ST_FUNC
void gen_expr64(ExprValue
*pe
);
1725 ST_FUNC
void asm_opcode(TCCState
*s1
, int opcode
);
1726 ST_FUNC
int asm_parse_regvar(int t
);
1727 ST_FUNC
void asm_compute_constraints(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, const uint8_t *clobber_regs
, int *pout_reg
);
1728 ST_FUNC
void subst_asm_operand(CString
*add_str
, SValue
*sv
, int modifier
);
1729 ST_FUNC
void asm_gen_code(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, int is_output
, uint8_t *clobber_regs
, int out_reg
);
1730 ST_FUNC
void asm_clobber(uint8_t *clobber_regs
, const char *str
);
1733 /* ------------ tccpe.c -------------- */
1734 #ifdef TCC_TARGET_PE
1735 ST_FUNC
int pe_load_file(struct TCCState
*s1
, const char *filename
, int fd
);
1736 ST_FUNC
int pe_output_file(TCCState
* s1
, const char *filename
);
1737 ST_FUNC
int pe_putimport(TCCState
*s1
, int dllindex
, const char *name
, addr_t value
);
1738 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1739 ST_FUNC SValue
*pe_getimport(SValue
*sv
, SValue
*v2
);
1741 #ifdef TCC_TARGET_X86_64
1742 ST_FUNC
void pe_add_unwind_data(unsigned start
, unsigned end
, unsigned stack
);
1744 PUB_FUNC
int tcc_get_dllexports(const char *filename
, char **pp
);
1745 /* symbol properties stored in Elf32_Sym->st_other */
1746 # define ST_PE_EXPORT 0x10
1747 # define ST_PE_IMPORT 0x20
1748 # define ST_PE_STDCALL 0x40
1750 #define ST_ASM_SET 0x04
1752 /* ------------ tccmacho.c ----------------- */
1753 #ifdef TCC_TARGET_MACHO
1754 ST_FUNC
int macho_output_file(TCCState
* s1
, const char *filename
);
1755 ST_FUNC
int macho_load_dll(TCCState
*s1
, int fd
, const char *filename
, int lev
);
1757 /* ------------ tccrun.c ----------------- */
1758 #ifdef TCC_IS_NATIVE
1759 #ifdef CONFIG_TCC_STATIC
1760 #define RTLD_LAZY 0x001
1761 #define RTLD_NOW 0x002
1762 #define RTLD_GLOBAL 0x100
1763 #define RTLD_DEFAULT NULL
1764 /* dummy function for profiling */
1765 ST_FUNC
void *dlopen(const char *filename
, int flag
);
1766 ST_FUNC
void dlclose(void *p
);
1767 ST_FUNC
const char *dlerror(void);
1768 ST_FUNC
void *dlsym(void *handle
, const char *symbol
);
1770 ST_FUNC
void tcc_run_free(TCCState
*s1
);
1773 /* ------------ tcctools.c ----------------- */
1774 #if 0 /* included in tcc.c */
1775 ST_FUNC
int tcc_tool_ar(TCCState
*s
, int argc
, char **argv
);
1776 #ifdef TCC_TARGET_PE
1777 ST_FUNC
int tcc_tool_impdef(TCCState
*s
, int argc
, char **argv
);
1779 ST_FUNC
void tcc_tool_cross(TCCState
*s
, char **argv
, int option
);
1780 ST_FUNC
void gen_makedeps(TCCState
*s
, const char *target
, const char *filename
);
1783 /********************************************************/
1786 #define ST_DATA static
1790 /********************************************************/
1792 #define text_section TCC_STATE_VAR(text_section)
1793 #define data_section TCC_STATE_VAR(data_section)
1794 #define bss_section TCC_STATE_VAR(bss_section)
1795 #define common_section TCC_STATE_VAR(common_section)
1796 #define cur_text_section TCC_STATE_VAR(cur_text_section)
1797 #define bounds_section TCC_STATE_VAR(bounds_section)
1798 #define lbounds_section TCC_STATE_VAR(lbounds_section)
1799 #define symtab_section TCC_STATE_VAR(symtab_section)
1800 #define stab_section TCC_STATE_VAR(stab_section)
1801 #define stabstr_section stab_section->link
1802 #define gnu_ext TCC_STATE_VAR(gnu_ext)
1803 #define tcc_error_noabort TCC_SET_STATE(_tcc_error_noabort)
1804 #define tcc_error TCC_SET_STATE(_tcc_error)
1805 #define tcc_warning TCC_SET_STATE(_tcc_warning)
1807 #define total_idents TCC_STATE_VAR(total_idents)
1808 #define total_lines TCC_STATE_VAR(total_lines)
1809 #define total_bytes TCC_STATE_VAR(total_bytes)
1811 PUB_FUNC
void tcc_enter_state(TCCState
*s1
);
1812 PUB_FUNC
void tcc_exit_state(void);
1814 /********************************************************/
1817 #undef TCC_STATE_VAR
1818 #undef TCC_SET_STATE
1820 #ifdef USING_GLOBALS
1821 # define TCC_STATE_VAR(sym) tcc_state->sym
1822 # define TCC_SET_STATE(fn) fn
1823 # undef USING_GLOBALS
1825 # define TCC_STATE_VAR(sym) s1->sym
1826 # define TCC_SET_STATE(fn) (tcc_enter_state(s1),fn)
1827 /* actually we could avoid the tcc_enter_state(s1) hack by using
1828 __VA_ARGS__ except that some compiler doesn't support it. */