Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 591542 - most static lib's emerged with lto cannot be linked against: "undefined reference to ..."
Summary: most static lib's emerged with lto cannot be linked against: "undefined refer...
Status: RESOLVED DUPLICATE of bug 603594
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Richard Freeman
Depends on:
Blocks: lto
  Show dependency tree
Reported: 2016-08-17 19:08 UTC by Klaus Kusche
Modified: 2019-12-29 14:06 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Note You need to log in before you can comment on or make changes to this bug.
Description Klaus Kusche 2016-08-17 19:08:02 UTC
I currently try to build a statically linked executable of "dar"
(app-backup/dar with USE static).

However, the emerge failed when linking the dar_static executable:

libtool: link: x86_64-pc-linux-gnu-g++ -march=native -mtune=native -flto -fuse-linker-plugin -O3 -fweb -ftracer -fivopts -frename-registers -maccumulate-outgoing-args -pipe -fno-lto -fno-use-linker-plugin -std=c++11 -static -march=native -mtune=native -flto -fuse-linker-plugin -O3 -fweb -ftracer -fivopts -frename-registers -maccumulate-outgoing-args -pipe -fno-lto -fno-use-linker-plugin -o dar_static command_line.o config_file.o dar.o dar_suite.o hide_file.o no_comment.o shell_interaction.o line_tools.o crit_action_cmd_line.o  ../libdar/.libs/libdar64.a -lpthread /usr/lib64/libattr.a -llzma -llzo2 -lbz2 -lz -ldl -lcap
../libdar/.libs/libdar64.a(compressor.o): In function `libdar::compressor::lzo_compress_buffer_and_write()':
compressor.cpp:(.text+0x334e): undefined reference to `lzo1x_999_compress_level'
../libdar/.libs/libdar64.a(compressor.o): In function `libdar::compressor::lzo_write(char const*, unsigned long)':
compressor.cpp:(.text+0x4537): undefined reference to `lzo1x_999_compress_level'
../libdar/.libs/libdar64.a(compressor.o): In function `libdar::compressor::lzo_read_and_uncompress_to_buffer()':
compressor.cpp:(.text+0x4a15): undefined reference to `lzo1x_decompress_safe'
../libdar/.libs/libdar64.a(libdar.o): In function `libdar::libdar_init(bool)':
libdar.cpp:(.text+0x178): undefined reference to `__lzo_init_v2'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_compress(int)':
wrapperlib.cpp:(.text+0x1826): undefined reference to `BZ2_bzCompress'
wrapperlib.cpp:(.text+0x184b): undefined reference to `BZ2_bzCompress'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_decompress(int)':
wrapperlib.cpp:(.text+0x1a86): undefined reference to `inflate'
wrapperlib.cpp:(.text+0x1aa3): undefined reference to `inflate'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::lzma_encode(int)':
wrapperlib.cpp:(.text+0x1cf6): undefined reference to `lzma_code'
wrapperlib.cpp:(.text+0x1d13): undefined reference to `lzma_code'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_decompressEnd()':
wrapperlib.cpp:(.text+0x1fa4): undefined reference to `BZ2_bzDecompressEnd'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_compressEnd()':
wrapperlib.cpp:(.text+0x2174): undefined reference to `BZ2_bzCompressEnd'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_decompress(int)':
wrapperlib.cpp:(.text+0x2344): undefined reference to `BZ2_bzDecompress'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_decompressInit()':
wrapperlib.cpp:(.text+0x2528): undefined reference to `BZ2_bzDecompressInit'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::bz_compressInit(unsigned long)':
wrapperlib.cpp:(.text+0x26fb): undefined reference to `BZ2_bzCompressInit'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_compressEnd()':
wrapperlib.cpp:(.text+0x28c3): undefined reference to `deflateEnd'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_decompressEnd()':
wrapperlib.cpp:(.text+0x2aa3): undefined reference to `inflateEnd'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_decompressInit()':
wrapperlib.cpp:(.text+0x2c8d): undefined reference to `inflateInit_'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_compressInit(unsigned long)':
wrapperlib.cpp:(.text+0x2e6d): undefined reference to `deflateInit_'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::z_compress(int)':
wrapperlib.cpp:(.text+0x30d6): undefined reference to `deflate'
wrapperlib.cpp:(.text+0x30f3): undefined reference to `deflate'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::lzma_compressInit(unsigned long)':
wrapperlib.cpp:(.text+0x32b9): undefined reference to `lzma_easy_encoder'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::lzma_decompressInit()':
wrapperlib.cpp:(.text+0x357d): undefined reference to `lzma_auto_decoder'
../libdar/.libs/libdar64.a(wrapperlib.o): In function `libdar::wrapperlib::~wrapperlib()':
wrapperlib.cpp:(.text+0x3ff9): undefined reference to `lzma_end'
../libdar/.libs/libdar64.a(capabilities.o): In function `libdar::capability_LINUX_IMMUTABLE(libdar::user_interaction&, bool)':
capabilities.cpp:(.text+0x49): undefined reference to `cap_get_proc'
capabilities.cpp:(.text+0x60): undefined reference to `cap_get_flag'
capabilities.cpp:(.text+0x70): undefined reference to `cap_free'
capabilities.cpp:(.text+0xc0): undefined reference to `cap_free'
capabilities.cpp:(.text+0x16e): undefined reference to `cap_free'
../libdar/.libs/libdar64.a(capabilities.o): In function `libdar::capability_SYS_RESOURCE(libdar::user_interaction&, bool)':
capabilities.cpp:(.text+0x209): undefined reference to `cap_get_proc'
capabilities.cpp:(.text+0x220): undefined reference to `cap_get_flag'
capabilities.cpp:(.text+0x230): undefined reference to `cap_free'
capabilities.cpp:(.text+0x280): undefined reference to `cap_free'
capabilities.cpp:(.text+0x32e): undefined reference to `cap_free'
../libdar/.libs/libdar64.a(capabilities.o): In function `libdar::capability_FOWNER(libdar::user_interaction&, bool)':
capabilities.cpp:(.text+0x3fe): undefined reference to `cap_get_proc'
capabilities.cpp:(.text+0x415): undefined reference to `cap_get_flag'
capabilities.cpp:(.text+0x425): undefined reference to `cap_free'
capabilities.cpp:(.text+0x478): undefined reference to `cap_free'
capabilities.cpp:(.text+0x526): undefined reference to `cap_free'
../libdar/.libs/libdar64.a(capabilities.o): In function `libdar::capability_CHOWN(libdar::user_interaction&, bool)':
capabilities.cpp:(.text+0x5f0): undefined reference to `cap_get_proc'
capabilities.cpp:(.text+0x604): undefined reference to `cap_get_flag'
capabilities.cpp:(.text+0x614): undefined reference to `cap_free'
capabilities.cpp:(.text+0x668): undefined reference to `cap_free'
capabilities.cpp:(.text+0x716): undefined reference to `cap_free'
collect2: error: ld returned 1 exit status

It turned out that all the required lib*.a files actually existed
and were found by the linker. They also contained all the symbols
listed above as "undefined reference", however, the linker silently
ignored them!

After some experiments, I ran "ar s ..." on all these libs
(libattr.a, liblzma.a, liblzo2.a, libbz2.a, libz.a, libcap.a)
to regenerate the archive index of those lib's.
After that, dar emerged with no problem and produced a working dar_static.

Hence, it seems that emerging the packages providing the lib's listed above 
with "USE static-libs" produces .a lib's without an index,
and the linker refuses to link against such lib's.

emerge --info:
Portage 2.3.0 (python 2.7.12-final-0, default/linux/amd64/13.0/no-multilib, gcc-5.4.0, glibc-2.23-r2, 4.6.5-hardened-r1 x86_64)
System uname: Linux-4.6.5-hardened-r1-x86_64-Intel-R-_Core-TM-_i7-3940XM_CPU_@_3.00GHz-with-gentoo-2.2
KiB Mem:    32902668 total,  30120692 free
KiB Swap:          0 total,         0 free
Timestamp of repository gentoo: Wed, 17 Aug 2016 14:45:01 +0000
sh bash 4.3_p46
ld GNU ld (Gentoo 2.26.1 p1.0) 2.26.1
app-shells/bash:          4.3_p46::gentoo
dev-java/java-config:     2.2.0-r3::gentoo
dev-lang/perl:            5.24.0-r1::gentoo
dev-lang/python:          2.7.12::gentoo, 3.5.2::gentoo
dev-util/cmake:           3.6.1::gentoo
dev-util/pkgconfig:       0.29.1::gentoo
sys-apps/baselayout:      2.2-r1::gentoo
sys-apps/openrc:          0.21.3::gentoo
sys-apps/sandbox:         2.10-r2::gentoo
sys-devel/autoconf:       2.13::gentoo, 2.69-r2::gentoo
sys-devel/automake:       1.13.4-r1::gentoo, 1.14.1-r1::gentoo, 1.15-r2::gentoo
sys-devel/binutils:       2.26.1::gentoo
sys-devel/gcc:            5.4.0::gentoo
sys-devel/gcc-config:     1.8-r1::gentoo
sys-devel/libtool:        2.4.6-r2::gentoo
sys-devel/make:           4.2.1::gentoo
sys-kernel/linux-headers: 4.7::gentoo (virtual/os-headers)
sys-libs/glibc:           2.23-r2::gentoo

    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://
    priority: -1000

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="* -@EULA dlj-1.1 AdobeFlash-11.x Oracle-BCLA-JavaSE google-chrome googleearth Vivaldi FraunhoferFDK"
CFLAGS="-march=native -mtune=native -flto -fuse-linker-plugin -O3 -fomit-frame-pointer -fweb -ftracer -fivopts -frename-registers -maccumulate-outgoing-args -pipe"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -mtune=native -flto -fuse-linker-plugin -O3 -fomit-frame-pointer -fweb -ftracer -fivopts -frename-registers -maccumulate-outgoing-args -pipe"
EMERGE_DEFAULT_OPTS="--quiet-build --quiet-fail --with-bdeps=y"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-logs collision-protect config-protect-if-modified distlocks ebuild-locks fixlafiles keeptemp keepwork merge-sync news noclean parallel-fetch preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe"
LDFLAGS="-march=native -mtune=native -flto -fuse-linker-plugin -O3 -fomit-frame-pointer -fweb -ftracer -fivopts -frename-registers -maccumulate-outgoing-args -pipe"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
USE="64bit X a52 aac adobe-cff alsa amd64 apng applet archive ass avx bzip2 cairo cdda cdparanoia clang cli clipboard clockdiff contrast cups curl cxx dbus dconf demosaic detex devfs-compat dga divx dns dot dri dri3 drm dts dvd dvdnav dvdr dvi dvipdfm egl encode epspdf exif expat extra faad fdk ffmpeg fftw flac fontconfig foomaticdb fts3 g3dvl gallium gbm gdk-pixbuf gegl gif gimp glamor gles gles1 gles2 glib glibc-omitfp gmp graphics gs gstreamer gtk gtk2 gudev harfbuzz hpack-tools hpn htmlreport http http2 hwdb iconv icu imagemagick inotify javascript jbig jemalloc jemalloc3 jit jpeg jpeg2k kpathsea lasi latex latex3 lcdfilter lcms leaps_timezone lensfun libkms libnotify libopts libressl libsamplerate libwww lightning llvm llvm-gcc llvm-shared-libs lz4 lzma lzo mad matroska metric midi minizip mmap mms mmx mmxext mng modern-top modules mp3 mpeg mpfr mta mudflap multicall natspec ncat ncurses ndiff nping nptl nscd nsplugin offensive ogg oldnet opencl opengl openmax openmp openvg opus orc pam pango pax_kernel pcap pcre pdf pic plugins png policykit postproc postscript ppds proprietary-codecs pstricks pth ptpax quicktime r600-llvm-compiler rar raw readline realmedia right_timezone rle rpc rtc rule_generator sanitize scanner schroedinger scope seccomp secure-delete session smp sndfile sound sqlite sqlite3 sse sse2 sse3 sse4 sse4_1 sse4_2 ssh ssl ssse3 svc svg symlink sync-plugin-portage system-cairo system-ffmpeg system-harfbuzz system-icu system-jpeg system-jsoncpp system-libevent system-libvpx system-sqlite systemd t1lib texi2html theora threads thunar tiff tools tracepath tremor truetype udev udisks unicode unlock-notify unwind usb user-session utils v4l v4l2 vaapi vdpau vim-with-x vorbis vpx webkit2 webp wext wifi wmf wmp wxwidgets x264 x265 xa xattr xcb xcomposite xetex xkb xmp xorg xpm xrandr xtpax xulrunner xv xvid xvmc zenmap zip zlib" ABI_X86="64" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump author" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" CURL_SSL="libressl" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="keyboard evdev synaptics" KERNEL="linux" L10N="en" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer pdfimport" LINGUAS="en" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php5-5" PYTHON_SINGLE_TARGET="python2_7" PYTHON_TARGETS="python3_5 python2_7" RUBY_TARGETS="ruby22" SANE_BACKENDS="epson" USERLAND="GNU" VIDEO_CARDS="radeon radeonsi amdgpu" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Comment 1 Alex Xu (Hello71) 2016-08-18 15:03:03 UTC
please attach full build.log
Comment 2 Klaus Kusche 2016-08-18 15:31:36 UTC
(In reply to Alex Xu (Hello71) from comment #1)
> please attach full build.log

I can't, at least not easily. 
My build logs are on a RAM disk, and gone since yesterday night.

To reproduce the error in the dar build, I would need some way 
to undo the effect of "ar s" on the six libraries I fixed yesterday
(my libraries are fixed now, so dar currently builds fine).

Is there an easy way to do so?

Besides, I don't think that this is a problem of the dar build,
that's why I didn't enter the dar component in the description of this bug:
I extracted the link command from the log, tried it on the command line,
reduced it to the absolute minimum needed to link dar_static,
and it also failed in the same way, 
although the command was absolutely correct and reasonable
(the same one would use for linking "by hand").

The fact that "ar s" on the libraries fixed the problem
indicates that the libs were broken,
but these lib's are not generated by the dar build,
but by sys-apps/attr, app-arch/bzip2, dev-libs/lzo, sys-libs/zlib, sys-libs/libcap and app-arch/xz-utils.
These seem to cause the problem (or there is something wrong with building
static-libs in general on my system).
Comment 3 Mike Gilbert gentoo-dev 2016-08-23 01:49:01 UTC
The static libs on my system seem to already have an index, so I would guess that something strange happened on your system.

Please always attach a full build log when reporting a build failure.
Comment 4 Klaus Kusche 2016-08-23 06:33:21 UTC
(In reply to Mike Gilbert from comment #3)
> The static libs on my system seem to already have an index, so I would guess
> that something strange happened on your system.

I re-emerged the libs.
They actually all have an archive index, 
but it is broken and results in an un-linkable lib,
because it only contains lto info
and not the linkable symbols.

Example libattr.a:

nm -s after emerging:

Archive index:
__gnu_lto_v1 in libattr.o
__gnu_lto_slim in libattr.o
__gnu_lto_v1 in attr_copy_fd.o
__gnu_lto_slim in attr_copy_fd.o
__gnu_lto_v1 in attr_copy_file.o
__gnu_lto_slim in attr_copy_file.o
__gnu_lto_v1 in attr_copy_check.o
__gnu_lto_slim in attr_copy_check.o
__gnu_lto_v1 in attr_copy_action.o
__gnu_lto_slim in attr_copy_action.o
__gnu_lto_v1 in syscalls.o
__gnu_lto_slim in syscalls.o

==> emerging dar fails

nm -s after ar s:

Archive index:
attr_get in libattr.o
attr_getf in libattr.o
attr_set in libattr.o
attr_setf in libattr.o
attr_remove in libattr.o
attr_removef in libattr.o
attr_list in libattr.o
attr_listf in libattr.o
attr_multi in libattr.o
attr_multif in libattr.o
attr_copy_fd in attr_copy_fd.o
attr_copy_file in attr_copy_file.o
attr_copy_check_permissions in attr_copy_check.o
attr_copy_action in attr_copy_action.o
setxattr in syscalls.o
lsetxattr in syscalls.o
fsetxattr in syscalls.o
getxattr in syscalls.o
lgetxattr in syscalls.o
fgetxattr in syscalls.o
listxattr in syscalls.o
llistxattr in syscalls.o
flistxattr in syscalls.o
removexattr in syscalls.o
lremovexattr in syscalls.o
fremovexattr in syscalls.o

==> emerging dar works

Exactly the same for almost all other static lib's I checked
(not only the six packages mentioned in this bug report,
but also e.g. libjemalloc, libtasn1, the multimedia codec libs, ...),
only glibc and boost seem to produce correct .a libs.

So building the static libs with lto is the culprit.
Emerging the libs without lto results in correct archive indices,
and dar emerges fine afterwards.

However, building the libs without lto would mean that 
lto is lost also for all dynamically linked executables using these libs,
so that's an ugly workaround.
Comment 5 Klaus Kusche 2016-08-28 13:44:15 UTC
Please re-assign to gcc, binutils, libtool or whatever.
This problem has nothing to do with dar,
but only with the creation of static libs, for almost any ebuild.

I tried to emerge some other packages which are expected to produce
statically linked executables (e.g. libarchive after applying the fixes
described in bug 591096), and I also tried to link some of my own
programs statically, and all failed in the same way when linking:

Most of the lib*.a libraries produced by emerging a package with 
USE=static-libs and with lto cannot be linked against because
the linker is unable to find the symbols provided by the lib.
The problem occurs with .a libs from more than a dozen ebuilds,
and for any link target executable.

Applying "ar s" to all the .a libs or re-emerging all the .a lib without lto
fixes the problem: After that, the static executables link without problems. 

However, just dropping lto from many of the important lib's in the system
just to get working static libs is not an option (because it also affects
the performance of all dynamically linked libs and programs).
Comment 6 Paolo Pedroni 2017-05-16 11:20:23 UTC
Have you tried adding -ffat-lto-objects to the CFLAGS of the problematic package? This might solve your problem.
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2019-12-29 14:06:42 UTC

*** This bug has been marked as a duplicate of bug 603594 ***