tinycc-devel
[Top][All Lists]
Advanced

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

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


From: David Mertens
Subject: Re: [Tinycc-devel] Do you know of any forks of TinyCC?
Date: Sat, 7 May 2016 13:20:58 -0400

On Ubuntu I get segfaults when it tries to run the sample program you provided, 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. :-)

David

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
http://repo.or.cz/tinycc.git/shortlog/18a8013fe71a63633948bc40412f7939fe34907d

They are functional AFAICS, on i386.

For example download a snapshot (7kB) from Fabrice Bellard's initial revision
http://repo.or.cz/tinycc.git/snapshot/27f6e16bae9d0f73acec07f61aea696ab5adc680.tar.gz

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);
  }
  #endif
<---------------------------------------

compile:
  $ gcc tcc.c -o tcc
or
  $ cl -MD tcc.c

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

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

  Hello!
  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, and
things of this sort?



_______________________________________________
Tinycc-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/tinycc-devel



--
 "Debugging is twice as hard as writing the code in the first place.
  Therefore, if you write the code as cleverly as possible, you are,
  by definition, not smart enough to debug it." -- Brian Kernighan

reply via email to

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