move some global variables into TCCState
This commit is contained in:
parent
5c6509578e
commit
f9181416f6
9 changed files with 91 additions and 86 deletions
|
@ -480,7 +480,7 @@ void gfunc_prolog(CType *func_type)
|
||||||
func_ret_sub = addr - 8;
|
func_ret_sub = addr - 8;
|
||||||
|
|
||||||
/* leave some room for bound checking code */
|
/* leave some room for bound checking code */
|
||||||
if (do_bounds_check) {
|
if (tcc_state->do_bounds_check) {
|
||||||
oad(0xb8, 0); /* lbound section pointer */
|
oad(0xb8, 0); /* lbound section pointer */
|
||||||
oad(0xb8, 0); /* call to function */
|
oad(0xb8, 0); /* call to function */
|
||||||
func_bound_offset = lbounds_section->data_offset;
|
func_bound_offset = lbounds_section->data_offset;
|
||||||
|
@ -493,7 +493,8 @@ void gfunc_epilog(void)
|
||||||
int v, saved_ind;
|
int v, saved_ind;
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (do_bounds_check && func_bound_offset != lbounds_section->data_offset) {
|
if (tcc_state->do_bounds_check
|
||||||
|
&& func_bound_offset != lbounds_section->data_offset) {
|
||||||
int saved_ind;
|
int saved_ind;
|
||||||
int *bounds_ptr;
|
int *bounds_ptr;
|
||||||
Sym *sym, *sym_data;
|
Sym *sym, *sym_data;
|
||||||
|
|
63
libtcc.c
63
libtcc.c
|
@ -20,6 +20,10 @@
|
||||||
|
|
||||||
#include "tcc.h"
|
#include "tcc.h"
|
||||||
|
|
||||||
|
/* display benchmark infos */
|
||||||
|
int total_lines;
|
||||||
|
int total_bytes;
|
||||||
|
|
||||||
/* parser */
|
/* parser */
|
||||||
static struct BufferedFile *file;
|
static struct BufferedFile *file;
|
||||||
static int ch, tok;
|
static int ch, tok;
|
||||||
|
@ -93,19 +97,6 @@ static SValue vstack[VSTACK_SIZE], *vtop;
|
||||||
/* some predefined types */
|
/* some predefined types */
|
||||||
static CType char_pointer_type, func_old_type, int_type;
|
static CType char_pointer_type, func_old_type, int_type;
|
||||||
|
|
||||||
/* display some information during compilation */
|
|
||||||
static int verbose = 0;
|
|
||||||
|
|
||||||
/* compile with debug symbol (and use them if error during execution) */
|
|
||||||
static int do_debug = 0;
|
|
||||||
|
|
||||||
/* compile with built-in memory and bounds checker */
|
|
||||||
static int do_bounds_check = 0;
|
|
||||||
|
|
||||||
/* display benchmark infos */
|
|
||||||
static int total_lines;
|
|
||||||
static int total_bytes;
|
|
||||||
|
|
||||||
/* use GNU C extensions */
|
/* use GNU C extensions */
|
||||||
static int gnu_ext = 1;
|
static int gnu_ext = 1;
|
||||||
|
|
||||||
|
@ -114,17 +105,13 @@ static int tcc_ext = 1;
|
||||||
|
|
||||||
/* max number of callers shown if error */
|
/* max number of callers shown if error */
|
||||||
#ifdef CONFIG_TCC_BACKTRACE
|
#ifdef CONFIG_TCC_BACKTRACE
|
||||||
static int num_callers = 6;
|
int num_callers = 6;
|
||||||
static const char **rt_bound_error_msg;
|
const char **rt_bound_error_msg;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* XXX: get rid of this ASAP */
|
/* XXX: get rid of this ASAP */
|
||||||
static struct TCCState *tcc_state;
|
static struct TCCState *tcc_state;
|
||||||
|
|
||||||
/* give the path of the tcc libraries */
|
|
||||||
static const char *tcc_lib_path = CONFIG_TCCDIR;
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef TCC_TARGET_I386
|
#ifdef TCC_TARGET_I386
|
||||||
#include "i386-gen.c"
|
#include "i386-gen.c"
|
||||||
#endif
|
#endif
|
||||||
|
@ -564,7 +551,7 @@ static void put_extern_sym2(Sym *sym, Section *section,
|
||||||
if (!sym->c) {
|
if (!sym->c) {
|
||||||
name = get_tok_str(sym->v, NULL);
|
name = get_tok_str(sym->v, NULL);
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (do_bounds_check) {
|
if (tcc_state->do_bounds_check) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
|
|
||||||
/* XXX: avoid doing that for statics ? */
|
/* XXX: avoid doing that for statics ? */
|
||||||
|
@ -989,7 +976,7 @@ BufferedFile *tcc_open(TCCState *s1, const char *filename)
|
||||||
fd = 0, filename = "stdin";
|
fd = 0, filename = "stdin";
|
||||||
else
|
else
|
||||||
fd = open(filename, O_RDONLY | O_BINARY);
|
fd = open(filename, O_RDONLY | O_BINARY);
|
||||||
if ((verbose == 2 && fd >= 0) || verbose == 3)
|
if ((s1->verbose == 2 && fd >= 0) || s1->verbose == 3)
|
||||||
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
|
printf("%s %*s%s\n", fd < 0 ? "nf":"->",
|
||||||
(s1->include_stack_ptr - s1->include_stack), "", filename);
|
(s1->include_stack_ptr - s1->include_stack), "", filename);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
@ -1039,7 +1026,7 @@ static int tcc_compile(TCCState *s1)
|
||||||
|
|
||||||
/* file info: full path + filename */
|
/* file info: full path + filename */
|
||||||
section_sym = 0; /* avoid warning */
|
section_sym = 0; /* avoid warning */
|
||||||
if (do_debug) {
|
if (s1->do_debug) {
|
||||||
section_sym = put_elf_sym(symtab_section, 0, 0,
|
section_sym = put_elf_sym(symtab_section, 0, 0,
|
||||||
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
|
ELFW(ST_INFO)(STB_LOCAL, STT_SECTION), 0,
|
||||||
text_section->sh_num, NULL);
|
text_section->sh_num, NULL);
|
||||||
|
@ -1108,7 +1095,7 @@ static int tcc_compile(TCCState *s1)
|
||||||
expect("declaration");
|
expect("declaration");
|
||||||
|
|
||||||
/* end of translation unit info */
|
/* end of translation unit info */
|
||||||
if (do_debug) {
|
if (s1->do_debug) {
|
||||||
put_stabs_r(NULL, N_SO, 0, 0,
|
put_stabs_r(NULL, N_SO, 0, 0,
|
||||||
text_section->data_offset, text_section, section_sym);
|
text_section->data_offset, text_section, section_sym);
|
||||||
}
|
}
|
||||||
|
@ -1579,7 +1566,7 @@ int tcc_run(TCCState *s1, int argc, char **argv)
|
||||||
|
|
||||||
prog_main = tcc_get_symbol_err(s1, "main");
|
prog_main = tcc_get_symbol_err(s1, "main");
|
||||||
|
|
||||||
if (do_debug) {
|
if (s1->do_debug) {
|
||||||
#ifdef CONFIG_TCC_BACKTRACE
|
#ifdef CONFIG_TCC_BACKTRACE
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
/* install TCC signal handlers to print debug info on fatal
|
/* install TCC signal handlers to print debug info on fatal
|
||||||
|
@ -1598,7 +1585,7 @@ int tcc_run(TCCState *s1, int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (do_bounds_check) {
|
if (s1->do_bounds_check) {
|
||||||
void (*bound_init)(void);
|
void (*bound_init)(void);
|
||||||
|
|
||||||
/* set error function */
|
/* set error function */
|
||||||
|
@ -1659,6 +1646,7 @@ TCCState *tcc_new(void)
|
||||||
return NULL;
|
return NULL;
|
||||||
tcc_state = s;
|
tcc_state = s;
|
||||||
s->output_type = TCC_OUTPUT_MEMORY;
|
s->output_type = TCC_OUTPUT_MEMORY;
|
||||||
|
s->tcc_lib_path = CONFIG_TCCDIR;
|
||||||
|
|
||||||
preprocess_new();
|
preprocess_new();
|
||||||
|
|
||||||
|
@ -1995,17 +1983,17 @@ int tcc_set_output_type(TCCState *s, int output_type)
|
||||||
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/local/include");
|
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/local/include");
|
||||||
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/include");
|
tcc_add_sysinclude_path(s, CONFIG_SYSROOT "/usr/include");
|
||||||
#endif
|
#endif
|
||||||
snprintf(buf, sizeof(buf), "%s/include", tcc_lib_path);
|
snprintf(buf, sizeof(buf), "%s/include", s->tcc_lib_path);
|
||||||
tcc_add_sysinclude_path(s, buf);
|
tcc_add_sysinclude_path(s, buf);
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
snprintf(buf, sizeof(buf), "%s/include/winapi", tcc_lib_path);
|
snprintf(buf, sizeof(buf), "%s/include/winapi", s->tcc_lib_path);
|
||||||
tcc_add_sysinclude_path(s, buf);
|
tcc_add_sysinclude_path(s, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if bound checking, then add corresponding sections */
|
/* if bound checking, then add corresponding sections */
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (do_bounds_check) {
|
if (s->do_bounds_check) {
|
||||||
/* define symbol */
|
/* define symbol */
|
||||||
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
|
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
|
||||||
/* create bounds sections */
|
/* create bounds sections */
|
||||||
|
@ -2021,7 +2009,7 @@ int tcc_set_output_type(TCCState *s, int output_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add debug sections */
|
/* add debug sections */
|
||||||
if (do_debug) {
|
if (s->do_debug) {
|
||||||
/* stab symbols */
|
/* stab symbols */
|
||||||
stab_section = new_section(s, ".stab", SHT_PROGBITS, 0);
|
stab_section = new_section(s, ".stab", SHT_PROGBITS, 0);
|
||||||
stab_section->sh_entsize = sizeof(Stab_Sym);
|
stab_section->sh_entsize = sizeof(Stab_Sym);
|
||||||
|
@ -2043,7 +2031,7 @@ int tcc_set_output_type(TCCState *s, int output_type)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
snprintf(buf, sizeof(buf), "%s/lib", tcc_lib_path);
|
snprintf(buf, sizeof(buf), "%s/lib", s->tcc_lib_path);
|
||||||
tcc_add_library_path(s, buf);
|
tcc_add_library_path(s, buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2127,6 +2115,19 @@ int tcc_set_flag(TCCState *s, const char *flag_name, int value)
|
||||||
/* set CONFIG_TCCDIR at runtime */
|
/* set CONFIG_TCCDIR at runtime */
|
||||||
void tcc_set_lib_path(TCCState *s, const char *path)
|
void tcc_set_lib_path(TCCState *s, const char *path)
|
||||||
{
|
{
|
||||||
tcc_lib_path = tcc_strdup(path);
|
s->tcc_lib_path = tcc_strdup(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LIBTCCAPI void print_stats(TCCState *s, int64_t total_time)
|
||||||
|
{
|
||||||
|
double tt;
|
||||||
|
tt = (double)total_time / 1000000.0;
|
||||||
|
if (tt < 0.001)
|
||||||
|
tt = 0.001;
|
||||||
|
if (total_bytes < 1)
|
||||||
|
total_bytes = 1;
|
||||||
|
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
|
||||||
|
tok_ident - TOK_IDENT, total_lines, total_bytes,
|
||||||
|
tt, (int)(total_lines / tt),
|
||||||
|
total_bytes / tt / 1000000.0);
|
||||||
|
}
|
||||||
|
|
30
tcc.c
30
tcc.c
|
@ -303,12 +303,12 @@ int parse_args(TCCState *s, int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
case TCC_OPTION_b:
|
case TCC_OPTION_b:
|
||||||
do_bounds_check = 1;
|
s->do_bounds_check = 1;
|
||||||
do_debug = 1;
|
s->do_debug = 1;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case TCC_OPTION_g:
|
case TCC_OPTION_g:
|
||||||
do_debug = 1;
|
s->do_debug = 1;
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_c:
|
case TCC_OPTION_c:
|
||||||
multiple_files = 1;
|
multiple_files = 1;
|
||||||
|
@ -355,7 +355,7 @@ int parse_args(TCCState *s, int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case TCC_OPTION_v:
|
case TCC_OPTION_v:
|
||||||
do {
|
do {
|
||||||
if (0 == verbose++)
|
if (0 == s->verbose++)
|
||||||
printf("tcc version %s\n", TCC_VERSION);
|
printf("tcc version %s\n", TCC_VERSION);
|
||||||
} while (*optarg++ == 'v');
|
} while (*optarg++ == 'v');
|
||||||
break;
|
break;
|
||||||
|
@ -439,11 +439,11 @@ int main(int argc, char **argv)
|
||||||
optind = parse_args(s, argc - 1, argv + 1);
|
optind = parse_args(s, argc - 1, argv + 1);
|
||||||
if (print_search_dirs) {
|
if (print_search_dirs) {
|
||||||
/* enough for Linux kernel */
|
/* enough for Linux kernel */
|
||||||
printf("install: %s/\n", tcc_lib_path);
|
printf("install: %s/\n", s->tcc_lib_path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (optind == 0 || nb_files == 0) {
|
if (optind == 0 || nb_files == 0) {
|
||||||
if (optind && verbose)
|
if (optind && s->verbose)
|
||||||
return 0;
|
return 0;
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -517,7 +517,7 @@ int main(int argc, char **argv)
|
||||||
if (tcc_add_library(s, filename + 2) < 0)
|
if (tcc_add_library(s, filename + 2) < 0)
|
||||||
error("cannot find %s", filename);
|
error("cannot find %s", filename);
|
||||||
} else {
|
} else {
|
||||||
if (1 == verbose)
|
if (1 == s->verbose)
|
||||||
printf("-> %s\n", filename);
|
printf("-> %s\n", filename);
|
||||||
if (tcc_add_file(s, filename) < 0)
|
if (tcc_add_file(s, filename) < 0)
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -530,18 +530,8 @@ int main(int argc, char **argv)
|
||||||
if (ret)
|
if (ret)
|
||||||
goto the_end;
|
goto the_end;
|
||||||
|
|
||||||
if (do_bench) {
|
if (do_bench)
|
||||||
double total_time;
|
print_stats(s, getclock_us() - start_time);
|
||||||
total_time = (double)(getclock_us() - start_time) / 1000000.0;
|
|
||||||
if (total_time < 0.001)
|
|
||||||
total_time = 0.001;
|
|
||||||
if (total_bytes < 1)
|
|
||||||
total_bytes = 1;
|
|
||||||
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
|
|
||||||
tok_ident - TOK_IDENT, total_lines, total_bytes,
|
|
||||||
total_time, (int)(total_lines / total_time),
|
|
||||||
total_bytes / total_time / 1000000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
if (s->output_type == TCC_OUTPUT_PREPROCESS) {
|
||||||
if (outfile)
|
if (outfile)
|
||||||
|
@ -552,7 +542,7 @@ int main(int argc, char **argv)
|
||||||
ret = tcc_output_file(s, outfile) ? 1 : 0;
|
ret = tcc_output_file(s, outfile) ? 1 : 0;
|
||||||
the_end:
|
the_end:
|
||||||
/* XXX: cannot do it with bound checking because of the malloc hooks */
|
/* XXX: cannot do it with bound checking because of the malloc hooks */
|
||||||
if (!do_bounds_check)
|
if (!s->do_bounds_check)
|
||||||
tcc_delete(s);
|
tcc_delete(s);
|
||||||
|
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
|
|
15
tcc.h
15
tcc.h
|
@ -385,7 +385,6 @@ struct TCCState {
|
||||||
|
|
||||||
int nostdinc; /* if true, no standard headers are added */
|
int nostdinc; /* if true, no standard headers are added */
|
||||||
int nostdlib; /* if true, no standard libraries are added */
|
int nostdlib; /* if true, no standard libraries are added */
|
||||||
|
|
||||||
int nocommon; /* if true, do not use common symbols for .bss data */
|
int nocommon; /* if true, do not use common symbols for .bss data */
|
||||||
|
|
||||||
/* if true, static linking is performed */
|
/* if true, static linking is performed */
|
||||||
|
@ -418,6 +417,15 @@ struct TCCState {
|
||||||
int warn_none;
|
int warn_none;
|
||||||
int warn_implicit_function_declaration;
|
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;
|
||||||
|
/* compile with built-in memory and bounds checker */
|
||||||
|
int do_bounds_check;
|
||||||
|
/* give the path of the tcc libraries */
|
||||||
|
const char *tcc_lib_path;
|
||||||
|
|
||||||
/* error handling */
|
/* error handling */
|
||||||
void *error_opaque;
|
void *error_opaque;
|
||||||
void (*error_func)(void *opaque, const char *msg);
|
void (*error_func)(void *opaque, const char *msg);
|
||||||
|
@ -842,6 +850,11 @@ static int tcc_assemble(TCCState *s1, int do_preprocess);
|
||||||
static void asm_instr(void);
|
static void asm_instr(void);
|
||||||
static void asm_global_instr(void);
|
static void asm_global_instr(void);
|
||||||
|
|
||||||
|
#ifdef CONFIG_TCC_BACKTRACE
|
||||||
|
extern int num_callers;
|
||||||
|
extern const char **rt_bound_error_msg;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* true if float/double/long double type */
|
/* true if float/double/long double type */
|
||||||
static inline int is_float(int t)
|
static inline int is_float(int t)
|
||||||
{
|
{
|
||||||
|
|
12
tcccoff.c
12
tcccoff.c
|
@ -183,7 +183,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
coff_sec->s_nlnno = 0;
|
coff_sec->s_nlnno = 0;
|
||||||
coff_sec->s_lnnoptr = 0;
|
coff_sec->s_lnnoptr = 0;
|
||||||
|
|
||||||
if (do_debug && tcc_sect == stext) {
|
if (s1->do_debug && tcc_sect == stext) {
|
||||||
// count how many line nos data
|
// count how many line nos data
|
||||||
|
|
||||||
// also find association between source file name and function
|
// also find association between source file name and function
|
||||||
|
@ -311,7 +311,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
|
|
||||||
file_hdr.f_symptr = file_pointer; /* file pointer to symtab */
|
file_hdr.f_symptr = file_pointer; /* file pointer to symtab */
|
||||||
|
|
||||||
if (do_debug)
|
if (s1->do_debug)
|
||||||
file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */
|
file_hdr.f_nsyms = coff_nb_syms; /* number of symtab entries */
|
||||||
else
|
else
|
||||||
file_hdr.f_nsyms = 0;
|
file_hdr.f_nsyms = 0;
|
||||||
|
@ -362,7 +362,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
// group the symbols in order of filename, func1, func2, etc
|
// group the symbols in order of filename, func1, func2, etc
|
||||||
// finally global symbols
|
// finally global symbols
|
||||||
|
|
||||||
if (do_debug)
|
if (s1->do_debug)
|
||||||
SortSymbolTable();
|
SortSymbolTable();
|
||||||
|
|
||||||
// write line no data
|
// write line no data
|
||||||
|
@ -371,7 +371,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
coff_sec = §ion_header[i];
|
coff_sec = §ion_header[i];
|
||||||
tcc_sect = s1->sections[i];
|
tcc_sect = s1->sections[i];
|
||||||
|
|
||||||
if (do_debug && tcc_sect == stext) {
|
if (s1->do_debug && tcc_sect == stext) {
|
||||||
// count how many line nos data
|
// count how many line nos data
|
||||||
|
|
||||||
|
|
||||||
|
@ -499,7 +499,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write symbol table
|
// write symbol table
|
||||||
if (do_debug) {
|
if (s1->do_debug) {
|
||||||
int k;
|
int k;
|
||||||
struct syment csym;
|
struct syment csym;
|
||||||
AUXFUNC auxfunc;
|
AUXFUNC auxfunc;
|
||||||
|
@ -670,7 +670,7 @@ int tcc_output_coff(TCCState *s1, FILE *f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (do_debug) {
|
if (s1->do_debug) {
|
||||||
// write string table
|
// write string table
|
||||||
|
|
||||||
// first write the size
|
// first write the size
|
||||||
|
|
14
tccelf.c
14
tccelf.c
|
@ -1163,7 +1163,7 @@ static void tcc_add_runtime(TCCState *s1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
if (do_bounds_check) {
|
if (s1->do_bounds_check) {
|
||||||
unsigned long *ptr;
|
unsigned long *ptr;
|
||||||
Section *init_section;
|
Section *init_section;
|
||||||
unsigned char *pinit;
|
unsigned char *pinit;
|
||||||
|
@ -1176,7 +1176,7 @@ static void tcc_add_runtime(TCCState *s1)
|
||||||
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
|
ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
|
||||||
bounds_section->sh_num, "__bounds_start");
|
bounds_section->sh_num, "__bounds_start");
|
||||||
/* add bound check code */
|
/* add bound check code */
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "bcheck.o");
|
snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "bcheck.o");
|
||||||
tcc_add_file(s1, buf);
|
tcc_add_file(s1, buf);
|
||||||
#ifdef TCC_TARGET_I386
|
#ifdef TCC_TARGET_I386
|
||||||
if (s1->output_type != TCC_OUTPUT_MEMORY) {
|
if (s1->output_type != TCC_OUTPUT_MEMORY) {
|
||||||
|
@ -1199,7 +1199,7 @@ static void tcc_add_runtime(TCCState *s1)
|
||||||
#ifdef CONFIG_USE_LIBGCC
|
#ifdef CONFIG_USE_LIBGCC
|
||||||
tcc_add_file(s1, CONFIG_SYSROOT "/lib/libgcc_s.so.1");
|
tcc_add_file(s1, CONFIG_SYSROOT "/lib/libgcc_s.so.1");
|
||||||
#else
|
#else
|
||||||
snprintf(buf, sizeof(buf), "%s/%s", tcc_lib_path, "libtcc1.a");
|
snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "libtcc1.a");
|
||||||
tcc_add_file(s1, buf);
|
tcc_add_file(s1, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1574,9 +1574,9 @@ int elf_output_file(TCCState *s1, const char *filename)
|
||||||
/* //gr: avoid bogus relocs for empty (debug) sections */
|
/* //gr: avoid bogus relocs for empty (debug) sections */
|
||||||
if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC)
|
if (s1->sections[s->sh_info]->sh_flags & SHF_ALLOC)
|
||||||
prepare_dynamic_rel(s1, s);
|
prepare_dynamic_rel(s1, s);
|
||||||
else if (do_debug)
|
else if (s1->do_debug)
|
||||||
s->sh_size = s->data_offset;
|
s->sh_size = s->data_offset;
|
||||||
} else if (do_debug ||
|
} else if (s1->do_debug ||
|
||||||
file_type == TCC_OUTPUT_OBJ ||
|
file_type == TCC_OUTPUT_OBJ ||
|
||||||
(s->sh_flags & SHF_ALLOC) ||
|
(s->sh_flags & SHF_ALLOC) ||
|
||||||
i == (s1->nb_sections - 1)) {
|
i == (s1->nb_sections - 1)) {
|
||||||
|
@ -1817,7 +1817,7 @@ int elf_output_file(TCCState *s1, const char *filename)
|
||||||
put_dt(dynamic, DT_RELSZ, rel_size);
|
put_dt(dynamic, DT_RELSZ, rel_size);
|
||||||
put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel));
|
put_dt(dynamic, DT_RELENT, sizeof(ElfW_Rel));
|
||||||
#endif
|
#endif
|
||||||
if (do_debug)
|
if (s1->do_debug)
|
||||||
put_dt(dynamic, DT_DEBUG, 0);
|
put_dt(dynamic, DT_DEBUG, 0);
|
||||||
put_dt(dynamic, DT_NULL, 0);
|
put_dt(dynamic, DT_NULL, 0);
|
||||||
}
|
}
|
||||||
|
@ -1888,7 +1888,7 @@ int elf_output_file(TCCState *s1, const char *filename)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
f = fdopen(fd, "wb");
|
f = fdopen(fd, "wb");
|
||||||
if (verbose)
|
if (s1->verbose)
|
||||||
printf("<- %s\n", filename);
|
printf("<- %s\n", filename);
|
||||||
|
|
||||||
#ifdef TCC_TARGET_COFF
|
#ifdef TCC_TARGET_COFF
|
||||||
|
|
20
tccgen.c
20
tccgen.c
|
@ -1311,7 +1311,7 @@ void gen_op(int op)
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
/* if evaluating constant expression, no code should be
|
/* if evaluating constant expression, no code should be
|
||||||
generated, so no bound check */
|
generated, so no bound check */
|
||||||
if (do_bounds_check && !const_wanted) {
|
if (tcc_state->do_bounds_check && !const_wanted) {
|
||||||
/* if bounded pointers, we generate a special code to
|
/* if bounded pointers, we generate a special code to
|
||||||
test bounds */
|
test bounds */
|
||||||
if (op == '-') {
|
if (op == '-') {
|
||||||
|
@ -2880,7 +2880,7 @@ static void indir(void)
|
||||||
&& (vtop->type.t & VT_BTYPE) != VT_FUNC) {
|
&& (vtop->type.t & VT_BTYPE) != VT_FUNC) {
|
||||||
vtop->r |= lvalue_type(vtop->type.t);
|
vtop->r |= lvalue_type(vtop->type.t);
|
||||||
/* if bound checking, the referenced pointer must be checked */
|
/* if bound checking, the referenced pointer must be checked */
|
||||||
if (do_bounds_check)
|
if (tcc_state->do_bounds_check)
|
||||||
vtop->r |= VT_MUSTBOUND;
|
vtop->r |= VT_MUSTBOUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3294,7 +3294,7 @@ static void unary(void)
|
||||||
if (!(vtop->type.t & VT_ARRAY)) {
|
if (!(vtop->type.t & VT_ARRAY)) {
|
||||||
vtop->r |= lvalue_type(vtop->type.t);
|
vtop->r |= lvalue_type(vtop->type.t);
|
||||||
/* if bound checking, the referenced pointer must be checked */
|
/* if bound checking, the referenced pointer must be checked */
|
||||||
if (do_bounds_check)
|
if (tcc_state->do_bounds_check)
|
||||||
vtop->r |= VT_MUSTBOUND;
|
vtop->r |= VT_MUSTBOUND;
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
|
@ -3794,7 +3794,7 @@ static void block(int *bsym, int *csym, int *case_sym, int *def_sym,
|
||||||
Sym *s;
|
Sym *s;
|
||||||
|
|
||||||
/* generate line number info */
|
/* generate line number info */
|
||||||
if (do_debug &&
|
if (tcc_state->do_debug &&
|
||||||
(last_line_num != file->line_num || last_ind != ind)) {
|
(last_line_num != file->line_num || last_ind != ind)) {
|
||||||
put_stabn(N_SLINE, 0, file->line_num, ind - func_ind);
|
put_stabn(N_SLINE, 0, file->line_num, ind - func_ind);
|
||||||
last_ind = ind;
|
last_ind = ind;
|
||||||
|
@ -4649,14 +4649,14 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
||||||
}
|
}
|
||||||
if ((r & VT_VALMASK) == VT_LOCAL) {
|
if ((r & VT_VALMASK) == VT_LOCAL) {
|
||||||
sec = NULL;
|
sec = NULL;
|
||||||
if (do_bounds_check && (type->t & VT_ARRAY))
|
if (tcc_state->do_bounds_check && (type->t & VT_ARRAY))
|
||||||
loc--;
|
loc--;
|
||||||
loc = (loc - size) & -align;
|
loc = (loc - size) & -align;
|
||||||
addr = loc;
|
addr = loc;
|
||||||
/* handles bounds */
|
/* handles bounds */
|
||||||
/* XXX: currently, since we do only one pass, we cannot track
|
/* XXX: currently, since we do only one pass, we cannot track
|
||||||
'&' operators, so we add only arrays */
|
'&' operators, so we add only arrays */
|
||||||
if (do_bounds_check && (type->t & VT_ARRAY)) {
|
if (tcc_state->do_bounds_check && (type->t & VT_ARRAY)) {
|
||||||
unsigned long *bounds_ptr;
|
unsigned long *bounds_ptr;
|
||||||
/* add padding between regions */
|
/* add padding between regions */
|
||||||
loc--;
|
loc--;
|
||||||
|
@ -4722,7 +4722,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
||||||
because initializers themselves can create new initializers */
|
because initializers themselves can create new initializers */
|
||||||
data_offset += size;
|
data_offset += size;
|
||||||
/* add padding if bound check */
|
/* add padding if bound check */
|
||||||
if (do_bounds_check)
|
if (tcc_state->do_bounds_check)
|
||||||
data_offset++;
|
data_offset++;
|
||||||
sec->data_offset = data_offset;
|
sec->data_offset = data_offset;
|
||||||
/* allocate section space to put the data */
|
/* allocate section space to put the data */
|
||||||
|
@ -4763,7 +4763,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
||||||
|
|
||||||
/* handles bounds now because the symbol must be defined
|
/* handles bounds now because the symbol must be defined
|
||||||
before for the relocation */
|
before for the relocation */
|
||||||
if (do_bounds_check) {
|
if (tcc_state->do_bounds_check) {
|
||||||
unsigned long *bounds_ptr;
|
unsigned long *bounds_ptr;
|
||||||
|
|
||||||
greloc(bounds_section, sym, bounds_section->data_offset, R_DATA_32);
|
greloc(bounds_section, sym, bounds_section->data_offset, R_DATA_32);
|
||||||
|
@ -4860,7 +4860,7 @@ static void gen_function(Sym *sym)
|
||||||
funcname = get_tok_str(sym->v, NULL);
|
funcname = get_tok_str(sym->v, NULL);
|
||||||
func_ind = ind;
|
func_ind = ind;
|
||||||
/* put debug symbol */
|
/* put debug symbol */
|
||||||
if (do_debug)
|
if (tcc_state->do_debug)
|
||||||
put_func_debug(sym);
|
put_func_debug(sym);
|
||||||
/* push a dummy symbol to enable local sym storage */
|
/* push a dummy symbol to enable local sym storage */
|
||||||
sym_push2(&local_stack, SYM_FIELD, 0, 0);
|
sym_push2(&local_stack, SYM_FIELD, 0, 0);
|
||||||
|
@ -4876,7 +4876,7 @@ static void gen_function(Sym *sym)
|
||||||
/* patch symbol size */
|
/* patch symbol size */
|
||||||
((ElfW(Sym) *)symtab_section->data)[sym->c].st_size =
|
((ElfW(Sym) *)symtab_section->data)[sym->c].st_size =
|
||||||
ind - func_ind;
|
ind - func_ind;
|
||||||
if (do_debug) {
|
if (tcc_state->do_debug) {
|
||||||
put_stabn(N_FUN, 0, 0, ind - func_ind);
|
put_stabn(N_FUN, 0, 0, ind - func_ind);
|
||||||
}
|
}
|
||||||
/* It's better to crash than to generate wrong code */
|
/* It's better to crash than to generate wrong code */
|
||||||
|
|
12
tccpe.c
12
tccpe.c
|
@ -577,7 +577,7 @@ ST_FN int pe_write(struct pe_info *pe)
|
||||||
file_offset = pe->sizeofheaders;
|
file_offset = pe->sizeofheaders;
|
||||||
pe_fpad(op, file_offset);
|
pe_fpad(op, file_offset);
|
||||||
|
|
||||||
if (2 == verbose)
|
if (2 == pe->s1->verbose)
|
||||||
printf("-------------------------------"
|
printf("-------------------------------"
|
||||||
"\n virt file size section" "\n");
|
"\n virt file size section" "\n");
|
||||||
|
|
||||||
|
@ -588,7 +588,7 @@ ST_FN int pe_write(struct pe_info *pe)
|
||||||
unsigned long size = si->sh_size;
|
unsigned long size = si->sh_size;
|
||||||
IMAGE_SECTION_HEADER *psh = &si->ish;
|
IMAGE_SECTION_HEADER *psh = &si->ish;
|
||||||
|
|
||||||
if (2 == verbose)
|
if (2 == pe->s1->verbose)
|
||||||
printf("%6lx %6lx %6lx %s\n",
|
printf("%6lx %6lx %6lx %s\n",
|
||||||
addr, file_offset, size, sh_name);
|
addr, file_offset, size, sh_name);
|
||||||
|
|
||||||
|
@ -662,9 +662,9 @@ ST_FN int pe_write(struct pe_info *pe)
|
||||||
fwrite(&pe->sec_info[i].ish, 1, sizeof(IMAGE_SECTION_HEADER), op);
|
fwrite(&pe->sec_info[i].ish, 1, sizeof(IMAGE_SECTION_HEADER), op);
|
||||||
fclose (op);
|
fclose (op);
|
||||||
|
|
||||||
if (2 == verbose)
|
if (2 == pe->s1->verbose)
|
||||||
printf("-------------------------------\n");
|
printf("-------------------------------\n");
|
||||||
if (verbose)
|
if (pe->s1->verbose)
|
||||||
printf("<- %s (%lu bytes)\n", pe->filename, file_offset);
|
printf("<- %s (%lu bytes)\n", pe->filename, file_offset);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -859,7 +859,7 @@ ST_FN void pe_build_exports(struct pe_info *pe)
|
||||||
error_noabort("could not create '%s': %s", buf, strerror(errno));
|
error_noabort("could not create '%s': %s", buf, strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname);
|
fprintf(op, "LIBRARY %s\n\nEXPORTS\n", dllname);
|
||||||
if (verbose)
|
if (pe->s1->verbose)
|
||||||
printf("<- %s (%d symbols)\n", buf, sym_count);
|
printf("<- %s (%d symbols)\n", buf, sym_count);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1065,7 +1065,7 @@ ST_FN int pe_assign_addresses (struct pe_info *pe)
|
||||||
flags & SHF_EXECINSTR ? "exec" : ""
|
flags & SHF_EXECINSTR ? "exec" : ""
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
verbose = 2;
|
pe->s1->verbose = 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tcc_free(section_order);
|
tcc_free(section_order);
|
||||||
|
|
6
tccpp.c
6
tccpp.c
|
@ -440,7 +440,7 @@ static uint8_t *parse_comment(uint8_t *p)
|
||||||
#define cinp minp
|
#define cinp minp
|
||||||
|
|
||||||
/* space exlcuding newline */
|
/* space exlcuding newline */
|
||||||
static inline int is_space(int ch)
|
LIBTCCAPI static inline int is_space(int ch)
|
||||||
{
|
{
|
||||||
return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
|
return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
|
||||||
}
|
}
|
||||||
|
@ -1336,7 +1336,7 @@ static void preprocess(int is_bof)
|
||||||
pstrcpy(f->inc_filename, sizeof(f->inc_filename), buf);
|
pstrcpy(f->inc_filename, sizeof(f->inc_filename), buf);
|
||||||
file = f;
|
file = f;
|
||||||
/* add include file debug info */
|
/* add include file debug info */
|
||||||
if (do_debug) {
|
if (tcc_state->do_debug) {
|
||||||
put_stabs(file->filename, N_BINCL, 0, 0, 0);
|
put_stabs(file->filename, N_BINCL, 0, 0, 0);
|
||||||
}
|
}
|
||||||
tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
|
tok_flags |= TOK_FLAG_BOF | TOK_FLAG_BOL;
|
||||||
|
@ -1946,7 +1946,7 @@ static inline void next_nomacro1(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add end of include file debug info */
|
/* add end of include file debug info */
|
||||||
if (do_debug) {
|
if (tcc_state->do_debug) {
|
||||||
put_stabd(N_EINCL, 0, 0);
|
put_stabd(N_EINCL, 0, 0);
|
||||||
}
|
}
|
||||||
/* pop include stack */
|
/* pop include stack */
|
||||||
|
|
Loading…
Reference in a new issue