History

Misc. fixes

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

grischka committed 10 years ago

Commit b42cb161 parent b6915856 files · +44 −32Browse files

Unified · Split

6 files
  1. Makefile +7 −8
  2. libtcc.c +13 −9
  3. tcc.h +6 −3
  4. tccelf.c +15 −3
  5. tccgen.c +2 −1
  6. tccrun.c +1 −8
Makefile+7−8
@@ -18,10 +18,6 @@ else · 17 unmodified lines
18 endif18 endif
19endif19endif
20 20
21CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
22LIBS_P=
23LDFLAGS_P = $(LDFLAGS)
24
25LIBTCC = libtcc.a21LIBTCC = libtcc.a
26LIBTCC1 = libtcc1.a22LIBTCC1 = libtcc1.a
27LINK_LIBTCC =23LINK_LIBTCC =
@@ -50,6 +46,10 @@ ifeq ($(TARGETOS),Darwin) · 22 unmodified lines
50 export MACOSX_DEPLOYMENT_TARGET:=10.246 export MACOSX_DEPLOYMENT_TARGET:=10.2
51endif47endif
52 48
49CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
50LIBS_P= $(LIBS)
51LDFLAGS_P = $(LDFLAGS)
52
53CONFIG_$(ARCH) = yes53CONFIG_$(ARCH) = yes
54NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I38654NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
55NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_6455NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
@@ -136,8 +136,8 @@ endif · 80 unmodified lines
136all: $(PROGS) $(TCCLIBS) $(TCCDOCS)136all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
137 137
138# Host Tiny C Compiler138# Host Tiny C Compiler
139tcc$(EXESUF): tcc.c $(LIBTCC)139tcc$(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 Compilers142# Cross Tiny C Compilers
143%-tcc$(EXESUF): tcc.c143%-tcc$(EXESUF): tcc.c
@@ -182,7 +182,6 @@ else · 38 unmodified lines
182LIBTCC_OBJ = libtcc.o182LIBTCC_OBJ = libtcc.o
183LIBTCC_INC = $(NATIVE_FILES)183LIBTCC_INC = $(NATIVE_FILES)
184libtcc.o : NATIVE_DEFINES += -DONE_SOURCE184libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
185tcc.o : NATIVE_DEFINES += -DONE_SOURCE
186endif185endif
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"
273else272else
274# on windows273# on windows
275install: $(PROGS) $(TCCLIBS) $(TCCDOCS)274install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
libtcc.c+13−9
@@ -116,7 +116,7 @@ static void tcc_add_systemdir(TCCState *s) · 115 unmodified lines
116}116}
117#endif117#endif
118 118
119#if defined TCC_IS_NATIVE && !defined CONFIG_TCC_STATIC119#if defined TCC_IS_NATIVE
120static void dlclose(void *p)120static 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_BCHECK1520#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#endif1531#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_PE1546#ifdef TCC_TARGET_PE
1544# ifdef _WIN321547# ifdef _WIN32
1545 tcc_add_systemdir(s);1548 if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
1549 tcc_add_systemdir(s);
1546# endif1550# endif
1547#else1551#else
1548 /* add libc crt1/crti objects */1552 /* add libc crt1/crti objects */
tcc.h+6−3
@@ -76,6 +76,7 @@ · 75 unmodified lines
76# pragma warning (disable : 4018) // signed/unsigned mismatch76# pragma warning (disable : 4018) // signed/unsigned mismatch
77# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned77# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
78# endif78# endif
79# undef CONFIG_TCC_STATIC
79#endif80#endif
80 81
81#ifndef O_BINARY82#ifndef O_BINARY
@@ -1052,6 +1053,10 @@ static inline int toup(int c) · 970 unmodified lines
1052# define PUB_FUNC1053# define PUB_FUNC
1053#endif1054#endif
1054 1055
1056#ifdef TCC_PROFILE /* profile all functions */
1057# define static
1058#endif
1059
1055#ifdef ONE_SOURCE1060#ifdef ONE_SOURCE
1056#define ST_INLN static inline1061#define ST_INLN static inline
1057#define ST_FUNC static1062#define ST_FUNC static
@@ -1559,9 +1564,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); · 501 unmodified lines
1559ST_FUNC void *dlopen(const char *filename, int flag);1564ST_FUNC void *dlopen(const char *filename, int flag);
1560ST_FUNC void dlclose(void *p);1565ST_FUNC void dlclose(void *p);
1561ST_FUNC const char *dlerror(void);1566ST_FUNC const char *dlerror(void);
1562ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);1567ST_FUNC void *dlsym(int flag, const char *symbol);
1563#elif !defined _WIN32
1564ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
1565#endif1568#endif
1566 1569
1567#ifdef CONFIG_TCC_BACKTRACE1570#ifdef CONFIG_TCC_BACKTRACE
tccelf.c+15−3
@@ -450,7 +450,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve) · 449 unmodified lines
450#if defined TCC_IS_NATIVE && !defined _WIN32450#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_RELOC456#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 library585 /* This reloction must copy initialized data from the library
584 to the program .bss segment. Currently made like for ARM586 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 dependency776 /* 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#else988#else
977#error unsupported processor989#error unsupported processor
978#endif990#endif
tccgen.c+2−1
@@ -54,6 +54,7 @@ ST_DATA Sym *define_stack; · 53 unmodified lines
54ST_DATA Sym *global_label_stack;54ST_DATA Sym *global_label_stack;
55ST_DATA Sym *local_label_stack;55ST_DATA Sym *local_label_stack;
56static int local_scope;56static int local_scope;
57static int in_sizeof;
57 58
58ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */59ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */
59ST_DATA int vla_sp_root_loc; /* vla_sp_loc for SP before any VLAs were pushed */60ST_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);
tccrun.c+1−8
@@ -748,7 +748,7 @@ static TCCSyms tcc_syms[] = { · 747 unmodified lines
748 { NULL, NULL },748 { NULL, NULL },
749};749};
750 750
751ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)751ST_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
765ST_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/* ------------------------------------------------------------- */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t