代码之家  ›  专栏  ›  技术社区  ›  Hassan Syed

GCC减少二进制膨胀-奇怪的副作用

  •  5
  • Hassan Syed  · 技术社区  · 14 年前

    怪诞

    我编译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 .
    

     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
    

    问题

    --gc-sections “在连接过程中,如果不是更大的话,不允许的构建是相同的吗?是什么导致了尺寸的缩小?

    背景

    相关问题

    我的 next question

    2 回复  |  直到 7 年前
        1
  •  1
  •   Samuel Tardieu    14 年前

    -ffunction-sections -fdata-sections :当您指定 CXXFLAGS="-ffunction-sections -fdata-sections" -O2 -g -DNDEBUG . 因此,您的代码在编译时没有进行任何优化。

    你应该重做你的测试 CXXFLAGS="-ffunction-sections -fdata-sections -O2 -g -DNDEBUG" 您将得到预期的(即相同的)结果。

        2
  •  1
  •   Employed Russian    14 年前

    编译 -ffunction-sections .text .text.foo , .text.bar 等)。同样适用于 -fdata-sections

    但你呢 关心你的建筑面积有多大。你说什么 关心的是最终可执行文件(或共享库)有多大。

    -Wl,--gc-sections