Picon

tcc as jit-compiler

hi all,
I would try to play with tcc as jit compiler
in a program working with win32 gui
and implementing a scripting language.

Something like a microscopic emacs,
where elisp functions are replaced by C compiled code.
tcc should compile and (most important) re-compile user-functions
in a quite large number and number of times.
(Probably C code coompiled by tcc will be the translation of an hl 
script lang).

Playing with the examples for tcclib it sounds promising to me,
but I just can't figure out which kind of problems will issue a massive
use of JIT compilation over the same execution session.

I'll appreciate any suggestions (...even "Emacs? forget it...").

best regards
paolo

Jared Maddox | 2 Oct 12:53 2014
Picon

Re: Tinycc-devel Digest, Vol 138, Issue 1

> Date: Wed, 01 Oct 2014 01:27:09 +0200
> From: JFC Morfin <jefsey@...>
> To: tinycc-devel@...
> Subject: Re: [Tinycc-devel] How to use char "\"
> Message-ID: <E1XZ6p5-00042o-QF@...>
> Content-Type: text/plain; charset="iso-8859-1"; format=flowed
>

> btw, would you know a clean and clear uptodate C
> documentation including internetworking tools?
>

To the best of my knowledge there aren't any STANDARD tools that
provide networking, but most networking systems are derived in one
sense or another from the Berkley Unix version. Common link:
http://beej.us/guide/bgnet/
Apple might be an exception.

You should be able to find a abstraction library.

Christian JULLIEN | 30 Sep 13:57 2014
Picon

RE : How to use char "\"

Hi!

You need two \\
=> strpbrk (file_name,"\\*?")

First '\' is an escape for next character which is the '\' you want to use.

Christian

----- Message d'origine -----
De : "JFC Morfin" <jefsey-QmVraOcjfJbQT0dZR+AlfA@public.gmane.org>
Date mar. 30/09/2014 12:31 (GMT +02:00)
À : "tinycc-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org" <tinycc-devel <at> nongnu.org>
Objet : [Tinycc-devel] How to use char "\"

May be not the right place to ask?
I am trying to port my old bcc32 libraries under tcc.

I have a problem with the char "\". For example in the line:

strpbrk (file_name,"\*?")

ir order to know if i have a simple file name, tcc tells me "unknown
escape sequence".

When I want use as a char both text[i]='\' and text[i]='\\' do not
work. Since I am there working on text strings I cannot equate '\' to
ascii 28 first.

Thank you for your help.
jfc


_______________________________________________
Tinycc-devel mailing list
Tinycc-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel
<div>
<p>Hi!<br><br>You need two \\<br>=&gt; strpbrk (file_name,"\\*?")<br><br>First '\' is an escape for next character which is the '\' you want to use.<br><br>Christian<br></p>
<blockquote>----- Message d'origine -----<br>De : <span dir="ltr">"JFC Morfin"</span> <span dir="lrt">&lt;jefsey@...&gt;</span><br>Date mar. 30/09/2014 12:31 (GMT +02:00)<br>&Agrave; : <span dir="ltr">"tinycc-devel@..."</span> <span dir="lrt">&lt;tinycc-devel <at> nongnu.org&gt;</span><br>Objet : [Tinycc-devel] How to use char "\"<br><br>May be not the right place to ask?<br>I am trying to port my old bcc32 libraries under tcc.<br><br>I have a problem with the char "\". For example in the line:<br><br>    strpbrk (file_name,"\*?")<br><br>ir order to know if i have a simple file name, tcc tells me "unknown <br>escape sequence".<br><br>When I want use as a char both text[i]='\' and text[i]='\\' do not <br>work. Since I am there working on text strings I cannot equate '\' to <br>ascii 28 first.<br><br>Thank you for your help.<br>jfc<br><br><br>_______________________________________________<br>Tinycc-devel mailing list<br>Tinycc-devel@...<br>https://lists.nongnu.org/mailman/listinfo/tinycc-devel<br>
</blockquote>
</div>
Issam Anour | 29 Sep 15:39 2014

How to build a static executable ?

Hi;

