`

使用GCC/GNU-ld删除dead code

 
阅读更多
[url]
https://gcc.gnu.org/ml/gcc-help/2003-08/msg00128.html
https://embeddedfreak.wordpress.com/2009/02/10/removing-unused-functionsdead-codes-with-gccgnu-ld/
[/url]


引用

Hi Dr. Rupp,

I was just looking into this very thing!

Do this in your Makefile...
--------8<--------
DEADCODESTRIP := -Wl,-static -fvtable-gc -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,-s

foo : foo.c
    g++ $(DEADCODESTRIP) $< -o $@
--------8<--------

Step by step...

-Wl,-static
Link against static libraries.  Required for dead-code elimination.

-fvtable-gc
C++ virtual method table instrumented with garbage collection information for the linker.

-fdata-sections
Keeps data in separate data sections, so they can be discarded if unused.

-ffunction-sections
Keeps funcitons in separate data sections, so they can be discarded if unused.

-Wl,--gc-sections
Tell the linker to garbage collect and discard unused sections.

-s
Strip the debug information, so as to make the code as small as possible.  (I presume that you'd want to do this in a dead-code removal build.)

The requirement to link against the static libraries was surprising to me.  But there you go.

HTH,
分享到:
评论

相关推荐

    mtk 6572 modem tools tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    解决mtk6572平台modem编译错误! Please install the GCC Cross-Compiler on correct path: tools/GCC/4.6.2/linux/bin/arm-none-eabi-gcc

    gcc-arm-none-eabi-7-2018-q2-update-win32.zip

    It includes the GNU Compiler (GCC) and is available free of charge directly from Arm for embedded software development on Windows, Linux and Mac OS X operating systems. Follow the links on this page ...

    64位linux 编译c提示gnu/stubs-32.h:No such file or directory的解决方法

    C语言编译器关于gnu/stubs-32.h文件的解决方法 在64位Linux系统下编译C语言程序时,可能会出现gnu/stubs-32.h文件不存在的错误,主要是因为缺少32位兼容包的原因。今天,我们就来探讨解决这个问题的方法。 首先,...

    mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp64-r5.1.1.tar.bz2

    mips-linux-gnu-ingenic-gcc7.2.0-glibc2.29-fp64-r5.1.1.tar.bz2

    arm-linux-gcc-4.3.2(交叉编译器)

    Configured with: /opt/crosstool/crosstool-0.28/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-linux/gcc-3.4.1-...

    gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz

    标题中的“gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu.tar.gz”指的是一款由Linaro组织提供的GCC(GNU Compiler Collection)交叉编译器,版本号为6.3.1,发布于2017年5月。这个版本是针对x86_64架构的主机...

    aarch64-linux-gnu-gcc gcc version 7.5.0 (Linaro GCC 7.5-2019.12

    标题中的"aarch64-linux-gnu-gcc"是一个交叉编译器,用于在aarch64(也称为ARM64或AArch64)架构上构建Linux应用程序。它基于GNU工具链,是GCC(GNU Compiler Collection)的一个特定版本,这里是7.5.0,由Linaro...

    gcc-linaro-6.3.1-2017.05-x86-64-aarch64-linux-gnu.7z

    标题中的“gcc-linaro-6.3.1-2017.05-x86-64-aarch64-linux-gnu.7z”是一个GCC(GNU Compiler Collection)的特定版本,由Linaro组织提供。Linaro是一个开源软件工程组织,专注于优化和维护开源软件在ARM架构上的...

    gcc-arm-none-eabi-8-2019-q3-update-win32-sha1.exe

    It includes the GNU Compiler (GCC) and is available free of charge directly from Arm for embedded software development on Windows, Linux and Mac OS X operating systems. Follow the links on this page ...

    arm-linux-gcc和arm-elf-gcc 区别

    arm-linux-gcc 使用 GNU 的 Glibc,而 arm-elf-gcc 一般使用 uClibc/uC-libc 或者 newlib。 uClibc/uC-libc 和 newlib 都是 C 语言库文件,只是所应用的领域不同而已。uClibc/uC-libc 是与 Glibc API 兼容的小型化 ...

    arm-2014.05-29-arm-none-linux-gnueabi

    Configured with: /scratch/maciej/arm-linux-2014.05-rel/src/gcc-4.8-2014.05/configure --build=i686-pc-linux-gnu --host=i686-mingw32 --target=arm-none-linux-gnueabi ...... Thread model: posix gcc ...

    gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.tar

    gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.tar是由 Linaro 公司基于GCC推出的的ARM交叉编译工具。可用于交叉编译64-bit Armv8 Cortex-A, little-endian目标中的裸机程序、u-boot、Linux kernel、...

    arm-linux-gcc-3.4.1(交叉编译器)

    Configured with: /opt/crosstool/crosstool-0.28/build/arm-linux/gcc-3.4.1-glibc-2.3.2/gcc-3.4.1/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/opt/crosstool/arm-linux/gcc-3.4.1-...

    gcc/pcre-devel/openssl-devel/zlib-devel negix centos7依赖rpm

    2. **gcc**: GCC(GNU Compiler Collection)是GNU项目的一部分,提供了C、C++、Objective-C、Fortran等多种编程语言的编译器。在Linux环境中,GCC是开发和编译软件的基础工具,它将源代码转化为可执行程序。 3. **...

    gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.gz

    gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.tar是由 Linaro 公司基于GCC推出的的ARM交叉编译工具。可用于交叉编译64-bit Armv8 Cortex-A, little-endian目标中的裸机程序、u-boot、Linux kernel、...

    arm-linux-gnueabi-5.4.0.tar

    arm-linux-gcc交叉编译工具: 备注:使用此资源时需要解压两次,因为上传时显示资源重复上传失败,于是套了两层压缩。建议使用window系统下载先解压一次再到Linux中进行解压,这样方便查看 此外,如果把编译器gcc...

    gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar

    例如,使用`aarch64-linux-gnu-gcc`替代原本的`gcc`来编译源代码。 在实际开发过程中,交叉编译链可以极大地提高效率,尤其是在嵌入式系统开发中,目标平台的资源有限,直接在其上编译可能会非常耗时。此外,Linaro...

    gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.7z

    交叉编译工具:gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.bz2 解压命令:tar jxvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.09_linux.tar.bz2

    gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu.tar.xz.7z

    gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu是由 Linaro 公司基于GCC推出的的ARM交叉编译工具。可用于交叉编译64-bit Armv8 Cortex-A, little-endian hard-float, little-endian目标中的裸机程序、u-boot、...

Global site tag (gtag.js) - Google Analytics