Nonexistent handling of related LDFLAGS options in pkg-config
dbn.lists at gmail.com
Tue Nov 6 05:50:24 PST 2012
On Mon, Nov 5, 2012 at 1:54 AM, Boszormenyi Zoltan <zb at cybertec.at> wrote:
> in pursuing the revival of embedding the Gecko engine
> ( https://wiki.mozilla.org/Embedding/NewApi ), I have come
> across a misfeature of pkg-config: while merging --libs options
> from different modules, it puts them into 3 classes (-L options,
> -l options and everything else) and reorders them.
> However, some linker options have a consequence that subsequent
> options are treated differently by the linker. Such options are "-static"
> and some "-Wl,..." options, most notably "-Wl,--whole-archive".
> The xulrunner libraries expect the main app to link to some static
> libraries and they dlopen symbols from these static libraries. The
> symbols unused by the main app would get thrown away unless
> they are to be linked as whole archive.
> I have a preliminary patch at
> that only handles the -Wl,--whole-archive part. The same treatment
> is needed for plain static libs, e.g. putting them into their own class
> and emitting them after all other dynamic -l... options.
I saw your patch the other day. Thanks a lot for sending it in. This
is a long standing problem in pkg-config, and I believe our reference
bug is #19950 (https://bugs.freedesktop.org/show_bug.cgi?id=19950). As
you say, this isn't specific to any one linker option, so
unfortunately I think your patch is too narrow in scope. I think the
only general way to fix this bug is to output the flags exactly as
they are in the pkg-config files and not pretend to have any knowledge
about the meaning of the options. There's no way we can patch for
every specific oddball linker or compiler argument that needs to stay
in a specific order.
The issue is that pkg-config currently breaks apart the Cflags and
Libs fields into separate lists depending on the type of argument they
are. This is great to support the narrow scope --libs-only-* and
--cflags-only-* options, but it means we completely lose track of the
order of the arguments. My solution here is to keep the parsed
arguments in one list and just mark each argument type appropriately.
Then at output time we can just walk over the list and output only the
flags we care about.
The other issue is that currently pkg-config will scan the whole
output string and remove duplicate arguments. This is bug #16101
(https://bugs.freedesktop.org/show_bug.cgi?id=16101). This is a nice
optimization so that you don't see -L/foo repeated over and over, but
it means that flags that are critical to order will get broken. To
think about one case like yours, if your Libs field had
-Wl,--whole-archive -la --Wl,-no-whole-archive -lb
--Wl,--whole-archive -lc --Wl,--no-whole-archive, then the second set
of linker options would be stripped out and you'd link incorrectly.
The only thing I can think of here that might be appropriate is to
remove consecutive repeated arguments. Otherwise, I think we just have
to throw it all at the compiler/linker and trust it will do the right
I have a patch for the first part I'm almost done with, and the second
should be easy to strip out. I'm a little hesitant to make the
changes, though, since pkg-config has worked the way it has for a long
time. I'd need to find some bigger workloads and see what the effect
More information about the pkg-config