I didn't manage to build a simple Hello world program statically.

main.c

#include <stdio.h>

int main(int argc, char* argv[]) {

   printf("Hello world!\n");
   return 0;
}

tcc -static main.c -o main

output:

tcc: error: undefined symbol '__rel_iplt_end'
tcc: error: undefined symbol '__rel_iplt_start'
tcc: error: undefined symbol '__gcc_personality_v0'
tcc: error: undefined symbol '_Unwind_Resume'
tcc: error: undefined symbol '_Unwind_GetIP'
tcc: error: undefined symbol '_Unwind_GetGR'
tcc: error: undefined symbol '_Unwind_GetCFA'
tcc: error: undefined symbol '_Unwind_Backtrace'


What is the issue ? i have googled and find that libgcc_eh.a is missing, but when i like against it using :

tcc /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/libgcc_eh.a -static main.c -o main

I get the same error.

How to resolve the issue ? If this require to build glibc using tcc than i didn't manage because the errors from the configure script i already mentioned in a previous message.

Thank you very much.

Best regards
<div><div dir="ltr">Hi;<br><br>I didn't manage to build a simple Hello world program statically.<br><br>main.c<br><br>#include &lt;stdio.h&gt;<br><br>int main(int argc, char* argv[]) {<br><br>&nbsp;&nbsp; printf("Hello world!\n");<br>&nbsp;&nbsp; return 0;<br>}<br><br>tcc -static main.c -o main<br><br>output:<br><br>tcc: error: undefined symbol '__rel_iplt_end'<br>tcc: error: undefined symbol '__rel_iplt_start'<br>tcc: error: undefined symbol '__gcc_personality_v0'<br>tcc: error: undefined symbol '_Unwind_Resume'<br>tcc: error: undefined symbol '_Unwind_GetIP'<br>tcc: error: undefined symbol '_Unwind_GetGR'<br>tcc: error: undefined symbol '_Unwind_GetCFA'<br>tcc: error: undefined symbol '_Unwind_Backtrace'<br><br><br>What is the issue ? i have googled and find that libgcc_eh.a is missing, but when i like against it using :<br><br>tcc /usr/lib/i386-linux-gnu/gcc/i686-linux-gnu/4.5/libgcc_eh.a -static main.c -o main<br><br>I get the same error.<br><br>How to resolve the issue ? If this require to build glibc using tcc than i didn't manage because the errors from the configure script i already mentioned in a previous message.<br><br>Thank you very much.<br><br>Best regards<br>
</div></div>
Issam Anour | 29 Sep 04:45 2014

Build glibc

Hi

I would like to build glibc version 2.20 using Tinycc. The issue i got is in the configure command which fail to continue due to the following :

checking whether ln -s works... yes
tcc: error: invalid option -- '-print-prog-name=as'
tcc: error: invalid option -- '-print-prog-name=ld'
tcc: error: invalid option -- '-print-prog-name=ar'
tcc: error: invalid option -- '-print-prog-name=objdump'
tcc: error: invalid option -- '-print-prog-name=objcopy'
checking whether  is GNU as... no
checking whether  is GNU ld... no
checking for gcc... /home/eros/prfx/tcc/bin/tcc
checking version of /home/eros/prfx/tcc/bin/tcc... 0.9.26, bad
checking for gnumake... no
checking for gmake... no
checking for make... make
checking version of make... 3.81, ok
checking for gnumsgfmt... no
checking for gmsgfmt... no
checking for msgfmt... msgfmt
checking version of msgfmt... 0.18.1, ok
checking for makeinfo... no
checking for sed... sed
checking version of sed... 4.2.1, ok
checking for gawk... gawk
checking version of gawk... 3.1.7, ok
checking for nm... nm
configure: error:
*** These critical programs are missing or too old: as ld gcc
*** Check the INSTALL file for required versions.

So how to resolve this issue ?

Thank you

