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