Problem on static libraries enabled with LinkTimeOptimization
Lei YU
mine260309 at gmail.com
Wed Sep 12 19:26:38 AEST 2018
This email is to describe a problem about static libraries enabled with
LinkTimeOptimization (-flto), and asking for suggestions how to fix the
problem.
## Background
When a repo enables lto, and if the repo builds a static library, it gets
build error, e.g. for [phosphor-fan-presence#11][1]
arm-openbmc-linux-gnueabi-ar: .libs/libfan_la-utility.o: plugin
needed to handle lto object
arm-openbmc-linux-gnueabi-ar: .libs/libfan_la-timer.o: plugin
needed to handle lto object
arm-openbmc-linux-gnueabi-libtool: link:
arm-openbmc-linux-gnueabi-ranlib .libs/libfan.a
arm-openbmc-linux-gnueabi-ranlib:
.libs/libfan.a(libfan_la-utility.o): plugin needed to handle lto
object
arm-openbmc-linux-gnueabi-ranlib:
.libs/libfan.a(libfan_la-timer.o): plugin needed to handle lto object
And eventually it causes undefined references during linking.
The same for phosphor-time-manager.
## Root Cause
ar needs to load liblto_plugin to handle lto objects, and our build
environment does not tell ar to load the plugin.
According to https://gcc.gnu.org/wiki/LinkTimeOptimizationFAQ:
> In order to handle archives of these objects you have to use the gcc
> wrappers: gcc-ar, gcc-nm and gcc-ranlib.
So the simplest way to load the plugin is to use gcc-ar instead of ar.
## Question
Most of phosphor repos in OpenBMC uses autotool to configure, and it depends
on environment variables to configure the repo.
By default, AR is defined as `${TARGET_PREFIX}ar`, I do not find a way to
change it.
So my question is, how to handle this case? E.g. how to specify gcc-ar in
autoconf?
## References
* I have an *ugly* workaround to override AR by define it in `EXTRA_OECONF`,
see https://gerrit.openbmc-project.xyz/#/c/openbmc/openbmc/+/12721/ for
details.
* bmcweb uses CMake and it specifies gcc-ar in [CMakefiles][2].
[1]: https://github.com/openbmc/phosphor-fan-presence/issues/11
[2]: https://github.com/openbmc/bmcweb/blob/master/CMakeLists.txt#L70
More information about the openbmc
mailing list