Bug 15126

Summary: [REGRESSION] 2.23.51.0.9 fails to link cairo with libstdc++ (could not read symbols: Invalid operation)
Product: binutils Reporter: Maciej Piechotka <uzytkownik2>
Component: ldAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WORKSFORME    
Severity: normal CC: amodra, hjl.tools, hp, meadori, vapier
Priority: P2    
Version: 2.24   
Target Milestone: ---   
See Also: http://sourceware.org/bugzilla/show_bug.cgi?id=15149
https://bugs.gentoo.org/show_bug.cgi?id=458164
Host: Target:
Build: Last reconfirmed: 2013-02-16 00:00:00

Description Maciej Piechotka 2013-02-09 12:15:29 UTC
libtool: link: x86_64-pc-linux-gnu-gcc -D_REENTRANT -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libdrm -I/usr/include/libpng15 -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/include/valgrind -Wall -Wextra -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Werror-implicit-function-declaration -Wnested-externs -Wpointer-arith -Wwrite-strings -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wpacked -Wswitch-enum -Wmissing-format-attribute -Wbad-function-cast -Wvolatile-register-var -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations -Wno-missing-field-initializers -Wno-unused-parameter -Wno-attributes -Wno-long-long -Winline -flto -fno-strict-aliasing -fno-common -Wp,-D_FORTIFY_SOURCE=2 -Wno-unused-but-set-variable -D_REENTRANT -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -O2 -march=native -pipe -ggdb -Wa,--compress-debug-sections -finline-limit=1200 -Wl,-O1 -Wl,--hash-style=both -Wl,--sort-common -Wl,--no-keep-memory -o .libs/cairo-sphinx cairo_sphinx-sphinx.o  -Wl,--as-needed ../../util/cairo-script/.libs/libcairo-script-interpreter.so -L/usr/lib64/qt4 -llzo2 ../../boilerplate/.libs/libcairoboilerplate.a /var/tmp/portage/x11-libs/cairo-1.12.12/work/cairo-1.12.12/src/.libs/libcairo.so ../../src/.libs/libcairo.so -lpthread -lpixman-1 -lfontconfig -lfreetype -lEGL -ldl 
-lpng15 -lQtGui -lQtCore -lxcb-shm -lxcb-render -lxcb -lXrender -lX11 -lXext -lz -lGL -lglib-2.0 -lrt -lm
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../x86_64-pc-linux-gnu/bin/ld: libcairoboilerplate_cxx_la-cairo-boilerplate-qt.o (symbol from plugin): undefined reference to symbol 'vtable for __cxxabiv1::__class_type_info@@CXXABI_1.3'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.6.3/../../../../x86_64-pc-linux-gnu/bin/ld: note: 'vtable for __cxxabiv1::__class_type_info@@CXXABI_1.3' is defined in DSO /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/libstdc++.so.6 so try adding it to the linker command line
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/libstdc++.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

