mirror of
https://github.com/mirror/tinycc.git
synced 2025-03-30 12:20:06 +08:00
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
8e4d64be2f
- do not -Lsystemdir if compiling to .o
This commit is contained in:
parent
b691585785
commit
b42cb16b65
15
Makefile
15
Makefile
@ -18,10 +18,6 @@ else
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC
|
|
||||||
LIBS_P=
|
|
||||||
LDFLAGS_P = $(LDFLAGS)
|
|
||||||
|
|
||||||
LIBTCC = libtcc.a
|
LIBTCC = libtcc.a
|
||||||
LIBTCC1 = libtcc1.a
|
LIBTCC1 = libtcc1.a
|
||||||
LINK_LIBTCC =
|
LINK_LIBTCC =
|
||||||
@ -50,6 +46,10 @@ ifeq ($(TARGETOS),Darwin)
|
|||||||
export MACOSX_DEPLOYMENT_TARGET:=10.2
|
export MACOSX_DEPLOYMENT_TARGET:=10.2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
CFLAGS_P = $(CFLAGS) -pg -static -DCONFIG_TCC_STATIC -DTCC_PROFILE
|
||||||
|
LIBS_P= $(LIBS)
|
||||||
|
LDFLAGS_P = $(LDFLAGS)
|
||||||
|
|
||||||
CONFIG_$(ARCH) = yes
|
CONFIG_$(ARCH) = yes
|
||||||
NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
|
NATIVE_DEFINES_$(CONFIG_i386) += -DTCC_TARGET_I386
|
||||||
NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
|
NATIVE_DEFINES_$(CONFIG_x86-64) += -DTCC_TARGET_X86_64
|
||||||
@ -136,8 +136,8 @@ endif
|
|||||||
all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
|
all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
|
||||||
|
|
||||||
# Host Tiny C Compiler
|
# Host Tiny C Compiler
|
||||||
tcc$(EXESUF): tcc.c $(LIBTCC)
|
tcc$(EXESUF): tcc.o $(LIBTCC)
|
||||||
$(CC) -o $@ $^ $(LIBS) $(NATIVE_DEFINES) $(CFLAGS) $(LDFLAGS) $(LINK_LIBTCC)
|
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) $(LINK_LIBTCC)
|
||||||
|
|
||||||
# Cross Tiny C Compilers
|
# Cross Tiny C Compilers
|
||||||
%-tcc$(EXESUF): tcc.c
|
%-tcc$(EXESUF): tcc.c
|
||||||
@ -182,7 +182,6 @@ else
|
|||||||
LIBTCC_OBJ = libtcc.o
|
LIBTCC_OBJ = libtcc.o
|
||||||
LIBTCC_INC = $(NATIVE_FILES)
|
LIBTCC_INC = $(NATIVE_FILES)
|
||||||
libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
|
libtcc.o : NATIVE_DEFINES += -DONE_SOURCE
|
||||||
tcc.o : NATIVE_DEFINES += -DONE_SOURCE
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
|
$(LIBTCC_OBJ) tcc.o : %.o : %.c $(LIBTCC_INC)
|
||||||
@ -269,7 +268,7 @@ uninstall:
|
|||||||
rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
|
rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
|
||||||
rm -fv $(libdir)/libtcc.so*
|
rm -fv $(libdir)/libtcc.so*
|
||||||
rm -rv "$(tccdir)"
|
rm -rv "$(tccdir)"
|
||||||
rm -rv "$(docdir)"
|
rm -fv "$(docdir)/tcc-doc.html"
|
||||||
else
|
else
|
||||||
# on windows
|
# on windows
|
||||||
install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
|
install: $(PROGS) $(TCCLIBS) $(TCCDOCS)
|
||||||
|
22
libtcc.c
22
libtcc.c
@ -116,7 +116,7 @@ static void tcc_add_systemdir(TCCState *s)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined TCC_IS_NATIVE && !defined CONFIG_TCC_STATIC
|
#if defined TCC_IS_NATIVE
|
||||||
static void dlclose(void *p)
|
static void dlclose(void *p)
|
||||||
{
|
{
|
||||||
FreeLibrary((HMODULE)p);
|
FreeLibrary((HMODULE)p);
|
||||||
@ -412,7 +412,7 @@ PUB_FUNC void tcc_memstats(int bench)
|
|||||||
mem_cur_size, mem_max_size);
|
mem_cur_size, mem_max_size);
|
||||||
|
|
||||||
while (header) {
|
while (header) {
|
||||||
fprintf(stderr, " file %s, line %u: %u bytes\n",
|
fprintf(stderr, "%s:%u: error: %u bytes leaked\n",
|
||||||
header->file_name, header->line_num, header->size);
|
header->file_name, header->line_num, header->size);
|
||||||
header = header->next;
|
header = header->next;
|
||||||
}
|
}
|
||||||
@ -1504,14 +1504,21 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
|||||||
{
|
{
|
||||||
s->output_type = output_type;
|
s->output_type = output_type;
|
||||||
|
|
||||||
|
/* always elf for objects */
|
||||||
|
if (output_type == TCC_OUTPUT_OBJ)
|
||||||
|
s->output_format = TCC_OUTPUT_FORMAT_ELF;
|
||||||
|
|
||||||
|
if (s->char_is_unsigned)
|
||||||
|
tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL);
|
||||||
|
|
||||||
if (!s->nostdinc) {
|
if (!s->nostdinc) {
|
||||||
/* default include paths */
|
/* default include paths */
|
||||||
/* -isystem paths have already been handled */
|
/* -isystem paths have already been handled */
|
||||||
tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
|
tcc_add_sysinclude_path(s, CONFIG_TCC_SYSINCLUDEPATHS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if bound checking, then add corresponding sections */
|
|
||||||
#ifdef CONFIG_TCC_BCHECK
|
#ifdef CONFIG_TCC_BCHECK
|
||||||
|
/* if bound checking, then add corresponding sections */
|
||||||
if (s->do_bounds_check) {
|
if (s->do_bounds_check) {
|
||||||
/* define symbol */
|
/* define symbol */
|
||||||
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
|
tcc_define_symbol(s, "__BOUNDS_CHECKING_ON", NULL);
|
||||||
@ -1522,11 +1529,6 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
|||||||
SHT_PROGBITS, SHF_ALLOC);
|
SHT_PROGBITS, SHF_ALLOC);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (s->char_is_unsigned) {
|
|
||||||
tcc_define_symbol(s, "__CHAR_UNSIGNED__", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add debug sections */
|
/* add debug sections */
|
||||||
if (s->do_debug) {
|
if (s->do_debug) {
|
||||||
/* stab symbols */
|
/* stab symbols */
|
||||||
@ -1540,9 +1542,11 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
|
tcc_add_library_path(s, CONFIG_TCC_LIBPATHS);
|
||||||
|
|
||||||
#ifdef TCC_TARGET_PE
|
#ifdef TCC_TARGET_PE
|
||||||
# ifdef _WIN32
|
# ifdef _WIN32
|
||||||
tcc_add_systemdir(s);
|
if (!s->nostdlib && output_type != TCC_OUTPUT_OBJ)
|
||||||
|
tcc_add_systemdir(s);
|
||||||
# endif
|
# endif
|
||||||
#else
|
#else
|
||||||
/* add libc crt1/crti objects */
|
/* add libc crt1/crti objects */
|
||||||
|
9
tcc.h
9
tcc.h
@ -76,6 +76,7 @@
|
|||||||
# pragma warning (disable : 4018) // signed/unsigned mismatch
|
# pragma warning (disable : 4018) // signed/unsigned mismatch
|
||||||
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
||||||
# endif
|
# endif
|
||||||
|
# undef CONFIG_TCC_STATIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef O_BINARY
|
#ifndef O_BINARY
|
||||||
@ -1052,6 +1053,10 @@ static inline int toup(int c)
|
|||||||
# define PUB_FUNC
|
# define PUB_FUNC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef TCC_PROFILE /* profile all functions */
|
||||||
|
# define static
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ONE_SOURCE
|
#ifdef ONE_SOURCE
|
||||||
#define ST_INLN static inline
|
#define ST_INLN static inline
|
||||||
#define ST_FUNC static
|
#define ST_FUNC static
|
||||||
@ -1559,9 +1564,7 @@ ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
|
|||||||
ST_FUNC void *dlopen(const char *filename, int flag);
|
ST_FUNC void *dlopen(const char *filename, int flag);
|
||||||
ST_FUNC void dlclose(void *p);
|
ST_FUNC void dlclose(void *p);
|
||||||
ST_FUNC const char *dlerror(void);
|
ST_FUNC const char *dlerror(void);
|
||||||
ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
|
ST_FUNC void *dlsym(int flag, const char *symbol);
|
||||||
#elif !defined _WIN32
|
|
||||||
ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_TCC_BACKTRACE
|
#ifdef CONFIG_TCC_BACKTRACE
|
||||||
|
18
tccelf.c
18
tccelf.c
@ -450,7 +450,7 @@ ST_FUNC void relocate_syms(TCCState *s1, int do_resolve)
|
|||||||
#if defined TCC_IS_NATIVE && !defined _WIN32
|
#if defined TCC_IS_NATIVE && !defined _WIN32
|
||||||
void *addr;
|
void *addr;
|
||||||
name = (char *) symtab_section->link->data + sym->st_name;
|
name = (char *) symtab_section->link->data + sym->st_name;
|
||||||
addr = resolve_sym(s1, name);
|
addr = dlsym(RTLD_DEFAULT, name);
|
||||||
if (addr) {
|
if (addr) {
|
||||||
sym->st_value = (addr_t)addr;
|
sym->st_value = (addr_t)addr;
|
||||||
#ifdef DEBUG_RELOC
|
#ifdef DEBUG_RELOC
|
||||||
@ -576,15 +576,18 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
|
|||||||
goto output_file;
|
goto output_file;
|
||||||
write16le(ptr, read16le(ptr) + val - addr);
|
write16le(ptr, read16le(ptr) + val - addr);
|
||||||
break;
|
break;
|
||||||
case R_386_RELATIVE:
|
|
||||||
/* do nothing */
|
#ifdef TCC_TARGET_PE
|
||||||
|
case R_386_RELATIVE: /* handled in pe_relocate_rva() */
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case R_386_COPY:
|
case R_386_COPY:
|
||||||
/* This reloction must copy initialized data from the library
|
/* This reloction must copy initialized data from the library
|
||||||
to the program .bss segment. Currently made like for ARM
|
to the program .bss segment. Currently made like for ARM
|
||||||
(to remove noise of defaukt case). Is this true?
|
(to remove noise of defaukt case). Is this true?
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
|
fprintf(stderr,"FIXME: handle reloc type %d at %x [%p] to %x\n",
|
||||||
type, (unsigned)addr, ptr, (unsigned)val);
|
type, (unsigned)addr, ptr, (unsigned)val);
|
||||||
@ -773,6 +776,10 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
|
|||||||
/* Nothing to do. Normally used to indicate a dependency
|
/* Nothing to do. Normally used to indicate a dependency
|
||||||
on a certain symbol (like for exception handling under EABI). */
|
on a certain symbol (like for exception handling under EABI). */
|
||||||
break;
|
break;
|
||||||
|
#ifdef TCC_TARGET_PE
|
||||||
|
case R_ARM_RELATIVE: /* handled in pe_relocate_rva() */
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
|
fprintf(stderr,"FIXME: handle reloc type %x at %x [%p] to %x\n",
|
||||||
type, (unsigned)addr, ptr, (unsigned)val);
|
type, (unsigned)addr, ptr, (unsigned)val);
|
||||||
@ -973,6 +980,11 @@ ST_FUNC void relocate_section(TCCState *s1, Section *s)
|
|||||||
/* we load the got offset */
|
/* we load the got offset */
|
||||||
write32le(ptr, read32le(ptr) + s1->sym_attrs[sym_index].got_offset);
|
write32le(ptr, read32le(ptr) + s1->sym_attrs[sym_index].got_offset);
|
||||||
break;
|
break;
|
||||||
|
#ifdef TCC_TARGET_PE
|
||||||
|
case R_X86_64_RELATIVE: /* handled in pe_relocate_rva() */
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error unsupported processor
|
#error unsupported processor
|
||||||
#endif
|
#endif
|
||||||
|
3
tccgen.c
3
tccgen.c
@ -54,6 +54,7 @@ ST_DATA Sym *define_stack;
|
|||||||
ST_DATA Sym *global_label_stack;
|
ST_DATA Sym *global_label_stack;
|
||||||
ST_DATA Sym *local_label_stack;
|
ST_DATA Sym *local_label_stack;
|
||||||
static int local_scope;
|
static int local_scope;
|
||||||
|
static int in_sizeof;
|
||||||
|
|
||||||
ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */
|
ST_DATA int vlas_in_scope; /* number of VLAs that are currently in scope */
|
||||||
ST_DATA int vla_sp_root_loc; /* vla_sp_loc for SP before any VLAs were pushed */
|
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)
|
|||||||
CType type;
|
CType type;
|
||||||
Sym *s;
|
Sym *s;
|
||||||
AttributeDef ad;
|
AttributeDef ad;
|
||||||
static int in_sizeof = 0;
|
|
||||||
|
|
||||||
sizeof_caller = in_sizeof;
|
sizeof_caller = in_sizeof;
|
||||||
in_sizeof = 0;
|
in_sizeof = 0;
|
||||||
@ -5235,6 +5235,7 @@ static void block(int *bsym, int *csym, int is_expr)
|
|||||||
gcase(sw.p, sw.n, c, &a);
|
gcase(sw.p, sw.n, c, &a);
|
||||||
if (sw.def_sym)
|
if (sw.def_sym)
|
||||||
gjmp_addr(sw.def_sym);
|
gjmp_addr(sw.def_sym);
|
||||||
|
dynarray_reset(&sw.p, &sw.n);
|
||||||
cur_switch = saved;
|
cur_switch = saved;
|
||||||
/* break label */
|
/* break label */
|
||||||
gsym(a);
|
gsym(a);
|
||||||
|
9
tccrun.c
9
tccrun.c
@ -748,7 +748,7 @@ static TCCSyms tcc_syms[] = {
|
|||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)
|
ST_FUNC void *dlsym(int flag, const char *symbol)
|
||||||
{
|
{
|
||||||
TCCSyms *p;
|
TCCSyms *p;
|
||||||
p = tcc_syms;
|
p = tcc_syms;
|
||||||
@ -760,13 +760,6 @@ ST_FUNC void *resolve_sym(TCCState *s1, const char *symbol)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif !defined(_WIN32)
|
|
||||||
|
|
||||||
ST_FUNC void *resolve_sym(TCCState *s1, const char *sym)
|
|
||||||
{
|
|
||||||
return dlsym(RTLD_DEFAULT, sym);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* CONFIG_TCC_STATIC */
|
#endif /* CONFIG_TCC_STATIC */
|
||||||
#endif /* TCC_IS_NATIVE */
|
#endif /* TCC_IS_NATIVE */
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user