2810 |
static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long) |
static void parse_escape_string(CString *outstr, const uint8_t *buf, int is_long) |
2811 |
{ |
{ |
2812 |
int c, n; |
int c, n; |
2813 |
const char *p; |
const uint8_t *p; |
2814 |
|
|
2815 |
p = buf; |
p = buf; |
2816 |
for(;;) { |
for(;;) { |
2890 |
break; |
break; |
2891 |
default: |
default: |
2892 |
invalid_escape: |
invalid_escape: |
2893 |
error("invalid escaped char"); |
if (c >= '!' && c <= '~') |
2894 |
|
warning("unknown escape sequence: \'\\%c\'", c); |
2895 |
|
else |
2896 |
|
warning("unknown escape sequence: \'\\x%x\'", c); |
2897 |
|
break; |
2898 |
} |
} |
2899 |
} |
} |
2900 |
p++; |
p++; |
9088 |
|
|
9089 |
tcc_add_runtime(s1); |
tcc_add_runtime(s1); |
9090 |
|
|
9091 |
|
build_got_entries(s1); |
9092 |
|
|
9093 |
relocate_common_syms(); |
relocate_common_syms(); |
9094 |
|
|
9095 |
/* compute relocation address : section are relocated in place. We |
/* compute relocation address : section are relocated in place. We |
9321 |
Elf32_Ehdr ehdr; |
Elf32_Ehdr ehdr; |
9322 |
int fd, ret; |
int fd, ret; |
9323 |
BufferedFile *saved_file; |
BufferedFile *saved_file; |
9324 |
|
|
9325 |
/* find source file type with extension */ |
/* find source file type with extension */ |
9326 |
filename1 = strrchr(filename, '/'); |
filename1 = strrchr(filename, '/'); |
9327 |
if (filename1) |
if (filename1) |
9373 |
if (ehdr.e_type == ET_REL) { |
if (ehdr.e_type == ET_REL) { |
9374 |
ret = tcc_load_object_file(s1, fd, 0); |
ret = tcc_load_object_file(s1, fd, 0); |
9375 |
} else if (ehdr.e_type == ET_DYN) { |
} else if (ehdr.e_type == ET_DYN) { |
9376 |
ret = tcc_load_dll(s1, fd, filename, |
if (s1->output_type == TCC_OUTPUT_MEMORY) { |
9377 |
(flags & AFF_REFERENCED_DLL) != 0); |
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 |
|
} |
9387 |
} else { |
} else { |
9388 |
error_noabort("unrecognized ELF file"); |
error_noabort("unrecognized ELF file"); |
9389 |
goto fail; |
goto fail; |
9445 |
{ |
{ |
9446 |
char buf[1024]; |
char buf[1024]; |
9447 |
int i; |
int i; |
|
void *h; |
|
9448 |
|
|
9449 |
/* first we look for the dynamic library if not static linking */ |
/* first we look for the dynamic library if not static linking */ |
9450 |
if (!s->static_link) { |
if (!s->static_link) { |
9451 |
snprintf(buf, sizeof(buf), "lib%s.so", libraryname); |
snprintf(buf, sizeof(buf), "lib%s.so", libraryname); |
9452 |
/* if we output to memory, then we simply we dlopen(). */ |
if (tcc_add_dll(s, buf, 0) == 0) |
9453 |
if (s->output_type == TCC_OUTPUT_MEMORY) { |
return 0; |
|
/* Since the libc is already loaded, we don't need to load it again */ |
|
|
if (!strcmp(libraryname, "c")) |
|
|
return 0; |
|
|
h = dlopen(buf, RTLD_GLOBAL | RTLD_LAZY); |
|
|
if (h) |
|
|
return 0; |
|
|
} else { |
|
|
if (tcc_add_dll(s, buf, 0) == 0) |
|
|
return 0; |
|
|
} |
|
9454 |
} |
} |
9455 |
|
|
9456 |
/* then we look for the static library */ |
/* then we look for the static library */ |
9682 |
{ "static", TCC_OPTION_static, 0 }, |
{ "static", TCC_OPTION_static, 0 }, |
9683 |
{ "shared", TCC_OPTION_shared, 0 }, |
{ "shared", TCC_OPTION_shared, 0 }, |
9684 |
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, |
{ "o", TCC_OPTION_o, TCC_OPTION_HAS_ARG }, |
9685 |
{ "run", TCC_OPTION_run, 0 }, |
{ "run", TCC_OPTION_run, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
9686 |
{ "rdynamic", TCC_OPTION_rdynamic, 0 }, |
{ "rdynamic", TCC_OPTION_rdynamic, 0 }, |
9687 |
{ "r", TCC_OPTION_r, 0 }, |
{ "r", TCC_OPTION_r, 0 }, |
9688 |
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
{ "W", TCC_OPTION_W, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP }, |
9697 |
{ NULL }, |
{ NULL }, |
9698 |
}; |
}; |
9699 |
|
|
9700 |
int main(int argc, char **argv) |
/* convert 'str' into an array of space separated strings */ |
9701 |
|
static int expand_args(char ***pargv, const char *str) |
9702 |
{ |
{ |
9703 |
char *r; |
const char *s1; |
9704 |
int optind, output_type, multiple_files, i, reloc_output; |
char **argv, *arg; |
9705 |
TCCState *s; |
int argc, len; |
|
char **files; |
|
|
int nb_files, nb_libraries, nb_objfiles, dminus, ret; |
|
|
char objfilename[1024]; |
|
|
int64_t start_time = 0; |
|
|
const TCCOption *popt; |
|
|
const char *optarg, *p1, *r1, *outfile; |
|
|
int print_search_dirs; |
|
9706 |
|
|
9707 |
s = tcc_new(); |
argc = 0; |
9708 |
output_type = TCC_OUTPUT_EXE; |
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 |
optind = 1; |
int parse_args(TCCState *s, int argc, char **argv) |
9736 |
outfile = NULL; |
{ |
9737 |
multiple_files = 1; |
int optind; |
9738 |
dminus = 0; |
const TCCOption *popt; |
9739 |
files = NULL; |
const char *optarg, *p1, *r1; |
9740 |
nb_files = 0; |
char *r; |
9741 |
nb_libraries = 0; |
|
9742 |
reloc_output = 0; |
optind = 0; |
|
print_search_dirs = 0; |
|
9743 |
while (1) { |
while (1) { |
9744 |
if (optind >= argc) { |
if (optind >= argc) { |
9745 |
if (nb_files == 0 && !print_search_dirs) |
if (nb_files == 0 && !print_search_dirs) |
9793 |
case TCC_OPTION_HELP: |
case TCC_OPTION_HELP: |
9794 |
show_help: |
show_help: |
9795 |
help(); |
help(); |
9796 |
return 1; |
exit(1); |
9797 |
case TCC_OPTION_I: |
case TCC_OPTION_I: |
9798 |
if (tcc_add_include_path(s, optarg) < 0) |
if (tcc_add_include_path(s, optarg) < 0) |
9799 |
error("too many include paths"); |
error("too many include paths"); |
9868 |
print_search_dirs = 1; |
print_search_dirs = 1; |
9869 |
break; |
break; |
9870 |
case TCC_OPTION_run: |
case TCC_OPTION_run: |
9871 |
multiple_files = 0; |
{ |
9872 |
output_type = TCC_OUTPUT_MEMORY; |
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 |
|
} |
9881 |
break; |
break; |
9882 |
case TCC_OPTION_v: |
case TCC_OPTION_v: |
9883 |
printf("tcc version %s\n", TCC_VERSION); |
printf("tcc version %s\n", TCC_VERSION); |
9884 |
return 0; |
exit(0); |
9885 |
case TCC_OPTION_W: |
case TCC_OPTION_W: |
9886 |
{ |
{ |
9887 |
const char *p = optarg; |
const char *p = optarg; |
9910 |
} |
} |
9911 |
} |
} |
9912 |
} |
} |
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 |
|
|
9936 |
if (print_search_dirs) { |
if (print_search_dirs) { |
9937 |
/* enough for Linux kernel */ |
/* enough for Linux kernel */ |
9938 |
printf("install: %s/\n", tcc_lib_path); |
printf("install: %s/\n", tcc_lib_path); |