Best regards
<div><div dir="ltr">Hi<br><br>I would like to build glibc version 2.20 using Tinycc. The issue i got is in the configure command which fail to continue due to the following :<br><br>checking whether ln -s works... yes<br>tcc: error: invalid option -- '-print-prog-name=as'<br>tcc: error: invalid option -- '-print-prog-name=ld'<br>tcc: error: invalid option -- '-print-prog-name=ar'<br>tcc: error: invalid option -- '-print-prog-name=objdump'<br>tcc: error: invalid option -- '-print-prog-name=objcopy'<br>checking whether&nbsp; is GNU as... no<br>checking whether&nbsp; is GNU ld... no<br>checking for gcc... /home/eros/prfx/tcc/bin/tcc<br>checking version of /home/eros/prfx/tcc/bin/tcc... 0.9.26, bad<br>checking for gnumake... no<br>checking for gmake... no<br>checking for make... make<br>checking version of make... 3.81, ok<br>checking for gnumsgfmt... no<br>checking for gmsgfmt... no<br>checking for msgfmt... msgfmt<br>checking version of msgfmt... 0.18.1, ok<br>checking for makeinfo... no<br>checking for sed... sed<br>checking version of sed... 4.2.1, ok<br>checking for gawk... gawk<br>checking version of gawk... 3.1.7, ok<br>checking for nm... nm<br>configure: error: <br>*** These critical programs are missing or too old: as ld gcc<br>*** Check the INSTALL file for required versions.<br><br>So how to resolve this issue ?<br><br>Thank you<br><br>Best regards<br>
</div></div>
grischka | 23 Sep 12:37 2014
Picon
Picon

Re: two fixes (was: Cannot code on TinyCC for now)

Thomas Preud'homme wrote:
> Grischka: it would be nice to have a release now (Debian is freezing soon) 
> after the issue I'm discussing with Michael is sorted out. I would have liked 
> to have the two fixes Jiang is working on but he didn't reply in some time.

I fixed one:
http://repo.or.cz/w/tinycc.git/commitdiff/9d7fb3336049243a16ce20ba907946d1de9e1c0d

What was the other?  (Anyway I'd leave it for someone else to try.)

--- grischka

Daniel Fiala | 22 Sep 07:50 2014

Alignment issue

Hello.
It seems that alignment in tcc is not working properly. I tried following program:

#include <stdio.h>

static float x[4] = { 1, 2, 3, 4 };
static float y[4] __attribute__((aligned(32))) = { 4, 5, 6, 7 };

int
main(void) {
        fprintf(stderr, "%p\n", x);
        fprintf(stderr, "%p\n", y);

        return 0;
}

I compiled it with tcc 0.9.5 under Ubuntu 14.04 and I got following output:

0x8049544
0x8049554

It looks that address is not aligned. :-(

Alignment to 32bytes is useful for AVX development.

Regards,
Daniel Fiala
<div><div>Hello.<div>It seems that alignment in tcc is not working properly. I tried following program:</div>
<div><br></div>
<div>
<div>#include &lt;stdio.h&gt;</div>
<div><br></div>
<div>static float x[4] = { 1, 2, 3, 4 };</div>
<div>static float y[4] __attribute__((aligned(32))) = { 4, 5, 6, 7 };</div>
<div><br></div>
<div>int</div>
<div>main(void) {</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, "%p\n", x);</div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; fprintf(stderr, "%p\n", y);</div>
<div><br></div>
<div>&nbsp; &nbsp; &nbsp; &nbsp; return 0;</div>
<div>}</div>
</div>
<div><br></div>
<div>I compiled it with tcc 0.9.5 under Ubuntu 14.04 and I got following output:</div>
<div><br></div>
<div>
<div>0x8049544</div>
<div>0x8049554</div>
</div>
<div><br></div>
<div>It looks that address is not aligned. :-(</div>
<div><br></div>
<div>Alignment to 32bytes is useful for AVX development.</div>
<div><br></div>
<div>Regards,</div>
<div>Daniel Fiala</div>
</div></div>
Michael Matz | 18 Sep 17:46 2014
Picon

Re: Fallout from commit 01c041923474750a236da02561f0f8835445848b

Hi,

On Tue, 9 Sep 2014, Thomas Preud'homme wrote:

> 1) You added the support for R_ARM_GLOB_DAT and R_ARM_JUMP_SLOT 
> relocations but the computation you added ignore the possible addend at 
> *ptr by doing a simple assignment. Is that normal? Did I miss something?

This is per the ABI.  The addend for both relocations (when using REL 
form) is (and must be) always zero.  I didn't bother checking for this, 
but rather just ignored anything that was in there.

> 2) When creating a GOT and PLT entry for a R_ARM_PC24, R_ARM_CALL or 
> R_ARM_JUMP24 you add the offset of the PLT entry to the place being relocated. 
> I'm not sure I got it right but it seems to me that the relocation will be 
> processed again in relocate_section and seems the symbol referenced is still 
> the target function (and not the PLT entry created) as the index in the r_info 
> field of the relocation has remained unchanged. Also this put some relocation 
> computation in build_got_entries. Why not change the initial relocation to 
> make it resolve to the PLT entry.

