History

tcc -vv/--print-search-dirs: print more info

tests/Makefile: - print-search-dirs when 'hello' fails - split off hello-run win32/include/_mingw.h: - fix for compatibility with mingw headers (While our headers in win32 are from mingw-64 and don't have the problem) tiny_libmaker: - don't use "dangerous" mktemp

grischka committed 13 years ago

Commit 80421211 parent d6d76867 files · +113 −58Browse files

Unified · Split

7 files
  1. lib/Makefile +1 −1
  2. libtcc.c +64 −14
  3. tcc.c +8 −4
  4. tcc.h +1 −0
  5. tests/Makefile +9 −4
  6. win32/include/_mingw.h +2 −1
  7. win32/tools/tiny_libmaker.c +28 −34
lib/Makefile+1−1
@@ -91,7 +91,7 @@ $(DIR)/%.o : %.c · 90 unmodified lines
9191 $(DIR)/%.o : %.S
9292 $(XCC) -c $< -o $@ $(XFLAGS)
9393 $(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c
94− $(CC) -Os -s -w -o $@ $< $(XFLAGS) $(LDFLAGS)
94+ $(CC) -Os -s -o $@ $< $(XFLAGS) $(LDFLAGS)
9595
9696 $(OBJ) $(XAR) : $(DIR)/exists
9797 $(DIR)/exists :
libtcc.c+64−14
@@ -1589,20 +1589,6 @@ PUB_FUNC const char * tcc_set_linker(TCCState *s, char *option, int multi) · 1588 unmodified lines
15891589 return NULL;
15901590 }
15911591
1592−PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
1593−{
1594− double tt;
1595− tt = (double)total_time / 1000000.0;
1596− if (tt < 0.001)
1597− tt = 0.001;
1598− if (total_bytes < 1)
1599− total_bytes = 1;
1600− printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
1601− tok_ident - TOK_IDENT, total_lines, total_bytes,
1602− tt, (int)(total_lines / tt),
1603− total_bytes / tt / 1000000.0);
1604−}
1605−
16061592 /* set CONFIG_TCCDIR at runtime */
16071593 LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
16081594 {
@@ -1668,3 +1654,67 @@ PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *file · 59 unmodified lines
16681654 fprintf(depout, "\n");
16691655 fclose(depout);
16701656 }
1657+
1658+PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
1659+{
1660+ double tt;
1661+ tt = (double)total_time / 1000000.0;
1662+ if (tt < 0.001)
1663+ tt = 0.001;
1664+ if (total_bytes < 1)
1665+ total_bytes = 1;
1666+ printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
1667+ tok_ident - TOK_IDENT, total_lines, total_bytes,
1668+ tt, (int)(total_lines / tt),
1669+ total_bytes / tt / 1000000.0);
1670+}
1671+
1672+static void print_paths(const char *msg, char **paths, int nb_paths)
1673+{
1674+ int i;
1675+ printf("%s:\n%s", msg, nb_paths ? "" : " -\n");
1676+ for(i = 0; i < nb_paths; i++)
1677+ printf(" %s\n", paths[i]);
1678+}
1679+
1680+PUB_FUNC void tcc_display_info(TCCState *s, int what)
1681+{
1682+ switch (what) {
1683+ case 0:
1684+ printf("tcc version %s ("
1685+#ifdef TCC_TARGET_I386
1686+ "i386"
1687+# ifdef TCC_TARGET_PE
1688+ " Win32"
1689+# endif
1690+#elif defined TCC_TARGET_X86_64
1691+ "x86-64"
1692+# ifdef TCC_TARGET_PE
1693+ " Win64"
1694+# endif
1695+#elif defined TCC_TARGET_ARM
1696+ "ARM"
1697+# ifdef TCC_ARM_HARDFLOAT
1698+ " Hard Float"
1699+# endif
1700+# ifdef TCC_TARGET_PE
1701+ " WinCE"
1702+# endif
1703+#endif
1704+#ifndef TCC_TARGET_PE
1705+# ifdef __linux
1706+ " Linux"
1707+# endif
1708+#endif
1709+ ")\n", TCC_VERSION);
1710+ break;
1711+ case 1:
1712+ printf("install: %s/\n", s->tcc_lib_path);
1713+ /* print_paths("programs", NULL, 0); */
1714+ print_paths("crt", s->crt_paths, s->nb_crt_paths);
1715+ print_paths("libraries", s->library_paths, s->nb_library_paths);
1716+ print_paths("include", s->sysinclude_paths, s->nb_sysinclude_paths);
1717+ break;
1718+ }
1719+}
1720+
tcc.c+8−4
@@ -508,17 +508,21 @@ int main(int argc, char **argv) · 507 unmodified lines
508508 #endif
509509
510510 if (print_search_dirs) {
511− /* enough for Linux kernel */
512− printf("install: %s/\n", s->tcc_lib_path);
511+psd:
512+ tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
513+ tcc_display_info(s, 1);
513514 return 0;
514515 }
515516
516517 if (s->verbose)
517− printf("tcc version %s\n", TCC_VERSION);
518+ tcc_display_info(s, 0);
518519
519520 if (optind == 0 || nb_files == 0) {
520− if (optind && s->verbose)
521+ if (optind && s->verbose) {
522+ if (s->verbose == 2)
523+ goto psd;
521524 return 0;
525+ }
522526 help();
523527 return 1;
524528 }
tcc.h+1−0
@@ -1067,6 +1067,7 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value); · 1066 unmodified lines
10671067 PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
10681068 PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);
10691069 PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
1070+PUB_FUNC void tcc_display_info(TCCState *s, int what);
10701071
10711072 /* ------------ tccpp.c ------------ */
10721073
tests/Makefile+9−4
@@ -8,7 +8,8 @@ VPATH = $(top_srcdir)/tests · 7 unmodified lines
88
99 # what tests to run
1010 TESTS = \
11− hello \
11+ hello-exe \
12+ hello-run \
1213 libtest \
1314 test3 \
1415 moretests
@@ -26,7 +27,7 @@ ifdef CONFIG_WIN32 · 11 unmodified lines
2627 TESTS := $(filter-out test3,$(TESTS))
2728 endif
2829 ifeq ($(TARGETOS),Darwin)
29− TESTS := $(filter-out hello test3 btest,$(TESTS))
30+ TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
3031 endif
3132
3233 ifdef DISABLE_STATIC
@@ -57,9 +58,12 @@ endif · 24 unmodified lines
5758
5859 all test : $(TESTS)
5960
60−hello: ../examples/ex1.c
61+hello-exe: ../examples/ex1.c
62+ @echo ------------ $@ ------------
63+ $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
64+
65+hello-run: ../examples/ex1.c
6166 @echo ------------ $@ ------------
62− $(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF)
6367 $(TCC) -run $<
6468
6569 libtest: libtcc_test$(EXESUF) $(LIBTCC1)
@@ -192,3 +196,4 @@ clean: · 126 unmodified lines
192196 $(MAKE) -C tests2 $@
193197 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
194198 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
199+
win32/include/_mingw.h+2−1
@@ -37,8 +37,9 @@ · 36 unmodified lines
3737 #define __unaligned __attribute__((packed))
3838 #define __fastcall __attribute__((fastcall))
3939
40−#define __MINGW_IMPORT extern __declspec(dllimport)
40+#define __MSVCRT__ 1
4141 #undef _MSVCRT_
42+#define __MINGW_IMPORT extern __declspec(dllimport)
4243 #define __MINGW_ATTRIB_NORETURN
4344 #define __MINGW_ATTRIB_CONST
4445 #define __MINGW_ATTRIB_DEPRECATED
win32/tools/tiny_libmaker.c+28−34
@@ -21,10 +21,6 @@ · 20 unmodified lines
2121 #include <stdio.h>
2222 #include <stdlib.h>
2323 #include <string.h>
24−#ifdef _WIN32
25−#include <io.h> /* for mktemp */
26−#endif
27−
2824 #include "../../elf.h"
2925
3026 #ifdef TCC_TARGET_X86_64
@@ -77,7 +73,7 @@ ArHdr arhdro = { · 46 unmodified lines
7773
7874 int main(int argc, char **argv)
7975 {
80− FILE *fi, *fh, *fo;
76+ FILE *fi, *fh = NULL, *fo = NULL;
8177 ElfW(Ehdr) *ehdr;
8278 ElfW(Shdr) *shdr;
8379 ElfW(Sym) *sym;
@@ -89,6 +85,7 @@ int main(int argc, char **argv) · 5 unmodified lines
8985 int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
9086 char afile[260], tfile[260], stmp[20];
9187 char *file, *name;
88+ int ret = 2;
9289
9390
9491 strcpy(afile, "ar_test.a");
@@ -111,19 +108,17 @@ int main(int argc, char **argv) · 16 unmodified lines
111108 }
112109 }
113110
114− strcpy(tfile, "./XXXXXX");
115− if (!mktemp(tfile) || (fo = fopen(tfile, "wb+")) == NULL)
111+ if ((fh = fopen(afile, "wb")) == NULL)
116112 {
117− fprintf(stderr, "Can't open temporary file %s\n", tfile);
118− return 2;
113+ fprintf(stderr, "Can't open file %s \n", afile);
114+ goto the_end;
119115 }
120116
121− if ((fh = fopen(afile, "wb")) == NULL)
117+ sprintf(tfile, "%s.tmp", afile);
118+ if ((fo = fopen(tfile, "wb+")) == NULL)
122119 {
123− fprintf(stderr, "Can't open file %s \n", afile);
124− fclose(fo);
125− remove(tfile);
126− return 2;
120+ fprintf(stderr, "Can't create temporary file %s\n", tfile);
121+ goto the_end;
127122 }
128123
129124 funcmax = 250;
@@ -140,9 +135,7 @@ int main(int argc, char **argv) · 10 unmodified lines
140135 if ((fi = fopen(argv[iarg], "rb")) == NULL)
141136 {
142137 fprintf(stderr, "Can't open file %s \n", argv[iarg]);
143− fclose(fo);
144− remove(tfile);
145− return 2;
138+ goto the_end;
146139 }
147140 fseek(fi, 0, SEEK_END);
148141 fsize = ftell(fi);
@@ -152,14 +145,13 @@ int main(int argc, char **argv) · 3 unmodified lines
152145 fclose(fi);
153146
154147 //printf("%s:\n", argv[iarg]);
148+
155149 // elf header
156150 ehdr = (ElfW(Ehdr) *)buf;
157151 if (ehdr->e_ident[4] != ELFCLASSW)
158152 {
159153 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
160− fclose(fo);
161− remove(tfile);
162− return 2;
154+ goto the_end;
163155 }
164156
165157 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
@@ -167,7 +159,8 @@ int main(int argc, char **argv) · 1 unmodified line
167159 for (i = 0; i < ehdr->e_shnum; i++)
168160 {
169161 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
170− if (!shdr->sh_offset) continue;
162+ if (!shdr->sh_offset)
163+ continue;
171164 if (shdr->sh_type == SHT_SYMTAB)
172165 {
173166 symtab = (char *)(buf + shdr->sh_offset);
@@ -210,7 +203,7 @@ int main(int argc, char **argv) · 36 unmodified lines
210203 }
211204
212205 file = argv[iarg];
213− for (name = strchr(file, 0);
206+ for (name = strchr(file, 0);
214207 name > file && name[-1] != '/' && name[-1] != '\\';
215208 --name);
216209 istrlen = strlen(name);
@@ -219,7 +212,6 @@ int main(int argc, char **argv) · 2 unmodified lines
219212 memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));
220213 memcpy(arhdro.ar_name, name, istrlen);
221214 arhdro.ar_name[istrlen] = '/';
222−
223215 sprintf(stmp, "%-10d", fsize);
224216 memcpy(&arhdro.ar_size, stmp, 10);
225217 fwrite(&arhdro, sizeof(arhdro), 1, fo);
@@ -229,36 +221,38 @@ int main(int argc, char **argv) · 3 unmodified lines
229221 fpos += (fsize + sizeof(arhdro));
230222 }
231223 hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
232− if ((hofs & 1)) { // align
233− hofs++;
234− fpos = 1;
235− } else fpos = 0;
224+ fpos = 0;
225+ if ((hofs & 1)) // align
226+ hofs++, fpos = 1;
236227 // write header
237228 fwrite("!<arch>\n", 8, 1, fh);
238229 sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
239230 memcpy(&arhdr.ar_size, stmp, 10);
240231 fwrite(&arhdr, sizeof(arhdr), 1, fh);
241232 afpos[0] = le2belong(funccnt);
242− for (i=1; i<=funccnt; i++) {
233+ for (i=1; i<=funccnt; i++)
243234 afpos[i] = le2belong(afpos[i] + hofs);
244− }
245235 fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
246236 fwrite(anames, strpos, 1, fh);
247− if (fpos) fwrite("", 1, 1, fh);
237+ if (fpos)
238+ fwrite("", 1, 1, fh);
248239 // write objects
249240 fseek(fo, 0, SEEK_END);
250241 fsize = ftell(fo);
251242 fseek(fo, 0, SEEK_SET);
252243 buf = malloc(fsize + 1);
253244 fread(buf, fsize, 1, fo);
254− fclose(fo);
255245 fwrite(buf, fsize, 1, fh);
256− fclose(fh);
257246 free(buf);
247+ ret = 0;
248+the_end:
258249 if (anames)
259250 free(anames);
260251 if (afpos)
261252 free(afpos);
262− remove(tfile);
263− return 0;
253+ if (fh)
254+ fclose(fh);
255+ if (fo)
256+ fclose(fo), remove(tfile);
257+ return ret;
264258 }

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