From 8ca8b08890c220a9e238c711aef96b49727e80f0 Mon Sep 17 00:00:00 2001 From: Milutin Jovanovic Date: Thu, 9 Feb 2012 12:53:17 -0500 Subject: [PATCH] Patch attempting to build OSX TinyCC. Applied patch found on stackoverflow (link below). I also found some related changes that looked like logically needed. The stackoverflow changes addressed only two registers which were breaking a compile. However reading the code in the same file shows two other register accesses that, while not breaking the build, should have the same fix. http://stackoverflow.com/questions/3712902/problems-compiling-tcc-on-os-x/3713144#3713144 The test driver was changed by changing 'cp -u' into 'cp' as '-u' is not supported on mac osx. I found that osx build required the WITHOUT_LIBTCC define. I suspect the reason for this is tcc unability to handle mach-o files. In order to properly address this I had to change 'configure' to propagate target os name to Makefile. Current state is that simple tests work, but not the whole 'make test' suite runs. To the best of my knowledge, these changes should not impact other platforms. --- .gitignore | 5 +++++ Makefile | 4 ++++ configure | 2 ++ tccrun.c | 16 ++++++++++++---- tests/Makefile | 2 +- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a845ddcb..4985f6a3 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,8 @@ config.mak config.texi tests tags +.DS_Store +*.swp +lib/x86_64 +tcc-doc.info +conftest* diff --git a/Makefile b/Makefile index 43d7cfd0..fd8602e9 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,10 @@ NATIVE_DEFINES+=$(if $(wildcard /lib/ld-linux.so.3),-DTCC_ARM_EABI) NATIVE_DEFINES+=$(if $(shell grep -l "^Features.* \(vfp\|iwmmxt\) " /proc/cpuinfo),-DTCC_ARM_VFP) endif +ifeq ($(TARGETOS),Darwin) +NATIVE_DEFINES+=-DWITHOUT_LIBTCC +endif + ifdef CONFIG_WIN32 NATIVE_DEFINES+=-DTCC_TARGET_PE endif diff --git a/configure b/configure index 3d68b1c0..188c3609 100755 --- a/configure +++ b/configure @@ -352,6 +352,7 @@ echo "Doc directory $docdir" echo "Target root prefix $sysroot" echo "Source path $source_path" echo "C compiler $cc" +echo "Target OS $targetos" echo "CPU $cpu" echo "Big Endian $bigendian" echo "gprof enabled $gprof" @@ -425,6 +426,7 @@ else echo "Unsupported CPU" exit 1 fi +echo "TARGETOS=$targetos" >> config.mak if test "$noldl" = "yes" ; then echo "CONFIG_NOLDL=yes" >> config.mak fi diff --git a/tccrun.c b/tccrun.c index 64a1dfd6..de0ef891 100644 --- a/tccrun.c +++ b/tccrun.c @@ -461,7 +461,9 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level) int i; if (level == 0) { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__APPLE__) + *paddr = uc->uc_mcontext->__ss.__eip; +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) *paddr = uc->uc_mcontext.mc_eip; #elif defined(__dietlibc__) *paddr = uc->uc_mcontext.eip; @@ -470,7 +472,9 @@ static int rt_get_caller_pc(unsigned long *paddr, ucontext_t *uc, int level) #endif return 0; } else { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__APPLE__) + fp = uc->uc_mcontext->__ss.__ebp; +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) fp = uc->uc_mcontext.mc_ebp; #elif defined(__dietlibc__) fp = uc->uc_mcontext.ebp; @@ -500,14 +504,18 @@ static int rt_get_caller_pc(unsigned long *paddr, if (level == 0) { /* XXX: only support linux */ -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__APPLE__) + *paddr = uc->uc_mcontext->__ss.__rip; +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) *paddr = uc->uc_mcontext.mc_rip; #else *paddr = uc->uc_mcontext.gregs[REG_RIP]; #endif return 0; } else { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#if defined(__APPLE__) + fp = uc->uc_mcontext->__ss.__rbp; +#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) fp = uc->uc_mcontext.mc_rbp; #else fp = uc->uc_mcontext.gregs[REG_RBP]; diff --git a/tests/Makefile b/tests/Makefile index 8cd906d4..2cf9e281 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -45,7 +45,7 @@ libtcc_test$(EXESUF): libtcc_test.c ../$(LIBTCC) # test.ref - generate using gcc # copy only tcclib.h so GCC's stddef and stdarg will be used test.ref: tcctest.c - cp -u ../include/tcclib.h . + cp ../include/tcclib.h . $(CC) -o tcctest.gcc $< -I. -w $(CFLAGS) -std=gnu99 ./tcctest.gcc > $@ -- 2.11.4.GIT