It might be that I got some of the logic wrong, though I obviously did 
check tcc on arm with itself (and IIRC gawk).  I'll need to reproduce the 
problem somewhen.  Are you positive that it was my commit that broke it?  
Hmm, or it might be that I also hit an error but somehow convinced myself 
that it was a pre-existing but possibly hidden problem.  Man, it's long 
ago :)

> 3) I don't see any test for the type of output when deciding what type of 
> relocation to add. So even when the output is in memory reloc_type will be 
> JUMP_SLOT which will lead to a PLT entry being created. This seems to 
> contradict the comment near the end of put_got_entry. The comment seems wrong 
> as I don't see how a branch could be relocated without a PLT entry.

I think what I wanted to convey in the comment is the following situation: 
normally with memory output (or static linking) no symbolic relocations 
whatsoever are required in the executable, because, well, everything is 
relocated from the beginning.  But the means by which that is ensured is 
itself (at least in TCCs link editor) by creating (and later processing) 
relocations.  Where it matters are indirect calls:

  extern void f(void);
  g() { void (*ptr)(void) = f; ptr(); }

Here there will be a GOT slot allocated for 'f'.  The initialization of 
'ptr' will load from that GOT slot.  So even though direct calls to 'f' 
can (and will be, when 'f' is defined) fully resolved without a PLT slot, 
this indirect access needs a GOT slot, and because of that also needs to 
initialize that slot with f's address, which is done by an relocation 
(which are processed for static and memory output right at the end of most 
processing).

> 4) the jump table that was removed in subsequent patch was only available when 
> outputing to memory. But now a PLT and GOT entry is created no matter what 
> type of output (see 3) above).

Yes, PLT and GOT together (when unconditionally created) take over the 
role of the old jump table.

Now obviously I bungled something regarding all that on ARM and will have 
to look at the details.  Let me first try to reproduce and I'll come back.

Ciao,
Michael.

Thomas Preud'homme | 18 Sep 16:37 2014
Picon

Re: sizeof (long double) vs sizeof (double)

Le dimanche 07 septembre 2014, 13:47:39 Mads a écrit :
> So basically, I should be able to get additional 2 bytes? And I suppose it
> will be stored as 12 bytes to maintain data structure alignment?

LDOUBLE_SIZE is defined to be 16 so you should have 16 bytes for long double 
(twice that of double).

> 
> Reading through the code as well as changelogs, x87 is indeed implemented,
> which means I should be able to use long double with higher precision than
> double.
> Correct me if I'm wrong, but shouldn't long double precision be like that
> declared in floats.h (see below __i386__ / __x86_64__ ).
> 
> (sorry for the hassle, but long double as extended precision is a necessary
> evil for me).
> 
> *From include\floats.h*
> /* horrible intel long double */
> #if defined __i386__ || defined __x86_64__
> 
> #define LDBL_MANT_DIG 64
> #define LDBL_DIG 18
> #define LDBL_EPSILON 1.08420217248550443401e-19L
> #define LDBL_MIN_EXP (-16381)
> #define LDBL_MIN 3.36210314311209350626e-4932L
> #define LDBL_MIN_10_EXP (-4931)
> #define LDBL_MAX_EXP 16384
> #define LDBL_MAX 1.18973149535723176502e+4932L
> #define LDBL_MAX_10_EXP 4932
> 
> #else
> 
> /* same as IEEE double */
> #define LDBL_MANT_DIG 53
> #define LDBL_DIG 15
> #define LDBL_EPSILON 2.2204460492503131e-16
> #define LDBL_MIN_EXP (-1021)
> #define LDBL_MIN 2.2250738585072014e-308
> #define LDBL_MIN_10_EXP (-307)
> #define LDBL_MAX_EXP 1024
> #define LDBL_MAX 1.7976931348623157e+308
> #define LDBL_MAX_10_EXP 308
> 
> #endif