2.23.1 and 2.23.51.0.8 links without problems.
Comment 1 H.J. Lu 2013-02-09 17:30:12 UTC
You can either use g++ to link against C++ libraries or drop
-Wl,--as-needed.
Comment 2 Maciej Piechotka 2013-02-10 11:39:12 UTC
(In reply to comment #1)
> You can either use g++ to link against C++ libraries or drop
> -Wl,--as-needed.

Without -Wl,--as-needed there are undefined references to new and delete.
I believe g++/gcc choice was made by libtool and it did worked with binutils 2.23.51.0.8.
Comment 3 H.J. Lu 2013-02-11 16:42:53 UTC
Please provide a stand alone testcase.
Comment 4 H.J. Lu 2013-02-13 17:54:22 UTC
Please double check if it is a real regression. I think it is a bug,
not a regression.
Comment 5 H.J. Lu 2013-02-15 19:33:45 UTC
(In reply to comment #4)
> Please double check if it is a real regression. I think it is a bug,
> not a regression.

You can re-run the failed linking command by hand with different linker to
verify it.
Comment 6 Maciej Piechotka 2013-02-16 00:36:43 UTC
(In reply to comment #4)
> Please double check if it is a real regression. I think it is a bug,
> not a regression.

Sorry for delay. When I posted bug I tried binutils 2.23.51.0.8, 2.23.51.0.9 and 2.23.1. The only change was the version of binutils installed - in all cases but 2.23.51.0.9 linking succeeded.
Comment 7 H.J. Lu 2013-02-16 01:37:22 UTC
(In reply to comment #6)
> (In reply to comment #4)
> > Please double check if it is a real regression. I think it is a bug,
> > not a regression.
> 
> Sorry for delay. When I posted bug I tried binutils 2.23.51.0.8, 2.23.51.0.9
> and 2.23.1. The only change was the version of binutils installed - in all
> cases but 2.23.51.0.9 linking succeeded.

Please do

1. Install binutils 2.23.51.0.9
2. Configure and build cairo.  It will fail.
3. Install binutils 2.23.51.0.8.
4. Go to cairo build directory without reconfigure and try the
failed command by hand.
4. Install binutils 2.23.1.
5. Go to cairo build directory without reconfigure and try the
failed command by hand.
Comment 8 Maciej Piechotka 2013-02-16 09:29:54 UTC
Sight. Binutils 2.23.51.0.8 and 2.23.1 succeeded even if I did not reconfigured.
Comment 9 H.J. Lu 2013-02-16 18:23:23 UTC
Binutils 2.23.1 and 2.23.51.0.8/2.23.51.0.9 fail for me.
If you don't have a small testcase, please provide
the whole cairo build directory.
Comment 10 Maciej Piechotka 2013-02-16 20:28:39 UTC
(In reply to comment #9)
> Binutils 2.23.1 and 2.23.51.0.8/2.23.51.0.9 fail for me.
> If you don't have a small testcase, please provide
> the whole cairo build directory.

Compressed directory takes nearly 60 MiB. How should I send it?
Comment 11 H.J. Lu 2013-02-19 16:52:09 UTC
(In reply to comment #10)
> 
> Compressed directory takes nearly 60 MiB. How should I send it?

You can upload it to a free file share web site.
Comment 12 Maciej Piechotka 2013-02-20 11:27:59 UTC
https://www.dropbox.com/s/3mauit7c7ab4yh3/cairo-workdir.tar.xz?m

(In reply to comment #11)
> (In reply to comment #10)
> > 
> > Compressed directory takes nearly 60 MiB. How should I send it?
> 
> You can upload it to a free file share web site.

There are bugzillas which has policy against external services.
Comment 13 H.J. Lu 2013-02-20 19:19:02 UTC
(In reply to comment #12)
> https://www.dropbox.com/s/3mauit7c7ab4yh3/cairo-workdir.tar.xz?m
> 

I can't reproduce it:

[hjl@gnu-4 cairo-sphinx]$ /usr/gcc-4.6.3/bin/gcc -D_REENTRANT -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libdrm -I/usr/include/libpng15 -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/include/valgrind -Wall -Wextra -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Werror-implicit-function-declaration -Wnested-externs -Wpointer-arith -Wwrite-strings -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wpacked -Wswitch-enum -Wmissing-format-attribute -Wbad-function-cast -Wvolatile-register-var -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations -Wno-missing-field-initializers -Wno-unused-parameter -Wno-attributes -Wno-long-long -Winline -flto -fno-strict-aliasing -fno-common -Wp,-D_FORTIFY_SOURCE=2 -Wno-unused-but-set-variable -D_REENTRANT -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -O2 -march=native -pipe -ggdb -Wa,--compress-debug-sections -finline-limit=1200 -Wl,-O1 -Wl,--hash-style=both -Wl,--sort-common -Wl,--no-keep-memory -o .libs/cairo-sphinx cairo_sphinx-sphinx.o  -Wl,--as-needed ../../util/cairo-script/.libs/libcairo-script-interpreter.so -L/usr/lib64/qt4 -llzo2 ../../boilerplate/.libs/libcairoboilerplate.a ../..//src/.libs/libcairo.so ../../src/.libs/libcairo.so -lpthread -lpixman-1 -lfontconfig -lfreetype -lEGL -ldl -lpng15 -lQtGui -lQtCore -lxcb-shm -lxcb-render -lxcb -lXrender -lX11 -lXext -lz -lGL -lglib-2.0 -lrt -lm -Busr/local/bin/
usr/local/bin/ld: libcairoboilerplate_cxx_la-cairo-boilerplate-qt.o (symbol from plugin): undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3'
usr/local/bin/ld: note: '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3' is defined in DSO /lib64/libstdc++.so.6 so try adding it to the linker command line
/lib64/libstdc++.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
[hjl@gnu-4 cairo-sphinx]$ usr/local/bin/ld -V
GNU ld (Linux/GNU Binutils) 2.23.51.0.8.20121218
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
[hjl@gnu-4 cairo-sphinx]$ 

[hjl@gnu-4 cairo-sphinx]$ /usr/gcc-4.6.3/bin/gcc -D_REENTRANT -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libdrm -I/usr/include/libdrm -I/usr/include/libpng15 -DQT_SHARED -I/usr/include/qt4 -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/include/qt4/QtCore -I/usr/include/valgrind -Wall -Wextra -Wold-style-definition -Wdeclaration-after-statement -Wmissing-declarations -Werror-implicit-function-declaration -Wnested-externs -Wpointer-arith -Wwrite-strings -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes -Wpacked -Wswitch-enum -Wmissing-format-attribute -Wbad-function-cast -Wvolatile-register-var -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations -Wno-missing-field-initializers -Wno-unused-parameter -Wno-attributes -Wno-long-long -Winline -flto -fno-strict-aliasing -fno-common -Wp,-D_FORTIFY_SOURCE=2 -Wno-unused-but-set-variable -D_REENTRANT -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -O2 -march=native -pipe -ggdb -Wa,--compress-debug-sections -finline-limit=1200 -Wl,-O1 -Wl,--hash-style=both -Wl,--sort-common -Wl,--no-keep-memory -o .libs/cairo-sphinx cairo_sphinx-sphinx.o  -Wl,--as-needed ../../util/cairo-script/.libs/libcairo-script-interpreter.so -L/usr/lib64/qt4 -llzo2 ../../boilerplate/.libs/libcairoboilerplate.a ../..//src/.libs/libcairo.so ../../src/.libs/libcairo.so -lpthread -lpixman-1 -lfontconfig -lfreetype -lEGL -ldl -lpng15 -lQtGui -lQtCore -lxcb-shm -lxcb-render -lxcb -lXrender -lX11 -lXext -lz -lGL -lglib-2.0 -lrt -lm -Busr/local/bin/
usr/local/bin/ld: libcairoboilerplate_cxx_la-cairo-boilerplate-qt.o (symbol from plugin): undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3'
usr/local/bin/ld: note: '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3' is defined in DSO /lib64/libstdc++.so.6 so try adding it to the linker command line
/lib64/libstdc++.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
[hjl@gnu-4 cairo-sphinx]$ usr/local/bin/ld -VGNU ld (GNU Binutils) 2.23.1
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
[hjl@gnu-4 cairo-sphinx]$ 

Did you make any local changes to binutils 2.23.51.0.8 or 2.23.51.0.9?
Comment 14 Mike Frysinger 2013-02-20 19:30:10 UTC
i'm seeing a similar bug i think:
  https://bugs.gentoo.org/458164

let's assume that the linking line is wrong (and is missing stuff/wrong order/whatever).  why is the linker issuing this message:
/lib64/libstdc++.so.6: could not read symbols: Invalid operation

that makes no sense.
Comment 15 Maciej Piechotka 2013-02-20 19:37:46 UTC
(In reply to comment #14)
> i'm seeing a similar bug i think:
>   https://bugs.gentoo.org/458164
> 

The same distro so it is likely they are the same bug.
Comment 16 Mike Frysinger 2013-02-20 21:24:04 UTC
i've verified that 2.23.51.0.8 works and 2.23.51.0.9 fails (the use case i posted involving webkit-gtk).  both done using Gentoo ebuilds, but sans Gentoo patches (i.e. USE=vanilla).  i can show the configure lines, but i don't think those are relevant -- it uses shared libs and a normal x86_64-pc-linux-gnu target.

these tests were done using ld.bfd.  ld.gold (both .8 and .9) is able to work.

that said, in the webkit example, the code is apparently missing an -lrt.  so maybe the .8 version is papering over the bug, and while .9 causes things to not link, it's not a bug with .9.  ignoring, of course, that "invalid operation" message which is wrong either way.

$ readelf -s Source/WebKit2/Platform/unix/Programs_WebKitPluginProcess-SharedMemoryUnix.o | grep shm_unlink
   65: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND shm_unlink
$ ./doit.sh
...
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: Source/WebKit2/Platform/unix/Programs_WebKitPluginProcess-SharedMemoryUnix.o: undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: note: 'shm_unlink@@GLIBC_2.2.5' is defined in DSO /lib64/librt.so.1 so try adding it to the linker command line
/lib64/librt.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
$ ./doit.sh -lrt
<works>
$ readelf -s Programs/.libs/WebKitPluginProcess | grep shm_unlink
  716: 0000000000000000 0 FUNC GLOBAL DEFAULT UND shm_unlink@GLIBC_2.2.5 (9)
 4389: 0000000000000000 0 FUNC GLOBAL DEFAULT UND shm_unlink@@GLIBC_2.2.5
Comment 17 Maciej Piechotka 2013-03-30 12:50:17 UTC
gptfdisk-0.8.6 + binutils 2.23.52.0.1.20130226 seems to repro the problem as well:

x86_64-pc-linux-gnu-g++ crc32.o support.o guid.o gptpart.o mbrpart.o basicmbr.o mbr.o gpt.o bsd.o parttypes.o attributes.o diskio.o diskio-unix.o cgdisk.o gptcurses.o -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=both -Wl,--sort-common -Wl,--no-keep-memory  -licuio -licuuc -luuid -lncurses  -o cgdisk
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: support.o: undefined reference to symbol 'pthread_cancel@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.2/../../../../x86_64-pc-linux-gnu/bin/ld: note: 'pthread_cancel@@GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line /lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
make: *** [cgdisk] Error 1
Comment 18 Mike Frysinger 2013-04-04 04:40:09 UTC
these errors are now actively hitting w/2.23.2

we've recorded a lot of broken packages in Gentoo:
  https://bugs.gentoo.org/464152

i'm not sure these are all bugs in the relevant packages
Comment 19 Alan Modra 2013-04-04 07:56:22 UTC
(In reply to comment #18)
> i'm not sure these are all bugs in the relevant packages

I'm going to assume they are.  --no-copy-dt-needed-entries is the default in 2.23, and it works.  The default was changed with 2.22 but didn't work properly, so not all buggy packages would have been found.  See http://sourceware.org/ml/binutils/2013-01/msg00085.html
Comment 20 Maciej Piechotka 2013-04-04 09:51:10 UTC
(In reply to comment #13)
> (In reply to comment #12)
> > https://www.dropbox.com/s/3mauit7c7ab4yh3/cairo-workdir.tar.xz?m
> > 
> 
> I can't reproduce it:
> (...)
> 
> Did you make any local changes to binutils 2.23.51.0.8 or 2.23.51.0.9?

Hmm. How did I missed mail from this comment? No - I haven't made any changes.
Comment 21 Mike Frysinger 2013-05-05 04:25:45 UTC
(In reply to comment #19)

i don't think all are.  if you build the cdrdao package, it uses the C++ <list> which implicitly pulls in __pthread_key_create() (by way of various gcc headers).  this isn't a problem because they're weak references.

however, starting with binutils-2.23.52.0.1, this throws up:
$ x86_64-pc-linux-gnu-g++ -O2 -march=amdfam10 -pipe -g  -o toc2cue toc2cue.o ../trackdb/libtrackdb.a -lmad -lm -lvorbisfile -lvorbis -lm -logg -lao
/usr/bin/ld: ../trackdb/libtrackdb.a(Toc.o): undefined reference to symbol '__pthread_key_create@@GLIBC_2.2.5'
/usr/bin/ld: note: '__pthread_key_create@@GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
Comment 22 Alan Modra 2013-05-05 07:28:53 UTC
Mike,
 Have you tried mainline, or anything after 2013-03-18?  I don't see the behaviour you report, on mainline.
Comment 23 Alan Modra 2014-11-27 23:51:08 UTC
As far as I know, we've fixed all the issues raised here.