diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2020-08-14 23:04:13 +0100 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2020-08-14 23:04:13 +0100 |
commit | afd09586d7ead4f146ad7a7a471be34196b3c6bc (patch) | |
tree | 87854be29fb4264b979b700fa45445f58faa4c26 /tcc.c | |
parent | e2ccf3981d78dfeb390d22c74625b60310100abb (diff) |
New upstream version 0.9.27+git20200814.62c30a4a
Diffstat (limited to 'tcc.c')
-rw-r--r-- | tcc.c | 139 |
1 files changed, 77 insertions, 62 deletions
@@ -29,46 +29,52 @@ static const char help[] = "Usage: tcc [options...] [-o outfile] [-c] infile(s)...\n" " tcc [options...] -run infile [arguments...]\n" "General options:\n" - " -c compile only - generate an object file\n" - " -o outfile set output filename\n" - " -run run compiled source\n" - " -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n" - " -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n" - " -w disable all warnings\n" - " -v -vv show version, show search paths or loaded files\n" - " -h -hh show this, show more help\n" - " -bench show compilation statistics\n" - " - use stdin pipe as infile\n" - " @listfile read arguments from listfile\n" + " -c compile only - generate an object file\n" + " -o outfile set output filename\n" + " -run run compiled source\n" + " -fflag set or reset (with 'no-' prefix) 'flag' (see tcc -hh)\n" + " -std=c99 Conform to the ISO 1999 C standard (default).\n" + " -std=c11 Conform to the ISO 2011 C standard.\n" + " -Wwarning set or reset (with 'no-' prefix) 'warning' (see tcc -hh)\n" + " -w disable all warnings\n" + " --version -v show version\n" + " -vv show search paths or loaded files\n" + " -h -hh show this, show more help\n" + " -bench show compilation statistics\n" + " - use stdin pipe as infile\n" + " @listfile read arguments from listfile\n" "Preprocessor options:\n" - " -Idir add include path 'dir'\n" - " -Dsym[=val] define 'sym' with value 'val'\n" - " -Usym undefine 'sym'\n" - " -E preprocess only\n" + " -Idir add include path 'dir'\n" + " -Dsym[=val] define 'sym' with value 'val'\n" + " -Usym undefine 'sym'\n" + " -E preprocess only\n" + " -C keep comments (not yet implemented)\n" "Linker options:\n" - " -Ldir add library path 'dir'\n" - " -llib link with dynamic or static library 'lib'\n" - " -r generate (relocatable) object file\n" - " -shared generate a shared library/dll\n" - " -rdynamic export all global symbols to dynamic linker\n" - " -soname set name for shared library to be used at runtime\n" + " -Ldir add library path 'dir'\n" + " -llib link with dynamic or static library 'lib'\n" + " -r generate (relocatable) object file\n" + " -shared generate a shared library/dll\n" + " -rdynamic export all global symbols to dynamic linker\n" + " -soname set name for shared library to be used at runtime\n" " -Wl,-opt[=val] set linker option (see tcc -hh)\n" "Debugger options:\n" - " -g generate runtime debug info\n" + " -g generate runtime debug info\n" #ifdef CONFIG_TCC_BCHECK - " -b compile with built-in memory and bounds checker (implies -g)\n" + " -b compile with built-in memory and bounds checker (implies -g)\n" #endif #ifdef CONFIG_TCC_BACKTRACE - " -bt N show N callers in stack traces\n" + " -bt[N] link with backtrace (stack dump) support [show max N callers]\n" #endif "Misc. options:\n" - " -x[c|a|n] specify type of the next infile\n" - " -nostdinc do not use standard system include paths\n" - " -nostdlib do not link with standard crt and libraries\n" - " -Bdir set tcc's private include/library dir\n" - " -MD generate dependency file for make\n" - " -MF file specify dependency file name\n" - " -m32/64 defer to i386/x86_64 cross compiler\n" + " -x[c|a|b|n] specify type of the next infile (C,ASM,BIN,NONE)\n" + " -nostdinc do not use standard system include paths\n" + " -nostdlib do not link with standard crt and libraries\n" + " -Bdir set tcc's private include/library dir\n" + " -MD generate dependency file for make\n" + " -MF file specify dependency file name\n" +#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64) + " -m32/64 defer to i386/x86_64 cross compiler\n" +#endif "Tools:\n" " create library : tcc -ar [rcsv] lib.a files\n" #ifdef TCC_TARGET_PE @@ -91,7 +97,7 @@ static const char help2[] = " -print-search-dirs print search paths\n" " -dt with -run/-E: auto-define 'test_...' macros\n" "Ignored options:\n" - " --param -pedantic -pipe -s -std -traditional\n" + " --param -pedantic -pipe -s -traditional\n" "-W... warnings:\n" " all turn on some (*) warnings\n" " error stop after first warning\n" @@ -117,6 +123,7 @@ static const char help2[] = " -nostdlib do not link with standard crt/libs\n" " -[no-]whole-archive load lib(s) fully/only as needed\n" " -export-all-symbols same as -rdynamic\n" + " -export-dynamic same as -rdynamic\n" " -image-base= -Ttext= set base address of executable\n" " -section-alignment= set section alignment in executable\n" #ifdef TCC_TARGET_PE @@ -152,6 +159,8 @@ static const char version[] = "ARM" #elif defined TCC_TARGET_ARM64 "AArch64" +#elif defined TCC_TARGET_RISCV64 + "riscv64" #endif #ifdef TCC_ARM_HARDFLOAT " Hard Float" @@ -182,8 +191,10 @@ static void print_search_dirs(TCCState *s) /* print_dirs("programs", NULL, 0); */ print_dirs("include", s->sysinclude_paths, s->nb_sysinclude_paths); print_dirs("libraries", s->library_paths, s->nb_library_paths); +#ifdef TCC_TARGET_PE + printf("libtcc1:\n %s/lib/"TCC_LIBTCC1"\n", s->tcc_lib_path); +#else printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path); -#ifndef TCC_TARGET_PE print_dirs("crt", s->crt_paths, s->nb_crt_paths); printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s)); #endif @@ -245,8 +256,8 @@ static unsigned getclock_ms(void) int main(int argc0, char **argv0) { - TCCState *s; - int ret, opt, n = 0, t = 0; + TCCState *s, *s1; + int ret, opt, n = 0, t = 0, done; unsigned start_time = 0; const char *first_file; int argc; char **argv; @@ -254,14 +265,20 @@ int main(int argc0, char **argv0) redo: argc = argc0, argv = argv0; - s = tcc_new(); + s = s1 = tcc_new(); opt = tcc_parse_args(s, &argc, &argv, 1); - if ((n | t) == 0) { - if (opt == OPT_HELP) - return printf(help), 1; - if (opt == OPT_HELP2) - return printf(help2), 1; + if (n == 0) { + if (opt == OPT_HELP) { + fputs(help, stdout); + if (!s->verbose) + return 0; + ++opt; + } + if (opt == OPT_HELP2) { + fputs(help2, stdout); + return 0; + } if (opt == OPT_M32 || opt == OPT_M64) tcc_tool_cross(s, argv, opt); /* never returns */ if (s->verbose) @@ -282,12 +299,11 @@ redo: return 0; } - n = s->nb_files; - if (n == 0) + if (s->nb_files == 0) tcc_error("no input files\n"); if (s->output_type == TCC_OUTPUT_PREPROCESS) { - if (s->outfile) { + if (s->outfile && 0!=strcmp("-",s->outfile)) { ppfp = fopen(s->outfile, "w"); if (!ppfp) tcc_error("could not write '%s'", s->outfile); @@ -295,11 +311,8 @@ redo: } else if (s->output_type == TCC_OUTPUT_OBJ && !s->option_r) { if (s->nb_libraries) tcc_error("cannot specify libraries with -c"); - if (n > 1 && s->outfile) + if (s->nb_files > 1 && s->outfile) tcc_error("cannot specify output file with -c many files"); - } else { - if (s->option_pthread) - tcc_set_options(s, "-lpthread"); } if (s->do_bench) @@ -313,15 +326,21 @@ redo: s->ppfp = ppfp; if ((s->output_type == TCC_OUTPUT_MEMORY - || s->output_type == TCC_OUTPUT_PREPROCESS) && (s->dflag & 16)) - s->dflag |= t ? 32 : 0, s->run_test = ++t, n = s->nb_files; + || s->output_type == TCC_OUTPUT_PREPROCESS) + && (s->dflag & 16)) { /* -dt option */ + if (t) + s->dflag |= 32; + s->run_test = ++t; + if (n) + --n; + } /* compile or add each files or library */ - for (first_file = NULL, ret = 0;;) { - struct filespec *f = s->files[s->nb_files - n]; + first_file = NULL, ret = 0; + do { + struct filespec *f = s->files[n]; s->filetype = f->type; - s->alacarte_link = f->alacarte; - if (f->type == AFF_TYPE_LIB) { + if (f->type & AFF_TYPE_LIB) { if (tcc_add_library_err(s, f->name) < 0) ret = 1; } else { @@ -332,12 +351,8 @@ redo: if (tcc_add_file(s, f->name) < 0) ret = 1; } - s->filetype = 0; - s->alacarte_link = 1; - if (--n == 0 || ret - || (s->output_type == TCC_OUTPUT_OBJ && !s->option_r)) - break; - } + done = ret || ++n >= s->nb_files; + } while (!done && (s->output_type != TCC_OUTPUT_OBJ || s->option_r)); if (s->run_test) { t = 0; @@ -358,10 +373,10 @@ redo: } } - if (s->do_bench && (n | t | ret) == 0) + if (s->do_bench && done && !(t | ret)) tcc_print_stats(s, getclock_ms() - start_time); tcc_delete(s); - if (ret == 0 && n) + if (!done) goto redo; /* compile more files with -c */ if (t) goto redo; /* run more tests with -dt -run */ |