Rebuilding facter...

59 views
Skip to first unread message

Brice Figureau

unread,
Jan 17, 2017, 11:27:25 AM1/17/17
to puppet-dev
Hi,

While I was trying to fix FACT-1559[1], which is a trivial 2 lines fix,
I embarked in an endless and very frustrating journey of trying to build
facter.

I was able to rebuild facter in isolation on an ubuntu 16.04, once all
the dependencies were fulfilled correctly.

But when I tried to build in the context of the puppet-agent package so
that my facter build would:
* be able to replace the shipped facter
* use the /opt/puppetlabs embedded ruby
* use the various /opt/puppetlabs/puppet/lib shipped library

I encountered an endless stream of issues:
* impossibility to build with static boost and/or static yaml-cpp, I
kept getting link errors about:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libyaml-cpp.a(parse.cpp.o): relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libyaml-cpp.a: error adding symbols: Bad value
or
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_locale.a(format.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libboost_locale.a: error adding symbols: Bad value

* if building a full dynamic lib, I get numerous boost link issues like
those:
../CMakeFiles/libfactersrc.dir/src/ruby/module.cc.o: In function `std::_Function_handler<unsigned long (), facter::ruby::module::ruby_search_external(unsigned long, unsigned long)::{lambda()#1}>::_M_invoke(std::_Any_data const&)':
module.cc:(.text+0x6145): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const'
../CMakeFiles/libfactersrc.dir/src/ruby/module.cc.o: In function `facter::ruby::module::load_facts()':
module.cc:(.text+0x6a10): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const'
../CMakeFiles/libfactersrc.dir/src/ruby/module.cc.o: In function `facter::ruby::require_context::require_context()':
module.cc:(.text._ZN6facter4ruby15require_contextC2Ev[_ZN6facter4ruby15require_contextC5Ev]+0x31e): undefined reference to `boost::program_options::abstract_variables_map::operator[](std::string const&) const'
CMakeFiles/libfacter_test.dir/ruby/ruby_helper.cc.o: In function `boost::locale::basic_format<char>::format_output(std::ostream&, std::string const&) const':
ruby_helper.cc:(.text._ZNK5boost6locale12basic_formatIcE13format_outputERSoRKSs[_ZNK5boost6locale12basic_formatIcE13format_outputERSoRKSs]+0x1dc): undefined reference to `boost::locale::details::format_parser::set_one_flag(std::string const&, std::string const&)'
../CMakeFiles/libfactersrc.dir/src/util/config/config.cc.o: In function `facter::util::config::fact_config_options()':
config.cc:(.text+0x3a): undefined reference to `boost::program_options::options_description::options_description(std::string const&, unsigned int, unsigned int)'
...

It's like if boost libs weren't there, but they seem specified in the
linker command line arguments. Cmake found them correctly.

I haven't done any serious C++ programming in the last 15 years, so I'm
all rusty (no pun intended of course), and I might have missed something
essential.

That would be great to be able to rebuild facter with my fix (I'm not
sure what's the plan on facter release nowadays, but I don't expect to
see an updated puppet-agent with facter including this coreos fix in a
timeframe that would allow me to make progress on my side).

My cmake looks like this:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 cmake
-DLEATHERMAN_GETTEXT=OFF \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_PREFIX_PATH=/opt/puppetlabs/puppet \
-DCMAKE_INSTALL_PREFIX=/opt/puppetlabs/puppet \
-DCMAKE_INSTALL_RPATH=/opt/puppetlabs/puppet \
-DRUBY_INCLUDE_DIR=/opt/puppetlabs/puppet/include/ruby-2.1.0/ \
-DBOOST_STATIC=OFF \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DYAMLCPP_STATIC=OFF \
-DAIO_AGENT_VERSION=1.8.0 \
-DINSTALL_BATCH_FILES=NO \
..

Any help is welcome :)

[1]: https://tickets.puppetlabs.com/browse/FACT-1559?jql=project%20%3D%
20FACT%20AND%20text%20~%20%22static%22
--
Brice Figureau
My Blog: http://www.masterzen.fr/

