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
1818 endif
1919 endif
2020
21−CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
22−LIBS_P=
23−LDFLAGS_P = $(LDFLAGS)
24−
2521 LIBTCC = libtcc.a
2622 LIBTCC1 = libtcc1.a
2723 LINK_LIBTCC =
@@ -50,6 +46,10 @@ ifeq ($(TARGETOS),Darwin) · 22 unmodified lines
5046 export MACOSX_DEPLOYMENT_TARGET:=10.2
5147 endif
5248
49+CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
50+LIBS_P= $(LIBS)
51+LDFLAGS_P = $(LDFLAGS)
52+
5353 CONFIG_$(ARCH) = yes
5454 NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
5555 NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
@@ -136,8 +136,8 @@ endif · 80 unmodified lines
136136 all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
137137
138138 # 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)
141141
142142 # Cross Tiny C Compilers
143143 %-tcc$(EXESUF): tcc.c
@@ -182,7 +182,6 @@ else · 38 unmodified lines
182182 LIBTCC_OBJ = libtcc.o
183183 LIBTCC_INC = $(NATIVE_FILES)
184184 libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
185−tcc.o : NATIVE_DEFINES += -DONE_SOURCE
186185 endif
187186
188187 $(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
@@ -269,7 +268,7 @@ uninstall: · 80 unmodified lines
269268 rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
270269 rm -fv $(libdir)/libtcc.so*
271270 rm -rv "$(tccdir)"
272− rm -rv "$(docdir)"
271+ rm -fv "$(docdir)/tcc-doc.html"
273272 else
274273 # on windows
275274 install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
libtcc.c+13−9
@@ -116,7 +116,7 @@ static void tcc_add_systemdir(TCCState *s) · 115 unmodified lines
116116 }
117117 #endif
118118
119−#if defined TCC_IS_NATIVE && !defined CONFIG_TCC_STATIC
119+#if defined TCC_IS_NATIVE
120120 static void dlclose(void *p)
121121 {
122122 FreeLibrary((HMODULE)p);
@@ -412,7 +412,7 @@ PUB_FUNC void tcc_memstats(int bench) · 289 unmodified lines
412412 mem_cur_size, mem_max_size);
413413
414414 while (header) {
415− fprintf(stderr, " file %s, line %u: %u bytes\n",
415+ fprintf(stderr, "%s:%u: error: %u bytes leaked\n",
416416 header->file_name, header->line_num, header->size);
417417 header = header->next;
418418 }
@@ -1504,14 +1504,21 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 1085 unmodified lines
15041504 {
15051505 s->output_type = output_type;
15061506
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+
15071514 if (!s->nostdinc) {
15081515 /* default include paths */
15091516 /* -isystem paths have already been handled */
15101517 tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
15111518 }
15121519
1513− /* if bound checking, then add corresponding sections */
15141520 #ifdef CONFIG_TCC_BCHECK
1521+ /* if bound checking, then add corresponding sections */
15151522 if (s->do_bounds_check) {
15161523 /* define symbol */
15171524 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
15221529 SHT_PROGBITS, SHF_ALLOC);
15231530 }
15241531 #endif
1525−
1526− if (s->char_is_unsigned) {
1527− tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL);
1528− }
1529−
15301532 /* add debug sections */
15311533 if (s->do_debug) {
15321534 /* stab symbols */
@@ -1540,9 +1542,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type) · 7 unmodified lines
15401542 }
15411543
15421544 tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
1545+
15431546 #ifdef TCC_TARGET_PE
15441547 # ifdef _WIN32
1545− tcc_add_systemdir(s);
1548+ if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
1549+ tcc_add_systemdir(s);
15461550 # endif
15471551 #else
15481552 /* add libc crt1/crti objects */
tcc.h+6−3
@@ -76,6 +76,7 @@ · 75 unmodified lines
7676 # pragma warning (disable : 4018) // signed/unsigned mismatch
7777 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
7878 # endif
79+# undef CONFIG_TCC_STATIC
7980 #endif
8081
8182 #ifndef O_BINARY
@@ -1052,6 +1053,10 @@ static inline int toup(int c) · 970 unmodified lines
10521053 # define PUB_FUNC
10531054 #endif
10541055
1056+#ifdef TCC_PROFILE /* profile all functions */
1057+# define static
1058+#endif
1059+
10551060 #ifdef ONE_SOURCE
10561061 #define ST_INLN static inline
10571062 #define ST_FUNC static
@@ -1559,9 +1564,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack); · 501 unmodified lines
15591564 ST_FUNC void *dlopen(const char *filename, int flag);
15601565 ST_FUNC void dlclose(void *p);
15611566 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);
15651568 #endif
15661569
15671570 #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
450450 #if defined TCC_IS_NATIVE && !defined _WIN32
451451 void *addr;
452452 name = (char *) symtab_section->link->data + sym->st_name;
453− addr = resolve_sym(s1, name);
453+ addr = dlsym(RTLD_DEFAULT, name);
454454 if (addr) {
455455 sym->st_value = (addr_t)addr;
456456 #ifdef DEBUG_RELOC
@@ -576,15 +576,18 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 119 unmodified lines
576576 goto output_file;
577577 write16le(ptr, read16le(ptr) + val - addr);
578578 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() */
581582 break;
583+#endif
582584 case R_386_COPY:
583585 /* This reloction must copy initialized data from the library
584586 to the program .bss segment. Currently made like for ARM
585587 (to remove noise of defaukt case). Is this true?
586588 */
587589 break;
590+
588591 default:
589592 fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
590593 type, (unsigned)addr, ptr, (unsigned)val);
@@ -773,6 +776,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 182 unmodified lines
773776 /* Nothing to do. Normally used to indicate a dependency
774777 on a certain symbol (like for exception handling under EABI). */
775778 break;
779+#ifdef TCC_TARGET_PE
780+ case R_ARM_RELATIVE: /* handled in pe_relocate_rva() */
781+ break;
782+#endif
776783 default:
777784 fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
778785 type, (unsigned)addr, ptr, (unsigned)val);
@@ -973,6 +980,11 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s) · 194 unmodified lines
973980 /* we load the got offset */
974981 write32le(ptr, read32le(ptr) + s1->sym_attrs[sym_index].got_offset);
975982 break;
983+#ifdef TCC_TARGET_PE
984+ case R_X86_64_RELATIVE: /* handled in pe_relocate_rva() */
985+ break;
986+#endif
987+
976988 #else
977989 #error unsupported processor
978990 #endif
tccgen.c+2−1
@@ -54,6 +54,7 @@ ST_DATA Sym *define_stack; · 53 unmodified lines
5454 ST_DATA Sym *global_label_stack;
5555 ST_DATA Sym *local_label_stack;
5656 static int local_scope;
57+static int in_sizeof;
5758
5859 ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */
5960 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
37623763 CType type;
37633764 Sym *s;
37643765 AttributeDef ad;
3765− static int in_sizeof = 0;
37663766
37673767 sizeof_caller = in_sizeof;
37683768 in_sizeof = 0;
@@ -5235,6 +5235,7 @@ static void block(int *bsym, int *csym, int is_expr) · 1466 unmodified lines
52355235 gcase(sw.p, sw.n, c, &a);
52365236 if (sw.def_sym)
52375237 gjmp_addr(sw.def_sym);
5238+ dynarray_reset(&sw.p, &sw.n);
52385239 cur_switch = saved;
52395240 /* break label */
52405241 gsym(a);
tccrun.c+1−8
@@ -748,7 +748,7 @@ static TCCSyms tcc_syms[] = { · 747 unmodified lines
748748 { NULL, NULL },
749749 };
750750
751−ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)
751+ST_FUNC void *dlsym(int flag, const char *symbol)
752752 {
753753 TCCSyms *p;
754754 p = tcc_syms;
@@ -760,13 +760,6 @@ ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol) · 5 unmodified lines
760760 return NULL;
761761 }
762762
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−
770763 #endif /* CONFIG_TCC_STATIC */
771764 #endif /* TCC_IS_NATIVE */
772765 /* ------------------------------------------------------------- */

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