cross-compilers: allow individual configuration

since configure supports only native configuration
a file 'cross-tcc.mak' needs to be created manually.
It is included in the Makefile if present.

# ----------------------------------------------------
# Example config-cross.mak:
#
# windows -> i386-linux cross-compiler
# (it expects the linux files in <prefix>/i386-linux)

ROOT-i386 = {B}/i386-linux
CRT-i386 = $(ROOT-i386)/usr/lib
LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib
INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include
DEF-i386 += -D__linux__

# ----------------------------------------------------

Also:
- use libtcc1-<target>.a instead of directories
- add dummy arm assembler
- remove include dependencies from armeabi.c/lib-arm64.c
- tccelf/ld_add_file: add SYSROOT (when defined) to absolute
  filenames coming from ld-scripts
This commit is contained in:
grischka 2017-02-23 08:41:57 +01:00
parent 576bee9a37
commit 569255e6c4
15 changed files with 366 additions and 243 deletions

14
.gitignore vendored
View File

@ -17,9 +17,10 @@ a.out
tcc_g
tcc
*-tcc
libtcc*.def
config.h
config.mak
config*.h
config*.mak
config.texi
conftest*
tags
@ -29,13 +30,6 @@ tcc.pod
tcc-doc.html
tcc-doc.info
lib/x86_64
lib/i386
lib/x86_64-win32
lib/i386-win32
lib/arm
lib/arm64
win32/doc
win32/libtcc
win32/lib/32
@ -60,5 +54,3 @@ tests/libtcc_test
tests/vla_test
tests/hello
tests/tests2/fred.txt
libtcc*.def

285
Makefile
View File