Except these don't seem to be used in tcc's code. It's probably for system 
headers only.

But I just tried compiling a similar testcase as yours and it gives the 
correct sizeof (16). Can you show me the output of the configure script?

Best regards,

Thomas
Le dimanche 07 septembre 2014, 13:47:39 Mads a écrit :
> So basically, I should be able to get additional 2 bytes? And I suppose it
> will be stored as 12 bytes to maintain data structure alignment?

LDOUBLE_SIZE is defined to be 16 so you should have 16 bytes for long double 
(twice that of double).

> 
> Reading through the code as well as changelogs, x87 is indeed implemented,
> which means I should be able to use long double with higher precision than
> double.
> Correct me if I'm wrong, but shouldn't long double precision be like that
> declared in floats.h (see below __i386__ / __x86_64__ ).
> 
> (sorry for the hassle, but long double as extended precision is a necessary
> evil for me).
> 
> *From include\floats.h*
> /* horrible intel long double */
> #if defined __i386__ || defined __x86_64__
> 
> #define LDBL_MANT_DIG 64
> #define LDBL_DIG 18
> #define LDBL_EPSILON 1.08420217248550443401e-19L
> #define LDBL_MIN_EXP (-16381)
> #define LDBL_MIN 3.36210314311209350626e-4932L
> #define LDBL_MIN_10_EXP (-4931)
> #define LDBL_MAX_EXP 16384
> #define LDBL_MAX 1.18973149535723176502e+4932L
> #define LDBL_MAX_10_EXP 4932
> 
> #else
> 
> /* same as IEEE double */
> #define LDBL_MANT_DIG 53
> #define LDBL_DIG 15
> #define LDBL_EPSILON 2.2204460492503131e-16
> #define LDBL_MIN_EXP (-1021)
> #define LDBL_MIN 2.2250738585072014e-308
> #define LDBL_MIN_10_EXP (-307)
> #define LDBL_MAX_EXP 1024
> #define LDBL_MAX 1.7976931348623157e+308
> #define LDBL_MAX_10_EXP 308
> 
> #endif

Except these don't seem to be used in tcc's code. It's probably for system 
headers only.

But I just tried compiling a similar testcase as yours and it gives the 
correct sizeof (16). Can you show me the output of the configure script?

Best regards,

Thomas
Vadim Ushakov | 12 Sep 11:50 2014
Picon

[patch] tcc reports wrong file name for static inline functions

Hello!

tcc reports wrong file name when an error occurs in a static inline function,
if that function is the last in a file. Here is an example:

test.c:
> #include "test.h"
> int test(void)
> {
>     return foo();
> }

test.h:
> static inline int foo(void)
> {
>     wrong_type_t t = 0;
>     return t + 1;
> }

result:
> $ tcc -o test test.c
> test.c:3: error: 'wrong_type_t' undeclared

tcc says it is test.c, however the error is in test.h.

The bug seems to be in decl0(). When it sees a static inline declaration,
it _first_ reads the function body and _then_ saves the body and the file
name in tcc_state->inline_fns.

If the function is the last declaration, the parser pops the file from the
stack after reading the function. After that, decl0() attempts to read
file->filename and gets the name of the previous file in the stack.

The patch is:

diff --git a/tccgen.c b/tccgen.c
index 5fd127f..f1146db 100644
--- a/tccgen.c
+++ b/tccgen.c
 <at>  <at>  -6055,7 +6055,11  <at>  <at>  static int decl0(int l, int is_for_loop_init)
                     int block_level;
                     struct InlineFunc *fn;
                     const char *filename;
