diff options
| author | grischka <grischka> | 2013-02-12 19:13:28 +0100 |
|---|---|---|
| committer | grischka <grischka> | 2013-02-12 19:13:28 +0100 |
| commit | 05108a3b0a8eff70739b253b8995999b1861f9f2 (patch) | |
| tree | 690c17ebe3cd0479e278bc3b65e00eba7ec674fd /tcc.h | |
| parent | 829655949b7964c66e1f7da9d44c19655dba88aa (diff) | |
| download | tinycc-05108a3b0a8eff70739b253b8995999b1861f9f2.tar.gz tinycc-05108a3b0a8eff70739b253b8995999b1861f9f2.tar.bz2 | |
libtcc: new LIBTCCAPI tcc_set_options(TCCState*, const char*str)
This replaces -> use instead:
-----------------------------------
- tcc_set_linker -> tcc_set_options(s, "-Wl,...");
- tcc_set_warning -> tcc_set_options(s, "-W...");
- tcc_enable_debug -> tcc_set_options(s, "-g");
parse_args is moved to libtcc.c (now tcc_parse_args).
Also some cleanups:
- reorder TCCState members
- add some comments here and there
- do not use argv's directly, make string copies
- use const char* in tcc_set_linker
- tccpe: use fd instead of fp
tested with -D MEM_DEBUG: 0 bytes left
Diffstat (limited to 'tcc.h')
| -rw-r--r-- | tcc.h | 328 |
1 files changed, 158 insertions, 170 deletions
@@ -25,10 +25,8 @@ #include "config.h" #ifdef CONFIG_TCCBOOT - #include "tccboot.h" #define CONFIG_TCC_STATIC - #else #include <stdlib.h> @@ -70,16 +68,8 @@ #endif /* !CONFIG_TCCBOOT */ -#ifndef PAGESIZE -#define PAGESIZE 4096 -#endif - #ifndef O_BINARY -#define O_BINARY 0 -#endif - -#ifndef SA_SIGINFO -#define SA_SIGINFO 0x00000004u +# define O_BINARY 0 #endif #include "elf.h" @@ -516,82 +506,22 @@ struct sym_attr { }; struct TCCState { - unsigned output_type : 8; - unsigned reloc_output : 1; - - BufferedFile **include_stack_ptr; - int *ifdef_stack_ptr; - - /* include file handling */ - char **include_paths; - int nb_include_paths; - char **sysinclude_paths; - int nb_sysinclude_paths; - CachedInclude **cached_includes; - int nb_cached_includes; - - char **library_paths; - int nb_library_paths; - char **crt_paths; - int nb_crt_paths; - - /* array of all loaded dlls (including those referenced by loaded - dlls) */ - DLLReference **loaded_dlls; - int nb_loaded_dlls; - - /* sections */ - Section **sections; - int nb_sections; /* number of sections, including first dummy section */ - - Section **priv_sections; - int nb_priv_sections; /* number of private sections */ - - /* got & plt handling */ - Section *got; - Section *plt; - struct sym_attr *sym_attrs; - int nb_sym_attrs; - /* give the correspondance from symtab indexes to dynsym indexes */ - int *symtab_to_dynsym; - - /* temporary dynamic symbol sections (for dll loading) */ - Section *dynsymtab_section; - /* exported dynamic symbol section */ - Section *dynsym; - - /* copy of the gobal symtab_section variable */ - Section *symtab; + int verbose; /* if true, display some information during compilation */ int nostdinc; /* if true, no standard headers are added */ int nostdlib; /* if true, no standard libraries are added */ int nocommon; /* if true, do not use common symbols for .bss data */ + int static_link; /* if true, static linking is performed */ + int rdynamic; /* if true, all symbols are exported */ + int symbolic; /* if true, resolve symbols in the current module first */ + int alacarte_link; /* if true, only link in referenced objects from archive */ - /* if true, static linking is performed */ - int static_link; - - /* soname as specified on the command line (-soname) */ - const char *soname; - /* rpath as specified on the command line (-Wl,-rpath=) */ - const char *rpath; - - /* if true, all symbols are exported */ - int rdynamic; - - /* if true, resolve symbols in the current module first (-Wl,Bsymbolic) */ - int symbolic; - - /* if true, only link in referenced objects from archive */ - int alacarte_link; - - /* address of text section */ - addr_t text_addr; - int has_text_addr; + char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ + char *soname; /* as specified on the command line (-soname) */ + char *rpath; /* as specified on the command line (-Wl,-rpath=) */ - /* symbols to call at load-time / unload-time */ - const char *init_symbol; - const char *fini_symbol; - + /* output type, see TCC_OUTPUT_XXX */ + int output_type; /* output format, see TCC_OUTPUT_FORMAT_xxx */ int output_format; @@ -606,16 +536,43 @@ struct TCCState { int warn_none; int warn_implicit_function_declaration; - /* display some information during compilation */ - int verbose; /* compile with debug symbol (and use them if error during execution) */ int do_debug; #ifdef CONFIG_TCC_BCHECK /* compile with built-in memory and bounds checker */ int do_bounds_check; #endif - /* give the path of the tcc libraries */ - char *tcc_lib_path; + + addr_t text_addr; /* address of text section */ + int has_text_addr; + + unsigned long section_align; /* section alignment */ + + char *init_symbol; /* symbols to call at load-time (not used currently) */ + char *fini_symbol; /* symbols to call at unload-time (not used currently) */ + +#ifdef TCC_TARGET_I386 + int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */ +#endif + + /* array of all loaded dlls (including those referenced by loaded dlls) */ + DLLReference **loaded_dlls; + int nb_loaded_dlls; + + /* include paths */ + char **include_paths; + int nb_include_paths; + + char **sysinclude_paths; + int nb_sysinclude_paths; + + /* library paths */ + char **library_paths; + int nb_library_paths; + + /* crt?.o object path */ + char **crt_paths; + int nb_crt_paths; /* error handling */ void *error_opaque; @@ -624,72 +581,101 @@ struct TCCState { jmp_buf error_jmp_buf; int nb_errors; - /* tiny assembler state */ - Sym *asm_labels; + /* output file for preprocessing (-E) */ + FILE *ppfp; - /* see include_stack_ptr */ + /* for -MD/-MF: collected dependencies for this compilation */ + char **target_deps; + int nb_target_deps; + + /* compilation */ BufferedFile *include_stack[INCLUDE_STACK_SIZE]; + BufferedFile **include_stack_ptr; - /* see ifdef_stack_ptr */ int ifdef_stack[IFDEF_STACK_SIZE]; + int *ifdef_stack_ptr; - /* see cached_includes */ + /* included files enclosed with #ifndef MACRO */ int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE]; + CachedInclude **cached_includes; + int nb_cached_includes; - /* pack stack */ + /* #pragma pack stack */ int pack_stack[PACK_STACK_SIZE]; int *pack_stack_ptr; - /* output file for preprocessing */ - FILE *outfile; - - /* automatically collected dependencies for this compilation */ - char **target_deps; - int nb_target_deps; - - /* for tcc_relocate */ - int runtime_added; - void *runtime_mem; -#ifdef HAVE_SELINUX - void *write_mem; - unsigned long mem_size; -#endif - + /* inline functions are stored as token lists and compiled last + only if referenced */ struct InlineFunc **inline_fns; int nb_inline_fns; -#ifdef TCC_TARGET_I386 - int seg_size; -#endif + /* sections */ + Section **sections; + int nb_sections; /* number of sections, including first dummy section */ + + Section **priv_sections; + int nb_priv_sections; /* number of private sections */ + + /* got & plt handling */ + Section *got; + Section *plt; + struct sym_attr *sym_attrs; + int nb_sym_attrs; + /* give the correspondance from symtab indexes to dynsym indexes */ + int *symtab_to_dynsym; - /* section alignment */ - unsigned long section_align; + /* temporary dynamic symbol sections (for dll loading) */ + Section *dynsymtab_section; + /* exported dynamic symbol section */ + Section *dynsym; + /* copy of the gobal symtab_section variable */ + Section *symtab; + /* tiny assembler state */ + Sym *asm_labels; #ifdef TCC_TARGET_PE /* PE info */ int pe_subsystem; - unsigned long pe_file_align; - unsigned long pe_stack_size; -#ifdef TCC_TARGET_X86_64 + unsigned pe_file_align; + unsigned pe_stack_size; +# ifdef TCC_TARGET_X86_64 Section *uw_pdata; int uw_sym; unsigned uw_offs; -#endif +# endif #endif -#if defined TCC_IS_NATIVE && !defined TCC_TARGET_PE \ - && (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) +#ifdef TCC_IS_NATIVE + /* for tcc_relocate */ + void *runtime_mem; +# ifdef HAVE_SELINUX + void *write_mem; + unsigned long mem_size; +# endif +# if !defined TCC_TARGET_PE && (defined TCC_TARGET_X86_64 || defined TCC_TARGET_ARM) /* write PLT and GOT here */ char *runtime_plt_and_got; - unsigned int runtime_plt_and_got_offset; -# define TCC_HAS_RUNTIME_PLTGOT + unsigned runtime_plt_and_got_offset; +# define TCC_HAS_RUNTIME_PLTGOT +# endif #endif + + /* used by main and tcc_parse_args only */ + char **files; /* files seen on command line */ + int nb_files; /* number thereof */ + int nb_libraries; /* number of libs thereof */ + char *outfile; /* output filename */ + char *option_m; /* only -m32/-m64 handled */ + int print_search_dirs; /* option */ + int option_r; /* option -r */ + int do_bench; /* option -bench */ + int gen_deps; /* option -MD */ + char *deps_outfile; /* option -MF */ }; /* The current value can be: */ -#define VT_VALMASK 0x003f -#define VT_CONST 0x0030 /* constant in vc - (must be first non register value) */ +#define VT_VALMASK 0x003f /* mask for value location, register or: */ +#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */ #define VT_LLOCAL 0x0031 /* lvalue, offset on stack */ #define VT_LOCAL 0x0032 /* offset on stack */ #define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */ @@ -710,29 +696,29 @@ struct TCCState { #define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED) /* types */ -#define VT_INT 0 /* integer type */ -#define VT_BYTE 1 /* signed byte type */ -#define VT_SHORT 2 /* short type */ -#define VT_VOID 3 /* void type */ -#define VT_PTR 4 /* pointer */ -#define VT_ENUM 5 /* enum definition */ -#define VT_FUNC 6 /* function type */ -#define VT_STRUCT 7 /* struct/union definition */ -#define VT_FLOAT 8 /* IEEE float */ -#define VT_DOUBLE 9 /* IEEE double */ -#define VT_LDOUBLE 10 /* IEEE long double */ -#define VT_BOOL 11 /* ISOC99 boolean type */ -#define VT_LLONG 12 /* 64 bit integer */ -#define VT_LONG 13 /* long integer (NEVER USED as type, only - during parsing) */ -#define VT_BTYPE 0x000f /* mask for basic type */ -#define VT_UNSIGNED 0x0010 /* unsigned type */ -#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */ -#define VT_VLA 0x20000 /* VLA type (also has VT_PTR and VT_ARRAY) */ -#define VT_BITFIELD 0x0040 /* bitfield modifier */ -#define VT_CONSTANT 0x0800 /* const modifier */ -#define VT_VOLATILE 0x1000 /* volatile modifier */ -#define VT_SIGNED 0x2000 /* signed type */ +#define VT_BTYPE 0x000f /* mask for basic type */ +#define VT_INT 0 /* integer type */ +#define VT_BYTE 1 /* signed byte type */ +#define VT_SHORT 2 /* short type */ +#define VT_VOID 3 /* void type */ +#define VT_PTR 4 /* pointer */ +#define VT_ENUM 5 /* enum definition */ +#define VT_FUNC 6 /* function type */ +#define VT_STRUCT 7 /* struct/union definition */ +#define VT_FLOAT 8 /* IEEE float */ +#define VT_DOUBLE 9 /* IEEE double */ +#define VT_LDOUBLE 10 /* IEEE long double */ +#define VT_BOOL 11 /* ISOC99 boolean type */ +#define VT_LLONG 12 /* 64 bit integer */ +#define VT_LONG 13 /* long integer (NEVER USED as type, only + during parsing) */ +#define VT_UNSIGNED 0x0010 /* unsigned type */ +#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */ +#define VT_BITFIELD 0x0040 /* bitfield modifier */ +#define VT_CONSTANT 0x0800 /* const modifier */ +#define VT_VOLATILE 0x1000 /* volatile modifier */ +#define VT_SIGNED 0x2000 /* signed type */ +#define VT_VLA 0x00020000 /* VLA type (also has VT_PTR and VT_ARRAY) */ /* storage */ #define VT_EXTERN 0x00000080 /* extern definition */ @@ -741,13 +727,13 @@ struct TCCState { #define VT_INLINE 0x00000400 /* inline definition */ #define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */ #define VT_EXPORT 0x00008000 /* win32: data exported from dll */ -#define VT_WEAK 0x00010000 /* win32: data exported from dll */ +#define VT_WEAK 0x00010000 /* weak symbol */ -#define VT_STRUCT_SHIFT 18 /* shift for bitfield shift values */ +#define VT_STRUCT_SHIFT 18 /* shift for bitfield shift values (max: 32 - 2*6) */ /* type mask (except storage) */ #define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE | VT_IMPORT | VT_EXPORT | VT_WEAK) -#define VT_TYPE (~(VT_STORAGE)) +#define VT_TYPE (~(VT_STORAGE)) /* token values */ @@ -999,6 +985,11 @@ ST_DATA int tcc_ext; /* XXX: get rid of this ASAP */ ST_DATA struct TCCState *tcc_state; +#ifdef MEM_DEBUG +ST_DATA int mem_cur_size; +ST_DATA int mem_max_size; +#endif + #define AFF_PRINT_ERROR 0x0001 /* print error if file not found */ #define AFF_REFERENCED_DLL 0x0002 /* load a referenced dll from another dll */ #define AFF_PREPROCESS 0x0004 /* preprocess file */ @@ -1020,19 +1011,19 @@ PUB_FUNC char *tcc_strdup(const char *str); #undef strdup #define strdup(s) use_tcc_strdup(s) PUB_FUNC void tcc_memstats(void); -PUB_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data); -PUB_FUNC void dynarray_reset(void *pp, int *n); PUB_FUNC void tcc_error_noabort(const char *fmt, ...); PUB_FUNC void tcc_error(const char *fmt, ...); PUB_FUNC void tcc_warning(const char *fmt, ...); /* other utilities */ -PUB_FUNC void cstr_ccat(CString *cstr, int ch); -PUB_FUNC void cstr_cat(CString *cstr, const char *str); -PUB_FUNC void cstr_wccat(CString *cstr, int ch); -PUB_FUNC void cstr_new(CString *cstr); -PUB_FUNC void cstr_free(CString *cstr); -PUB_FUNC void cstr_reset(CString *cstr); +ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data); +ST_FUNC void dynarray_reset(void *pp, int *n); +ST_FUNC void cstr_ccat(CString *cstr, int ch); +ST_FUNC void cstr_cat(CString *cstr, const char *str); +ST_FUNC void cstr_wccat(CString *cstr, int ch); +ST_FUNC void cstr_new(CString *cstr); +ST_FUNC void cstr_free(CString *cstr); +ST_FUNC void cstr_reset(CString *cstr); ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags); ST_FUNC void section_realloc(Section *sec, unsigned long new_size); @@ -1059,15 +1050,10 @@ ST_FUNC void tcc_close(void); ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags); ST_FUNC int tcc_add_crt(TCCState *s, const char *filename); -#ifndef TCC_TARGET_PE ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags); -#endif -PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value); PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time); -PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file); -PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename); -PUB_FUNC void tcc_display_info(TCCState *s, int what); +PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv); /* ------------ tccpp.c ------------ */ @@ -1208,6 +1194,10 @@ ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsign /* ------------ tccelf.c ------------ */ +#define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */ +#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */ +#define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */ + #define ARMAG "!<arch>\012" /* For COFF and a.out archives */ typedef struct { @@ -1259,11 +1249,11 @@ ST_FUNC int handle_eob(void); /* ------------ xxx-gen.c ------------ */ -ST_DATA const int reg_classes[NB_REGS #ifdef TCC_TARGET_X86_64 - + 7 +ST_DATA const int reg_classes[NB_REGS+7]; +#else +ST_DATA const int reg_classes[NB_REGS]; #endif -]; ST_FUNC void gsym_addr(int t, int a); ST_FUNC void gsym(int t); @@ -1329,7 +1319,6 @@ ST_FUNC int tcc_load_coff(TCCState * s1, int fd); /* ------------ tccasm.c ------------ */ ST_FUNC void asm_instr(void); ST_FUNC void asm_global_instr(void); - #ifdef CONFIG_TCC_ASM ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp); ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe); @@ -1343,14 +1332,13 @@ ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier); ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg); ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str); #endif + /* ------------ tccpe.c -------------- */ #ifdef TCC_TARGET_PE ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd); ST_FUNC int pe_output_file(TCCState * s1, const char *filename); ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value); ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2); -/* tiny_impdef.c */ -ST_FUNC char *get_export_names(FILE *fp); #ifdef TCC_TARGET_X86_64 ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); #endif @@ -1366,7 +1354,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); /* dummy function for profiling */ ST_FUNC void *dlopen(const char *filename, int flag); ST_FUNC void dlclose(void *p); -//ST_FUNC const char *dlerror(void); +ST_FUNC const char *dlerror(void); ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); #elif !defined _WIN32 ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); @@ -1376,7 +1364,7 @@ ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); ST_DATA int rt_num_callers; ST_DATA const char **rt_bound_error_msg; ST_DATA void *rt_prog_main; -PUB_FUNC void tcc_set_num_callers(int n); +ST_FUNC void tcc_set_num_callers(int n); #endif #endif |