@ -6,7 +6,6 @@ TOP ?= .
include $(TOP)/config.mak
VPATH = $(TOPSRC)
CFLAGS += -I$(TOP)
CFLAGS += $(CPPFLAGS)
ifeq (-$(findstring gcc,$(CC))-,-gcc-)
@ -66,113 +65,39 @@ NATIVE_DEFINES_$(CONFIG_arm_vfp) += -DTCC_ARM_VFP
NATIVE_DEFINES_$(CONFIG_arm64) += -DTCC_TARGET_ARM64
NATIVE_DEFINES += $(NATIVE_DEFINES_yes)
# --------------------------------------------------------------------------
# running top Makefile
ifeq ($(TOP),.)
PROGS=tcc$(EXESUF)
I386_CROSS = i386-tcc$(EXESUF)
WIN32_CROSS = i386-win32-tcc$(EXESUF)
WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
WINCE_CROSS = arm-wince-tcc$(EXESUF)
X64_CROSS = x86_64-tcc$(EXESUF)
ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
ARM_EABIHF_CROSS = arm-eabihf-tcc$(EXESUF)
ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS)
ARM64_CROSS = arm64-tcc$(EXESUF)
C67_CROSS = c67-tcc$(EXESUF)
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
CORE_FILES += tcc.h config.h libtcc.h tcctok.h
I386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
WIN32_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h tccpe.c
WIN64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h tccpe.c
WINCE_FILES = $(CORE_FILES) arm-gen.c arm-link.c tccpe.c
X86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
ARM_FILES = $(CORE_FILES) arm-gen.c arm-link.c
ARM64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
C67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
i386_FILES = $(CORE_FILES) i386-gen.c i386-link.c i386-asm.c i386-asm.h i386-tok.h
i386-win32_FILES = $(i386_FILES) tccpe.c
x86_64_FILES = $(CORE_FILES) x86_64-gen.c x86_64-link.c i386-asm.c x86_64-asm.h
x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c
arm-wince_FILES = $(arm_FILES) tccpe.c
arm64_FILES = $(CORE_FILES) arm64-gen.c arm64-link.c
c67_FILES = $(CORE_FILES) c67-gen.c c67-link.c tcccoff.c
ifdef CONFIG_WIN32
ifeq ($(ARCH),x86_64)
NATIVE_FILES=$(WIN64_FILES)
PROGS_CROSS=$(WIN32_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a
else
NATIVE_FILES=$(WIN32_FILES)
PROGS_CROSS=$(WIN64_CROSS) $(X64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
LIBTCC1_CROSS=lib/x86_64-win32/libtcc1.a
endif
else ifeq ($(ARCH),i386)
NATIVE_FILES=$(I386_FILES)
PROGS_CROSS=$(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
else ifeq ($(ARCH),x86_64)
NATIVE_FILES=$(X86_64_FILES)
PROGS_CROSS=$(I386_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
LIBTCC1_CROSS=lib/i386-win32/libtcc1.a lib/x86_64-win32/libtcc1.a
else ifeq ($(ARCH),arm)
NATIVE_FILES=$(ARM_FILES)
PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM64_CROSS) $(C67_CROSS) $(WINCE_CROSS)
else ifeq ($(ARCH),arm64)
NATIVE_FILES=$(ARM64_FILES)
PROGS_CROSS=$(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS) $(ARM_CROSS) $(C67_CROSS) $(WINCE_CROSS)
endif
CFGWIN = $(if $(CONFIG_WIN32),-win)
NATIVE_TARGET = $(ARCH)$(if $(CONFIG_WIN32),-win$(if $(eq $(ARCH),arm),ce,32))
NATIVE_FILES = $($(NATIVE_TARGET)_FILES)
PROGS = tcc$(EXESUF)
TCCLIBS = $(LIBTCC1) $(LIBTCC) $(LIBTCCDEF)
TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info
ifdef CONFIG_CROSS
PROGS += $(PROGS_CROSS)
TCCLIBS += $(LIBTCC1_CROSS)
endif
all: $(PROGS) $(TCCLIBS) $(TCCDOCS)
# Host Tiny C Compiler
tcc$(EXESUF): tcc.o $(LIBTCC)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(LIBS) $(LINK_LIBTCC)
# Cross Tiny C Compilers
%-tcc$(EXESUF): tcc.c
$(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
# profiling version
tcc_p$(EXESUF): $(NATIVE_FILES)
$(CC) -o $@ $< -DONE_SOURCE $(NATIVE_DEFINES) $(CPPFLAGS_P) $(CFLAGS_P) $(LIBS_P) $(LDFLAGS_P)
$(I386_CROSS): DEFINES = -DTCC_TARGET_I386 \
-DCONFIG_TCCDIR="\"$(tccdir)/i386\""
$(X64_CROSS) : DEFINES = -DTCC_TARGET_X86_64
-DCONFIG_TCCDIR="\"$(tccdir)/x86_64\""
$(WIN32_CROSS) : DEFINES = -DTCC_TARGET_I386 -DTCC_TARGET_PE \
-DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
-DCONFIG_TCC_LIBPATHS="\"{B}/lib/32;{B}/lib\""
$(WIN64_CROSS) : DEFINES = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE \
-DCONFIG_TCCDIR="\"$(tccdir)/win32\"" \
-DCONFIG_TCC_LIBPATHS="\"{B}/lib/64;{B}/lib\""
$(WINCE_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_TARGET_PE
$(C67_CROSS): DEFINES = -DTCC_TARGET_C67 -w # disable warnigs
$(ARM_FPA_CROSS): DEFINES = -DTCC_TARGET_ARM
$(ARM_FPA_LD_CROSS)$(EXESUF): DEFINES = -DTCC_TARGET_ARM -DLDOUBLE_SIZE=12
$(ARM_VFP_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_VFP
$(ARM_EABI_CROSS): DEFINES = -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP
$(ARM64_CROSS): DEFINES = -DTCC_TARGET_ARM64
$(I386_CROSS) : $(I386_FILES)
$(X64_CROSS) : $(X86_64_FILES)
$(WIN32_CROSS) : $(WIN32_FILES)
$(WIN64_CROSS) : $(WIN64_FILES)
$(WINCE_CROSS) : $(WINCE_FILES)
$(C67_CROSS) : $(C67_FILES)
$(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS): $(ARM_FILES)
$(ARM64_CROSS): $(ARM64_FILES)
# libtcc generation and test
ifndef ONE_SOURCE
LIBTCC_OBJ = $(filter-out tcc.o tcctools.o,$(patsubst %.c,%.o,$(filter %.c,$(NATIVE_FILES))))
@ -205,20 +130,142 @@ libtcc.def : libtcc.dll tcc$(EXESUF)
libtcc.dll : NATIVE_DEFINES += -DLIBTCC_AS_DLL
# windows : utilities
tiny_%$(EXESUF): $(TOPSRC)/win32/tools/tiny_%.c
$(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) $(NATIVE_DEFINES)
ifneq ($(LIBTCC1),)
# TinyCC runtime libraries
$(LIBTCC1) : FORCE $(PROGS)
$(MAKE) -C lib native
endif
lib/%/libtcc1.a : FORCE $(PROGS_CROSS)
$(MAKE) -C lib cross TARGET=$*
libtcc1.a : FORCE tcc$(EXESUF)
$(MAKE) -C lib TARGET=$(NATIVE_TARGET)
FORCE:
install: install-native$(CFGWIN)
uninstall: uninstall-native$(CFGWIN)
# cross compilers
# --------------------------------------------------------------------------
ifdef CONFIG_CROSS
I386_CROSS = i386-tcc$(EXESUF)
X64_CROSS = x86_64-tcc$(EXESUF)
WIN32_CROSS = i386-win32-tcc$(EXESUF)
WIN64_CROSS = x86_64-win32-tcc$(EXESUF)
WINCE_CROSS = arm-wince-tcc$(EXESUF)
C67_CROSS = c67-tcc$(EXESUF)
ARM64_CROSS = arm64-tcc$(EXESUF)
ARM_FPA_CROSS = arm-fpa-tcc$(EXESUF)
ARM_FPA_LD_CROSS = arm-fpa-ld-tcc$(EXESUF)
ARM_VFP_CROSS = arm-vfp-tcc$(EXESUF)
ARM_EABI_CROSS = arm-eabi-tcc$(EXESUF)
ARM_EABIHF_CROSS = arm-eabihf-tcc$(EXESUF)
# ARM_CROSS = $(ARM_FPA_CROSS) $(ARM_FPA_LD_CROSS) $(ARM_VFP_CROSS) $(ARM_EABI_CROSS) $(ARM_EABIHF_CROSS)
ARM_CROSS = $(ARM_EABIHF_CROSS)
$(I386_CROSS) : $(i386_FILES)
$(X64_CROSS) : $(x86_64_FILES)
$(WIN32_CROSS) : $(i386-win32_FILES)
$(WIN64_CROSS) : $(x86_64-win32_FILES)
$(WINCE_CROSS) : $(arm-wince_FILES)
$(ARM_CROSS) : $(arm_FILES)
$(ARM64_CROSS) : $(arm64_FILES)
$(C67_CROSS) : $(c67_FILES)
$(I386_CROSS) : T = i386
$(X64_CROSS) : T = x86_64
$(WIN32_CROSS) : T = i386-win32
$(WIN64_CROSS) : T = x86_64-win32
$(WINCE_CROSS) : T = arm-wince
$(ARM64_CROSS) : T = arm64
$(C67_CROSS) : T = c67
$(ARM_EABIHF_CROSS) : T = arm-eabihf
$(I386_CROSS) : DEFINES += -DTCC_TARGET_I386
$(X64_CROSS) : DEFINES += -DTCC_TARGET_X86_64
$(WIN32_CROSS) : DEFINES += -DTCC_TARGET_PE -DTCC_TARGET_I386
$(WIN64_CROSS) : DEFINES += -DTCC_TARGET_PE -DTCC_TARGET_X86_64
$(WINCE_CROSS) : DEFINES += -DTCC_TARGET_PE -DTCC_TARGET_ARM -DTCC_ARM_EABI -DTCC_ARM_VFP -DTCC_ARM_HARDFLOAT
$(ARM64_CROSS) : DEFINES += -DTCC_TARGET_ARM64
$(C67_CROSS) : DEFINES += -DTCC_TARGET_C67 -w # disable warnigs
$(ARM_CROSS) : DEFINES += -DTCC_TARGET_ARM
$(ARM_FPA_LD_CROSS) : DEFINES += -DLDOUBLE_SIZE=12
$(ARM_VFP_CROSS) : DEFINES += -DTCC_ARM_VFP
$(ARM_EABI_CROSS) : DEFINES += -DTCC_ARM_VFP -DTCC_ARM_EABI
$(ARM_EABIHF_CROSS) : DEFINES += -DTCC_ARM_VFP -DTCC_ARM_EABI -DTCC_ARM_HARDFLOAT
DEFINES += $(DEF-$T) $(DEF-all)
DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
DEFINES += $(DEF-$(or $(findstring win,$T),unx))
ifeq ($(CONFIG_WIN32),yes)
DEF-win += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
DEF-unx += -DTCC_LIBTCC1="\"lib/libtcc1-$T.a\""
else
DEF-all += -DTCC_LIBTCC1="\"libtcc1-$T.a\""
DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
endif
DEF-$(NATIVE_TARGET) += $(NATIVE_DEFINES)
# For a (non-windows-) cross compiler to really work
# you need to create a file 'config-cross.mak'
# ----------------------------------------------------
# Example config-cross.mak:
#
# windows -> i386-linux cross-compiler
# (it expects the linux files in <prefix>/i386-linux)
#
# ROOT-i386 = {B}/i386-linux
# CRT-i386 = $(ROOT-i386)/usr/lib
# LIB-i386 = $(ROOT-i386)/lib:$(ROOT-i386)/usr/lib
# INC-i386 = {B}/lib/include:$(ROOT-i386)/usr/include
# DEF-i386 += -D__linux__
#
# ----------------------------------------------------
-include config-cross.mak
# cross tcc to build
PROGS_CROSS = $(I386_CROSS) $(X64_CROSS) $(WIN32_CROSS) $(WIN64_CROSS)
PROGS_CROSS += $(ARM_CROSS) $(ARM64_CROSS) $(WINCE_CROSS) $(C67_CROSS)
# cross libtcc1.a targets to build
LIBTCC1_TARGETS = i386 x86_64 i386-win32 x86_64-win32 arm-eabihf arm64 arm-wince
all : $(foreach l,$(LIBTCC1_TARGETS),lib/libtcc1-$l.a)
all : $(PROGS_CROSS)
# Cross Tiny C Compilers
%-tcc$(EXESUF): tcc.c
$(CC) -o $@ $< -DONE_SOURCE $(DEFINES) $(CFLAGS) $(LIBS) $(LDFLAGS)
# Cross libtcc1.a
lib/libtcc1-%.a : FORCE %-tcc$(EXESUF)
$(MAKE) -C lib TARGET=$* CROSS=yes
# install cross progs & libs
install-cross:
$(INSTALLBIN) -m755 $(PROGS_CROSS) "$(bindir)"
mkdir -p "$(tccdir)/win32/include"
cp -r $(TOPSRC)/include/. "$(tccdir)/win32/include"
cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
mkdir -p "$(tccdir)/win32/lib"
$(INSTALL) -m644 $(TOPSRC)/win32/lib/*.def "$(tccdir)/win32/lib"
install-cross-lib-%:
$(INSTALL) -m644 lib/libtcc1-$*.a "$(tccdir)$(libtcc1dir)"
install-cross-lib-%-win32 install-cross-lib-%-wince: libtcc1dir = /win32/lib
# install cross progs & libs on windows
install-cross-win:
$(INSTALLBIN) -m755 $(PROGS_CROSS) "$(tccdir)"
mkdir -p "$(tccdir)/lib/include"
$(INSTALL) -m644 $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/lib/include"
install-cross-win-lib-%:
$(INSTALL) -m644 lib/libtcc1-$*.a "$(tccdir)/lib"
install: install-cross$(CFGWIN)
install: $(foreach t,$(LIBTCC1_TARGETS),install-cross$(CFGWIN)-lib-$t)
endif # def CONFIG_CROSS
# --------------------------------------------------------------------------
# install
INSTALL = install
@ -228,46 +275,32 @@ STRIP_yes = -s
install-strip: install
install-strip: STRIP_BINARIES = yes
ifndef CONFIG_WIN32
install:
install-native:
mkdir -p "$(bindir)"
$(INSTALLBIN) -m755 $(PROGS) "$(bindir)"
mkdir -p "$(tccdir)"
ifneq ($(LIBTCC1),)
$(INSTALL) -m644 $(LIBTCC1) "$(tccdir)"
endif
$(if $(LIBTCC1),$(INSTALL) -m644 $(LIBTCC1) "$(tccdir)")
mkdir -p "$(tccdir)/include"
$(INSTALL) -m644 $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
mkdir -p "$(libdir)"
$(INSTALL) -m644 $(LIBTCC) "$(libdir)"
mkdir -p "$(includedir)"
$(INSTALL) -m644 $(TOPSRC)/libtcc.h "$(includedir)"
mkdir -p "$(mandir)/man1"
-$(INSTALL) -m644 tcc.1 "$(mandir)/man1"
mkdir -p "$(infodir)"
-$(INSTALL) -m644 tcc-doc.info "$(infodir)"
mkdir -p "$(docdir)"
-$(INSTALL) -m644 tcc-doc.html "$(docdir)"
ifdef CONFIG_CROSS
mkdir -p "$(tccdir)/win32/lib/32"
mkdir -p "$(tccdir)/win32/lib/64"
$(INSTALL) -m644 $(TOPSRC)/win32/lib/*.def "$(tccdir)/win32/lib"
-$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/win32/lib/32"
-$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/win32/lib/64"
cp -r $(TOPSRC)/include/. "$(tccdir)/win32/include"
cp -r $(TOPSRC)/win32/include/. "$(tccdir)/win32/include"
endif
uninstall:
uninstall-native:
rm -fv $(foreach P,$(PROGS),"$(bindir)/$P")
rm -fv "$(libdir)/$(LIBTCC)" "$(includedir)/libtcc.h"
rm -fv "$(mandir)/man1/tcc.1" "$(infodir)/tcc-doc.info"
rm -fv "$(docdir)/tcc-doc.html"
rm -rv "$(tccdir)"
else
# on windows
install:
install-native-win:
mkdir -p "$(tccdir)"
mkdir -p "$(tccdir)/lib"
mkdir -p "$(tccdir)/include"
@ -282,16 +315,9 @@ install:
$(INSTALL) -m644 $(TOPSRC)/include/*.h $(TOPSRC)/tcclib.h "$(tccdir)/include"
$(INSTALL) -m644 $(TOPSRC)/libtcc.h $(subst .dll,.def,$(LIBTCC)) "$(tccdir)/libtcc"
-$(INSTALL) -m644 $(TOPSRC)/win32/tcc-win32.txt tcc-doc.html "$(tccdir)/doc"
ifdef CONFIG_CROSS
mkdir -p "$(tccdir)/lib/32"
mkdir -p "$(tccdir)/lib/64"
-$(INSTALL) -m644 lib/i386-win32/libtcc1.a "$(tccdir)/lib/32"
-$(INSTALL) -m644 lib/x86_64-win32/libtcc1.a "$(tccdir)/lib/64"
endif
uninstall:
uninstall-native-win:
rm -rfv "$(tccdir)/"*
endif
# documentation and man page
tcc-doc.html: tcc-doc.texi
@ -309,8 +335,9 @@ test:
$(MAKE) -C tests
clean:
rm -f $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.log \
lib*.def *.exe *.dll a.out tags TAGS libtcc_test$(EXESUF) tcc$(EXESUF)
rm -f $(PROGS) $(PROGS_CROSS) tcc_p$(EXESUF) tcc.pod \
*~ *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out \
tags TAGS libtcc_test$(EXESUF)
$(MAKE) -C tests $@
$(MAKE) -C lib $@

83
arm-asm.c Normal file
View File

@ -0,0 +1,83 @@
/*************************************************************/
/*
* ARM dummy assembler for TCC
*
*/
#ifdef TARGET_DEFS_ONLY
#define CONFIG_TCC_ASM
#define NB_ASM_REGS 16
ST_FUNC void g(int c);
ST_FUNC void gen_le16(int c);
ST_FUNC void gen_le32(int c);
/*************************************************************/
#else
/*************************************************************/
/* XXX: make it faster ? */
ST_FUNC void g(int c)
{
int ind1;
if (nocode_wanted)
return;
ind1 = ind + 1;
if (ind1 > cur_text_section->data_allocated)
section_realloc(cur_text_section, ind1);
cur_text_section->data[ind] = c;
ind = ind1;
}
ST_FUNC void gen_le16 (int i)
{
g(i);
g(i>>8);
}
ST_FUNC void gen_le32 (int i)
{
gen_le16(i);
gen_le16(i>>16);
}
ST_FUNC void gen_expr32(ExprValue *pe)
{
gen_le32(pe->v);
}
ST_FUNC void asm_opcode(TCCState *s1, int opcode)
{
}
ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier)
{
}
/* generate prolog and epilog code for asm statement */
ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands,
int nb_outputs, int is_output,
uint8_t *clobber_regs,
int out_reg)
{
}
ST_FUNC void asm_compute_constraints(ASMOperand *operands,
int nb_operands, int nb_outputs,
const uint8_t *clobber_regs,
int *pout_reg)
{
}
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str)
{
}
ST_FUNC int asm_parse_regvar (int t)
{
return -1;
}
/*************************************************************/
#endif /* ndef TARGET_DEFS_ONLY */

View File

@ -2147,3 +2147,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) {
/*************************************************************/
#endif
/*************************************************************/
#ifndef TCC_IS_NATIVE
#include "arm-asm.c"
#endif

View File

@ -6,34 +6,15 @@ TOP = ..
include $(TOP)/Makefile
VPATH = $(TOPSRC)/lib $(TOPSRC)/win32/lib
ifndef TARGET
# we're building the native libtcc1.a
ifdef CONFIG_WIN32
ifeq ($(ARCH),x86_64)
TARGET = x86_64-win32
else
TARGET = i386-win32
endif
else ifeq ($(ARCH),i386)
TARGET = i386
else ifeq ($(ARCH),x86_64)
TARGET = x86_64
else ifeq ($(ARCH),arm)
TARGET = arm
else ifeq ($(ARCH),arm64)
TARGET = arm64
endif
ifneq ($(CROSS),yes)
TCC = $(TOP)/tcc$(EXESUF)
OUT = ../libtcc1.a
BCHECK_O = bcheck.o
else
TCC = $(TOP)/$(TARGET)-tcc$(EXESUF)
OUT = libtcc1-$(TARGET).a
endif
DIR = $(TARGET)
native : ../libtcc1.a
cross : $(DIR)/libtcc1.a
native : TCC = $(TOP)/tcc$(EXESUF)
cross : TCC = $(TOP)/$(TARGET)-tcc$(EXESUF)
XCC = $(TCC) -B$(TOPSRC)
XAR = $(TCC) -ar
@ -41,33 +22,39 @@ I386_O = libtcc1.o alloca86.o alloca86-bt.o $(BCHECK_O)
X86_64_O = libtcc1.o alloca86_64.o alloca86_64-bt.o $(BCHECK_O)
ARM_O = libtcc1.o armeabi.o alloca-arm.o
ARM64_O = lib-arm64.o
WIN32_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o chkstk.o
WIN_O = crt1.o crt1w.o wincrt1.o wincrt1w.o dllcrt1.o dllmain.o
ifeq "$(TARGET)" "i386-win32"
OBJ = $(addprefix $(DIR)/,$(I386_O) $(WIN32_O))
OBJ = $(I386_O) chkstk.o $(WIN_O)
TGT = -DTCC_TARGET_I386 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "x86_64-win32"
OBJ = $(addprefix $(DIR)/,$(X86_64_O) $(WIN32_O))
OBJ = $(X86_64_O) chkstk.o $(WIN_O)
TGT = -DTCC_TARGET_X86_64 -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "arm-wince"
OBJ = $(ARM_O) $(WIN_O)
TGT = -DTCC_TARGET_ARM -DTCC_TARGET_PE
XCC = $(TCC) -B$(TOPSRC)/win32 -I$(TOPSRC)/include
else ifeq "$(TARGET)" "i386"
OBJ = $(addprefix $(DIR)/,$(I386_O))
OBJ = $(I386_O)
TGT = -DTCC_TARGET_I386
else ifeq "$(TARGET)" "x86_64"
OBJ = $(addprefix $(DIR)/,$(X86_64_O))
OBJ = $(X86_64_O)
TGT = -DTCC_TARGET_X86_64
else ifeq "$(TARGET)" "arm"
OBJ = $(addprefix $(DIR)/,$(ARM_O))
else ifeq "$(TARGET)" "arm-eabihf"
OBJ = $(ARM_O)
TGT = -DTCC_TARGET_ARM
ifneq ($(CROSS),yes)
# using gcc, need asm
XCC = $(CC)
XFLAGS = $(CFLAGS) -fPIC
XAR = $(AR)
endif
else ifeq "$(TARGET)" "arm64"
OBJ = $(addprefix $(DIR)/,$(ARM64_O))
OBJ = $(ARM64_O)
TGT = -DTCC_TARGET_ARM64
else
else ifneq "$(TARGET)" ""
$(error libtcc1.a not supported on target '$(TARGET)')
endif
@ -76,21 +63,18 @@ ifeq ($(TARGETOS),Darwin)
BCHECK_O =
endif
$(DIR)/libtcc1.a ../libtcc1.a : $(OBJ)
$(XAR) rcs $@ $(OBJ)
$(DIR)/%.o : %.c
all : $(OUT)
$(OUT) : $(patsubst %.o,%-$(TARGET).o,$(OBJ))
$(XAR) rcs $@ $^
%-$(TARGET).o : %.c
$(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
$(DIR)/%.o : %.S
%-$(TARGET).o : %.S
$(XCC) -c $< -o $@ $(TGT) $(XFLAGS)
$(DIR)/crt1w.o : crt1.c
$(DIR)/wincrt1w.o : wincrt1.c
$(OBJ) : $(DIR)/exists
%/exists :
mkdir -p $(DIR)
@echo $@ > $@
crt1w-$(TARGET).o : crt1.c
wincrt1w-$(TARGET).o : wincrt1.c
bcheck-$(TARGET).o : XFLAGS += -w
clean :
rm -rf i386-win32 x86_64-win32 i386 x86_64 arm arm64
rm -f *.a *.o $(OUT)

View File

@ -3,8 +3,15 @@
.global alloca
.type alloca, %function
alloca:
#ifdef __TINYC__
.int 0xe060d00d
.int 0xe3cdd007
.int 0xe1a0000d
.int 0xe1a0f00e
#else
rsb sp, r0, sp
bic sp, sp, #7
mov r0, sp
mov pc, lr
#endif
.size alloca, .-alloca

View File

@ -19,7 +19,19 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/
#ifdef __TINYC__
#define INT_MIN (-2147483647 - 1)
#define INT_MAX 2147483647
#define UINT_MAX 0xffffffff
#define LONG_MIN (-2147483647L - 1)
#define LONG_MAX 2147483647L
#define ULONG_MAX 0xffffffffUL
#define LLONG_MAX 9223372036854775807LL
#define LLONG_MIN (-9223372036854775807LL - 1)
#define ULLONG_MAX 0xffffffffffffffffULL
#else
#include <limits.h>
#endif
/* We rely on the little endianness and EABI calling convention for this to
work */

View File

@ -9,8 +9,20 @@
* without any warranty.
*/
#ifdef __TINYC__
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef short int16_t;
typedef unsigned short uint16_t;
typedef int int32_t;
typedef unsigned uint32_t;
typedef long long int64_t;
typedef unsigned long long uint64_t;
void *memcpy(void*,void*,__SIZE_TYPE__);
#else
#include <stdint.h>
#include <string.h>
#endif
void __clear_cache(void *beg, void *end)
{

View File

@ -693,7 +693,7 @@ void *__va_arg(__va_list_struct *ap,
}
#endif /* __x86_64__ */
#ifdef TCC_TARGET_ARM
#if defined TCC_TARGET_ARM && !defined __TINYC__
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>

View File

@ -1120,7 +1120,6 @@ static int tcc_add_library_internal(TCCState *s, const char *fmt,
return -1;
}
#ifndef TCC_TARGET_PE
/* find and load a dll. Return non zero if not found */
/* XXX: add '-rpath' option support ? */
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
@ -1128,7 +1127,6 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags)
return tcc_add_library_internal(s, "%s/%s", filename, flags,
s->library_paths, s->nb_library_paths);
}
#endif
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
{

1
tcc.c
View File

@ -182,6 +182,7 @@ static void print_search_dirs(TCCState *s)
print_dirs("libraries", s->library_paths, s->nb_library_paths);
#ifndef TCC_TARGET_PE
print_dirs("crt", s->crt_paths, s->nb_crt_paths);
printf("libtcc1:\n %s/"TCC_LIBTCC1"\n", s->tcc_lib_path);
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s));
#endif
}

53
tcc.h
View File

@ -254,13 +254,15 @@
# define DEFAULT_ELFINTERP(s) default_elfinterp(s)
#endif
/* target specific subdir for libtcc1.a */
#ifndef TCC_ARCH_DIR
# define TCC_ARCH_DIR ""
/* (target specific) libtcc1.a */
#ifndef TCC_LIBTCC1
# define TCC_LIBTCC1 "libtcc1.a"
#endif
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
#if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
#endif
/* -------------------------------------------- */
@ -286,6 +288,26 @@
/* target address type */
#define addr_t ElfW(Addr)
/* -------------------------------------------- */
#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
# define PUB_FUNC
#endif
#ifdef ONE_SOURCE
#define ST_INLN static inline
#define ST_FUNC static
#define ST_DATA static
#else
#define ST_INLN
#define ST_FUNC
#define ST_DATA extern
#endif
#ifdef TCC_PROFILE /* profile all functions */
# define static
#endif
/* -------------------------------------------- */
/* include the target specific definitions */
@ -1031,26 +1053,6 @@ enum tcc_token {
/* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
#define TOK_UIDENT TOK_DEFINE
/* -------------------------------------------- */
#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
# define PUB_FUNC
#endif
#ifdef ONE_SOURCE
#define ST_INLN static inline
#define ST_FUNC static
#define ST_DATA static
#else
#define ST_INLN
#define ST_FUNC
#define ST_DATA extern
#endif
#ifdef TCC_PROFILE /* profile all functions */
# define static
#endif
/* ------------ libtcc.c ------------ */
/* use GNU C extensions */
@ -1137,12 +1139,9 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
#define AFF_BINTYPE_AR 3
#define AFF_BINTYPE_C67 4
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
#ifndef TCC_TARGET_PE
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
#endif
ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);

View File

@ -1063,7 +1063,7 @@ static void add_init_array_defines(TCCState *s1, const char *section_name)
static int tcc_add_support(TCCState *s1, const char *filename)
{
char buf[1024];
snprintf(buf, sizeof(buf), "%s/"TCC_ARCH_DIR"%s", s1->tcc_lib_path, filename);
snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, filename);
return tcc_add_file(s1, buf);
}
@ -1106,12 +1106,15 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
/* add libc */
if (!s1->nostdlib) {
tcc_add_library_err(s1, "c");
#ifdef CONFIG_USE_LIBGCC
#ifdef TCC_LIBGCC
if (!s1->static_link) {
tcc_add_file(s1, TCC_LIBGCC);
if (TCC_LIBGCC[0] == '/')
tcc_add_file(s1, TCC_LIBGCC);
else
tcc_add_dll(s1, TCC_LIBGCC, 0);
}
#endif
tcc_add_support(s1, "libtcc1.a");
tcc_add_support(s1, TCC_LIBTCC1);
/* add crt end if not memory output */
if (s1->output_type != TCC_OUTPUT_MEMORY)
tcc_add_crt(s1, "crtn.o");
@ -2758,12 +2761,13 @@ static int ld_next(TCCState *s1, char *name, int name_size)
static int ld_add_file(TCCState *s1, const char filename[])
{
int ret;
ret = tcc_add_file_internal(s1, filename, AFF_TYPE_BIN);
if (ret)
ret = tcc_add_dll(s1, filename, 0);
return ret;
if (filename[0] == '/') {
if (CONFIG_SYSROOT[0] == '\0'
&& tcc_add_file_internal(s1, filename, AFF_TYPE_BIN) == 0)
return 0;
filename = tcc_basename(filename);
}
return tcc_add_dll(s1, filename, 0);
}
static inline int new_undef_syms(void)

View File

@ -1905,15 +1905,17 @@ static void pe_add_runtime(TCCState *s1, struct pe_info *pe)
if (0 == s1->nostdlib) {
static const char *libs[] = {
"tcc1", "msvcrt", "kernel32", "", "user32", "gdi32", NULL
TCC_LIBTCC1, "msvcrt", "kernel32", "", "user32", "gdi32", NULL
};
const char **pp, *p;
for (pp = libs; 0 != (p = *pp); ++pp) {
if (0 == *p) {
if (PE_DLL != pe_type && PE_GUI != pe_type)
break;
} else if (tcc_add_library_err(s1, p) < 0) {
break;
} else if (pp == libs && tcc_add_dll(s1, p, 0) >= 0) {
continue;
} else {
tcc_add_library_err(s1, p);
}
}
}

View File

@ -85,17 +85,17 @@ if %PROCESSOR_ARCHITEW6432%_==AMD64_ set T=64
set D32=-DTCC_TARGET_PE -DTCC_TARGET_I386
set D64=-DTCC_TARGET_PE -DTCC_TARGET_X86_64
set P32=i386-win32
set P64=x86_64-win32
if %T%==64 goto :t64
set D=%D32%
set DX=%D64%
set TX=64
set PX=x86_64-win32
set PX=%P64%
goto :t96
:t64
set D=%D64%
set DX=%D32%
set TX=32
set PX=i386-win32
set PX=%P32%
:t96
@echo on
@ -103,9 +103,9 @@ set PX=i386-win32
:config.h
echo>..\config.h #define TCC_VERSION "%VERSION%"
echo>> ..\config.h #ifdef TCC_TARGET_X86_64
echo>> ..\config.h #define CONFIG_TCC_LIBPATHS "{B}/lib/64;{B}/lib"
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-64.a"
echo>> ..\config.h #else
echo>> ..\config.h #define CONFIG_TCC_LIBPATHS "{B}/lib/32;{B}/lib"
echo>> ..\config.h #define TCC_LIBTCC1 "libtcc1-32.a"
echo>> ..\config.h #endif
for %%f in (*tcc.exe *tcc.dll) do @del %%f
@ -120,8 +120,6 @@ for %%f in (*tcc.exe *tcc.dll) do @del %%f
if not exist libtcc mkdir libtcc
if not exist doc mkdir doc
if not exist lib\32 mkdir lib\32
if not exist lib\64 mkdir lib\64
copy>nul ..\include\*.h include
copy>nul ..\tcclib.h include
copy>nul ..\libtcc.h libtcc
@ -144,7 +142,7 @@ copy>nul tcc-win32.txt doc
.\tcc -m32 %D32% -w -c ../lib/bcheck.c
.\tcc -m32 %D32% -c ../lib/alloca86.S
.\tcc -m32 %D32% -c ../lib/alloca86-bt.S
.\tcc -m32 -ar lib/32/libtcc1.a %O1% alloca86.o alloca86-bt.o
.\tcc -m32 -ar lib/libtcc1-32.a %O1% alloca86.o alloca86-bt.o
@if errorlevel 1 goto :the_end
.\tcc -m64 %D64% -c ../lib/libtcc1.c
.\tcc -m64 %D64% -c lib/crt1.c
@ -157,7 +155,7 @@ copy>nul tcc-win32.txt doc
.\tcc -m64 %D64% -w -c ../lib/bcheck.c
.\tcc -m64 %D64% -c ../lib/alloca86_64.S
.\tcc -m64 %D64% -c ../lib/alloca86_64-bt.S
.\tcc -m64 -ar lib/64/libtcc1.a %O1% alloca86_64.o alloca86_64-bt.o
.\tcc -m64 -ar lib/libtcc1-64.a %O1% alloca86_64.o alloca86_64-bt.o
@if errorlevel 1 goto :the_end
:tcc-doc.html
@ -172,9 +170,9 @@ for %%f in (*.o *.def) do @del %%f
:copy-install
@if (%INST%)==() goto :the_end
if not exist %INST% mkdir %INST%
@for %%f in (*tcc.exe tiny_*.exe *tcc.dll) do copy>nul %%f %INST%
@for %%f in (include lib examples libtcc doc) do xcopy>nul /s/i/q/y %%f %INST%\%%f
del %INST%\lib\*.c %INST%\lib\*.S
@if not exist %INST%\lib mkdir %INST%\lib
for %%f in (*tcc.exe *tcc.dll lib\*.a lib\*.def) do @copy>nul %%f %INST%\%%f
for %%f in (include examples libtcc doc) do @xcopy>nul /s/i/q/y %%f %INST%\%%f
:the_end
exit /B %ERRORLEVEL%