-
+
+                    filename = file ? file->filename : "";
+                    fn = tcc_malloc(sizeof *fn + strlen(filename));
+                    strcpy(fn->filename, filename);
+
                     tok_str_new(&func_str);

                     block_level = 0;
 <at>  <at>  -6076,9 +6080,7  <at>  <at>  static int decl0(int l, int is_for_loop_init)
                     }
                     tok_str_add(&func_str, -1);
                     tok_str_add(&func_str, 0);
-                    filename = file ? file->filename : "";
-                    fn = tcc_malloc(sizeof *fn + strlen(filename));
-                    strcpy(fn->filename, filename);
+
                     fn->sym = sym;
                     fn->token_str = func_str.str;
                     dynarray_add((void ***)&tcc_state->inline_fns,
&tcc_state->nb_inline_fns, fn);

--

-- 
Regards,
Vadim Ushakov

Simon Blomberg | 10 Sep 09:48 2014
Picon

Make tries to install cross compilers

Yesterday i tried to build tcc with:
$ ./configure --prefix=../pref --cc=tcc

everything worked fine until i issued
$ make install
and it tried to install the cross compilers which weren't built:
...
install -m755 tcc x86_64-tcc i386-win32-tcc x86_64-win32-tcc arm-fpa-tcc arm-fpa-ld-tcc arm-vfp-tcc arm-eabi-tcc  "../pref/bin"
install: cannot stat ‘x86_64-tcc’: No such file or directory
install: cannot stat ‘i386-win32-tcc’: No such file or directory
install: cannot stat ‘x86_64-win32-tcc’: No such file or directory
install: cannot stat ‘arm-fpa-tcc’: No such file or directory
install: cannot stat ‘arm-fpa-ld-tcc’: No such file or directory
install: cannot stat ‘arm-vfp-tcc’: No such file or directory
install: cannot stat ‘arm-eabi-tcc’: No such file or directory
make: *** [install] Error 1

i looked through the Makfile and found this part:

ifeq ($(CC),tcc)
    $(INSTALL) -m755 $(PROGS) $(PROGS_CROSS_LINK) "$(bindir)"
else

When i removed $(PROGS_CROSS_LINK) the installation worked fine.
i don't know it this is a bug or if there is something strange with my setup
but i thought i'd mention it here anyways.

Simon Blomberg
<div><div dir="ltr">
<div>
<div>
<div>Yesterday i tried to build tcc with:<br>$ ./configure --prefix=../pref --cc=tcc<br>
</div>
<br>everything worked fine until i issued <br>
</div>$ make install <br>
</div>and it tried to install the cross compilers which weren't built:<br><div>
<div>
<div>...<br>install -m755 tcc x86_64-tcc i386-win32-tcc x86_64-win32-tcc arm-fpa-tcc arm-fpa-ld-tcc arm-vfp-tcc arm-eabi-tcc&nbsp; "../pref/bin"<br>install: cannot stat &lsquo;x86_64-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;i386-win32-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;x86_64-win32-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;arm-fpa-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;arm-fpa-ld-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;arm-vfp-tcc&rsquo;: No such file or directory<br>install: cannot stat &lsquo;arm-eabi-tcc&rsquo;: No such file or directory<br>make: *** [install] Error 1<br><br>
</div>
<div>i looked through the Makfile and found this part:<br><br>ifeq ($(CC),tcc)<br>&nbsp;&nbsp;&nbsp; $(INSTALL) -m755 $(PROGS) $(PROGS_CROSS_LINK) "$(bindir)"<br>else<br><br>
</div>
<div>When i removed $(PROGS_CROSS_LINK) the installation worked fine.<br><div>i don't know it this is a bug or if there is something strange with my setup<br>
</div>
<div>but i thought i'd mention it here anyways.<br>
</div>
<div><br></div>
</div>
</div>
<div><div>Simon Blomberg<br>
</div></div>
</div>
</div></div>

Gmane