[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Do you know of any forks of TinyCC?

From: grischka
Subject: Re: [Tinycc-devel] Do you know of any forks of TinyCC?
Date: Tue, 10 May 2016 02:33:51 +0200
User-agent: Thunderbird (Windows/20090812)

David Mertens wrote: ---
On Ubuntu I get segfaults when it tries to run the sample program you
provided, ...

It doesn't like CRLF lines.

... but I managed to figure out the compile and link flags, at least.

Add this to the top of the tcc source:

#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
void expr(void);
void decl(int);

and compile like so:

gcc -Wno-int-conversion -Wno-implicit-int -o tcc tcc.c -ldl

That'll produce a tcc that will compile the provided source code, and then
segfault when it tries to run it. :-)


On Sat, May 7, 2016 at 5:05 AM, grischka <address@hidden> wrote:

David Mertens wrote: ---

Nope. I had to learn by diving into the source myself. But if you want to
learn the process of compilation, you should just try to follow the series
of function calls to compile code.

First commits to tinycc are from 2001


They are functional AFAICS, on i386.

For example download a snapshot (7kB) from Fabrice Bellard's initial


add this on top of tcc.c --------->
  void expr(void);
  void decl(int);
  #ifdef _WIN32
  #include <windows.h>
  void *dlsym(int x, const char *func) {
      return GetProcAddress(GetModuleHandle("msvcrt"), func);

  $ gcc tcc.c -o tcc
  $ cl -MD tcc.c

create hello.c ------------------------->
  #define HELLO "Hello!\n"
  int main (int argc, char **argv)
      int i;
      i = 0;
      while (i < argc) {
          printf("arg %d = %s\n", i, argv[i]);
      return 0;

and run it:
  $ tcc hello.c 111 222 333

  arg 0 = hello.c
  arg 1 = 111
  arg 2 = 222
  arg 3 = 333

As you can see, it works.  With preprocessor and all. ;)

-- gr

On Fri, May 6, 2016 at 1:16 AM, <address@hidden> wrote:
I want to understand how TCC works, in the way it is now it confuses me
greatly. Maybe you know of some forks that maybe dropped some of it's
features and made source a bit easier to understand? Or, maybe I should
look at some old enough commit, before TCC learned to compile asm code,
things of this sort?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]