Compile connection Optimizations

Source: Internet
Author: User

Recently in doing EXE volume optimization of things, so the VC10 compiler connector related options are all over again

In general, use/O1 for minimum volume optimization

According to the MSDN introduction,/o1 equals/og/os/oy/ob2/gs/gf/gy, which means
/O1 will automatically open <global optimization>/og, <favor small Code>/os, <omit Frame pointers>/oy, <string pooling >/GF,/GS (Control Stack Checking Calls), <enable function-level linking>/gy
And/o1 will automatically turn off <basic runtime checks>, <smaller type checks>

The effects of these parameters are

/og expression merging, variable register, loop-optimized, Nrvo

/os Optimization with Volume priority

/oy The compiler compiles a function, prologue does not produce a push ebp; MOV ebp Esp,epilogue does not produce a pop EBP code, the function body does not produce a code based on EBP addressing, which has some impact on the debugger, especially when the program uses dynamic stack memory allocation

/OB2, expand the inline function

/GF, needless to say.

/GS, default is 4k, when the function stack variable is greater than 4k, call the _CHKSTK function to allocate more stack space

/gy, merging the same functions, such as the same functions in different namespaces, non-template functions of template classes, and removing unused functions

Next you need to set the following options to make the exe smaller
Close <inline fuction expansion>/ob0, prohibit the compiler to expand the function labeled inline, personally think that the artificial inline is not advisable, you should trust the compiler and connector capabilities
Open the <whole program optimization>/GL for supporting the connector/LTCG
Prohibit <enable C + + exceptions> No/eh, compile parameters do not add any/eh related parameters
Prohibit <buffer security check>/gs-do not insert buffer check code

Buffer overflow Check principle, in the function stack, the return address and the stack variable insert a 4-byte tag, enter the function when the value is checked, the function returns to check whether the value has been modified, if modified, it proves that the function stack Overflow

Refer to MSDN Http://msdn.microsoft.com/library/aa290051.aspx
After turning on the/gy, you need to mate with the connector/OPT:REF/OPT:ICF
Prohibit <enable run-time Type information>/gr-do not use C + + RTTI, affecting very few use dynamic_cast

Connector options
Open <merge section>/merge. Rdata=.text Merge the same property PE segment, reduce the PE file volume; You cannot combine different attribute segments. RSRC segments must exist separately
Prohibit <randomized base address>/dynamicbase:no Note that randomized base address is a means of preventing buffer overflow attacks introduced by Vista

Starting with Msdn,vista, DLL-loaded addresses are no longer fixed and randomly selected within 256 possible addresses, making the destination address of the buffer overflow attack indeterminate.

Note that if this option is turned on, it indicates that the module supports RBA, the load address must be random, but does not open, does not mean that the load address is not changed, Windows Load DLL if the address conflict, will choose the new address loading, this ability is determined by the following option to open
Turn on <fixed base address>/fixed in conjunction with the previous option, Causes the connector not to generate a. reloc segment of the PE, reducing the PE file volume; Note that only for Exe,dll should not be set; If the DLL does not support a mutable base address, the DLL cannot load
Does not support <image has safe exception handlers>/safeseh:no does not create an SEH table, safe exception handlers table is a means of defending against buffer overflow attacks; note that When secure SEH processing tables are enabled, only exceptions that are enlisted in the table allow exception-handling routines to be performed to prevent buffer overflow attacks from overwriting exception-handling routine addresses.
Enable <link-time code generation> <profile guided optimization>/LTCG LTCG:PGI PGO Connector code generation, which can be optimized between modules, preferably with PGI PGO, if the condition is not allowed, using LTCG alone can also get better results.

Compile connection Optimizations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.