Michael Smith

unread,
Jan 17, 2017, 2:52:30 PM1/17/17
to puppet-dev
Unfortunately this is made a little harder since our builds of boost and yaml-cpp aren't hosted. However, the instructions for building them are at https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/boost.rb and https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/yaml-cpp.rb. Those both build statically, so you'd then use `-DBOOST_STATIC=ON -DYAMLCPP_STATIC=ON`. We use Boost 1.58 currently.


The dynamic link issues are harder to pin down. That is likely an issue in the order things are linked (there are lots of possible build configurations, so the one you're trying with dynamic libraries is likely not tested).

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/1484670441.32128.0.camel%40daysofwonder.com.
For more options, visit https://groups.google.com/d/optout.

Brice Figureau

unread,
Jan 18, 2017, 9:50:29 AM1/18/17
to puppe...@googlegroups.com
Hi Michael,

Thank you for your answers!

On Tue, 2017-01-17 at 19:52 +0000, Michael Smith wrote:
> Unfortunately this is made a little harder since our builds of boost
> and yaml-cpp aren't hosted. However, the instructions for building
> them are
> at https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/boost.rb and https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/yaml-cpp.rb. Those both build statically, so you'd then use `-DBOOST_STATIC=ON -DYAMLCPP_STATIC=ON`. We use Boost 1.58 currently.

I already had built YAML-CPP, but I was using ubuntu default Boost.

> As for the specific issues, it looks like building with -fPIC would
> help with the errors you saw with static libraries
> (see https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/boost.rb#L63-L64 and https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/files/cmake/linux-toolchain.cmake#L21-L22).

That's very interesting and probably the bits I was missing. I assumed
that my dependencies would be built with -fPIC enabled, including
yaml-cpp.
It looks like ubuntu's Boost static libraries are not built with -fPIC,
thus generating those errors.

> The dynamic link issues are harder to pin down. That is likely an
> issue in the order things are linked (there are lots of possible build
> configurations, so the one you're trying with dynamic libraries is
> likely not tested).

Yes, you're probably right.
Also the gcc linker is not very good at permutations :)

It might also come from using different compiler versions, since on
ubuntu 16.04 gcc defaults to version 5.x, and I'm building with gcc 4.8
which looks like is what facter is built with in the puppet-agent
package.

I have a battle plan now, thanks :)
I'll report my progress here.

Brice Figureau

unread,
Jan 20, 2017, 9:26:56 AM1/20/17
to puppe...@googlegroups.com
On Wed, 2017-01-18 at 15:50 +0100, Brice Figureau wrote:
> On Tue, 2017-01-17 at 19:52 +0000, Michael Smith wrote:
> > Unfortunately this is made a little harder since our builds of boost
> > and yaml-cpp aren't hosted. However, the instructions for building
> > them are
> > at https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/boost.rb and https://github.com/puppetlabs/pl-build-tools-vanagon/blob/master/configs/components/yaml-cpp.rb. Those both build statically, so you'd then use `-DBOOST_STATIC=ON -DYAMLCPP_STATIC=ON`. We use Boost 1.58 currently.
>
> [snip]
>
> I'll report my progress here.
> --
> Brice Figureau
> My Blog: http://www.masterzen.fr/
>

Just to report that I was able to rebuild facter in the context of the
puppet-agent AIO package.

This involved compiling boost statically, ICU statically along with the
other dependencies (yaml-cpp for instance).

Then a bit of cmake fiddling (notably adding a way to find the ICU
static libraries and adding them to the mix), careful set of the rpath,
and I was able to update facter in place.

So, I was able to verify my fix for FACT-1559, and consequently opened a
(actually my first facter) PR (without any tests, sorry I didn't have
the energy to start adding CoreOS tests).

I hope it will be merged (soon) :)
--
Brice Figureau <brice-...@daysofwonder.com>

Reply all
Reply to author
Forward
0 new messages