Problems compiling TCC on OS X
Asked Answered
P

3

9

Has anyone successfully compiled TCC on OS X?

From what I know it should be possible but when I run make I get the following error:

$ make
gcc -o tcc tcc.c -DTCC_TARGET_I386 -O2 -g -Wall -fno-strict-aliasing -mpreferred-stack-                boundary=2 -march=i386 -falign-functions=0 -Wno-pointer-sign -Wno-sign-compare -D_FORTIFY_SOURCE=0 -lm -ldl
tcc.c:1: error: CPU you selected does not support x86-64 instruction set
tcc.c:1: error: CPU you selected does not support x86-64 instruction set
tcc.c:1: error: -mpreferred-stack-boundary=2 is not between 4 and 12
make: *** [tcc] Error 1

./configure runs fine and gives the following output:

$ ./configure 
Binary  directory   /usr/local/bin
TinyCC directory    /usr/local/lib/tcc
Library directory   /usr/local/lib
Include directory   /usr/local/include
Manual directory    /usr/local/man
Doc directory       /usr/local/share/doc/tcc
Target root prefix  
Source path      /Users/aaron/Downloads/tcc-0.9.25
C compiler       gcc
CPU              x86
Big Endian       no
gprof enabled    no
cross compilers  no
use libgcc       no
Creating config.mak and config.h

I'm pretty sure the issue is something simple, but I haven't compiled enough programs on OS X to be aware of the pratfalls...

The primary purpose for installing TCC was to get libtcc so I could start experimenting with dynamic code generation from Ruby (in case that makes a difference :-p)

Thanks!

Pillowcase answered 14/9, 2010 at 21:4 Comment(2)
My MacBook running 10.5 gets a different error than you report. What version of the OS and what hardware are you running on?Thurgau
The error above was encountered on 10.6. Building on 10.5 encounters actual bugs in the program relating to register access code...Pillowcase
T
4

I'll consolidate my comments now.

There seem to be several issues.

  1. There has been a change in the naming scheme for the x86 register access as of Mac OS 10.5. See Access EIP and EBP via ucontext on OS X. This will require hacking the source until the maintainer can be convinced to support Mac OS X.
  2. The executable formats supported by tcc do not overlap with those that Mac OS X will run natively. However, XBinary may address this. (I didn't find either a fink package or a MacPorts package, however and don't have it installed yet. Not sure that I will--this is deep magic, and could in theory do very bad things indeed.) Ah... this was already on SO too: Possibility of loading/executing ELF files on OSX.
Thurgau answered 14/9, 2010 at 21:42 Comment(1)
Thanks for your answer! I was able to add the alternate code for register access under OS X and get TCC to compile. However the second issue you pointed out is a show-stopper... I going to leave it alone as there would be a lot of work to do to extend TCC for MACH-0 binaries. Thanks for your help!Pillowcase
D
29

I have just spent some serious time trying to make tcc run on osx. I have included several fixes, including the one from the answer above, and now they are all in the development repository at http://repo.or.cz/w/tinycc.git. Building, some tests and all examples should work.

I am not sure if you are aware, but http://bellard.org/tcc/ site that belongs to Fabrice Bellard who started this project, is not being updated very regularly. Mostly because there are not many 'official' tcc releases. tcc is one of those projects that mostly lives off of live sources and updates. So if you want to give this another try, please go to http://repo.or.cz/w/tinycc.git and get the 'mob' branch (not 'master'). Please see http://repo.or.cz/w/tinycc.git for details, and do join the mailing list to get involved.

Downtoearth answered 6/3, 2012 at 19:24 Comment(2)
I forgot to mention that currently tcc on osx is capable of being used as a scripting language both in the shell and in application. It it not able to create binaries that can be executed as standalone processes.Downtoearth
This is very cool, thanks for making this available. If you want more people to use it, you might want to give specific instructions on how to get and build it though. Not everyone knows git, and needing to get the mob branch adds an extra wrinkle for the uninitiated.Volant
T
4

I'll consolidate my comments now.

There seem to be several issues.

  1. There has been a change in the naming scheme for the x86 register access as of Mac OS 10.5. See Access EIP and EBP via ucontext on OS X. This will require hacking the source until the maintainer can be convinced to support Mac OS X.
  2. The executable formats supported by tcc do not overlap with those that Mac OS X will run natively. However, XBinary may address this. (I didn't find either a fink package or a MacPorts package, however and don't have it installed yet. Not sure that I will--this is deep magic, and could in theory do very bad things indeed.) Ah... this was already on SO too: Possibility of loading/executing ELF files on OSX.
Thurgau answered 14/9, 2010 at 21:42 Comment(1)
Thanks for your answer! I was able to add the alternate code for register access under OS X and get TCC to compile. However the second issue you pointed out is a show-stopper... I going to leave it alone as there would be a lot of work to do to extend TCC for MACH-0 binaries. Thanks for your help!Pillowcase
P
3

The errors can be fixed by edit configure script of TCC package (ver 0.9.25).

In the configure script, line 36 says cpu=uname -m If you run uname -m in the console of Mac OS X, it prints "i386" even if it is a 64-bit system.

A solution is to comment off this line, and replace it with cpu=x86_64,

Then some compiling errors will show up because of the register naming conventions in Mac OS X, as mentioned by dmckee in this thread.

My fix is to add a few lines to libtcc.c around line 1512. Finally it will look like

#ifdef __DARWIN_UNIX03
        *paddr = uc->uc_mcontext->__ss.__rip;
#else
        *paddr = uc->uc_mcontext.gregs[REG_RIP];
#endif
        return 0;
    } else {
#ifdef __DARWIN_UNIX03
        fp = uc->uc_mcontext->__ss.__rbp;
#else
        fp = uc->uc_mcontext.gregs[REG_RBP];
#endif

It compiles then.

Philan answered 17/8, 2011 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.