WinAsm Studio, The Assembly IDE - Free Downloads, Source Code
Forum

Pages: (2) [1] 2   ( Go to first unread post ) Reply to this topicStart new topicStart Poll

Tiny CC - Tiny C compiler, Build extremely small binaries

Vortex
Posted: Sep 2 2007, 10:41 AM
Quote Post


Very Active Member
****

Group: Moderators
Posts: 69
Member No.: 8
Joined: 13-May 04



Hi friends,

Here is an example project created with the Tiny C Compiler. This tool creates very small C executables :

http://fabrice.bellard.free.fr/tcc

Attached File ( Number of downloads: 6 )
Attached File  tcc1.zip

PMEmail PosterUsers Website
Top
akyprian
Posted: Sep 2 2007, 11:27 AM
Quote Post


Administrator
******

Group: Admins
Posts: 1845
Member No.: 1
Joined: 12-May 04



Thanks Vortex for sharing
PMEmail PosterUsers Website
Top
Vortex
Posted: Sep 7 2007, 10:07 AM
Quote Post


Very Active Member
****

Group: Moderators
Posts: 69
Member No.: 8
Joined: 13-May 04



libtcc1.a, the C runtime startup library supplied with TinyCC has two entry points _start and _winstart for console and GUI applications respectively. The compiler emits ELF object files so I decided to translate my own tiny C runtime startup modules to C modules with inline assembly. TinyCC accepts only the AT&T syntax to write inline assembly. Unfortunately, the compiler ignores the __declspec(naked) statement disabling the standard prologue\epilogue code. The solution was to patch the object modules to remove the overhead. Without removing the prologue\epilogue code, I could not terminate the modules with the ExitProcess function. Finally, I was able to eliminate the msvcrt.dll dependency and the size of the demo executable hello_win.exe decreased from 3584 bytes to 3072 bytes :

CODE
\tcc\tcc\tcc -ID:\tcc\include\winapi -ID:\tcc\include -L..\lib -lkernel32 -luser32 -lgdi32 hello_win.c ..\crt0ELF\crt0ELF.a -o hello_win.exe


I could not find a way to use my static library crt0ELF.a with TinyCC. The compiler emits the following error message :

CODE
\tcc\tcc\tcc -ID:\tcc\include\winapi -ID:\tcc\include -L..\lib -lkernel32 -luser32 -lgdi32 hello_win.c ..\crt0ELF\crt0ELF.a -o hello_win.exe

tcc: undefined symbol '_winstart'


crt0ELF.a is a static library including the two startup modules for console and GUI applications. I used the librarian ar.exe supplied with the MinGW package to build the static library :

CODE
\MinGW\bin\ar rc crt0ELF.a crt0cons.o crt0gui.o


Is there a way to use static libraries with TinyCC?

Attached File ( Number of downloads: 1 )
Attached File  tcc_crt0.zip
PMEmail PosterUsers Website
Top
samael
Posted: Sep 7 2007, 12:42 PM
Quote Post


Typo-lord
******

Group: Admins
Posts: 217
Member No.: 5187
Joined: 10-June 07



Vortex, this may sound dumb as i have never played with Tiny CC, but i thing the __declspec(naked) statement is Microsoft compiler specific. I really don't know if it's supported by Tiny CC.


Also, according to this page, the -B option specifies whether bindings of libraries for linking are static or dynamic.

-B [static|dynamic].

Hope this helps.
PM
Top
Vortex
Posted: Sep 7 2007, 12:51 PM
Quote Post


Very Active Member
****

Group: Moderators
Posts: 69
Member No.: 8
Joined: 13-May 04



Hi Samael,

Many thanks for your help.

It's true that __declspec(naked) is specific to MS compilers but it's interesting to note that the Tiny C compiler does not display any warning message if a function is declared with __declspec(naked) The compiler ignores the statement.

The Tiny C compiler does not support the -b switch :

CODE
tcc: invalid option -- '-b'
PMEmail PosterUsers Website
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

Topic Options Pages: (2) [1] 2  Reply to this topicStart new topicStart Poll