History

added arguments to -run - fixed libc linking when running in memory - output a warning instead of an error if invalid escaped sequence in character

bellard committed 23 years ago

Commit bef87031 parent 46169b91 file · +98 −45Browse files

Unified · Split

tcc.c+98−45
@@ -2810,7 +2810,7 @@ static void preprocess(int is_bof) · 2809 unmodified lines
2810static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long)2810static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long)
2811{2811{
2812 int c, n;2812 int c, n;
2813 const char *p;2813 const uint8_t *p;
2814 2814
2815 p = buf;2815 p = buf;
2816 for(;;) {2816 for(;;) {
@@ -2890,7 +2890,11 @@ static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long · 73 unmodified lines
2890 break;2890 break;
2891 default:2891 default:
2892 invalid_escape:2892 invalid_escape:
2893 error("invalid escaped char");2893 if (c >= '!' && c <= '~')
2894 warning("unknown escape sequence: \'\\%c\'", c);
2895 else
2896 warning("unknown escape sequence: \'\\x%x\'", c);
2897 break;
2894 }2898 }
2895 }2899 }
2896 p++;2900 p++;
@@ -9084,6 +9088,8 @@ int tcc_relocate(TCCState *s1) · 6187 unmodified lines
9084 9088
9085 tcc_add_runtime(s1);9089 tcc_add_runtime(s1);
9086 9090
9091 build_got_entries(s1);
9092
9087 relocate_common_syms();9093 relocate_common_syms();
9088 9094
9089 /* compute relocation address : section are relocated in place. We9095 /* compute relocation address : section are relocated in place. We
@@ -9315,7 +9321,7 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 225 unmodified lines
9315 Elf32_Ehdr ehdr;9321 Elf32_Ehdr ehdr;
9316 int fd, ret;9322 int fd, ret;
9317 BufferedFile *saved_file;9323 BufferedFile *saved_file;
9318 9324
9319 /* find source file type with extension */9325 /* find source file type with extension */
9320 filename1 = strrchr(filename, '/');9326 filename1 = strrchr(filename, '/');
9321 if (filename1)9327 if (filename1)
@@ -9367,8 +9373,17 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 45 unmodified lines
9367 if (ehdr.e_type == ET_REL) {9373 if (ehdr.e_type == ET_REL) {
9368 ret = tcc_load_object_file(s1, fd, 0);9374 ret = tcc_load_object_file(s1, fd, 0);
9369 } else if (ehdr.e_type == ET_DYN) {9375 } else if (ehdr.e_type == ET_DYN) {
9370 ret = tcc_load_dll(s1, fd, filename, 9376 if (s1->output_type == TCC_OUTPUT_MEMORY) {
9371 (flags & AFF_REFERENCED_DLL) != 0);9377 void *h;
9378 h = dlopen(filename, RTLD_GLOBAL | RTLD_LAZY);
9379 if (h)
9380 ret = 0;
9381 else
9382 ret = -1;
9383 } else {
9384 ret = tcc_load_dll(s1, fd, filename,
9385 (flags & AFF_REFERENCED_DLL) != 0);
9386 }
9372 } else {9387 } else {
9373 error_noabort("unrecognized ELF file");9388 error_noabort("unrecognized ELF file");
9374 goto fail;9389 goto fail;
@@ -9430,23 +9445,12 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 55 unmodified lines
9430{9445{
9431 char buf[1024];9446 char buf[1024];
9432 int i;9447 int i;
9433 void *h;
9434 9448
9435 /* first we look for the dynamic library if not static linking */9449 /* first we look for the dynamic library if not static linking */
9436 if (!s->static_link) {9450 if (!s->static_link) {
9437 snprintf(buf, sizeof(buf), "lib%s.so", libraryname);9451 snprintf(buf, sizeof(buf), "lib%s.so", libraryname);
9438 /* if we output to memory, then we simply we dlopen(). */9452 if (tcc_add_dll(s, buf, 0) == 0)
9439 if (s->output_type == TCC_OUTPUT_MEMORY) {9453 return 0;
9440 /* Since the libc is already loaded, we don't need to load it again */
9441 if (!strcmp(libraryname, "c"))
9442 return 0;
9443 h = dlopen(buf, RTLD_GLOBAL | RTLD_LAZY);
9444 if (h)
9445 return 0;
9446 } else {
9447 if (tcc_add_dll(s, buf, 0) == 0)
9448 return 0;
9449 }
9450 }9454 }
9451 9455
9452 /* then we look for the static library */9456 /* then we look for the static library */
@@ -9678,7 +9682,7 @@ static const TCCOption tcc_options[] = { · 225 unmodified lines
9678 { "static", TCC_OPTION_static, 0 },9682 { "static", TCC_OPTION_static, 0 },
9679 { "shared", TCC_OPTION_shared, 0 },9683 { "shared", TCC_OPTION_shared, 0 },
9680 { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },9684 { "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG },
9681 { "run", TCC_OPTION_run, 0 },9685 { "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
9682 { "rdynamic", TCC_OPTION_rdynamic, 0 },9686 { "rdynamic", TCC_OPTION_rdynamic, 0 },
9683 { "r", TCC_OPTION_r, 0 },9687 { "r", TCC_OPTION_r, 0 },
9684 { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },9688 { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
@@ -9693,31 +9697,49 @@ static const TCCOption tcc_options[] = { · 8 unmodified lines
9693 { NULL },9697 { NULL },
9694};9698};
9695 9699
9696int main(int argc, char **argv)9700/* convert 'str' into an array of space separated strings */
9701static int expand_args(char ***pargv, const char *str)
9697{9702{
9698 char *r;9703 const char *s1;
9699 int optind, output_type, multiple_files, i, reloc_output;9704 char **argv, *arg;
9700 TCCState *s;9705 int argc, len;
9701 char **files;
9702 int nb_files, nb_libraries, nb_objfiles, dminus, ret;
9703 char objfilename[1024];
9704 int64_t start_time = 0;
9705 const TCCOption *popt;
9706 const char *optarg, *p1, *r1, *outfile;
9707 int print_search_dirs;
9708 9706
9709 s = tcc_new();9707 argc = 0;
9710 output_type = TCC_OUTPUT_EXE;9708 argv = NULL;
9709 for(;;) {
9710 while (is_space(*str))
9711 str++;
9712 if (*str == '\0')
9713 break;
9714 s1 = str;
9715 while (*str != '\0' && !is_space(*str))
9716 str++;
9717 len = str - s1;
9718 arg = tcc_malloc(len + 1);
9719 memcpy(arg, s1, len);
9720 arg[len] = '\0';
9721 dynarray_add((void ***)&argv, &argc, arg);
9722 }
9723 *pargv = argv;
9724 return argc;
9725}
9726
9727static char **files;
9728static int nb_files, nb_libraries;
9729static int multiple_files;
9730static int print_search_dirs;
9731static int output_type;
9732static int reloc_output;
9733static const char *outfile;
9734
9735int parse_args(TCCState *s, int argc, char **argv)
9736{
9737 int optind;
9738 const TCCOption *popt;
9739 const char *optarg, *p1, *r1;
9740 char *r;
9711 9741
9712 optind = 1;9742 optind = 0;
9713 outfile = NULL;
9714 multiple_files = 1;
9715 dminus = 0;
9716 files = NULL;
9717 nb_files = 0;
9718 nb_libraries = 0;
9719 reloc_output = 0;
9720 print_search_dirs = 0;
9721 while (1) {9743 while (1) {
9722 if (optind >= argc) {9744 if (optind >= argc) {
9723 if (nb_files == 0 && !print_search_dirs)9745 if (nb_files == 0 && !print_search_dirs)
@@ -9771,7 +9793,7 @@ int main(int argc, char **argv) · 47 unmodified lines
9771 case TCC_OPTION_HELP:9793 case TCC_OPTION_HELP:
9772 show_help:9794 show_help:
9773 help();9795 help();
9774 return 1;9796 exit(1);
9775 case TCC_OPTION_I:9797 case TCC_OPTION_I:
9776 if (tcc_add_include_path(s, optarg) < 0)9798 if (tcc_add_include_path(s, optarg) < 0)
9777 error("too many include paths");9799 error("too many include paths");
@@ -9846,12 +9868,20 @@ int main(int argc, char **argv) · 68 unmodified lines
9846 print_search_dirs = 1;9868 print_search_dirs = 1;
9847 break;9869 break;
9848 case TCC_OPTION_run:9870 case TCC_OPTION_run:
9849 multiple_files = 0;9871 {
9850 output_type = TCC_OUTPUT_MEMORY;9872 int argc1;
9873 char **argv1;
9874 argc1 = expand_args(&argv1, optarg);
9875 if (argc1 > 0) {
9876 parse_args(s, argc1, argv1);
9877 }
9878 multiple_files = 0;
9879 output_type = TCC_OUTPUT_MEMORY;
9880 }
9851 break;9881 break;
9852 case TCC_OPTION_v:9882 case TCC_OPTION_v:
9853 printf("tcc version %s\n", TCC_VERSION);9883 printf("tcc version %s\n", TCC_VERSION);
9854 return 0;9884 exit(0);
9855 case TCC_OPTION_W:9885 case TCC_OPTION_W:
9856 {9886 {
9857 const char *p = optarg;9887 const char *p = optarg;
@@ -9880,6 +9910,29 @@ int main(int argc, char **argv) · 22 unmodified lines
9880 }9910 }
9881 }9911 }
9882 }9912 }
9913 return optind;
9914}
9915
9916int main(int argc, char **argv)
9917{
9918 int i;
9919 TCCState *s;
9920 int nb_objfiles, ret, optind;
9921 char objfilename[1024];
9922 int64_t start_time = 0;
9923
9924 s = tcc_new();
9925 output_type = TCC_OUTPUT_EXE;
9926 outfile = NULL;
9927 multiple_files = 1;
9928 files = NULL;
9929 nb_files = 0;
9930 nb_libraries = 0;
9931 reloc_output = 0;
9932 print_search_dirs = 0;
9933
9934 optind = parse_args(s, argc - 1, argv + 1) + 1;
9935
9883 if (print_search_dirs) {9936 if (print_search_dirs) {
9884 /* enough for Linux kernel */9937 /* enough for Linux kernel */
9885 printf("install: %s/\n", tcc_lib_path);9938 printf("install: %s/\n", tcc_lib_path);