Do definitions in headers still help optimization?

Xi Ruoyao xry111@xry111.site
Fri Jan 12 16:01:53 GMT 2024


在 2024-01-12星期五的 22:49 +0800,LIU Hao via Gcc-help写道:
> 在 2024/1/12 22:07, Licht Martin Werner via Gcc-help 写道:
> > The answer used to be a certain yes when all optimizations were exclusive to the translation unit. 
> > By now, link-time optimization has been a thing for a while, and one might imagine that defining 
> > functions in header does not make a difference for optimization anymore.
> > 
> > (Of course, placing functions in header files or asking for link-time optimization will affect the 
> > compilation speed and memory use)
> > 
> > Discussions of this question seem to be based on hearsay, so I'd rather hope for an answer straight 
> > from the source. Thanks.
> 
> I'm still having a project which usually compiles and links in two minutes, but with LTO would take 
> hours to link. I can give a link if you are interested.
> 
> I'd like to say that LTO is still not an option for me.

And LTO cannot cross shared library boundary.  It even cannot cross
static library boundary if the static library is intended to be
distributed in binary form: a static library containing LTO bitcode
will just blow up if attempting to "link" against it using a different
compiler or even a different version of the compiler.  So LTO-enabled
distros build packages containing static libraries with -ffat-lto-
objects and then strip the LTO bitcode away from the static libraries.

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University


More information about the Gcc-help mailing list