On Wed, Jul 01, 2020 at 09:50:20AM +0200, Thomas Monjalon wrote:
> 30/06/2020 16:14, Bruce Richardson:
> > When calling pkg-config --static --libs, pkg-config will always output the
> > regular libs first, and then the extra libs from libraries.private field,
> > since the assumption is that those are additional dependencies for building
> > statically that the .a files depend upon.
> > 
> > However, for DPDK, we only link the driver files for static builds, and
> Sorry, I'm lost here. Why "only" driver files?

My fault for poor word ordering. Should be rewritten as "link the driver
files only for static builds".

> > those need to come *before* the regular libraries.
> Given whole libs are linked, is it really needed to have drivers first?

If we are considering only static libs, then I suspect not, but to avoid
having the shared libraries also linked into the static binaries they
definitely need to come last, so they can be linked with as-needed i.e.
skipped by the linker.

> > To get this result, we
> > need two pkgconfig files for DPDK, one for the shared libs, and a second
> > for the static libs and drivers, which depends upon the first. Using a
> > dependency means that the shared libs are printed only after the
> > libraries.private field rather than before.
> > 
> > Without this patch, the linking works in DPDK because in all cases we
> > specify the libraries after the drivers in the Libs.private line, ensuring
> > that the references to the libs from the drivers can be resolved. The
> > current output is therefore of the form, "(shared)libs, drivers,
> > (static)libs", while after this patch the output is, "drivers,
> > (static)libs, (shared)libs". The former case will not work if we use the
> > --whole-archive flag on the static libs as it will lead to duplicate
> > definitions due to some references having been previously resolved from the
> > shared libraries.
> I'm completely lost. In which case we link both static and shared libs?
It will depend partially upon other linker flags used before the pkgconfig
insert. We would be relying upon the user integrating this to explicitly
pass in -Bstatic flag before putting the pkgconfig flags output. With the
current config, we can't add that ourselves because to go first it would
have to go (ironically) in the shared lib part of the pkg-config file. By
splitting things into two, it allows the static libs to come before the
shared ones, which gives us the ability to control things far better.

> > By ensuring the shared libraries come last in the link
> > link, this issue does not occur, as duplicate references when linking the
> > shared libs will be ignored.
> > 
> > Signed-off-by: Bruce Richardson <bruce.richard...@intel.com>
> > Acked-by: Luca Boccassi <bl...@debian.org>
> > Acked-by: Sunil Pai G <sunil.pa...@intel.com>

Reply via email to