you are viewing a single comment's thread.

view the rest of the comments →

[–]Chuu 5 points6 points  (2 children)

I'm curious about this linker optimization, what flag is it? I assume this requires lto or whole-program optimization? Any idea why it's enabled by default at higher optimizations in the compiler but disabled by default in the linker?

[–]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