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
91$(DIR)/%.o : %.S91$(DIR)/%.o : %.S
92 $(XCC) -c $< -o $@ $(XFLAGS)92 $(XCC) -c $< -o $@ $(XFLAGS)
93$(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c93$(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c
94 $(CC) -Os -s -w -o $@ $< $(XFLAGS) $(LDFLAGS)94 $(CC) -Os -s -o $@ $< $(XFLAGS) $(LDFLAGS)
95 95
96$(OBJ) $(XAR) : $(DIR)/exists96$(OBJ) $(XAR) : $(DIR)/exists
97$(DIR)/exists :97$(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
1589 return NULL;1589 return NULL;
1590}1590}
1591 1591
1592PUB_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
1606/* set CONFIG_TCCDIR at runtime */1592/* set CONFIG_TCCDIR at runtime */
1607LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)1593LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
1608{1594{
@@ -1668,3 +1654,67 @@ PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *file · 59 unmodified lines
1668 fprintf(depout, "\n");1654 fprintf(depout, "\n");
1669 fclose(depout);1655 fclose(depout);
1670}1656}
1657
1658PUB_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
1672static 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
1680PUB_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
508#endif508#endif
509 509
510 if (print_search_dirs) {510 if (print_search_dirs) {
511 /* enough for Linux kernel */511psd:
512 printf("install: %s/\n", s->tcc_lib_path);512 tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
513 tcc_display_info(s, 1);
513 return 0;514 return 0;
514 }515 }
515 516
516 if (s->verbose)517 if (s->verbose)
517 printf("tcc version %s\n", TCC_VERSION);518 tcc_display_info(s, 0);
518 519
519 if (optind == 0 || nb_files == 0) {520 if (optind == 0 || nb_files == 0) {
520 if (optind && s->verbose)521 if (optind && s->verbose) {
522 if (s->verbose == 2)
523 goto psd;
521 return 0;524 return 0;
525 }
522 help();526 help();
523 return 1;527 return 1;
524 }528 }
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
1067PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);1067PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
1068PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);1068PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);
1069PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);1069PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
1070PUB_FUNC void tcc_display_info(TCCState *s, int what);
1070 1071
1071/* ------------ tccpp.c ------------ */1072/* ------------ tccpp.c ------------ */
1072 1073
tests/Makefile+9−4
@@ -8,7 +8,8 @@ VPATH = $(top_srcdir)/tests · 7 unmodified lines
8 8
9# what tests to run9# what tests to run
10TESTS = \10TESTS = \
11 hello \11 hello-exe \
12 hello-run \
12 libtest \13 libtest \
13 test3 \14 test3 \
14 moretests15 moretests
@@ -26,7 +27,7 @@ ifdef CONFIG_WIN32 · 11 unmodified lines
26 TESTS := $(filter-out test3,$(TESTS))27 TESTS := $(filter-out test3,$(TESTS))
27endif28endif
28ifeq ($(TARGETOS),Darwin)29ifeq ($(TARGETOS),Darwin)
29 TESTS := $(filter-out hello test3 btest,$(TESTS))30 TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
30endif31endif
31 32
32ifdef DISABLE_STATIC33ifdef DISABLE_STATIC
@@ -57,9 +58,12 @@ endif · 24 unmodified lines
57 58
58all test : $(TESTS)59all test : $(TESTS)
59 60
60hello: ../examples/ex1.c61hello-exe: ../examples/ex1.c
62 @echo ------------ $@ ------------
63 $(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
64
65hello-run: ../examples/ex1.c
61 @echo ------------ $@ ------------66 @echo ------------ $@ ------------
62 $(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF)
63 $(TCC) -run $<67 $(TCC) -run $<
64 68
65libtest: libtcc_test$(EXESUF) $(LIBTCC1)69libtest: libtcc_test$(EXESUF) $(LIBTCC1)
@@ -192,3 +196,4 @@ clean: · 126 unmodified lines
192 $(MAKE) -C tests2 $@196 $(MAKE) -C tests2 $@
193 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \197 rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
194 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h198 hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
199
win32/include/_mingw.h+2−1
@@ -37,8 +37,9 @@ · 36 unmodified lines
37#define __unaligned __attribute__((packed))37#define __unaligned __attribute__((packed))
38#define __fastcall __attribute__((fastcall))38#define __fastcall __attribute__((fastcall))
39 39
40#define __MINGW_IMPORT extern __declspec(dllimport)40#define __MSVCRT__ 1
41#undef _MSVCRT_41#undef _MSVCRT_
42#define __MINGW_IMPORT extern __declspec(dllimport)
42#define __MINGW_ATTRIB_NORETURN43#define __MINGW_ATTRIB_NORETURN
43#define __MINGW_ATTRIB_CONST44#define __MINGW_ATTRIB_CONST
44#define __MINGW_ATTRIB_DEPRECATED45#define __MINGW_ATTRIB_DEPRECATED
win32/tools/tiny_libmaker.c+28−34
@@ -21,10 +21,6 @@ · 20 unmodified lines
21#include <stdio.h>21#include <stdio.h>
22#include <stdlib.h>22#include <stdlib.h>
23#include <string.h>23#include <string.h>
24#ifdef _WIN32
25#include <io.h> /* for mktemp */
26#endif
27
28#include "../../elf.h"24#include "../../elf.h"
29 25
30#ifdef TCC_TARGET_X86_6426#ifdef TCC_TARGET_X86_64
@@ -77,7 +73,7 @@ ArHdr arhdro = { · 46 unmodified lines
77 73
78int main(int argc, char **argv)74int main(int argc, char **argv)
79{75{
80 FILE *fi, *fh, *fo;76 FILE *fi, *fh = NULL, *fo = NULL;
81 ElfW(Ehdr) *ehdr;77 ElfW(Ehdr) *ehdr;
82 ElfW(Shdr) *shdr;78 ElfW(Shdr) *shdr;
83 ElfW(Sym) *sym;79 ElfW(Sym) *sym;
@@ -89,6 +85,7 @@ int main(int argc, char **argv) · 5 unmodified lines
89 int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;85 int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
90 char afile[260], tfile[260], stmp[20];86 char afile[260], tfile[260], stmp[20];
91 char *file, *name;87 char *file, *name;
88 int ret = 2;
92 89
93 90
94 strcpy(afile, "ar_test.a");91 strcpy(afile, "ar_test.a");
@@ -111,19 +108,17 @@ int main(int argc, char **argv) · 16 unmodified lines
111 }108 }
112 }109 }
113 110
114 strcpy(tfile, "./XXXXXX");111 if ((fh = fopen(afile, "wb")) == NULL)
115 if (!mktemp(tfile) || (fo = fopen(tfile, "wb+")) == NULL)
116 {112 {
117 fprintf(stderr, "Can't open temporary file %s\n", tfile);113 fprintf(stderr, "Can't open file %s \n", afile);
118 return 2;114 goto the_end;
119 }115 }
120 116
121 if ((fh = fopen(afile, "wb")) == NULL)117 sprintf(tfile, "%s.tmp", afile);
118 if ((fo = fopen(tfile, "wb+")) == NULL)
122 {119 {
123 fprintf(stderr, "Can't open file %s \n", afile);120 fprintf(stderr, "Can't create temporary file %s\n", tfile);
124 fclose(fo);121 goto the_end;
125 remove(tfile);
126 return 2;
127 }122 }
128 123
129 funcmax = 250;124 funcmax = 250;
@@ -140,9 +135,7 @@ int main(int argc, char **argv) · 10 unmodified lines
140 if ((fi = fopen(argv[iarg], "rb")) == NULL)135 if ((fi = fopen(argv[iarg], "rb")) == NULL)
141 {136 {
142 fprintf(stderr, "Can't open file %s \n", argv[iarg]);137 fprintf(stderr, "Can't open file %s \n", argv[iarg]);
143 fclose(fo);138 goto the_end;
144 remove(tfile);
145 return 2;
146 }139 }
147 fseek(fi, 0, SEEK_END);140 fseek(fi, 0, SEEK_END);
148 fsize = ftell(fi);141 fsize = ftell(fi);
@@ -152,14 +145,13 @@ int main(int argc, char **argv) · 3 unmodified lines
152 fclose(fi);145 fclose(fi);
153 146
154 //printf("%s:\n", argv[iarg]);147 //printf("%s:\n", argv[iarg]);
148
155 // elf header149 // elf header
156 ehdr = (ElfW(Ehdr) *)buf;150 ehdr = (ElfW(Ehdr) *)buf;
157 if (ehdr->e_ident[4] != ELFCLASSW)151 if (ehdr->e_ident[4] != ELFCLASSW)
158 {152 {
159 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);153 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
160 fclose(fo);154 goto the_end;
161 remove(tfile);
162 return 2;
163 }155 }
164 156
165 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);157 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
167 for (i = 0; i < ehdr->e_shnum; i++)159 for (i = 0; i < ehdr->e_shnum; i++)
168 {160 {
169 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);161 shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
170 if (!shdr->sh_offset) continue;162 if (!shdr->sh_offset)
163 continue;
171 if (shdr->sh_type == SHT_SYMTAB)164 if (shdr->sh_type == SHT_SYMTAB)
172 {165 {
173 symtab = (char *)(buf + shdr->sh_offset);166 symtab = (char *)(buf + shdr->sh_offset);
@@ -210,7 +203,7 @@ int main(int argc, char **argv) · 36 unmodified lines
210 }203 }
211 204
212 file = argv[iarg];205 file = argv[iarg];
213 for (name = strchr(file, 0); 206 for (name = strchr(file, 0);
214 name > file && name[-1] != '/' && name[-1] != '\\';207 name > file && name[-1] != '/' && name[-1] != '\\';
215 --name);208 --name);
216 istrlen = strlen(name);209 istrlen = strlen(name);
@@ -219,7 +212,6 @@ int main(int argc, char **argv) · 2 unmodified lines
219 memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));212 memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));
220 memcpy(arhdro.ar_name, name, istrlen);213 memcpy(arhdro.ar_name, name, istrlen);
221 arhdro.ar_name[istrlen] = '/';214 arhdro.ar_name[istrlen] = '/';
222
223 sprintf(stmp, "%-10d", fsize);215 sprintf(stmp, "%-10d", fsize);
224 memcpy(&arhdro.ar_size, stmp, 10);216 memcpy(&arhdro.ar_size, stmp, 10);
225 fwrite(&arhdro, sizeof(arhdro), 1, fo);217 fwrite(&arhdro, sizeof(arhdro), 1, fo);
@@ -229,36 +221,38 @@ int main(int argc, char **argv) · 3 unmodified lines
229 fpos += (fsize + sizeof(arhdro));221 fpos += (fsize + sizeof(arhdro));
230 }222 }
231 hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);223 hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
232 if ((hofs & 1)) { // align224 fpos = 0;
233 hofs++;225 if ((hofs & 1)) // align
234 fpos = 1;226 hofs++, fpos = 1;
235 } else fpos = 0;
236 // write header227 // write header
237 fwrite("!<arch>\n", 8, 1, fh);228 fwrite("!<arch>\n", 8, 1, fh);
238 sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));229 sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
239 memcpy(&arhdr.ar_size, stmp, 10);230 memcpy(&arhdr.ar_size, stmp, 10);
240 fwrite(&arhdr, sizeof(arhdr), 1, fh);231 fwrite(&arhdr, sizeof(arhdr), 1, fh);
241 afpos[0] = le2belong(funccnt);232 afpos[0] = le2belong(funccnt);
242 for (i=1; i<=funccnt; i++) {233 for (i=1; i<=funccnt; i++)
243 afpos[i] = le2belong(afpos[i] + hofs);234 afpos[i] = le2belong(afpos[i] + hofs);
244 }
245 fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);235 fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
246 fwrite(anames, strpos, 1, fh);236 fwrite(anames, strpos, 1, fh);
247 if (fpos) fwrite("", 1, 1, fh);237 if (fpos)
238 fwrite("", 1, 1, fh);
248 // write objects239 // write objects
249 fseek(fo, 0, SEEK_END);240 fseek(fo, 0, SEEK_END);
250 fsize = ftell(fo);241 fsize = ftell(fo);
251 fseek(fo, 0, SEEK_SET);242 fseek(fo, 0, SEEK_SET);
252 buf = malloc(fsize + 1);243 buf = malloc(fsize + 1);
253 fread(buf, fsize, 1, fo);244 fread(buf, fsize, 1, fo);
254 fclose(fo);
255 fwrite(buf, fsize, 1, fh);245 fwrite(buf, fsize, 1, fh);
256 fclose(fh);
257 free(buf);246 free(buf);
247 ret = 0;
248the_end:
258 if (anames)249 if (anames)
259 free(anames);250 free(anames);
260 if (afpos)251 if (afpos)
261 free(afpos);252 free(afpos);
262 remove(tfile);253 if (fh)
263 return 0;254 fclose(fh);
255 if (fo)
256 fclose(fo), remove(tfile);
257 return ret;
264}258}

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