Dead Code Stripping. Its usage in Adobe InDesign

Let me first explain what dead code is

Dead – Code ( Unreachable code ) :- It is the part of the program that is never executed, because the control flow never reaches it.

Example of Dead Code :-

     int f (int x, int y)
     {
          return x+y;
          int z=x*y;
     }.

In this code “int z=x*y;” this line is never going to execute so this is dead code, relative to this code.

Read more on dead-code : – http://en.wikipedia.org/wiki/Unreachable_code

Dead – Code Stripping :-

The process of removing unused code and data blocks from executable files is called dead-code stripping. This reduces the overall size of the executable which decreases memory footprint and improves performance. It also allows programs to link successfully when unused code refers to an undefined symbol (instead of resulting in a link error).
Dead-code stripping is not limited to removing only unused functions and executable code from a binary but also removes any unused symbols and data that reside in data blocks.

For more information : http://tuvix.apple.com/mac/library/documentation/DeveloperTools/Conceptual/XcodeBuildSystem/500-Linking/bs_linking.html

Example of intelligent usage of dead stripping in Adobe Indesign.

In Adobe Indesign there is a file known a “FactoryList.h” in this file you have to register all the custom implementation with the object model of Indesign. This file is no where used in the C++ code. This is used by the ODFRC compiler. So to avoid the dead stripping of the FactoryList.h by VC++ compiler optimization, InDesign created another file DontDeadStrip in this file there is code in which FactoryList.h is used so the complier doesn’t dead strips the FactoryList.h but Wait!!!

From where is the DontDeadStrip called so that it doesn’t get dead stripped. It is called from wpluginmain.cpp. It is the code where the DontDeadStrip() is called so that it is also not dead stripped

extern "C" BOOL APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
    switch( dwReason ){
          case DLL_PROCESS_ATTACH:
          {
            DontDeadStrip();    // force static constructors & destructors 
            .....
         }
    }
    ...
}

 Isn’t this interesting ….

150 150 Burnignorance | Where Minds Meet And Sparks Fly!