stupid_idiot
Group: Members
Posts: 344
Joined: Oct. 2006 |
|
Posted: Dec. 19 2007,05:37 |
|
Also, would like to suggest some other flags:
(1a) '-fdata-sections -ffunction-sections': QUOTE, GCC 3.3.6 manual:Quote | Place each function or data item into its own section in the output file if the target supports arbitrary sections. The name of the function or the name of the data item determines the section's name in the output file. | (1b) '-Wl,--gc-sections': This linker flag will strip out sections that contain only unused code (aka "dead code"), thereby decreasing object size. For this flag to have any effect, you must compile your code with the flags '-fdata-sections' and '-ffunction-sections'.
(2) '-fomit-frame-pointer' increases speed for C code without increasing object size. When using g++-3.3.x, '-fomit-frame-pointer' increases object size for C++ code noticeably, so I don't use it for C++.
(3) '-fno-exceptions' (C++ only): QUOTE, GCC 3.3.6 manual:Quote | -fexceptions Enable exception handling. Generates extra code needed to propagate exceptions. For some targets, this implies GCC will generate frame unwind information for all functions, which can produce significant data size overhead, although it does not affect execution. If you do not specify this option, GCC will enable it by default for languages like C++ which normally require exception handling, and disable it for languages like C that do not normally require it.[...] | '-fno-exceptions' is the opposite of '-fexceptions'. '-fno-exceptions' disables the generation of exception-handling code (by default enabled for C++). In short, '-fno-exceptions' decreases C++ object size. However, 'fno-exceptions' will not work for source code that makes use of exception handling. In such cases, you will probably get this error message:Code Sample | <FOO>.cpp: In method `<BAR>': <FOO>.cpp:<LINE_NUM>: exception handling disabled, use -fexceptions to enable | This tells you that '-fno-exceptions' cannot be used.
(4) '-fno-rtti' (C++ only): QUOTE, GCC manual:Quote | Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (`dynamic_cast' and `typeid'). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed. | In short, '-fno-rtti' decreases C++ object size, especially for larger programs/libraries. However, '-fno-rtti' will not work for source code that makes use of the run-time type information (RTTI) feature of C++. In such cases, you will probably get many errors like this:Code Sample | undefined reference to `typeinfo for foo' | This tells you that '-fno-rtti' cannot be used.
In summary, these are the compiler/linker flags I normally use: CFLAGS='-Os -fdata-sections -ffunction-sections -fomit-frame-pointer' CXXFLAGS='-Os -fdata-sections -ffunction-sections -fno-exceptions -fno-rtti' LDFLAGS='-Wl,--gc-sections'
|