Has*_*yed 5 c++ gcc compilation toolchain
古怪
我已经编译了Google协议缓冲区,没有使用额外的参数进行"膨胀"编译,并使用以下命令进行编译./configure CXXFLAGS="-ffunction-sections -fdata-sections".du-h透露:
120K ./bloat/bin
124K ./bloat/include/google/protobuf/io
8.0K ./bloat/include/google/protobuf/compiler/java
12K ./bloat/include/google/protobuf/compiler/python
8.0K ./bloat/include/google/protobuf/compiler/cpp
128K ./bloat/include/google/protobuf/compiler
52K ./bloat/include/google/protobuf/stubs
848K ./bloat/include/google/protobuf
852K ./bloat/include/google
856K ./bloat/include
12K ./bloat/lib/pkgconfig
37M ./bloat/lib
38M ./bloat
20K ./unbloat/bin
124K ./unbloat/include/google/protobuf/io
8.0K ./unbloat/include/google/protobuf/compiler/java
12K ./unbloat/include/google/protobuf/compiler/python
8.0K ./unbloat/include/google/protobuf/compiler/cpp
128K ./unbloat/include/google/protobuf/compiler
52K ./unbloat/include/google/protobuf/stubs
848K ./unbloat/include/google/protobuf
852K ./unbloat/include/google
856K ./unbloat/include
12K ./unbloat/lib/pkgconfig
15M ./unbloat/lib
16M ./unbloat
53M .
Run Code Online (Sandbox Code Playgroud)
深入研究:
ls -gGh bloat/lib/
total 37M
-rw-r--r-- 1 13M 2010-09-07 13:57 libprotobuf.a
-rwxr-xr-x 1 986 2010-09-07 13:57 libprotobuf.la
-rw-r--r-- 1 1.6M 2010-09-07 13:57 libprotobuf-lite.a
-rwxr-xr-x 1 1021 2010-09-07 13:57 libprotobuf-lite.la
lrwxrwxrwx 1 25 2010-09-07 13:57 libprotobuf-lite.so -> libprotobuf-lite.so.6.0.0
lrwxrwxrwx 1 25 2010-09-07 13:57 libprotobuf-lite.so.6 -> libprotobuf-lite.so.6.0.0
-rwxr-xr-x 1 771K 2010-09-07 13:57 libprotobuf-lite.so.6.0.0
lrwxrwxrwx 1 20 2010-09-07 13:57 libprotobuf.so -> libprotobuf.so.6.0.0
lrwxrwxrwx 1 20 2010-09-07 13:57 libprotobuf.so.6 -> libprotobuf.so.6.0.0
-rwxr-xr-x 1 5.5M 2010-09-07 13:57 libprotobuf.so.6.0.0
-rw-r--r-- 1 12M 2010-09-07 13:57 libprotoc.a
-rwxr-xr-x 1 1.1K 2010-09-07 13:57 libprotoc.la
lrwxrwxrwx 1 18 2010-09-07 13:57 libprotoc.so -> libprotoc.so.6.0.0
lrwxrwxrwx 1 18 2010-09-07 13:57 libprotoc.so.6 -> libprotoc.so.6.0.0
-rwxr-xr-x 1 4.6M 2010-09-07 13:57 libprotoc.so.6.0.0
drwxr-xr-x 2 4.0K 2010-09-07 13:57 pkgconfig
ls -gGh unbloat/lib/
total 15M
-rw-r--r-- 1 5.8M 2010-09-07 14:03 libprotobuf.a
-rwxr-xr-x 1 988 2010-09-07 14:03 libprotobuf.la
-rw-r--r-- 1 764K 2010-09-07 14:03 libprotobuf-lite.a
-rwxr-xr-x 1 1023 2010-09-07 14:03 libprotobuf-lite.la
lrwxrwxrwx 1 25 2010-09-07 14:03 libprotobuf-lite.so -> libprotobuf-lite.so.6.0.0
lrwxrwxrwx 1 25 2010-09-07 14:03 libprotobuf-lite.so.6 -> libprotobuf-lite.so.6.0.0
-rwxr-xr-x 1 393K 2010-09-07 14:03 libprotobuf-lite.so.6.0.0
lrwxrwxrwx 1 20 2010-09-07 14:03 libprotobuf.so -> libprotobuf.so.6.0.0
lrwxrwxrwx 1 20 2010-09-07 14:03 libprotobuf.so.6 -> libprotobuf.so.6.0.0
-rwxr-xr-x 1 2.7M 2010-09-07 14:03 libprotobuf.so.6.0.0
-rw-r--r-- 1 3.7M 2010-09-07 14:04 libprotoc.a
-rwxr-xr-x 1 1.1K 2010-09-07 14:04 libprotoc.la
lrwxrwxrwx 1 18 2010-09-07 14:04 libprotoc.so -> libprotoc.so.6.0.0
lrwxrwxrwx 1 18 2010-09-07 14:04 libprotoc.so.6 -> libprotoc.so.6.0.0
-rwxr-xr-x 1 1.3M 2010-09-07 14:04 libprotoc.so.6.0.0
drwxr-xr-x 2 4.0K 2010-09-07 14:03 pkgconfig
Run Code Online (Sandbox Code Playgroud)
问题
我没有改变构建脚本以--gc-sections在链接期间执行" ",因此如果不是更大,unbloat构建不应该是相同的吗?导致尺寸减小的原因是什么?
背景
我目前正在使用gcc编译一个低级库,该库是一个巨大的2.5MB无条件和970KB剥离.这是不可接受的,我需要删除死代码 - 我依赖OpenSSL,协议缓冲区和Boost的3个库,我将静态链接最后2个到我的库中.这两个静态链接的库必须使用"-ffunction-sections -fdata-sections"进行编译,以便我删除死代码.
相关问题
我的下一个问题是如何指定用于消除死代码的根.
恐怕增益与-ffunction-sections -fdata-sections:当您在配置命令行上指定时CXXFLAGS="-ffunction-sections -fdata-sections",您覆盖了默认标志-O2 -g -DNDEBUG。因此,您的代码是在没有优化的情况下编译的。
您应该重做您的测试CXXFLAGS="-ffunction-sections -fdata-sections -O2 -g -DNDEBUG",您将得到预期的(即相同的)结果。
| 归档时间: |
|
| 查看次数: |
1124 次 |
| 最近记录: |