David Mertens | 5 Nov 23:16 2014
Picon

FreeBSD compilation issues

Hey everyone,

I've had a bug filed against the tcc built using my Perl Alien::TinyCC package. The poster claims that tcc cannot build viable executables on FreeBSD. I'm not a FreeBSD user and wouldn't know where to start, but I thought that tcc was supposed to build a viable executable on BSDs.

BTW, the current version of tinycc distributed with Alien::TinyCC is a bit out of date. I tried to update it a few months ago and the update broke things, so I'm sticking with an older version. When I have some time, I'll bring it back up to speed.

Does anybody care to work on this?

David

P. S. I've had tests against my package on MidnightBSD. My own patches indicate that we can get support for this system by adding a case for MidnightBSD that looks identical to the other BSD configurations in the vicinity of line 50 of the configure script.

--
 "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
<div><div dir="ltr">
<div>
<div>
<div>
<div>Hey everyone,<br><br>
</div>I've had <a href="https://github.com/run4flat/Alien-TinyCC/issues/8">a bug filed against the tcc built using my Perl Alien::TinyCC package</a>. The poster claims that tcc cannot build viable executables on FreeBSD. I'm not a FreeBSD user and wouldn't know where to start, but I thought that tcc was supposed to build a viable executable on BSDs.<br><br>
</div>BTW, the current version of tinycc distributed with Alien::TinyCC is a bit out of date. I tried to update it a few months ago and the update broke things, so I'm sticking with an older version. When I have some time, I'll bring it back up to speed.<br><br>
</div>
<div>Does anybody care to work on this?<br>
</div>
<div><br></div>David<br><br>
</div>P. S. I've had tests against my package on MidnightBSD. My own patches indicate that we can get support for this system by adding a case for MidnightBSD that looks identical to the other BSD configurations in the vicinity of line 50 of the configure script.<br clear="all"><div><div><div><div><div>
<br>-- <br><div class="gmail_signature">&nbsp;"Debugging is twice as hard as writing the code in the first place.<br>
 &nbsp; Therefore, if you write the code as cleverly as possible, you are,<br>
 &nbsp; by definition, not smart enough to debug it." -- Brian Kernighan<br>
</div>
</div></div></div></div></div>
</div></div>
James Buren | 3 Nov 23:34 2014

libtcc.dll on win32 issues

If this library is dynamically loaded when compiled with recent MinGW environments, it causes the host
process to crash when it exits. It seems to happen with any dll compiled with gcc if libgcc.so is linked to it
dynamically. The only known workaround I know of is to link with the -static-libgcc flag. I'm not sure how
this should be patched into the build environment if I were to try to send this to upstream. Thoughts?

James Buren | 3 Nov 23:24 2014

win32 fix implicit warning patch

I pushed a patch to the mob branch, as per the instructions. It fixes an implicit warning for 'ExitProcess'
usage in one of the win32 source files. See here:

http://repo.or.cz/w/tinycc.git/commit/1e07ea71d3f564beb7f71dd868499eef996ffbae

Please look into merging it with themaster branch. Thank you.

James Buren | 2 Nov 23:09 2014

libtcc memory leak

When using tcc_compile_string() to compile a simple function, I have found a memory leak that was reported
by valgrind. It appears to be allocated at line 5972 in function decl0 in the file tccgen.c. It appears to
happen after tcc_strdup() is called and the loop containing the asm_label variable ends, either via a
break or return statement. The pointer appears to be lost, thus leaking the memory allocated by tcc_strdup().

Here is my valgrind output:
==6286== Memcheck, a memory error detector
==6286== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al.
==6286== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info
==6286== Command: ./test
==6286== Parent PID: 3345
==6286==
==6286==
==6286== HEAP SUMMARY:
==6286==     in use at exit: 97 bytes in 6 blocks
==6286==   total heap usage: 3,199 allocs, 3,193 frees, 822,391 bytes allocated
==6286==
==6286== 97 bytes in 6 blocks are definitely lost in loss record 1 of 1
==6286==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==6286==    by 0x40199F: tcc_malloc (libtcc.c:215)
==6286==    by 0x401A6B: tcc_strdup (libtcc.c:255)
==6286==    by 0x41639E: decl0 (tccgen.c:5972)
==6286==    by 0x416A38: decl (tccgen.c:6162)
==6286==    by 0x402D4A: tcc_compile (libtcc.c:791)
==6286==    by 0x402EA1: tcc_compile_string (libtcc.c:825)
==6286==    by 0x401755: main (in /home/ryuo/ndisapi/test)
==6286==
==6286== LEAK SUMMARY:
==6286==    definitely lost: 97 bytes in 6 blocks
==6286==    indirectly lost: 0 bytes in 0 blocks
==6286==      possibly lost: 0 bytes in 0 blocks
==6286==    still reachable: 0 bytes in 0 blocks
==6286==         suppressed: 0 bytes in 0 blocks
==6286==
==6286== For counts of detected and suppressed errors, rerun with: -v
==6286== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)

