What kind of dead code can GCC eliminate from the final output?

后端 未结 3 498
深忆病人
深忆病人 2020-12-14 09:51

I have always been told that compiler is sufficient smart to eliminate dead code. Much of the code that I am writing has a lot of information known at compile time but the c

3条回答
  •  甜味超标
    2020-12-14 10:35

    Your example focuses on dead code elimination inside functions.

    Another type of dead code elimination, is removal of entire unused symbols (functions or variables) which can be achieved with:

    -fdata-sections -ffunction-sections -Wl,--gc-sections
    

    as mentioned at: How to remove unused C/C++ symbols with GCC and ld?

    These flags are not enabled in the various GCC -O levels (-O1, -O2, etc) by default.

提交回复
热议问题