Fix order of singlefilehost libarires passed to the linker (#42094)
authorOmair Majid <omajid@redhat.com>
Thu, 17 Sep 2020 14:26:52 +0000 (10:26 -0400)
committerGitHub <noreply@github.com>
Thu, 17 Sep 2020 14:26:52 +0000 (16:26 +0200)
commit0ed3f3311e4d07cf6840b78c32055ab1b16d092c
treeb184b52154c4dc4909f4b443816dbe5d4c82e212
parent1b491f603275a0d943d613da1e914502b9102e0f
Fix order of singlefilehost libarires passed to the linker (#42094)

We give a list of arguments to the linker which includes a list of
static objects we want to be linked together and a set of system-wide
native libraries they should be dynamically linked against.

Some build environments, such as Fedora, use the `--as-needed` linker
flag. This makes the linker pay attention to the order in which
libraries appear and remove uneeded libararies.

When the linker sees this:

    ld --as-needed -lz staticobject.a

It works from left to right and sess that nothing so far depends on
libz. The linker removes libz from the set of objects being linked. Then
it links staticobject.a, which needs symbols from libz. The linker then
complains that it contains an undefined reference.

We can fix that by changing the order so that dependencies appear last
in the linker command line:

    ld --as-needed staticobject.a -lz

This makes the linker link staticobject.a against libz correctly.
src/installer/corehost/cli/apphost/static/CMakeLists.txt