I would fix it myself, but I am not familiar with the innards well enough to propose a viable patch. Thank you.

Feng Nauh | 24 Oct 06:20 2014
Picon

win64: stdarg va_start and va_arg fails

Self-compiled tcc output error like this on win64:
tcc -c file-not-exits.c
tcc: error: file 'file '%s' not found' not found

The output backtrace:
  libtcc.c:626: tcc_error
    libtcc.c:569: error1
      libtcc.c:561: strcat_printf
        libtcc.c:564: va_start(ap, fmt);
It seems ap get wrong address of fmt.

In stdarg.h:
#else /* _WIN64 */
typedef char *va_list;
#define va_start(ap,last) __builtin_va_start(ap,last)
#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)

I notice va_arg not like the one in Windows SDK:
#define _crt_va_arg(ap, t)   \
    ( ( sizeof(t) > sizeof(__int64) || ( sizeof(t) & (sizeof(t) - 1) ) != 0 ) \
        ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \
        :  *(t  *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )
It has 8 bytes offset.

Patch followed:
diff --git a/include/stdarg.h b/include/stdarg.h
index 5aa9d57..23f820f 100644
--- a/include/stdarg.h
+++ b/include/stdarg.h
<at> <at> -29,8 +29,8 <at> <at> void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);
 
 #else /* _WIN64 */
 typedef char *va_list;
-#define va_start(ap,last) __builtin_va_start(ap,last)
-#define va_arg(ap,type) (ap += 8, sizeof(type)<=8 ? *(type*)ap : **(type**)ap)
+#define va_start(ap,last) (__builtin_va_start(ap,last), ap += 8)
+#define va_arg(ap,type) (ap += 8, (sizeof(type)>8 || (sizeof(type)&(sizeof(type)-1))!=0) ? **(type**)(ap-8) : *(type*)(ap-8))
 #define va_copy(dest, src) ((dest) = (src))
 #define va_end(ap)
 #endif

Or someone can fix __builtin_va_start.

tests/abitest.c also works.

This problem does not happened with x86_64-w64-mingw-tcc or tcc-win32.
<div><div dir="ltr">
<div>Self-compiled tcc output error like this on win64:</div>
<div>tcc -c file-not-exits.c</div>
<div>tcc: error: file 'file '%s' not found' not found</div>
<div><br></div>
<div>The output backtrace:</div>
<div>&nbsp; libtcc.c:626: tcc_error</div>
<div>&nbsp;&nbsp;&nbsp; libtcc.c:569: error1</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libtcc.c:561: strcat_printf</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libtcc.c:564:&nbsp;va_start(ap, fmt);</div>
<div>It seems ap get wrong address of fmt.</div>
<div><br></div>
<div>In stdarg.h:</div>
<div>#else /* _WIN64 */<br>typedef char *va_list;<br>#define va_start(ap,last) __builtin_va_start(ap,last)<br>#define va_arg(ap,type) (ap += 8, sizeof(type)&lt;=8 ? *(type*)ap : **(type**)ap)</div>
<div><br></div>
<div>I notice va_arg not like the one in Windows SDK:</div>
<div>#define _crt_va_arg(ap, t)&nbsp;&nbsp; \<br>&nbsp;&nbsp;&nbsp; ( ( sizeof(t) &gt; sizeof(__int64) || ( sizeof(t) &amp; (sizeof(t) - 1) ) != 0 ) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ? **(t **)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) \<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :&nbsp; *(t&nbsp; *)( ( ap += sizeof(__int64) ) - sizeof(__int64) ) )<br>It has&nbsp;8 bytes offset.</div>
<div><br></div>
<div>Patch followed:</div>
<div>diff --git a/include/stdarg.h b/include/stdarg.h<br>index 5aa9d57..23f820f 100644<br>--- a/include/stdarg.h<br>+++ b/include/stdarg.h<br> <at>  <at>  -29,8 +29,8  <at>  <at>  void *__va_arg(__va_list_struct *ap, int arg_type, int size, int align);<br>&nbsp;<br>&nbsp;#else /* _WIN64 */<br>&nbsp;typedef char *va_list;<br>-#define va_start(ap,last) __builtin_va_start(ap,last)<br>-#define va_arg(ap,type) (ap += 8, sizeof(type)&lt;=8 ? *(type*)ap : **(type**)ap)<br>+#define va_start(ap,last) (__builtin_va_start(ap,last), ap += 8)<br>+#define va_arg(ap,type) (ap += 8, (sizeof(type)&gt;8 || (sizeof(type)&amp;(sizeof(type)-1))!=0) ? **(type**)(ap-8) : *(type*)(ap-8))<br>&nbsp;#define va_copy(dest, src) ((dest) = (src))<br>&nbsp;#define va_end(ap)<br>&nbsp;#endif<br><br>Or someone can fix __builtin_va_start.</div>
<p>tests/abitest.c also works.</p>
<div>This problem&nbsp;does not happened with x86_64-w64-mingw-tcc or tcc-win32.<br>
</div>
</div></div>
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


Gmane