tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] Why is there extra code in TCC compiled EXE files?


From: Carlos Montiers
Subject: Re: [Tinycc-devel] Why is there extra code in TCC compiled EXE files?
Date: Mon, 28 Dec 2015 18:08:57 -0300

That bytes maybe are of the crt.
Look:
http://repo.or.cz/tinycc.git/blob/HEAD:/win32/lib/crt1.c

For very small executable compile this:


int _start(void)
{
    return 1;
}






2015-12-28 4:48 GMT-03:00 Ben Hutchinson <address@hidden>:
So when I compile this C code (which is the absolute simplest possible program to write in C) :
int main(){
return 1;
}

it should generate an EXE file that would be equivalent to assembling the following ASM code:

MOV EAX,1
RET

When viewing this EXE file in a hex editor, and looking at the code section of the EXE file, I should see this:
B8 01 00 00 00 C3

Instead, it compiles into a "much more complicated than needed" piece of code which has the following hexidecimal representation:
55 89 E5 81 EC 00 00 00 00 90 B8 01 00 00 00 E9 00 00 00 00 C9 C3

And that's just for the function that I'm TRYING to compile. It also automatically tacks on this extra function which has the following hex representation:
55 89 E5 81 EC 2C 00 00 00 90 8D 45 E8 50 E8 FE 00 00 00 83 C4 04 B8 00 00 00 00 89 45 D4 B8 00 00 03 00 50 B8 00 00 01 00 50 E8 21 01 00 00 83 C4 08 B8 01 00 00 00 50 E8 1B 01 00 00 83 C4 04 8D 45 D4 50 B8 00 00 00 00 50 8D 45 DC 50 8D 45 E0 50 8D 45 E4 50 E8 05 01 00 00 83 C4 14 8B 45 DC 50 8B 45 E0 50 8B 45 E4 50 E8 71 FF FF FF 83 C4 0C 89 45 D8 8B 45 D8 50 E8 EA 00 00 00 83 C4 04 C9 C3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 87 2C 24 55 8D 6C 24 04 51 89 E9 81 E9 00 10 00 00 85 01 2D 00 10 00 00 3D 00 10 00 00 7D EC 29 C1 85 01 89 E0 89 CC 8B 08 FF 60 04 8B 45 EC C3 E8 F7 FF FF FF 8B 00 8B 00 C3 E8 ED FF FF FF 50 E8 EB FF FF FF 50 E8 85 00 00 00 81 C4 08 00 00 00 C3 8B 65 E8 E8 D6 FF FF FF 50 E8 78 00 00 00 FF FF FF FF FA 10 40 00 12 11 40 00 E9 6F 00 00 00 55 8B 6C 24 08 8D 44 24 0C 89 45 00 31 C0 89 45 04 64 A1 00 00 00 00 89 45 08 B8 2C 11 40 00 89 45 0C B8 20 11 40 00 89 45 10 31 C0 89 45 14 8D 45 08 64 A3 00 00 00 00 5D C3 00 00 00 00 00 FF 25 28 20 40 00 00 00 FF 25 2C 20 40 00 00 00 FF 25 30 20 40 00 00 00 FF 25 34 20 40 00 00 00 FF 25 38 20 40 00 00 00 FF 25 3C 20 40 00 00 00 FF 25 40 20 40 00 00 00


Running the program in a debugger, I see that the program's entry point is actually IN THIS EXTRA FUNCTION, which means my program has to execute a HUGE amount of overhead code before it even gets to the function that I created which was SUPPOSED TO BE the entrypoint function. It appearantly at some point in this mess of code (which is what I'm calling the "extra function") has some jump that takes it to the correct piece of code that is what is SUPPOSED TO BE where the entry point is.

Is there any command line switch, or combination of command line switches, that I can use to cause it to compile ONLY the code that I have specifically written, and NOT create an extra function that gets run before the code that I've written? If yes, please tell me the command line switch/switches that I will need. If no, please add this feature in a future version of TCC.

Why is this important? Well the smallest possible valid EXE file is 1024 bytes in size. TCC smallest EXE file output is 1536 bytes in size. This is 512 bytes of space WASTED.

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



reply via email to

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