Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang removing dead code during static linking (gcc equivalent of -Wl, --gc-sections)

I'm linking against a static library and I wonder how one should handle stripping of dead code in llvm/Clang. I can't find any documentation that hints that Clang has some equivalent of -Wl, --gc-section or -dead_strip.

I assume that some dead code elimination is performed automatically at the higher optimisation levels, but that's the case in gcc too, right? Yet, gcc provides some explicit control of this via the above mentioned flags. Does Clang not provide that or am I missing something?

(The system is OSX)

like image 894
kamjagin Avatar asked Jul 17 '13 20:07

kamjagin


1 Answers

Dead stripping is a linker feature, not a compiler feature. Neither gcc nor clang have it, as a result. That's why you had to use -Wl - you're passing that flag to the linker. The Mac OS X linker uses -dead_strip. You can pass the flag directly to your clang invocation and it will pass it through automatically.

like image 84
Carl Norum Avatar answered Sep 23 '22 21:09

Carl Norum