Makefile : - do not 'uninstall' peoples /usr/local/doc entirely libtcc.c : - MEM_DEBUG : IDE-friendly output "file:line: ..." - always ELF for objects tccgen.c : - fix memory leak in new switch code - move static 'in_sizeof' out of function profiling : - define 'static' to empty resolve_sym() : - replace by dlsym() win32/64: fix R_XXX_RELATIVE fixme - was fixed for i386 already in 8e4d64be2fc1d707c7800c5096f6e0ea22cbd - do not -Lsystemdir if compiling to .o
Unified · Split
| @@ -18,10 +18,6 @@ else · 17 unmodified lines | |||
| 18 | endif | 18 | endif |
| 19 | endif | 19 | endif |
| 20 | 20 | ||
| 21 | CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC | ||
| 22 | LIBS_P= | ||
| 23 | LDFLAGS_P = $(LDFLAGS) | ||
| 24 | |||
| 25 | LIBTCC = libtcc.a | 21 | LIBTCC = libtcc.a |
| 26 | LIBTCC1 = libtcc1.a | 22 | LIBTCC1 = libtcc1.a |
| 27 | LINK_LIBTCC = | 23 | LINK_LIBTCC = |
| @@ -50,6 +46,10 @@ ifeq ($(TARGETOS),Darwin) · 22 unmodified lines | |||
| 50 | export MACOSX_DEPLOYMENT_TARGET:=10.2 | 46 | export MACOSX_DEPLOYMENT_TARGET:=10.2 |
| 51 | endif | 47 | endif |
| 52 | 48 | ||
| 49 | CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE | ||
| 50 | LIBS_P= $(LIBS) | ||
| 51 | LDFLAGS_P = $(LDFLAGS) | ||
| 52 | |||
| 53 | CONFIG_$(ARCH) = yes | 53 | CONFIG_$(ARCH) = yes |
| 54 | NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 | 54 | NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386 |
| 55 | NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64 | 55 | NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64 |
| @@ -136,8 +136,8 @@ endif · 80 unmodified lines | |||
| 136 | all: $(PROGS) $(TCCLIBS) $(TCCDOCS) | 136 | all: $(PROGS) $(TCCLIBS) $(TCCDOCS) |
| 137 | 137 | ||
| 138 | # Host Tiny C Compiler | 138 | # Host Tiny C Compiler |
| 139 | tcc$(EXESUF): tcc.c $(LIBTCC) | 139 | tcc$(EXESUF): tcc.o $(LIBTCC) |
| 140 | $(CC) -o $@ $^ $(LIBS) $(NATIVE_DEFINES) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC) | 140 | $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) $(LINK_LIBTCC) |
| 141 | 141 | ||
| 142 | # Cross Tiny C Compilers | 142 | # Cross Tiny C Compilers |
| 143 | %-tcc$(EXESUF): tcc.c | 143 | %-tcc$(EXESUF): tcc.c |
| @@ -182,7 +182,6 @@ else · 38 unmodified lines | |||
| 182 | LIBTCC_OBJ = libtcc.o | 182 | LIBTCC_OBJ = libtcc.o |
| 183 | LIBTCC_INC = $(NATIVE_FILES) | 183 | LIBTCC_INC = $(NATIVE_FILES) |
| 184 | libtcc.o : NATIVE_DEFINES += -DONE_SOURCE | 184 | libtcc.o : NATIVE_DEFINES += -DONE_SOURCE |
| 185 | tcc.o : NATIVE_DEFINES += -DONE_SOURCE | ||
| 186 | endif | 185 | endif |
| 187 | 186 | ||
| 188 | $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC) | 187 | $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC) |
| @@ -269,7 +268,7 @@ uninstall: · 80 unmodified lines | |||
| 269 | rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h" | 268 | rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h" |
| 270 | rm -fv $(libdir)/libtcc.so* | 269 | rm -fv $(libdir)/libtcc.so* |
| 271 | rm -rv "$(tccdir)" | 270 | rm -rv "$(tccdir)" |
| 272 | rm -rv "$(docdir)" | 271 | rm -fv "$(docdir)/tcc-doc.html" |
| 273 | else | 272 | else |
| 274 | # on windows | 273 | # on windows |
| 275 | install: $(PROGS) $(TCCLIBS) $(TCCDOCS) | 274 | install: $(PROGS) $(TCCLIBS) $(TCCDOCS) |
| @@ -116,7 +116,7 @@ static void tcc_add_systemdir(TCCState *s) · 115 unmodified lines | |||
| 116 | } | 116 | } |
| 117 | #endif | 117 | #endif |
| 118 | 118 | ||
| 119 | #if defined TCC_IS_NATIVE && !defined CONFIG_TCC_STATIC | 119 | #if defined TCC_IS_NATIVE |
| 120 | static void dlclose(void *p) | 120 | static void dlclose(void *p) |
| 121 | { | 121 | { |
| 122 | FreeLibrary((HMODULE)p); | 122 | FreeLibrary((HMODULE)p); |
| @@ -412,7 +412,7 @@ PUB_FUNC void tcc_memstats(int bench) · 289 unmodified lines | |||
| 412 | mem_cur_size, mem_max_size); | 412 | mem_cur_size, mem_max_size); |
| 413 | 413 | ||
| 414 | while (header) { | 414 | while (header) { |
| 415 | fprintf(stderr, " file %s, line %u: %u bytes\n", | 415 | fprintf(stderr, "%s:%u: error: %u bytes leaked\n", |
| 416 | header->file_name, header->line_num, header->size); | 416 | header->file_name, header->line_num, header->size); |
| 417 | header = header->next; | 417 | header = header->next; |
| 418 | } | 418 | } |
| @@ -1504,14 +1504,21 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1085 unmodified lines | |||
| 1504 | { | 1504 | { |
| 1505 | s->output_type = output_type; | 1505 | s->output_type = output_type; |
| 1506 | 1506 | ||
| 1507 | /* always elf for objects */ | ||
| 1508 | if (output_type == TCC_OUTPUT_OBJ) | ||
| 1509 | s->output_format = TCC_OUTPUT_FORMAT_ELF; | ||
| 1510 | |||
| 1511 | if (s->char_is_unsigned) | ||
| 1512 | tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL); | ||
| 1513 | |||
| 1507 | if (!s->nostdinc) { | 1514 | if (!s->nostdinc) { |
| 1508 | /* default include paths */ | 1515 | /* default include paths */ |
| 1509 | /* -isystem paths have already been handled */ | 1516 | /* -isystem paths have already been handled */ |
| 1510 | tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); | 1517 | tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS); |
| 1511 | } | 1518 | } |
| 1512 | 1519 | ||
| 1513 | /* if bound checking, then add corresponding sections */ | ||
| 1514 | #ifdef CONFIG_TCC_BCHECK | 1520 | #ifdef CONFIG_TCC_BCHECK |
| 1521 | /* if bound checking, then add corresponding sections */ | ||
| 1515 | if (s->do_bounds_check) { | 1522 | if (s->do_bounds_check) { |
| 1516 | /* define symbol */ | 1523 | /* define symbol */ |
| 1517 | tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL); | 1524 | tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL); |
| @@ -1522,11 +1529,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 4 unmodified lines | |||
| 1522 | SHT_PROGBITS, SHF_ALLOC); | 1529 | SHT_PROGBITS, SHF_ALLOC); |
| 1523 | } | 1530 | } |
| 1524 | #endif | 1531 | #endif |
| 1525 | |||
| 1526 | if (s->char_is_unsigned) { | ||
| 1527 | tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL); | ||
| 1528 | } | ||
| 1529 | |||
| 1530 | /* add debug sections */ | 1532 | /* add debug sections */ |
| 1531 | if (s->do_debug) { | 1533 | if (s->do_debug) { |
| 1532 | /* stab symbols */ | 1534 | /* stab symbols */ |
| @@ -1540,9 +1542,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 7 unmodified lines | |||
| 1540 | } | 1542 | } |
| 1541 | 1543 | ||
| 1542 | tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); | 1544 | tcc_add_library_path(s, CONFIG_TCC_LIBPATHS); |
| 1545 | |||
| 1543 | #ifdef TCC_TARGET_PE | 1546 | #ifdef TCC_TARGET_PE |
| 1544 | # ifdef _WIN32 | 1547 | # ifdef _WIN32 |
| 1545 | tcc_add_systemdir(s); | 1548 | if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ) |
| 1549 | tcc_add_systemdir(s); | ||
| 1546 | # endif | 1550 | # endif |
| 1547 | #else | 1551 | #else |
| 1548 | /* add libc crt1/crti objects */ | 1552 | /* add libc crt1/crti objects */ |
| @@ -76,6 +76,7 @@ · 75 unmodified lines | |||
| 76 | # pragma warning (disable : 4018) // signed/unsigned mismatch | 76 | # pragma warning (disable : 4018) // signed/unsigned mismatch |
| 77 | # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned | 77 | # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned |
| 78 | # endif | 78 | # endif |
| 79 | # undef CONFIG_TCC_STATIC | ||
| 79 | #endif | 80 | #endif |
| 80 | 81 | ||
| 81 | #ifndef O_BINARY | 82 | #ifndef O_BINARY |
| @@ -1052,6 +1053,10 @@ static inline int toup(int c) · 970 unmodified lines | |||
| 1052 | # define PUB_FUNC | 1053 | # define PUB_FUNC |
| 1053 | #endif | 1054 | #endif |
| 1054 | 1055 | ||
| 1056 | #ifdef TCC_PROFILE /* profile all functions */ | ||
| 1057 | # define static | ||
| 1058 | #endif | ||
| 1059 | |||
| 1055 | #ifdef ONE_SOURCE | 1060 | #ifdef ONE_SOURCE |
| 1056 | #define ST_INLN static inline | 1061 | #define ST_INLN static inline |
| 1057 | #define ST_FUNC static | 1062 | #define ST_FUNC static |
| @@ -1559,9 +1564,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); · 501 unmodified lines | |||
| 1559 | ST_FUNC void *dlopen(const char *filename, int flag); | 1564 | ST_FUNC void *dlopen(const char *filename, int flag); |
| 1560 | ST_FUNC void dlclose(void *p); | 1565 | ST_FUNC void dlclose(void *p); |
| 1561 | ST_FUNC const char *dlerror(void); | 1566 | ST_FUNC const char *dlerror(void); |
| 1562 | ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); | 1567 | ST_FUNC void *dlsym(int flag, const char *symbol); |
| 1563 | #elif !defined _WIN32 | ||
| 1564 | ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol); | ||
| 1565 | #endif | 1568 | #endif |
| 1566 | 1569 | ||
| 1567 | #ifdef CONFIG_TCC_BACKTRACE | 1570 | #ifdef CONFIG_TCC_BACKTRACE |
| @@ -450,7 +450,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 449 unmodified lines | |||
| 450 | #if defined TCC_IS_NATIVE && !defined _WIN32 | 450 | #if defined TCC_IS_NATIVE && !defined _WIN32 |
| 451 | void *addr; | 451 | void *addr; |
| 452 | name = (char *) symtab_section->link->data + sym->st_name; | 452 | name = (char *) symtab_section->link->data + sym->st_name; |
| 453 | addr = resolve_sym(s1, name); | 453 | addr = dlsym(RTLD_DEFAULT, name); |
| 454 | if (addr) { | 454 | if (addr) { |
| 455 | sym->st_value = (addr_t)addr; | 455 | sym->st_value = (addr_t)addr; |
| 456 | #ifdef DEBUG_RELOC | 456 | #ifdef DEBUG_RELOC |
| @@ -576,15 +576,18 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 119 unmodified lines | |||
| 576 | goto output_file; | 576 | goto output_file; |
| 577 | write16le(ptr, read16le(ptr) + val - addr); | 577 | write16le(ptr, read16le(ptr) + val - addr); |
| 578 | break; | 578 | break; |
| 579 | case R_386_RELATIVE: | 579 | |
| 580 | /* do nothing */ | 580 | #ifdef TCC_TARGET_PE |
| 581 | case R_386_RELATIVE: /* handled in pe_relocate_rva() */ | ||
| 581 | break; | 582 | break; |
| 583 | #endif | ||
| 582 | case R_386_COPY: | 584 | case R_386_COPY: |
| 583 | /* This reloction must copy initialized data from the library | 585 | /* This reloction must copy initialized data from the library |
| 584 | to the program .bss segment. Currently made like for ARM | 586 | to the program .bss segment. Currently made like for ARM |
| 585 | (to remove noise of defaukt case). Is this true? | 587 | (to remove noise of defaukt case). Is this true? |
| 586 | */ | 588 | */ |
| 587 | break; | 589 | break; |
| 590 | |||
| 588 | default: | 591 | default: |
| 589 | fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n", | 592 | fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n", |
| 590 | type, (unsigned)addr, ptr, (unsigned)val); | 593 | type, (unsigned)addr, ptr, (unsigned)val); |
| @@ -773,6 +776,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 182 unmodified lines | |||
| 773 | /* Nothing to do. Normally used to indicate a dependency | 776 | /* Nothing to do. Normally used to indicate a dependency |
| 774 | on a certain symbol (like for exception handling under EABI). */ | 777 | on a certain symbol (like for exception handling under EABI). */ |
| 775 | break; | 778 | break; |
| 779 | #ifdef TCC_TARGET_PE | ||
| 780 | case R_ARM_RELATIVE: /* handled in pe_relocate_rva() */ | ||
| 781 | break; | ||
| 782 | #endif | ||
| 776 | default: | 783 | default: |
| 777 | fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n", | 784 | fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n", |
| 778 | type, (unsigned)addr, ptr, (unsigned)val); | 785 | type, (unsigned)addr, ptr, (unsigned)val); |
| @@ -973,6 +980,11 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 194 unmodified lines | |||
| 973 | /* we load the got offset */ | 980 | /* we load the got offset */ |
| 974 | write32le(ptr, read32le(ptr) + s1->sym_attrs[sym_index].got_offset); | 981 | write32le(ptr, read32le(ptr) + s1->sym_attrs[sym_index].got_offset); |
| 975 | break; | 982 | break; |
| 983 | #ifdef TCC_TARGET_PE | ||
| 984 | case R_X86_64_RELATIVE: /* handled in pe_relocate_rva() */ | ||
| 985 | break; | ||
| 986 | #endif | ||
| 987 | |||
| 976 | #else | 988 | #else |
| 977 | #error unsupported processor | 989 | #error unsupported processor |
| 978 | #endif | 990 | #endif |
| @@ -54,6 +54,7 @@ ST_DATA Sym *define_stack; · 53 unmodified lines | |||
| 54 | ST_DATA Sym *global_label_stack; | 54 | ST_DATA Sym *global_label_stack; |
| 55 | ST_DATA Sym *local_label_stack; | 55 | ST_DATA Sym *local_label_stack; |
| 56 | static int local_scope; | 56 | static int local_scope; |
| 57 | static int in_sizeof; | ||
| 57 | 58 | ||
| 58 | ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */ | 59 | ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */ |
| 59 | ST_DATA int vla_sp_root_loc; /* vla_sp_loc for SP before any VLAs were pushed */ | 60 | ST_DATA int vla_sp_root_loc; /* vla_sp_loc for SP before any VLAs were pushed */ |
| @@ -3762,7 +3763,6 @@ ST_FUNC void unary(void) · 3702 unmodified lines | |||
| 3762 | CType type; | 3763 | CType type; |
| 3763 | Sym *s; | 3764 | Sym *s; |
| 3764 | AttributeDef ad; | 3765 | AttributeDef ad; |
| 3765 | static int in_sizeof = 0; | ||
| 3766 | 3766 | ||
| 3767 | sizeof_caller = in_sizeof; | 3767 | sizeof_caller = in_sizeof; |
| 3768 | in_sizeof = 0; | 3768 | in_sizeof = 0; |
| @@ -5235,6 +5235,7 @@ static void block(int *bsym, int *csym, int is_expr) · 1466 unmodified lines | |||
| 5235 | gcase(sw.p, sw.n, c, &a); | 5235 | gcase(sw.p, sw.n, c, &a); |
| 5236 | if (sw.def_sym) | 5236 | if (sw.def_sym) |
| 5237 | gjmp_addr(sw.def_sym); | 5237 | gjmp_addr(sw.def_sym); |
| 5238 | dynarray_reset(&sw.p, &sw.n); | ||
| 5238 | cur_switch = saved; | 5239 | cur_switch = saved; |
| 5239 | /* break label */ | 5240 | /* break label */ |
| 5240 | gsym(a); | 5241 | gsym(a); |
| @@ -748,7 +748,7 @@ static TCCSyms tcc_syms[] = { · 747 unmodified lines | |||
| 748 | { NULL, NULL }, | 748 | { NULL, NULL }, |
| 749 | }; | 749 | }; |
| 750 | 750 | ||
| 751 | ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol) | 751 | ST_FUNC void *dlsym(int flag, const char *symbol) |
| 752 | { | 752 | { |
| 753 | TCCSyms *p; | 753 | TCCSyms *p; |
| 754 | p = tcc_syms; | 754 | p = tcc_syms; |
| @@ -760,13 +760,6 @@ ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol) · 5 unmodified lines | |||
| 760 | return NULL; | 760 | return NULL; |
| 761 | } | 761 | } |
| 762 | 762 | ||
| 763 | #elif !defined(_WIN32) | ||
| 764 | |||
| 765 | ST_FUNC void *resolve_sym(TCCState *s1, const char *sym) | ||
| 766 | { | ||
| 767 | return dlsym(RTLD_DEFAULT, sym); | ||
| 768 | } | ||
| 769 | |||
| 770 | #endif /* CONFIG_TCC_STATIC */ | 763 | #endif /* CONFIG_TCC_STATIC */ |
| 771 | #endif /* TCC_IS_NATIVE */ | 764 | #endif /* TCC_IS_NATIVE */ |
| 772 | /* ------------------------------------------------------------- */ | 765 | /* ------------------------------------------------------------- */ |