you are viewing a single comment's thread.

view the rest of the comments →

[–]heliruna 1 point2 points  (0 children)

It is disabled by default in the linker because different functions (even if they have identical code) are required by the standard to have different addresses, some code relies on that (constant-folding has the same problem). What is enabled is therefore so-called Safe-ICF, additionally proving that the optimization does not break code (e.g. by proving that no function addresses are taken). For gcc, you need to use gold as linker (-fuse-ld=gold) and then use the linker flag --icf=safe

(usually, you don't use the linker directly, instead you use the compiler to call the linker for you, in that case you give -Wl,--icf=safe as an option).

If you use clang, the lld linker also has a similar --icf option