(→Underlinked library) |
m (Change Mandriva reference to Mageia) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | {{Template:Draft}} | ||
+ | |||
= What is overlinking = | = What is overlinking = | ||
Line 19: | Line 21: | ||
== When building a package== | == When building a package== | ||
− | You will get a warning as explained [[ | + | You will get a warning as explained [[Packaging problems and solutions#overlinking|here]] (the check is done by strip_and_check_elf_files from spec-helper) |
= How to fix = | = How to fix = | ||
Line 65: | Line 67: | ||
However, usually software bundles their own libtool. One way to update it is | However, usually software bundles their own libtool. One way to update it is | ||
− | to run "autoreconf" before configure. But it sometimes fail, so | + | to run "autoreconf" before configure. But it sometimes fail, so Mageia has a |
script "fix-libtool-overlinking" called in %configure and %configure2_5x | script "fix-libtool-overlinking" called in %configure and %configure2_5x | ||
Line 80: | Line 82: | ||
== --as-needed == | == --as-needed == | ||
− | It can be hard and time consuming to correctly fix and report upstream. An easier way to fix is to use --as-needed. A global --as-needed is used in | + | It can be hard and time consuming to correctly fix and report upstream. An easier way to fix is to use --as-needed. A global --as-needed is used in Mageia. |
= Problems introduced by --as-needed = | = Problems introduced by --as-needed = |
Latest revision as of 09:32, 16 August 2014
Please remove this {{Draft}}template, when you're sure the page is complete and correct.
|
Contents
What is overlinking
example: when emacs build with libpng support, it uses -lz in case we're linking with a static PNG library. Alas this is bad when doing dynamic linking: if we update zlib to a new major version, emacs will have to be rebuilt, even if emacs doesn't use it all, only libpng does.
How to detect
Check a binary
Use "ldd -u -r", example:
% ldd -u -r /usr/bin/emacs Unused direct dependencies: /usr/lib/libXext.so.6 /lib/libz.so.1
When building a package
You will get a warning as explained here (the check is done by strip_and_check_elf_files from spec-helper)
How to fix
pkgconfig issues
Some software uses $(pkg-config --libs somefoo) to get the needed linker flags. Pkg-config uses the "Libs:" and "Requires:" entry from *.pc file to get the linker flags.
However, many *.pc files incorrectly specify their own dependencies in "Libs:" or "Requires:" while their own dependencies should be in "Libs.private:" and "Requires.private:".<ref>they are historical reasons for this: Requires.private and Libs.private were not existing in early pkgconfig (before 0.18) and were not backward compatible.</ref>
Example from gtk+-2.0.pc:
Requires: gdk-${target}-2.0 atk cairo
whereas it should be:
Requires.private: gdk-${target}-2.0 atk cairo
Example from libavcodec.pc from ffmpeg:
Libs: -L${libdir} -lavcodec -lz -pthread -lm -la52 -lfaac -lfaad -lmp3lame -lm -lnut -ltheora -logg -lvorbisenc -lvorbis -logg -lx264 -lm -lxvidcore -ldl -ldl -lX11 -lXext
whereas it should be:
Libs.private: -lz -pthread -lm -la52 -lfaac -lfaad -lmp3lame -lm -lnut -ltheora -logg -lvorbisenc -lvorbis -logg -lx264 -lm -lxvidcore -ldl -ldl -lX11 -lXext Libs: -L${libdir} -lavcodec
libtool issues
Libtool archives (*.la) contain a list of the used libraries, recursively. Default libtool specificies all those libraries explicitly, even for dynamic linking. This is fixed using a patch from debian.
However, usually software bundles their own libtool. One way to update it is to run "autoreconf" before configure. But it sometimes fail, so Mageia has a script "fix-libtool-overlinking" called in %configure and %configure2_5x
See also : libtool archives
various issues
Alas fixing libtool and *.pc files is not enough:
- xdm is built with -lXinerama whereas it doesn't need it, only /usr/lib/X11/xdm/authdir needs it. But to simplify the Makefile, the same LDFLAGS is used.
- emacs is wrongly built with -lz, just in case emacs is built statically. The configure.in of emacs would need to fixed.
The best way to fix those issues is to fix them and report the fix upstream.
--as-needed
It can be hard and time consuming to correctly fix and report upstream. An easier way to fix is to use --as-needed. A global --as-needed is used in Mageia.
Problems introduced by --as-needed
Underlinked library
Problems introduced by --as-needed can come from an underlinked library.
Do not use %define _disable_ld_as_needed 1
to workaround this, or only temporarily. Fix the library instead! (hint: fedora has already done patches to fix those issues, back in 2003 when they introduced prelink)
Wrong linking order
gcc -Wl,--as-needed -lfoo bar.o
is wrong, since ld will look for the symbols missing only in the files coming after it. So -lfoo
will be simply ignored when using --as-needed.
You must ensure the libraries are put after *.o files:
gcc -Wl,--as-needed bar.o -lfoo
It usually happens when libraries are fed into LDFLAGS (which is incorrect)
See Gentoo's really nice page about --as--needed for more explanations.
Same symbol is different libraries
See segfault using pcre and --as-needed
Links
- nice overall explanation of overlinking issues (on debian mailing list)
- about libtool and dependency libs
- Gentoo's page about --as-needed
- discussion on potential problems using --as-needed by default (on debian mailing list)