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
30 #define CONFIG_TCC_STATIC
47 #include <sys/timeb.h>
48 #include <io.h> /* open, close etc. */
49 #include <direct.h> /* getcwd */
50 #define inline __inline
53 #define uplong unsigned long long
60 #include <sys/ucontext.h>
65 #endif /* !CONFIG_TCCBOOT */
68 #define uplong unsigned long
83 #define SA_SIGINFO 0x00000004u
90 /* preprocessor debug */
92 /* include file debug */
100 /* target selection */
101 //#define TCC_TARGET_I386 /* i386 code generator */
102 //#define TCC_TARGET_ARM /* ARMv4 code generator */
103 //#define TCC_TARGET_C67 /* TMS320C67xx code generator */
104 //#define TCC_TARGET_X86_64 /* x86-64 code generator */
106 /* default target is I386 */
107 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
108 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
109 #define TCC_TARGET_I386
112 #if !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
113 !defined(TCC_TARGET_C67) && !defined(TCC_TARGET_X86_64)
114 #define CONFIG_TCC_BCHECK /* enable bound checking code */
117 #if defined(_WIN32) && !defined(TCC_TARGET_PE)
118 #define CONFIG_TCC_STATIC
121 /* define it to include assembler support */
122 #if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_C67)
123 #define CONFIG_TCC_ASM
126 /* object format selection */
127 #if defined(TCC_TARGET_C67)
128 #define TCC_TARGET_COFF
131 #if !defined(CONFIG_TCCBOOT)
132 #define CONFIG_TCC_BACKTRACE
135 /* ------------ path configuration ------------ */
137 #ifndef CONFIG_TCC_LDDIR
138 # if defined(TCC_TARGET_X86_64_CENTOS)
139 # define CONFIG_TCC_LDDIR "/lib64"
141 # define CONFIG_TCC_LDDIR "/lib"
145 /* path to find crt1.o, crti.o and crtn.o */
146 #ifndef CONFIG_TCC_CRTPREFIX
147 # define CONFIG_TCC_CRTPREFIX CONFIG_SYSROOT "/usr" CONFIG_TCC_LDDIR
150 /* system include paths */
151 #ifndef CONFIG_TCC_SYSINCLUDEPATHS
152 # ifdef TCC_TARGET_PE
153 # define CONFIG_TCC_SYSINCLUDEPATHS "\b/include;\b/include/winapi"
155 # define CONFIG_TCC_SYSINCLUDEPATHS \
156 CONFIG_SYSROOT "/usr/local/include" \
157 ":" CONFIG_SYSROOT "/usr/include" \
162 /* library search paths */
163 #ifndef CONFIG_TCC_LIBPATHS
164 # ifdef TCC_TARGET_PE
165 # define CONFIG_TCC_LIBPATHS "\b/lib"
167 # define CONFIG_TCC_LIBPATHS \
168 CONFIG_SYSROOT CONFIG_TCC_CRTPREFIX \
169 ":" CONFIG_SYSROOT CONFIG_TCC_LDDIR \
170 ":" CONFIG_SYSROOT "/usr/local" CONFIG_TCC_LDDIR
174 /* name of ELF interpreter */
175 #ifndef CONFIG_TCC_ELFINTERP
176 # if defined __FreeBSD__
177 # define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
178 # elif defined __FreeBSD_kernel__
179 # define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld.so.1"
180 # elif defined TCC_ARM_EABI
181 # define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux.so.3"
182 # elif defined(TCC_TARGET_X86_64)
183 # define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux-x86-64.so.2"
184 # elif defined(TCC_UCLIBC)
185 # define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-uClibc.so.0"
187 # define CONFIG_TCC_ELFINTERP CONFIG_TCC_LDDIR"/ld-linux.so.2"
191 /* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
192 #define TCC_LIBGCC CONFIG_SYSROOT CONFIG_TCC_LDDIR "/libgcc_s.so.1"
194 /* -------------------------------------------- */
202 #define INCLUDE_STACK_SIZE 32
203 #define IFDEF_STACK_SIZE 64
204 #define VSTACK_SIZE 256
205 #define STRING_MAX_SIZE 1024
206 #define PACK_STACK_SIZE 8
208 #define TOK_HASH_SIZE 8192 /* must be a power of two */
209 #define TOK_ALLOC_INCR 512 /* must be a power of two */
210 #define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
212 /* token symbol management */
213 typedef struct TokenSym
{
214 struct TokenSym
*hash_next
;
215 struct Sym
*sym_define
; /* direct pointer to define */
216 struct Sym
*sym_label
; /* direct pointer to label */
217 struct Sym
*sym_struct
; /* direct pointer to structure */
218 struct Sym
*sym_identifier
; /* direct pointer to identifier */
219 int tok
; /* token number */
225 typedef unsigned short nwchar_t
;
227 typedef int nwchar_t
;
230 typedef struct CString
{
231 int size
; /* size in bytes */
232 void *data
; /* either 'char *' or 'nwchar_t *' */
234 void *data_allocated
; /* if non NULL, data has been malloced */
237 /* type definition */
238 typedef struct CType
{
244 typedef union CValue
{
250 unsigned int ul
; /* address (should be unsigned long on 64 bit cpu) */
252 unsigned long long ull
;
253 struct CString
*cstr
;
259 typedef struct SValue
{
260 CType type
; /* type */
261 unsigned short r
; /* register + flags */
262 unsigned short r2
; /* second register, used for 'long long'
263 type. If not used, set to VT_CONST */
264 CValue c
; /* constant, if VT_CONST */
265 struct Sym
*sym
; /* symbol, if (VT_SYM | VT_CONST) */
268 /* symbol management */
270 int v
; /* symbol token */
271 char *asm_label
; /* associated asm label */
272 long r
; /* associated register */
274 long c
; /* associated number */
275 int *d
; /* define token stream */
277 CType type
; /* associated type */
279 struct Sym
*next
; /* next related symbol */
280 long jnext
; /* next jump label */
282 struct Sym
*prev
; /* prev symbol in stack */
283 struct Sym
*prev_tok
; /* previous symbol for this token */
286 /* section definition */
287 /* XXX: use directly ELF structure for parameters ? */
288 /* special flag to indicate that the section should not be linked to
290 #define SHF_PRIVATE 0x80000000
292 /* special flag, too */
293 #define SECTION_ABS ((void *)1)
295 typedef struct Section
{
296 unsigned long data_offset
; /* current data offset */
297 unsigned char *data
; /* section data */
298 unsigned long data_allocated
; /* used for realloc() handling */
299 int sh_name
; /* elf section name (only used during output) */
300 int sh_num
; /* elf section number */
301 int sh_type
; /* elf section type */
302 int sh_flags
; /* elf section flags */
303 int sh_info
; /* elf section info */
304 int sh_addralign
; /* elf section alignment */
305 int sh_entsize
; /* elf entry size */
306 unsigned long sh_size
; /* section size (only used during output) */
307 unsigned long sh_addr
; /* address at which the section is relocated */
308 unsigned long sh_offset
; /* file offset */
309 int nb_hashed_syms
; /* used to resize the hash table */
310 struct Section
*link
; /* link to another section */
311 struct Section
*reloc
; /* corresponding section for relocation, if any */
312 struct Section
*hash
; /* hash table for symbols */
313 struct Section
*next
;
314 char name
[1]; /* section name */
317 typedef struct DLLReference
{
323 /* GNUC attribute definition */
324 typedef struct AttributeDef
{
326 func_call
: 3, /* calling convention (0..5), see below */
327 aligned
: 5, /* alignement (0..16) */
335 struct Section
*section
;
336 int alias_target
; /* token */
339 /* gr: wrappers for casting sym->r for other purposes */
340 #define FUNC_CALL(r) (((AttributeDef*)&(r))->func_call)
341 #define FUNC_EXPORT(r) (((AttributeDef*)&(r))->func_export)
342 #define FUNC_IMPORT(r) (((AttributeDef*)&(r))->func_import)
343 #define FUNC_ARGS(r) (((AttributeDef*)&(r))->func_args)
344 #define FUNC_ALIGN(r) (((AttributeDef*)&(r))->aligned)
345 #define FUNC_PACKED(r) (((AttributeDef*)&(r))->packed)
346 #define ATTR_MODE(r) (((AttributeDef*)&(r))->mode)
347 #define INT_ATTR(ad) (*(int*)(ad))
349 /* -------------------------------------------------- */
351 #define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
352 #define SYM_FIELD 0x20000000 /* struct/union field symbol space */
353 #define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
355 /* stored in 'Sym.c' field */
356 #define FUNC_NEW 1 /* ansi function prototype */
357 #define FUNC_OLD 2 /* old function prototype */
358 #define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
360 /* stored in 'Sym.r' field */
361 #define FUNC_CDECL 0 /* standard c call */
362 #define FUNC_STDCALL 1 /* pascal c call */
363 #define FUNC_FASTCALL1 2 /* first param in %eax */
364 #define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
365 #define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
366 #define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
368 /* field 'Sym.t' for macros */
369 #define MACRO_OBJ 0 /* object like macro */
370 #define MACRO_FUNC 1 /* function like macro */
372 /* field 'Sym.r' for C labels */
373 #define LABEL_DEFINED 0 /* label is defined */
374 #define LABEL_FORWARD 1 /* label is forward defined */
375 #define LABEL_DECLARED 2 /* label is declared but never used */
377 /* type_decl() types */
378 #define TYPE_ABSTRACT 1 /* type without variable */
379 #define TYPE_DIRECT 2 /* type with variable */
381 #define IO_BUF_SIZE 8192
383 typedef struct BufferedFile
{
387 struct BufferedFile
*prev
;
388 int line_num
; /* current line number - here to simplify code */
389 int ifndef_macro
; /* #ifndef macro / #endif search */
390 int ifndef_macro_saved
; /* saved ifndef_macro */
391 int *ifdef_stack_ptr
; /* ifdef_stack value at the start of the file */
392 char inc_type
; /* type of include */
393 char inc_filename
[512]; /* filename specified by the user */
394 char filename
[1024]; /* current filename - here to simplify code */
395 unsigned char buffer
[IO_BUF_SIZE
+ 1]; /* extra size for CH_EOB char */
398 #define CH_EOB '\\' /* end of buffer or '\0' char in file */
399 #define CH_EOF (-1) /* end of file */
401 /* parsing state (used to save parser state to reparse part of the
402 source several times) */
403 typedef struct ParseState
{
404 const int *macro_ptr
;
410 /* used to record tokens */
411 typedef struct TokenString
{
418 /* inline functions */
419 typedef struct InlineFunc
{
425 /* include file cache, used to find files faster and also to eliminate
426 inclusion if the include file is protected by #ifndef ... #endif */
427 typedef struct CachedInclude
{
429 int hash_next
; /* -1 if none */
430 char type
; /* '"' or '>' to give include type */
431 char filename
[1]; /* path specified in #include */
434 #define CACHED_INCLUDES_HASH_SIZE 512
436 #ifdef CONFIG_TCC_ASM
437 typedef struct ExprValue
{
442 #define MAX_ASM_OPERANDS 30
443 typedef struct ASMOperand
{
444 int id
; /* GCC 3 optionnal identifier (0 if number only supported */
446 char asm_str
[16]; /* computed asm string for operand */
447 SValue
*vt
; /* C value of the expression */
448 int ref_index
; /* if >= 0, gives reference to a output constraint */
449 int input_index
; /* if >= 0, gives reference to an input constraint */
450 int priority
; /* priority, used to assign registers */
451 int reg
; /* if >= 0, register number used for this operand */
452 int is_llong
; /* true if double register value */
453 int is_memory
; /* true if memory operand */
454 int is_rw
; /* for '+' modifier */
459 unsigned output_type
: 8;
460 unsigned reloc_output
: 1;
462 BufferedFile
**include_stack_ptr
;
463 int *ifdef_stack_ptr
;
465 /* include file handling */
466 char **include_paths
;
467 int nb_include_paths
;
468 char **sysinclude_paths
;
469 int nb_sysinclude_paths
;
470 CachedInclude
**cached_includes
;
471 int nb_cached_includes
;
473 char **library_paths
;
474 int nb_library_paths
;
478 /* array of all loaded dlls (including those referenced by loaded
480 DLLReference
**loaded_dlls
;
485 int nb_sections
; /* number of sections, including first dummy section */
487 Section
**priv_sections
;
488 int nb_priv_sections
; /* number of private sections */
493 unsigned long *got_offsets
;
495 /* give the correspondance from symtab indexes to dynsym indexes */
496 int *symtab_to_dynsym
;
498 /* temporary dynamic symbol sections (for dll loading) */
499 Section
*dynsymtab_section
;
500 /* exported dynamic symbol section */
503 int nostdinc
; /* if true, no standard headers are added */
504 int nostdlib
; /* if true, no standard libraries are added */
505 int nocommon
; /* if true, do not use common symbols for .bss data */
507 /* if true, static linking is performed */
510 /* soname as specified on the command line (-soname) */
512 /* rpath as specified on the command line (-Wl,-rpath=) */
515 /* if true, all symbols are exported */
518 /* if true, resolve symbols in the current module first (-Wl,Bsymbolic) */
521 /* if true, only link in referenced objects from archive */
524 /* address of text section */
525 unsigned long text_addr
;
528 /* symbols to call at load-time / unload-time */
529 const char *init_symbol
;
530 const char *fini_symbol
;
532 /* output format, see TCC_OUTPUT_FORMAT_xxx */
535 /* C language options */
536 int char_is_unsigned
;
537 int leading_underscore
;
539 /* warning switches */
540 int warn_write_strings
;
541 int warn_unsupported
;
544 int warn_implicit_function_declaration
;
546 /* display some information during compilation */
548 /* compile with debug symbol (and use them if error during execution) */
550 #ifdef CONFIG_TCC_BCHECK
551 /* compile with built-in memory and bounds checker */
554 /* give the path of the tcc libraries */
559 void (*error_func
)(void *opaque
, const char *msg
);
560 int error_set_jmp_enabled
;
561 jmp_buf error_jmp_buf
;
564 /* tiny assembler state */
567 /* see include_stack_ptr */
568 BufferedFile
*include_stack
[INCLUDE_STACK_SIZE
];
570 /* see ifdef_stack_ptr */
571 int ifdef_stack
[IFDEF_STACK_SIZE
];
573 /* see cached_includes */
574 int cached_includes_hash
[CACHED_INCLUDES_HASH_SIZE
];
577 int pack_stack
[PACK_STACK_SIZE
];
580 /* output file for preprocessing */
583 /* automatically collected dependencies for this compilation */
587 /* for tcc_relocate */
592 unsigned long mem_size
;
595 struct InlineFunc
**inline_fns
;
598 #ifdef TCC_TARGET_I386
602 /* section alignment */
603 unsigned long section_align
;
608 unsigned long pe_file_align
;
609 unsigned long pe_stack_size
;
610 #ifdef TCC_TARGET_X86_64
617 #ifndef TCC_TARGET_PE
618 #if defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM
619 /* write PLT and GOT here */
620 char *runtime_plt_and_got
;
621 unsigned int runtime_plt_and_got_offset
;
626 /* The current value can be: */
627 #define VT_VALMASK 0x003f
628 #define VT_CONST 0x0030 /* constant in vc
629 (must be first non register value) */
630 #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
631 #define VT_LOCAL 0x0032 /* offset on stack */
632 #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
633 #define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
634 #define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
635 #define VT_REF 0x0040 /* value is pointer to structure rather than address */
636 #define VT_LVAL 0x0100 /* var is an lvalue */
637 #define VT_SYM 0x0200 /* a symbol value is added */
638 #define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
639 char/short stored in integer registers) */
640 #define VT_MUSTBOUND 0x0800 /* bound checking must be done before
641 dereferencing value */
642 #define VT_BOUNDED 0x8000 /* value is bounded. The address of the
643 bounding function call point is in vc */
644 #define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
645 #define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
646 #define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
647 #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
650 #define VT_INT 0 /* integer type */
651 #define VT_BYTE 1 /* signed byte type */
652 #define VT_SHORT 2 /* short type */
653 #define VT_VOID 3 /* void type */
654 #define VT_PTR 4 /* pointer */
655 #define VT_ENUM 5 /* enum definition */
656 #define VT_FUNC 6 /* function type */
657 #define VT_STRUCT 7 /* struct/union definition */
658 #define VT_FLOAT 8 /* IEEE float */
659 #define VT_DOUBLE 9 /* IEEE double */
660 #define VT_LDOUBLE 10 /* IEEE long double */
661 #define VT_BOOL 11 /* ISOC99 boolean type */
662 #define VT_LLONG 12 /* 64 bit integer */
663 #define VT_LONG 13 /* long integer (NEVER USED as type, only
665 #define VT_BTYPE 0x000f /* mask for basic type */
666 #define VT_UNSIGNED 0x0010 /* unsigned type */
667 #define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
668 #define VT_VLA 0x20000 /* VLA type (also has VT_PTR and VT_ARRAY) */
669 #define VT_BITFIELD 0x0040 /* bitfield modifier */
670 #define VT_CONSTANT 0x0800 /* const modifier */
671 #define VT_VOLATILE 0x1000 /* volatile modifier */
672 #define VT_SIGNED 0x2000 /* signed type */
675 #define VT_EXTERN 0x00000080 /* extern definition */
676 #define VT_STATIC 0x00000100 /* static variable */
677 #define VT_TYPEDEF 0x00000200 /* typedef definition */
678 #define VT_INLINE 0x00000400 /* inline definition */
679 #define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */
680 #define VT_EXPORT 0x00008000 /* win32: data exported from dll */
681 #define VT_WEAK 0x00010000 /* win32: data exported from dll */
683 #define VT_STRUCT_SHIFT 18 /* shift for bitfield shift values */
685 /* type mask (except storage) */
686 #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE | VT_IMPORT | VT_EXPORT | VT_WEAK)
687 #define VT_TYPE (~(VT_STORAGE))
691 /* warning: the following compare tokens depend on i386 asm code */
698 #define TOK_Nset 0x98
699 #define TOK_Nclear 0x99
705 #define TOK_LAND 0xa0
709 #define TOK_MID 0xa3 /* inc/dec, to void constant */
711 #define TOK_UDIV 0xb0 /* unsigned division */
712 #define TOK_UMOD 0xb1 /* unsigned modulo */
713 #define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
714 #define TOK_CINT 0xb3 /* number in tokc */
715 #define TOK_CCHAR 0xb4 /* char constant in tokc */
716 #define TOK_STR 0xb5 /* pointer to string in tokc */
717 #define TOK_TWOSHARPS 0xb6 /* ## preprocessing token */
718 #define TOK_LCHAR 0xb7
719 #define TOK_LSTR 0xb8
720 #define TOK_CFLOAT 0xb9 /* float constant */
721 #define TOK_LINENUM 0xba /* line number info */
722 #define TOK_CDOUBLE 0xc0 /* double constant */
723 #define TOK_CLDOUBLE 0xc1 /* long double constant */
724 #define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
725 #define TOK_ADDC1 0xc3 /* add with carry generation */
726 #define TOK_ADDC2 0xc4 /* add with carry use */
727 #define TOK_SUBC1 0xc5 /* add with carry generation */
728 #define TOK_SUBC2 0xc6 /* add with carry use */
729 #define TOK_CUINT 0xc8 /* unsigned int constant */
730 #define TOK_CLLONG 0xc9 /* long long constant */
731 #define TOK_CULLONG 0xca /* unsigned long long constant */
732 #define TOK_ARROW 0xcb
733 #define TOK_DOTS 0xcc /* three dots */
734 #define TOK_SHR 0xcd /* unsigned shift right */
735 #define TOK_PPNUM 0xce /* preprocessor number */
736 #define TOK_NOSUBST 0xcf /* means following token has already been pp'd */
738 #define TOK_SHL 0x01 /* shift left */
739 #define TOK_SAR 0x02 /* signed shift right */
741 /* assignement operators : normal operator or 0x80 */
742 #define TOK_A_MOD 0xa5
743 #define TOK_A_AND 0xa6
744 #define TOK_A_MUL 0xaa
745 #define TOK_A_ADD 0xab
746 #define TOK_A_SUB 0xad
747 #define TOK_A_DIV 0xaf
748 #define TOK_A_XOR 0xde
749 #define TOK_A_OR 0xfc
750 #define TOK_A_SHL 0x81
751 #define TOK_A_SAR 0x82
754 #define offsetof(type, field) ((size_t) &((type *)0)->field)
758 #define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
761 #define TOK_EOF (-1) /* end of file */
762 #define TOK_LINEFEED 10 /* line feed */
764 /* all identificators and strings have token above that */
765 #define TOK_IDENT 256
767 #define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
768 #define TOK_ASM_int TOK_INT
769 #define TOK_ASM_weak TOK_WEAK1
771 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
772 /* only used for i386 asm opcodes definitions */
774 DEF(TOK_ASM_ ## x ## b, #x "b") \
775 DEF(TOK_ASM_ ## x ## w, #x "w") \
776 DEF(TOK_ASM_ ## x ## l, #x "l") \
777 DEF(TOK_ASM_ ## x, #x)
779 DEF(TOK_ASM_ ## x ## w, #x "w") \
780 DEF(TOK_ASM_ ## x ## l, #x "l") \
781 DEF(TOK_ASM_ ## x, #x)
782 #ifdef TCC_TARGET_X86_64
783 # define DEF_BWLQ(x) \
784 DEF(TOK_ASM_ ## x ## b, #x "b") \
785 DEF(TOK_ASM_ ## x ## w, #x "w") \
786 DEF(TOK_ASM_ ## x ## l, #x "l") \
787 DEF(TOK_ASM_ ## x ## q, #x "q") \
788 DEF(TOK_ASM_ ## x, #x)
789 # define DEF_WLQ(x) \
790 DEF(TOK_ASM_ ## x ## w, #x "w") \
791 DEF(TOK_ASM_ ## x ## l, #x "l") \
792 DEF(TOK_ASM_ ## x ## q, #x "q") \
793 DEF(TOK_ASM_ ## x, #x)
794 # define DEF_BWLX DEF_BWLQ
795 # define DEF_WLX DEF_WLQ
796 /* number of sizes + 1 */
799 # define DEF_BWLX DEF_BWL
800 # define DEF_WLX DEF_WL
801 /* number of sizes + 1 */
806 DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
807 DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
808 DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
809 DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
812 DEF(TOK_ASM_ ## f ## x, "f" #x ) \
813 DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
816 #define DEF_ASMTEST(x) \
848 #endif // defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
851 TOK_LAST
= TOK_IDENT
- 1,
852 #define DEF(id, str) id,
857 #define TOK_UIDENT TOK_DEFINE
860 #define snprintf _snprintf
861 #define vsnprintf _vsnprintf
863 #define strtold (long double)strtod
864 #define strtof (float)strtod
865 #define strtoll (long long)strtol
867 #elif defined(TCC_UCLIBC) || defined(__FreeBSD__) \
868 || defined(__FreeBSD_kernel__) || defined(__DragonFly__) \
869 || defined(__OpenBSD__)
870 /* currently incorrect */
871 static inline long double strtold(const char *nptr
, char **endptr
)
873 return (long double)strtod(nptr
, endptr
);
875 static inline float strtof(const char *nptr
, char **endptr
)
877 return (float)strtod(nptr
, endptr
);
880 /* XXX: need to define this to use them in non ISOC99 context */
881 extern float strtof (const char *__nptr
, char **__endptr
);
882 extern long double strtold (const char *__nptr
, char **__endptr
);
886 #define IS_DIRSEP(c) (c == '/' || c == '\\')
887 #define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
888 #define PATHCMP stricmp
890 #define IS_DIRSEP(c) (c == '/')
891 #define IS_ABSPATH(p) IS_DIRSEP(p[0])
892 #define PATHCMP strcmp
901 /* space exlcuding newline */
902 static inline int is_space(int ch
)
904 return ch
== ' ' || ch
== '\t' || ch
== '\v' || ch
== '\f' || ch
== '\r';
907 static inline int isid(int c
)
909 return (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z') || c
== '_';
912 static inline int isnum(int c
)
914 return c
>= '0' && c
<= '9';
917 static inline int isoct(int c
)
919 return c
>= '0' && c
<= '7';
922 static inline int toup(int c
)
924 return (c
>= 'a' && c
<= 'z') ? c
- 'a' + 'A' : c
;
930 #define ST_INLN static inline
931 #define ST_FUNC static
932 #define ST_DATA static
936 #define ST_DATA extern
939 /* ------------ libtcc.c ------------ */
941 /* use GNU C extensions */
943 /* use Tiny C extensions */
945 /* XXX: get rid of this ASAP */
946 ST_DATA
struct TCCState
*tcc_state
;
948 #ifdef CONFIG_TCC_BACKTRACE
949 ST_DATA
int num_callers
;
950 ST_DATA
const char **rt_bound_error_msg
;
951 ST_DATA
void *rt_prog_main
;
954 #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */
955 #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */
956 #define AFF_PREPROCESS 0x0004 /* preprocess file */
958 /* public functions currently used by the tcc main function */
959 PUB_FUNC
char *pstrcpy(char *buf
, int buf_size
, const char *s
);
960 PUB_FUNC
char *pstrcat(char *buf
, int buf_size
, const char *s
);
961 PUB_FUNC
char *pstrncpy(char *out
, const char *in
, size_t num
);
962 PUB_FUNC
char *tcc_basename(const char *name
);
963 PUB_FUNC
char *tcc_fileextension (const char *name
);
964 PUB_FUNC
void tcc_free(void *ptr
);
965 PUB_FUNC
void *tcc_malloc(unsigned long size
);
966 PUB_FUNC
void *tcc_mallocz(unsigned long size
);
967 PUB_FUNC
void *tcc_realloc(void *ptr
, unsigned long size
);
968 PUB_FUNC
char *tcc_strdup(const char *str
);
969 #define free(p) use_tcc_free(p)
970 #define malloc(s) use_tcc_malloc(s)
971 #define realloc(p, s) use_tcc_realloc(p, s)
973 #define strdup(s) use_tcc_strdup(s)
974 PUB_FUNC
void tcc_memstats(void);
975 PUB_FUNC
void dynarray_add(void ***ptab
, int *nb_ptr
, void *data
);
976 PUB_FUNC
void dynarray_reset(void *pp
, int *n
);
977 PUB_FUNC
void error_noabort(const char *fmt
, ...);
978 PUB_FUNC
void error(const char *fmt
, ...);
979 PUB_FUNC
void expect(const char *msg
);
980 PUB_FUNC
void warning(const char *fmt
, ...);
982 /* other utilities */
983 ST_INLN
void cstr_ccat(CString
*cstr
, int ch
);
984 ST_FUNC
void cstr_cat(CString
*cstr
, const char *str
);
985 ST_FUNC
void cstr_wccat(CString
*cstr
, int ch
);
986 ST_FUNC
void cstr_new(CString
*cstr
);
987 ST_FUNC
void cstr_free(CString
*cstr
);
988 ST_FUNC
void add_char(CString
*cstr
, int c
);
989 #define cstr_reset(cstr) cstr_free(cstr)
991 ST_FUNC Section
*new_section(TCCState
*s1
, const char *name
, int sh_type
, int sh_flags
);
992 ST_FUNC
void section_realloc(Section
*sec
, unsigned long new_size
);
993 ST_FUNC
void *section_ptr_add(Section
*sec
, unsigned long size
);
994 ST_FUNC
void section_reserve(Section
*sec
, unsigned long size
);
995 ST_FUNC Section
*find_section(TCCState
*s1
, const char *name
);
997 ST_FUNC
void put_extern_sym2(Sym
*sym
, Section
*section
, unsigned long value
, unsigned long size
, int can_add_underscore
);
998 ST_FUNC
void put_extern_sym(Sym
*sym
, Section
*section
, unsigned long value
, unsigned long size
);
999 ST_FUNC
void greloc(Section
*s
, Sym
*sym
, unsigned long offset
, int type
);
1001 ST_INLN
void sym_free(Sym
*sym
);
1002 ST_FUNC Sym
*sym_push2(Sym
**ps
, int v
, int t
, long c
);
1003 ST_FUNC Sym
*sym_find2(Sym
*s
, int v
);
1004 ST_FUNC Sym
*sym_push(int v
, CType
*type
, int r
, int c
);
1005 ST_FUNC
void sym_pop(Sym
**ptop
, Sym
*b
);
1006 ST_INLN Sym
*struct_find(int v
);
1007 ST_INLN Sym
*sym_find(int v
);
1008 ST_FUNC Sym
*global_identifier_push(int v
, int t
, int c
);
1010 ST_FUNC
void tcc_open_bf(TCCState
*s1
, const char *filename
, int initlen
);
1011 ST_FUNC
int tcc_open(TCCState
*s1
, const char *filename
);
1012 ST_FUNC
void tcc_close(void);
1014 ST_FUNC
int tcc_add_file_internal(TCCState
*s1
, const char *filename
, int flags
);
1015 ST_FUNC
int tcc_add_dll(TCCState
*s
, const char *filename
, int flags
);
1016 ST_FUNC
int tcc_add_crt(TCCState
*s
, const char *filename
);
1017 PUB_FUNC
int tcc_set_flag(TCCState
*s
, const char *flag_name
, int value
);
1018 PUB_FUNC
void tcc_print_stats(TCCState
*s
, int64_t total_time
);
1019 PUB_FUNC
void set_num_callers(int n
);
1021 PUB_FUNC
char *tcc_default_target(TCCState
*s
, const char *default_file
);
1022 PUB_FUNC
void tcc_gen_makedeps(TCCState
*s
, const char *target
, const char *filename
);
1024 /* ------------ tccpp.c ------------ */
1026 ST_DATA
struct BufferedFile
*file
;
1027 ST_DATA
int ch
, tok
;
1028 ST_DATA CValue tokc
;
1029 ST_DATA
const int *macro_ptr
;
1030 ST_DATA
int parse_flags
;
1031 ST_DATA
int tok_flags
;
1032 ST_DATA CString tokcstr
; /* current parsed string, if any */
1034 /* display benchmark infos */
1035 ST_DATA
int total_lines
;
1036 ST_DATA
int total_bytes
;
1037 ST_DATA
int tok_ident
;
1038 ST_DATA TokenSym
**table_ident
;
1040 #define TOK_FLAG_BOL 0x0001 /* beginning of line before */
1041 #define TOK_FLAG_BOF 0x0002 /* beginning of file before */
1042 #define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
1043 #define TOK_FLAG_EOF 0x0008 /* end of file */
1045 #define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
1046 #define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
1047 #define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
1048 token. line feed is also
1050 #define PARSE_FLAG_ASM_COMMENTS 0x0008 /* '#' can be used for line comment */
1051 #define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
1053 ST_FUNC TokenSym
*tok_alloc(const char *str
, int len
);
1054 ST_FUNC
char *get_tok_str(int v
, CValue
*cv
);
1055 ST_FUNC
void save_parse_state(ParseState
*s
);
1056 ST_FUNC
void restore_parse_state(ParseState
*s
);
1057 ST_INLN
void tok_str_new(TokenString
*s
);
1058 ST_FUNC
void tok_str_free(int *str
);
1059 ST_FUNC
void tok_str_add(TokenString
*s
, int t
);
1060 ST_FUNC
void tok_str_add_tok(TokenString
*s
);
1061 ST_INLN
void define_push(int v
, int macro_type
, int *str
, Sym
*first_arg
);
1062 ST_FUNC
void define_undef(Sym
*s
);
1063 ST_INLN Sym
*define_find(int v
);
1064 ST_FUNC
void free_defines(Sym
*b
);
1065 ST_FUNC Sym
*label_find(int v
);
1066 ST_FUNC Sym
*label_push(Sym
**ptop
, int v
, int flags
);
1067 ST_FUNC
void label_pop(Sym
**ptop
, Sym
*slast
);
1068 ST_FUNC
void parse_define(void);
1069 ST_FUNC
void preprocess(int is_bof
);
1070 ST_FUNC
void next_nomacro(void);
1071 ST_FUNC
void next(void);
1072 ST_INLN
void unget_tok(int last_tok
);
1073 ST_FUNC
void preprocess_init(TCCState
*s1
);
1074 ST_FUNC
void preprocess_new();
1075 ST_FUNC
int tcc_preprocess(TCCState
*s1
);
1076 ST_FUNC
void skip(int c
);
1078 /* ------------ tccgen.c ------------ */
1080 ST_DATA Section
*text_section
, *data_section
, *bss_section
; /* predefined sections */
1081 ST_DATA Section
*cur_text_section
; /* current section where function code is generated */
1082 #ifdef CONFIG_TCC_ASM
1083 ST_DATA Section
*last_text_section
; /* to handle .previous asm directive */
1085 #ifdef CONFIG_TCC_BCHECK
1086 /* bound check related sections */
1087 ST_DATA Section
*bounds_section
; /* contains global data bound description */
1088 ST_DATA Section
*lbounds_section
; /* contains local data bound description */
1090 /* symbol sections */
1091 ST_DATA Section
*symtab_section
, *strtab_section
;
1092 /* debug sections */
1093 ST_DATA Section
*stab_section
, *stabstr_section
;
1095 #define SYM_POOL_NB (8192 / sizeof(Sym))
1096 ST_DATA Sym
*sym_free_first
;
1097 ST_DATA
void **sym_pools
;
1098 ST_DATA
int nb_sym_pools
;
1100 ST_DATA Sym
*global_stack
;
1101 ST_DATA Sym
*local_stack
;
1102 ST_DATA Sym
*local_label_stack
;
1103 ST_DATA Sym
*global_label_stack
;
1104 ST_DATA Sym
*define_stack
;
1105 ST_DATA CType char_pointer_type
, func_old_type
, int_type
;
1106 ST_DATA SValue vstack
[VSTACK_SIZE
], *vtop
;
1107 ST_DATA
int rsym
, anon_sym
, ind
, loc
;
1109 ST_DATA
int const_wanted
; /* true if constant wanted */
1110 ST_DATA
int nocode_wanted
; /* true if no code generation wanted for an expression */
1111 ST_DATA
int global_expr
; /* true if compound literals must be allocated globally (used during initializers parsing */
1112 ST_DATA CType func_vt
; /* current function return type (used by return instruction) */
1113 ST_DATA
int func_vc
;
1114 ST_DATA
int last_line_num
, last_ind
, func_ind
; /* debug last line number and pc */
1115 ST_DATA
char *funcname
;
1117 ST_INLN
int is_float(int t
);
1118 ST_FUNC
int ieee_finite(double d
);
1119 ST_FUNC
void test_lvalue(void);
1120 ST_FUNC
void swap(int *p
, int *q
);
1121 ST_FUNC
void vpushi(int v
);
1122 ST_FUNC Sym
*external_global_sym(int v
, CType
*type
, int r
);
1123 ST_FUNC
void vset(CType
*type
, int r
, int v
);
1124 ST_FUNC
void vswap(void);
1125 ST_FUNC
void vpush_global_sym(CType
*type
, int v
);
1126 ST_FUNC
void vrott(int n
);
1127 #ifdef TCC_TARGET_ARM
1128 ST_FUNC
int get_reg_ex(int rc
, int rc2
);
1129 ST_FUNC
void vnrott(int n
);
1130 ST_FUNC
void lexpand_nr(void);
1132 ST_FUNC
void vpushv(SValue
*v
);
1133 ST_FUNC
void save_reg(int r
);
1134 ST_FUNC
int get_reg(int rc
);
1135 ST_FUNC
void save_regs(int n
);
1136 ST_FUNC
int gv(int rc
);
1137 ST_FUNC
void gv2(int rc1
, int rc2
);
1138 ST_FUNC
void vpop(void);
1139 ST_FUNC
void gen_op(int op
);
1140 ST_FUNC
int type_size(CType
*type
, int *a
);
1141 ST_FUNC
void mk_pointer(CType
*type
);
1142 ST_FUNC
void vstore(void);
1143 ST_FUNC
void inc(int post
, int c
);
1144 ST_FUNC
void parse_asm_str(CString
*astr
);
1145 ST_FUNC
int lvalue_type(int t
);
1146 ST_FUNC
void indir(void);
1147 ST_FUNC
void unary(void);
1148 ST_FUNC
void expr_prod(void);
1149 ST_FUNC
void expr_sum(void);
1150 ST_FUNC
void gexpr(void);
1151 ST_FUNC
int expr_const(void);
1152 ST_FUNC
void gen_inline_functions(void);
1153 ST_FUNC
void decl(int l
);
1154 #if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
1155 ST_FUNC Sym
*get_sym_ref(CType
*type
, Section
*sec
, unsigned long offset
, unsigned long size
);
1158 /* ------------ tccelf.c ------------ */
1160 #define ARMAG "!<arch>\012" /* For COFF and a.out archives */
1163 unsigned int n_strx
; /* index into string table of name */
1164 unsigned char n_type
; /* type of symbol */
1165 unsigned char n_other
; /* misc info (usually empty) */
1166 unsigned short n_desc
; /* description field */
1167 unsigned int n_value
; /* value of symbol */
1170 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
);
1172 ST_FUNC
int put_elf_str(Section
*s
, const char *sym
);
1173 ST_FUNC
int put_elf_sym(Section
*s
, uplong value
, unsigned long size
, int info
, int other
, int shndx
, const char *name
);
1174 ST_FUNC
int add_elf_sym(Section
*s
, uplong value
, unsigned long size
, int info
, int other
, int sh_num
, const char *name
);
1175 ST_FUNC
int find_elf_sym(Section
*s
, const char *name
);
1176 ST_FUNC
void put_elf_reloc(Section
*symtab
, Section
*s
, unsigned long offset
, int type
, int symbol
);
1178 ST_FUNC
void put_stabs(const char *str
, int type
, int other
, int desc
, unsigned long value
);
1179 ST_FUNC
void put_stabs_r(const char *str
, int type
, int other
, int desc
, unsigned long value
, Section
*sec
, int sym_index
);
1180 ST_FUNC
void put_stabn(int type
, int other
, int desc
, int value
);
1181 ST_FUNC
void put_stabd(int type
, int other
, int desc
);
1183 ST_FUNC
void relocate_common_syms(void);
1184 ST_FUNC
void relocate_syms(TCCState
*s1
, int do_resolve
);
1185 ST_FUNC
void relocate_section(TCCState
*s1
, Section
*s
);
1187 ST_FUNC
void tcc_add_linker_symbols(TCCState
*s1
);
1188 ST_FUNC
int tcc_load_object_file(TCCState
*s1
, int fd
, unsigned long file_offset
);
1189 ST_FUNC
int tcc_load_archive(TCCState
*s1
, int fd
);
1190 ST_FUNC
void *tcc_get_symbol_err(TCCState
*s
, const char *name
);
1191 ST_FUNC
void tcc_add_bcheck(TCCState
*s1
);
1193 ST_FUNC
void build_got_entries(TCCState
*s1
);
1194 ST_FUNC
void tcc_add_runtime(TCCState
*s1
);
1196 #ifndef TCC_TARGET_PE
1197 ST_FUNC
int tcc_load_dll(TCCState
*s1
, int fd
, const char *filename
, int level
);
1198 ST_FUNC
int tcc_load_ldscript(TCCState
*s1
);
1199 ST_FUNC
uint8_t *parse_comment(uint8_t *p
);
1200 ST_FUNC
void minp(void);
1201 ST_INLN
void inp(void);
1202 ST_FUNC
int handle_eob(void);
1205 #ifdef TCC_TARGET_X86_64
1206 # define ELFCLASSW ELFCLASS64
1207 # define ElfW(type) Elf##64##_##type
1208 # define ELFW(type) ELF##64##_##type
1209 # define ElfW_Rel ElfW(Rela)
1210 # define SHT_RELX SHT_RELA
1211 # define REL_SECTION_FMT ".rela%s"
1212 /* XXX: DLL with PLT would only work with x86-64 for now */
1213 # define TCC_OUTPUT_DLL_WITH_PLT
1215 # define ELFCLASSW ELFCLASS32
1216 # define ElfW(type) Elf##32##_##type
1217 # define ELFW(type) ELF##32##_##type
1218 # define ElfW_Rel ElfW(Rel)
1219 # define SHT_RELX SHT_REL
1220 # define REL_SECTION_FMT ".rel%s"
1223 /* ------------ xxx-gen.c ------------ */
1225 ST_FUNC
void gsym_addr(int t
, int a
);
1226 ST_FUNC
void gsym(int t
);
1227 ST_FUNC
void load(int r
, SValue
*sv
);
1228 ST_FUNC
void store(int r
, SValue
*v
);
1229 ST_FUNC
void gfunc_call(int nb_args
);
1230 ST_FUNC
void gfunc_prolog(CType
*func_type
);
1231 ST_FUNC
void gfunc_epilog(void);
1232 ST_FUNC
int gjmp(int t
);
1233 ST_FUNC
void gjmp_addr(int a
);
1234 ST_FUNC
int gtst(int inv
, int t
);
1235 ST_FUNC
void gen_opi(int op
);
1236 ST_FUNC
void gen_opf(int op
);
1237 ST_FUNC
void gen_cvt_ftoi(int t
);
1238 ST_FUNC
void gen_cvt_ftof(int t
);
1239 ST_FUNC
void ggoto(void);
1240 #ifndef TCC_TARGET_C67
1241 ST_FUNC
void o(unsigned int c
);
1243 #ifndef TCC_TARGET_ARM
1244 ST_FUNC
void gen_cvt_itof(int t
);
1247 /* ------------ i386-gen.c ------------ */
1248 #if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1249 ST_FUNC
void g(int c
);
1250 ST_FUNC
int oad(int c
, int s
);
1251 ST_FUNC
void gen_le16(int c
);
1252 ST_FUNC
void gen_le32(int c
);
1253 ST_FUNC
void gen_addr32(int r
, Sym
*sym
, int c
);
1254 ST_FUNC
void gen_addrpc32(int r
, Sym
*sym
, int c
);
1257 #ifdef CONFIG_TCC_BCHECK
1258 ST_FUNC
void gen_bounded_ptr_add(void);
1259 ST_FUNC
void gen_bounded_ptr_deref(void);
1262 /* ------------ x86_64-gen.c ------------ */
1263 #ifdef TCC_TARGET_X86_64
1264 ST_FUNC
void gen_addr64(int r
, Sym
*sym
, int64_t c
);
1267 /* ------------ arm-gen.c ------------ */
1268 #ifdef TCC_TARGET_ARM
1269 ST_FUNC
uint32_t encbranch(int pos
, int addr
, int fail
);
1270 ST_FUNC
void gen_cvt_itof1(int t
);
1273 /* ------------ c67-gen.c ------------ */
1274 #ifdef TCC_TARGET_C67
1277 /* ------------ tcccoff.c ------------ */
1279 #ifdef TCC_TARGET_COFF
1280 ST_FUNC
int tcc_output_coff(TCCState
*s1
, FILE *f
);
1281 ST_FUNC
int tcc_load_coff(TCCState
* s1
, int fd
);
1284 /* ------------ tccasm.c ------------ */
1285 ST_FUNC
void asm_instr(void);
1286 ST_FUNC
void asm_global_instr(void);
1288 #ifdef CONFIG_TCC_ASM
1289 ST_FUNC
int find_constraint(ASMOperand
*operands
, int nb_operands
, const char *name
, const char **pp
);
1290 ST_FUNC
void asm_expr(TCCState
*s1
, ExprValue
*pe
);
1291 ST_FUNC
int asm_int_expr(TCCState
*s1
);
1292 ST_FUNC
int tcc_assemble(TCCState
*s1
, int do_preprocess
);
1293 /* ------------ i386-asm.c ------------ */
1294 ST_FUNC
void gen_expr32(ExprValue
*pe
);
1295 ST_FUNC
void asm_opcode(TCCState
*s1
, int opcode
);
1296 ST_FUNC
void asm_compute_constraints(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, const uint8_t *clobber_regs
, int *pout_reg
);
1297 ST_FUNC
void subst_asm_operand(CString
*add_str
, SValue
*sv
, int modifier
);
1298 ST_FUNC
void asm_gen_code(ASMOperand
*operands
, int nb_operands
, int nb_outputs
, int is_output
, uint8_t *clobber_regs
, int out_reg
);
1299 ST_FUNC
void asm_clobber(uint8_t *clobber_regs
, const char *str
);
1301 /* ------------ tccpe.c -------------- */
1302 #ifdef TCC_TARGET_PE
1303 ST_FUNC
int pe_load_file(struct TCCState
*s1
, const char *filename
, int fd
);
1304 ST_FUNC
int pe_output_file(TCCState
* s1
, const char *filename
);
1305 ST_FUNC
int pe_putimport(TCCState
*s1
, int dllindex
, const char *name
, const void *value
);
1306 ST_FUNC SValue
*pe_getimport(SValue
*sv
, SValue
*v2
);
1308 ST_FUNC
char *get_export_names(FILE *fp
);
1309 #ifdef TCC_TARGET_X86_64
1310 ST_FUNC
void pe_add_unwind_data(unsigned start
, unsigned end
, unsigned stack
);
1314 /* ------------ tccrun.c ----------------- */
1315 #ifdef CONFIG_TCC_STATIC
1316 #define RTLD_LAZY 0x001
1317 #define RTLD_NOW 0x002
1318 #define RTLD_GLOBAL 0x100
1319 #define RTLD_DEFAULT NULL
1320 /* dummy function for profiling */
1321 ST_FUNC
void *dlopen(const char *filename
, int flag
);
1322 ST_FUNC
void dlclose(void *p
);
1323 //ST_FUNC const char *dlerror(void);
1324 ST_FUNC
void *resolve_sym(TCCState
*s1
, const char *symbol
);
1325 #elif !defined TCC_TARGET_PE || !defined _WIN32
1326 ST_FUNC
void *resolve_sym(TCCState
*s1
, const char *symbol
);
1328 /********************************************************/
1329 /* include the target specific definitions */
1331 #define TARGET_DEFS_ONLY
1332 #ifdef TCC_TARGET_I386
1333 #include "i386-gen.c"
1335 #ifdef TCC_TARGET_X86_64
1336 #include "x86_64-gen.c"
1338 #ifdef TCC_TARGET_ARM
1339 #include "arm-gen.c"
1341 #ifdef TCC_TARGET_C67
1343 #include "c67-gen.c"
1345 #undef TARGET_DEFS_ONLY
1347 ST_DATA
const int reg_classes
[NB_REGS
];
1349 /********************************************************/
1352 #define ST_DATA static
1356 /********************************************************/