Programming language that makes the smallest executables? [closed]

喜你入骨 提交于 2019-12-23 06:29:13

问题


I am looking for a programming language that generates the smallest EXE files.

It also needs to have no dependencies other than the DLLs that come with and are common to the following OS's: release Windows XP, Vista, 7, and 8. e.g. C++ application with static linking, Delphi, VB6, RealBasic, etc.

It should also run on all 32-bit & 64-bit Intel + AMD processors manufactured after 2000 with only one EXE.


回答1:


assembler! It can't get any smaller than that.




回答2:


You will not find an answer for this. C and assembly will give you some of the smallest executables you can find but they can also give you huge executables if you're not careful.

All modern compilers make highly efficient executables.

Don't worry about it. Pick the language that gets the job done the easiest for you.




回答3:


This is determined by the specific build tools (the compiler and linker) that you use, and by the configuration and content, not by the language per se.

Visual C++ 2010 can generate small executables if you use plain C and exclude the C runtime library.

If you need to use the C runtime library, you might have to try using Visual C++ 6 (disadvantage: out of support) or mingw (disadvantage: generates executables which are technically unsupported) both of which use the runtime library that is built into Windows XP and later.

The executable size for Visual C++ 2010 without the runtime library is 1K for up to 512 bytes of code and initialized data. This is as small as a working Windows executable can be, because there must be at least one section and the minimal section offset and size are both 512 bytes.

In general, the executable size will be 512 bytes of overhead plus the size of code and initialized data, rounded up to a multiple of 512 bytes.

To exclude the runtime library in Visual Studio 2010, set "Ignore All Default Libraries" to "Yes" under Linker->Input, and set an entry point (e.g., "NoCRTMain") under Linker->Advanced. The signature of the main function in this configuration is

void __stdcall NoCRTMain()

You may also need to set "Buffer Security Check" to "No" under C/C++->Code Generation. The buffer security check functionality uses a runtime library function.

At this point, if you have less than 512 bytes of code and constant data, the executable will be 3K in size, or 3.5K if you have initialized non-constant data.

You can save another 512 bytes by not including a manifest (Linker->Manifest File).

You can save another 512 bytes by making the image non-relocatable. Set "Randomized Base Address" to "No" and "Fixed Base Address" to "Yes" in Linker->Advanced.

To get it down to 1K, you need to merge the code, constant data, and initialized data sections. To do this, add these extra command-line options under Linker->Command Line:

 /SECTION:.text,ERW /MERGE:".rdata=.text" /MERGE:".data=.text" 

For security reasons, you may prefer to not merge the initialized data sections; doing so partially disables Data Execution Protection (DEP). If so, just use

 /MERGE:".rdata=.text" 

or set the equivalent option in Linker->Advanced.

If you did not merge all the sections, you may be able to save another 512 bytes by replacing the default MS-DOS stub with a smaller one, reducing the overall header size to fit within the 512 bytes minimum alignment size. This can be done by adding the /STUB command line option (Linker->Command Line) and using the minimal stub available here. If you prefer, you can create your own minimal stub by extracting the first 64 bytes of any Windows executable.



来源:https://stackoverflow.com/questions/16266795/programming-language-that-makes-the-smallest-executables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!