Opened 9 years ago
Last modified 9 years ago
#9102 new Bugs
Various Boost header files define variables with internal linkage, which results in unnecessary code bloat
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | system |
Version: | Boost 1.54.0 | Severity: | Optimization |
Keywords: | Cc: |
Description
Some Boost headers define variables with internal linkage. For example, in boost/system/error_code.hpp
:
static const error_category & posix_category = generic_category(); static const error_category & errno_ecat = generic_category(); static const error_category & native_ecat = system_category();
In boost/asio/error.hpp
:
static const boost::system::error_category& system_category = boost::asio::error::get_system_category(); static const boost::system::error_category& netdb_category = boost::asio::error::get_netdb_category(); static const boost::system::error_category& addrinfo_category = boost::asio::error::get_addrinfo_category(); static const boost::system::error_category& misc_category = boost::asio::error::get_misc_category();
Because of this, every translation unit that includes these headers results in a separate instance of each of these variables in the resulting executable file. Because these variables have non-constant initializers, not only they are not eliminated during linking, even if not used, but also each instance of such variable results in a call to a initialization function during program startup.
I think that merely including a Boost header, without using anything from it, should not result in any extra code remaining in the resulting executable - especially not if each translation unit results in a separate copy of such code.