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