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
28102810 static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long)
28112811 {
28122812 int c, n;
2813− const char *p;
2813+ const uint8_t *p;
28142814
28152815 p = buf;
28162816 for(;;) {
@@ -2890,7 +2890,11 @@ static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long · 73 unmodified lines
28902890 break;
28912891 default:
28922892 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;
28942898 }
28952899 }
28962900 p++;
@@ -9084,6 +9088,8 @@ int tcc_relocate(TCCState *s1) · 6187 unmodified lines
90849088
90859089 tcc_add_runtime(s1);
90869090
9091+ build_got_entries(s1);
9092+
90879093 relocate_common_syms();
90889094
90899095 /* 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
93159321 Elf32_Ehdr ehdr;
93169322 int fd, ret;
93179323 BufferedFile *saved_file;
9318−
9324+
93199325 /* find source file type with extension */
93209326 filename1 = strrchr(filename, '/');
93219327 if (filename1)
@@ -9367,8 +9373,17 @@ static int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 45 unmodified lines
93679373 if (ehdr.e_type == ET_REL) {
93689374 ret = tcc_load_object_file(s1, fd, 0);
93699375 } else if (ehdr.e_type == ET_DYN) {
9370− ret = tcc_load_dll(s1, fd, filename,
9371− (flags & AFF_REFERENCED_DLL) != 0);
9376+ if (s1->output_type == TCC_OUTPUT_MEMORY) {
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+ }
93729387 } else {
93739388 error_noabort("unrecognized ELF file");
93749389 goto fail;
@@ -9430,23 +9445,12 @@ int tcc_add_library(TCCState *s, const char *libraryname) · 55 unmodified lines
94309445 {
94319446 char buf[1024];
94329447 int i;
9433− void *h;
94349448
94359449 /* first we look for the dynamic library if not static linking */
94369450 if (!s->static_link) {
94379451 snprintf(buf, sizeof(buf), "lib%s.so", libraryname);
9438− /* if we output to memory, then we simply we dlopen(). */
9439− if (s->output_type == TCC_OUTPUT_MEMORY) {
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− }
9452+ if (tcc_add_dll(s, buf, 0) == 0)
9453+ return 0;
94509454 }
94519455
94529456 /* then we look for the static library */
@@ -9678,7 +9682,7 @@ static const TCCOption tcc_options[] = { · 225 unmodified lines
96789682 { "static", TCC_OPTION_static, 0 },
96799683 { "shared", TCC_OPTION_shared, 0 },
96809684 { "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 },
96829686 { "rdynamic", TCC_OPTION_rdynamic, 0 },
96839687 { "r", TCC_OPTION_r, 0 },
96849688 { "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
@@ -9693,31 +9697,49 @@ static const TCCOption tcc_options[] = { · 8 unmodified lines
96939697 { NULL },
96949698 };
96959699
9696−int main(int argc, char **argv)
9700+/* convert 'str' into an array of space separated strings */
9701+static int expand_args(char ***pargv, const char *str)
96979702 {
9698− char *r;
9699− int optind, output_type, multiple_files, i, reloc_output;
9700− TCCState *s;
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;
9703+ const char *s1;
9704+ char **argv, *arg;
9705+ int argc, len;
97089706
9709− s = tcc_new();
9710− output_type = TCC_OUTPUT_EXE;
9707+ argc = 0;
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+
9727+static char **files;
9728+static int nb_files, nb_libraries;
9729+static int multiple_files;
9730+static int print_search_dirs;
9731+static int output_type;
9732+static int reloc_output;
9733+static const char *outfile;
9734+
9735+int 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;
97119741
9712− optind = 1;
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;
9742+ optind = 0;
97219743 while (1) {
97229744 if (optind >= argc) {
97239745 if (nb_files == 0 && !print_search_dirs)
@@ -9771,7 +9793,7 @@ int main(int argc, char **argv) · 47 unmodified lines
97719793 case TCC_OPTION_HELP:
97729794 show_help:
97739795 help();
9774− return 1;
9796+ exit(1);
97759797 case TCC_OPTION_I:
97769798 if (tcc_add_include_path(s, optarg) < 0)
97779799 error("too many include paths");
@@ -9846,12 +9868,20 @@ int main(int argc, char **argv) · 68 unmodified lines
98469868 print_search_dirs = 1;
98479869 break;
98489870 case TCC_OPTION_run:
9849− multiple_files = 0;
9850− output_type = TCC_OUTPUT_MEMORY;
9871+ {
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+ }
98519881 break;
98529882 case TCC_OPTION_v:
98539883 printf("tcc version %s\n", TCC_VERSION);
9854− return 0;
9884+ exit(0);
98559885 case TCC_OPTION_W:
98569886 {
98579887 const char *p = optarg;
@@ -9880,6 +9910,29 @@ int main(int argc, char **argv) · 22 unmodified lines
98809910 }
98819911 }
98829912 }
9913+ return optind;
9914+}
9915+
9916+int 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+
98839936 if (print_search_dirs) {
98849937 /* enough for Linux kernel */
98859938 printf("install: %s/\n", tcc_lib_path);