[cfe-dev] linking and stripping compared to GCC 4.4
Douglas Gregor
dgregor at apple.com
Mon Nov 29 08:19:26 PST 2010
On Nov 27, 2010, at 8:05 AM, Luc Bourhis wrote:
> Hi,
>
> consider the following Boost.Python code:
>
> // demo.cpp
> #include <boost/python.hpp>
>
> template <typename T, typename U>
> T foo(T i, U j) { return i*j; }
>
> #define ARGS , (arg("i")=0, arg("j")=0)
>
> BOOST_PYTHON_MODULE(demo_ext)
> {
> using namespace boost::python;
> def("fii", foo<int,int> ARGS);
> def("fil", foo<int,long> ARGS);
> def("fif", foo<int,float> ARGS);
> def("fid", foo<int,double> ARGS);
> def("fic", foo<int,char> ARGS);
> def("fli", foo<long,int> ARGS);
> def("fll", foo<long,long> ARGS);
> def("flf", foo<long,float> ARGS);
> def("fld", foo<long,double> ARGS);
> def("flc", foo<long,char> ARGS);
> def("ffi", foo<float,int> ARGS);
> def("ffl", foo<float,long> ARGS);
> def("fff", foo<float,float> ARGS);
> def("ffd", foo<float,double> ARGS);
> def("ffc", foo<float,char> ARGS);
> def("fdi", foo<double,int> ARGS);
> def("fdl", foo<double,long> ARGS);
> def("fdf", foo<double,float> ARGS);
> def("fdd", foo<double,double> ARGS);
> def("fdc", foo<double,char> ARGS);
> }
>
> Then compare
>
> ~> g++ -c -DBOOST_PYTHON_MAX_BASES=2 -fPIC -fno-strict-aliasing -DNDEBUG -march=native -O3 -DBOOST_ALL_NO_LIB -DBOOST_DISABLE_THREADS -I../cctbx/boost -I/usr/include/python2.6 demo.cpp
> ~> g++ -o demo.so -shared demo.o -L../cctbx/cctbx_build/lib -lboost_python~>> g++ -o demo_strip.so -s -shared demo.o -L../cctbx/cctbx_build/lib -lboost_python
> ~> ls -lhS
> total 540K
> -rw-r--r-- 1 luc devcom 240K Nov 27 07:50 demo.o
> -rwxr-xr-x 1 luc devcom 170K Nov 27 07:50 demo.so*
> -rwxr-xr-x 1 luc devcom 121K Nov 27 07:50 demo_strip.so*
> -rw-r--r-- 1 luc devcom 902 Nov 27 07:18 demo.cpp
> ~> g++ --version
> g++ (GCC) 4.4.4 20100630 (Red Hat 4.4.4-10)
>
> to
>
> ~> clang++ -c -DBOOST_PYTHON_MAX_BASES=2 -fPIC -fno-strict-aliasing -DNDEBUG -O3 -DBOOST_ALL_NO_LIB -DBOOST_DISABLE_THREADS -I/Users/luc/Developer/cctbx/boost -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 demo.cpp
> ~> clang++ -o demo.so -w -bundle -undefined dynamic_lookup demo.o -L$cctbx_build_clang_pch/lib -lboost_python
> ~> clang++ -o demo_strip.so -s -w -bundle -undefined dynamic_lookup demo.o -L$cctbx_build_clang_pch/lib -lboost_python
> ~> ls -lhS
> total 1184
> -rwxr-xr-x 1 luc luc 203K Nov 27 16:56 demo.so
> -rwxr-xr-x 1 luc luc 202K Nov 27 16:56 demo_strip.so
> -rw------- 1 luc luc 178K Nov 27 16:56 demo.o
> -rw-r--r--@ 1 luc luc 952B Nov 27 05:13 demo.cpp
>
> ~> > clang++ --version
> clang version 2.9 (trunk 116866)
> Target: x86_64-apple-darwin10
> Thread model: posix
>
> First demo.so is significantly smaller than demo.o with gcc 4.4 whereas this is the other way around with clang. Moreover the stripping -s option significantly reduce the size of the .so further whereas clang -s does not do so.
>
> Is there any way to make clang++ competitive with GCC 4.4 here?
There certainly is, but only if we narrow down the problem to something manageable. Are there functions in the Clang-compiled demo.so that are significantly larger than their GCC-compiled counterparts? If so, we could look at those particular functions to see why we're generating more code.
Also, for code size, -O2 or -Os are generally a better bet than -O3.
- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20101129/977cce2c/attachment.html>
More information about the cfe-dev
mailing list