mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
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
This commit is contained in:
parent
d6d7686b60
commit
8042121d74
@ -91,7 +91,7 @@ $(DIR)/%.o : %.c
|
|||||||
$(DIR)/%.o : %.S
|
$(DIR)/%.o : %.S
|
||||||
$(XCC) -c $< -o $@ $(XFLAGS)
|
$(XCC) -c $< -o $@ $(XFLAGS)
|
||||||
$(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c
|
$(DIR)/%$(EXESUF) : $(TOP)/win32/tools/%.c
|
||||||
$(CC) -Os -s -w -o $@ $< $(XFLAGS) $(LDFLAGS)
|
$(CC) -Os -s -o $@ $< $(XFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
$(OBJ) $(XAR) : $(DIR)/exists
|
$(OBJ) $(XAR) : $(DIR)/exists
|
||||||
$(DIR)/exists :
|
$(DIR)/exists :
|
||||||
|
78
libtcc.c
78
libtcc.c
@ -1589,20 +1589,6 @@ PUB_FUNC const char * tcc_set_linker(TCCState *s, char *option, int multi)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
|
|
||||||
{
|
|
||||||
double tt;
|
|
||||||
tt = (double)total_time / 1000000.0;
|
|
||||||
if (tt < 0.001)
|
|
||||||
tt = 0.001;
|
|
||||||
if (total_bytes < 1)
|
|
||||||
total_bytes = 1;
|
|
||||||
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
|
|
||||||
tok_ident - TOK_IDENT, total_lines, total_bytes,
|
|
||||||
tt, (int)(total_lines / tt),
|
|
||||||
total_bytes / tt / 1000000.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set CONFIG_TCCDIR at runtime */
|
/* set CONFIG_TCCDIR at runtime */
|
||||||
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
|
LIBTCCAPI void tcc_set_lib_path(TCCState *s, const char *path)
|
||||||
{
|
{
|
||||||
@ -1668,3 +1654,67 @@ PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *file
|
|||||||
fprintf(depout, "\n");
|
fprintf(depout, "\n");
|
||||||
fclose(depout);
|
fclose(depout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time)
|
||||||
|
{
|
||||||
|
double tt;
|
||||||
|
tt = (double)total_time / 1000000.0;
|
||||||
|
if (tt < 0.001)
|
||||||
|
tt = 0.001;
|
||||||
|
if (total_bytes < 1)
|
||||||
|
total_bytes = 1;
|
||||||
|
printf("%d idents, %d lines, %d bytes, %0.3f s, %d lines/s, %0.1f MB/s\n",
|
||||||
|
tok_ident - TOK_IDENT, total_lines, total_bytes,
|
||||||
|
tt, (int)(total_lines / tt),
|
||||||
|
total_bytes / tt / 1000000.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_paths(const char *msg, char **paths, int nb_paths)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
printf("%s:\n%s", msg, nb_paths ? "" : " -\n");
|
||||||
|
for(i = 0; i < nb_paths; i++)
|
||||||
|
printf(" %s\n", paths[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PUB_FUNC void tcc_display_info(TCCState *s, int what)
|
||||||
|
{
|
||||||
|
switch (what) {
|
||||||
|
case 0:
|
||||||
|
printf("tcc version %s ("
|
||||||
|
#ifdef TCC_TARGET_I386
|
||||||
|
"i386"
|
||||||
|
# ifdef TCC_TARGET_PE
|
||||||
|
" Win32"
|
||||||
|
# endif
|
||||||
|
#elif defined TCC_TARGET_X86_64
|
||||||
|
"x86-64"
|
||||||
|
# ifdef TCC_TARGET_PE
|
||||||
|
" Win64"
|
||||||
|
# endif
|
||||||
|
#elif defined TCC_TARGET_ARM
|
||||||
|
"ARM"
|
||||||
|
# ifdef TCC_ARM_HARDFLOAT
|
||||||
|
" Hard Float"
|
||||||
|
# endif
|
||||||
|
# ifdef TCC_TARGET_PE
|
||||||
|
" WinCE"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
#ifndef TCC_TARGET_PE
|
||||||
|
# ifdef __linux
|
||||||
|
" Linux"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
")\n", TCC_VERSION);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
printf("install: %s/\n", s->tcc_lib_path);
|
||||||
|
/* print_paths("programs", NULL, 0); */
|
||||||
|
print_paths("crt", s->crt_paths, s->nb_crt_paths);
|
||||||
|
print_paths("libraries", s->library_paths, s->nb_library_paths);
|
||||||
|
print_paths("include", s->sysinclude_paths, s->nb_sysinclude_paths);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
12
tcc.c
12
tcc.c
@ -508,17 +508,21 @@ int main(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (print_search_dirs) {
|
if (print_search_dirs) {
|
||||||
/* enough for Linux kernel */
|
psd:
|
||||||
printf("install: %s/\n", s->tcc_lib_path);
|
tcc_set_output_type(s, TCC_OUTPUT_MEMORY);
|
||||||
|
tcc_display_info(s, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->verbose)
|
if (s->verbose)
|
||||||
printf("tcc version %s\n", TCC_VERSION);
|
tcc_display_info(s, 0);
|
||||||
|
|
||||||
if (optind == 0 || nb_files == 0) {
|
if (optind == 0 || nb_files == 0) {
|
||||||
if (optind && s->verbose)
|
if (optind && s->verbose) {
|
||||||
|
if (s->verbose == 2)
|
||||||
|
goto psd;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
help();
|
help();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
1
tcc.h
1
tcc.h
@ -1067,6 +1067,7 @@ PUB_FUNC int tcc_set_flag(TCCState *s, const char *flag_name, int value);
|
|||||||
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
|
PUB_FUNC void tcc_print_stats(TCCState *s, int64_t total_time);
|
||||||
PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);
|
PUB_FUNC char *tcc_default_target(TCCState *s, const char *default_file);
|
||||||
PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
|
PUB_FUNC void tcc_gen_makedeps(TCCState *s, const char *target, const char *filename);
|
||||||
|
PUB_FUNC void tcc_display_info(TCCState *s, int what);
|
||||||
|
|
||||||
/* ------------ tccpp.c ------------ */
|
/* ------------ tccpp.c ------------ */
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ VPATH = $(top_srcdir)/tests
|
|||||||
|
|
||||||
# what tests to run
|
# what tests to run
|
||||||
TESTS = \
|
TESTS = \
|
||||||
hello \
|
hello-exe \
|
||||||
|
hello-run \
|
||||||
libtest \
|
libtest \
|
||||||
test3 \
|
test3 \
|
||||||
moretests
|
moretests
|
||||||
@ -26,7 +27,7 @@ ifdef CONFIG_WIN32
|
|||||||
TESTS := $(filter-out test3,$(TESTS))
|
TESTS := $(filter-out test3,$(TESTS))
|
||||||
endif
|
endif
|
||||||
ifeq ($(TARGETOS),Darwin)
|
ifeq ($(TARGETOS),Darwin)
|
||||||
TESTS := $(filter-out hello test3 btest,$(TESTS))
|
TESTS := $(filter-out hello-exe test3 btest,$(TESTS))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifdef DISABLE_STATIC
|
ifdef DISABLE_STATIC
|
||||||
@ -57,9 +58,12 @@ endif
|
|||||||
|
|
||||||
all test : $(TESTS)
|
all test : $(TESTS)
|
||||||
|
|
||||||
hello: ../examples/ex1.c
|
hello-exe: ../examples/ex1.c
|
||||||
|
@echo ------------ $@ ------------
|
||||||
|
$(TCC) $< -o hello$(EXESUF) || ($(TOP)/tcc -vv; exit 1) && ./hello$(EXESUF)
|
||||||
|
|
||||||
|
hello-run: ../examples/ex1.c
|
||||||
@echo ------------ $@ ------------
|
@echo ------------ $@ ------------
|
||||||
$(TCC) $< -o $@$(EXESUF) && ./$@$(EXESUF)
|
|
||||||
$(TCC) -run $<
|
$(TCC) -run $<
|
||||||
|
|
||||||
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
|
libtest: libtcc_test$(EXESUF) $(LIBTCC1)
|
||||||
@ -192,3 +196,4 @@ clean:
|
|||||||
$(MAKE) -C tests2 $@
|
$(MAKE) -C tests2 $@
|
||||||
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
|
rm -vf *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.gcc *.exe \
|
||||||
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
|
hello libtcc_test tcctest[1234] ex? tcc_g tcclib.h
|
||||||
|
|
||||||
|
@ -37,8 +37,9 @@
|
|||||||
#define __unaligned __attribute__((packed))
|
#define __unaligned __attribute__((packed))
|
||||||
#define __fastcall __attribute__((fastcall))
|
#define __fastcall __attribute__((fastcall))
|
||||||
|
|
||||||
#define __MINGW_IMPORT extern __declspec(dllimport)
|
#define __MSVCRT__ 1
|
||||||
#undef _MSVCRT_
|
#undef _MSVCRT_
|
||||||
|
#define __MINGW_IMPORT extern __declspec(dllimport)
|
||||||
#define __MINGW_ATTRIB_NORETURN
|
#define __MINGW_ATTRIB_NORETURN
|
||||||
#define __MINGW_ATTRIB_CONST
|
#define __MINGW_ATTRIB_CONST
|
||||||
#define __MINGW_ATTRIB_DEPRECATED
|
#define __MINGW_ATTRIB_DEPRECATED
|
||||||
|
@ -21,10 +21,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#ifdef _WIN32
|
|
||||||
#include <io.h> /* for mktemp */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../../elf.h"
|
#include "../../elf.h"
|
||||||
|
|
||||||
#ifdef TCC_TARGET_X86_64
|
#ifdef TCC_TARGET_X86_64
|
||||||
@ -77,7 +73,7 @@ ArHdr arhdro = {
|
|||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
FILE *fi, *fh, *fo;
|
FILE *fi, *fh = NULL, *fo = NULL;
|
||||||
ElfW(Ehdr) *ehdr;
|
ElfW(Ehdr) *ehdr;
|
||||||
ElfW(Shdr) *shdr;
|
ElfW(Shdr) *shdr;
|
||||||
ElfW(Sym) *sym;
|
ElfW(Sym) *sym;
|
||||||
@ -89,6 +85,7 @@ int main(int argc, char **argv)
|
|||||||
int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
|
int istrlen, strpos = 0, fpos = 0, funccnt = 0, funcmax, hofs;
|
||||||
char afile[260], tfile[260], stmp[20];
|
char afile[260], tfile[260], stmp[20];
|
||||||
char *file, *name;
|
char *file, *name;
|
||||||
|
int ret = 2;
|
||||||
|
|
||||||
|
|
||||||
strcpy(afile, "ar_test.a");
|
strcpy(afile, "ar_test.a");
|
||||||
@ -111,19 +108,17 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(tfile, "./XXXXXX");
|
|
||||||
if (!mktemp(tfile) || (fo = fopen(tfile, "wb+")) == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Can't open temporary file %s\n", tfile);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((fh = fopen(afile, "wb")) == NULL)
|
if ((fh = fopen(afile, "wb")) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't open file %s \n", afile);
|
fprintf(stderr, "Can't open file %s \n", afile);
|
||||||
fclose(fo);
|
goto the_end;
|
||||||
remove(tfile);
|
}
|
||||||
return 2;
|
|
||||||
|
sprintf(tfile, "%s.tmp", afile);
|
||||||
|
if ((fo = fopen(tfile, "wb+")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Can't create temporary file %s\n", tfile);
|
||||||
|
goto the_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
funcmax = 250;
|
funcmax = 250;
|
||||||
@ -140,9 +135,7 @@ int main(int argc, char **argv)
|
|||||||
if ((fi = fopen(argv[iarg], "rb")) == NULL)
|
if ((fi = fopen(argv[iarg], "rb")) == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Can't open file %s \n", argv[iarg]);
|
fprintf(stderr, "Can't open file %s \n", argv[iarg]);
|
||||||
fclose(fo);
|
goto the_end;
|
||||||
remove(tfile);
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
fseek(fi, 0, SEEK_END);
|
fseek(fi, 0, SEEK_END);
|
||||||
fsize = ftell(fi);
|
fsize = ftell(fi);
|
||||||
@ -152,14 +145,13 @@ int main(int argc, char **argv)
|
|||||||
fclose(fi);
|
fclose(fi);
|
||||||
|
|
||||||
//printf("%s:\n", argv[iarg]);
|
//printf("%s:\n", argv[iarg]);
|
||||||
|
|
||||||
// elf header
|
// elf header
|
||||||
ehdr = (ElfW(Ehdr) *)buf;
|
ehdr = (ElfW(Ehdr) *)buf;
|
||||||
if (ehdr->e_ident[4] != ELFCLASSW)
|
if (ehdr->e_ident[4] != ELFCLASSW)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
|
fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
|
||||||
fclose(fo);
|
goto the_end;
|
||||||
remove(tfile);
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
|
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + ehdr->e_shstrndx * ehdr->e_shentsize);
|
||||||
@ -167,7 +159,8 @@ int main(int argc, char **argv)
|
|||||||
for (i = 0; i < ehdr->e_shnum; i++)
|
for (i = 0; i < ehdr->e_shnum; i++)
|
||||||
{
|
{
|
||||||
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
|
shdr = (ElfW(Shdr) *) (buf + ehdr->e_shoff + i * ehdr->e_shentsize);
|
||||||
if (!shdr->sh_offset) continue;
|
if (!shdr->sh_offset)
|
||||||
|
continue;
|
||||||
if (shdr->sh_type == SHT_SYMTAB)
|
if (shdr->sh_type == SHT_SYMTAB)
|
||||||
{
|
{
|
||||||
symtab = (char *)(buf + shdr->sh_offset);
|
symtab = (char *)(buf + shdr->sh_offset);
|
||||||
@ -210,7 +203,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
file = argv[iarg];
|
file = argv[iarg];
|
||||||
for (name = strchr(file, 0);
|
for (name = strchr(file, 0);
|
||||||
name > file && name[-1] != '/' && name[-1] != '\\';
|
name > file && name[-1] != '/' && name[-1] != '\\';
|
||||||
--name);
|
--name);
|
||||||
istrlen = strlen(name);
|
istrlen = strlen(name);
|
||||||
@ -219,7 +212,6 @@ int main(int argc, char **argv)
|
|||||||
memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));
|
memset(arhdro.ar_name, ' ', sizeof(arhdro.ar_name));
|
||||||
memcpy(arhdro.ar_name, name, istrlen);
|
memcpy(arhdro.ar_name, name, istrlen);
|
||||||
arhdro.ar_name[istrlen] = '/';
|
arhdro.ar_name[istrlen] = '/';
|
||||||
|
|
||||||
sprintf(stmp, "%-10d", fsize);
|
sprintf(stmp, "%-10d", fsize);
|
||||||
memcpy(&arhdro.ar_size, stmp, 10);
|
memcpy(&arhdro.ar_size, stmp, 10);
|
||||||
fwrite(&arhdro, sizeof(arhdro), 1, fo);
|
fwrite(&arhdro, sizeof(arhdro), 1, fo);
|
||||||
@ -229,36 +221,38 @@ int main(int argc, char **argv)
|
|||||||
fpos += (fsize + sizeof(arhdro));
|
fpos += (fsize + sizeof(arhdro));
|
||||||
}
|
}
|
||||||
hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
|
hofs = 8 + sizeof(arhdr) + strpos + (funccnt+1) * sizeof(int);
|
||||||
if ((hofs & 1)) { // align
|
fpos = 0;
|
||||||
hofs++;
|
if ((hofs & 1)) // align
|
||||||
fpos = 1;
|
hofs++, fpos = 1;
|
||||||
} else fpos = 0;
|
|
||||||
// write header
|
// write header
|
||||||
fwrite("!<arch>\n", 8, 1, fh);
|
fwrite("!<arch>\n", 8, 1, fh);
|
||||||
sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
|
sprintf(stmp, "%-10d", (int)(strpos + (funccnt+1) * sizeof(int)));
|
||||||
memcpy(&arhdr.ar_size, stmp, 10);
|
memcpy(&arhdr.ar_size, stmp, 10);
|
||||||
fwrite(&arhdr, sizeof(arhdr), 1, fh);
|
fwrite(&arhdr, sizeof(arhdr), 1, fh);
|
||||||
afpos[0] = le2belong(funccnt);
|
afpos[0] = le2belong(funccnt);
|
||||||
for (i=1; i<=funccnt; i++) {
|
for (i=1; i<=funccnt; i++)
|
||||||
afpos[i] = le2belong(afpos[i] + hofs);
|
afpos[i] = le2belong(afpos[i] + hofs);
|
||||||
}
|
|
||||||
fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
|
fwrite(afpos, (funccnt+1) * sizeof(int), 1, fh);
|
||||||
fwrite(anames, strpos, 1, fh);
|
fwrite(anames, strpos, 1, fh);
|
||||||
if (fpos) fwrite("", 1, 1, fh);
|
if (fpos)
|
||||||
|
fwrite("", 1, 1, fh);
|
||||||
// write objects
|
// write objects
|
||||||
fseek(fo, 0, SEEK_END);
|
fseek(fo, 0, SEEK_END);
|
||||||
fsize = ftell(fo);
|
fsize = ftell(fo);
|
||||||
fseek(fo, 0, SEEK_SET);
|
fseek(fo, 0, SEEK_SET);
|
||||||
buf = malloc(fsize + 1);
|
buf = malloc(fsize + 1);
|
||||||
fread(buf, fsize, 1, fo);
|
fread(buf, fsize, 1, fo);
|
||||||
fclose(fo);
|
|
||||||
fwrite(buf, fsize, 1, fh);
|
fwrite(buf, fsize, 1, fh);
|
||||||
fclose(fh);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
ret = 0;
|
||||||
|
the_end:
|
||||||
if (anames)
|
if (anames)
|
||||||
free(anames);
|
free(anames);
|
||||||
if (afpos)
|
if (afpos)
|
||||||
free(afpos);
|
free(afpos);
|
||||||
remove(tfile);
|
if (fh)
|
||||||
return 0;
|
fclose(fh);
|
||||||
|
if (fo)
|
||||||
|
fclose(fo), remove(tfile);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user