Date: Mon, 30 Sep 2013 22:59:54 +0200 From: Dimitry Andric <dim@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r255931 - head/contrib/binutils/bfd Message-ID: <E3EA05B2-0E2D-432A-B4F5-1C26E730EFED@FreeBSD.org> In-Reply-To: <201309282303.r8SN3foW022674@svn.freebsd.org> References: <201309282303.r8SN3foW022674@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--Apple-Mail=_0239F370-613E-4E66-A73E-9850C6252918 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Sep 29, 2013, at 01:03, Dimitry Andric <dim@freebsd.org> wrote: > Author: dim > Date: Sat Sep 28 23:03:40 2013 > New Revision: 255931 > URL: http://svnweb.freebsd.org/changeset/base/255931 >=20 > Log: > Fix a bug in ld, where indirect symbols are not handled properly = during > linking of a shared library, leading to corrupt indexes in the = dynamic > symbol table. This should fix the multimedia/ffmpegthumbnailer port. The reason for this commit is an unfortunate interaction between our base ld (which is at 2.17.50, quite ancient), and ports ld (2.23.2). The latter version can put versioned symbols into an .so file in a way that is not handled by the former version, leading to corrupt symbol table entries. Here is an example, derived from the original problem Steve Wills reported. Suppose we are building a libavcodec.so, which uses versioned symbols, and it assigns those versions to *all* its symbols, using the following version script: $ cat libavcodec.ver LIBAVCODEC_52 { global: *; }; Next we link some empty object file (the contents do not matter) into libavcodec.so, using the version script, with the base ld: $ touch empty.c $ cc empty.c -o libavcodec.so -shared -s = -Wl,--version-script,libavcodec.ver The resulting .so file has several NOTYPE GLOBAL symbols (_end, _edata and __bss_start), which are marked as ABS (absolute): $ readelf -a libavcodec.so | grep -A8 "Symbol table '\.dynsym'" Symbol table '.dynsym' contains 9 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 413 FUNC WEAK DEFAULT UND = __cxa_finalize@FBSD_1.0 (3) 2: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 3: 00001510 0 NOTYPE GLOBAL DEFAULT ABS _end@@LIBAVCODEC_52 4: 00001510 0 NOTYPE GLOBAL DEFAULT ABS _edata@@LIBAVCODEC_52 5: 00000000 0 OBJECT GLOBAL DEFAULT ABS LIBAVCODEC_52 6: 00001510 0 NOTYPE GLOBAL DEFAULT ABS = __bss_start@@LIBAVCODEC_52 But if you link the .so with the ports ld (by using the cc -B option), the output is slightly different: $ cc -B/usr/local/bin empty.c -o libavcodec.so -shared -s = -Wl,--version-script=3Dlibavcodec.ver The resulting .so file again has several NOTYPE GLOBAL symbols, but this time they point to the .data section (Ndx=3D21 in this case): $ readelf -a libavcodec.so | grep -A8 "Symbol table '\.dynsym'" Symbol table '.dynsym' contains 9 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 2: 00000000 0 FUNC WEAK DEFAULT UND = __cxa_finalize@FBSD_1.0 (3) 3: 00001510 0 NOTYPE GLOBAL DEFAULT 21 _edata@@LIBAVCODEC_52 4: 00001510 0 NOTYPE GLOBAL DEFAULT 21 _end@@LIBAVCODEC_52 5: 00000000 0 OBJECT GLOBAL DEFAULT ABS LIBAVCODEC_52 6: 00001510 0 NOTYPE GLOBAL DEFAULT 21 = __bss_start@@LIBAVCODEC_52 If you now attempt to link any other .so file, using the libavcodec.so produced by ports ld as a dependency, with the _base_ ld, it will not handle those symbols correctly, and corrupt them: $ cc empty.c -o libffmpegthumbnailer.so -shared -s libavcodec.so $ readelf -a libffmpegthumbnailer.so | grep -A8 "Symbol table = '\.dynsym'" Symbol table '.dynsym' contains 8 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 00000000 413 FUNC WEAK DEFAULT UND = __cxa_finalize@FBSD_1.0 (2) 2: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses 3: a5a5a5a5 0xa5a5a5a5 COMMON <OS specific>: 10 INTERNAL [<other>: = a4] bad section index[42405] <corrupt> 4: a5a5a5a5 0xa5a5a5a5 COMMON <OS specific>: 10 INTERNAL [<other>: = a4] bad section index[42405] <corrupt> 5: a5a5a5a5 0xa5a5a5a5 COMMON <OS specific>: 10 INTERNAL [<other>: = a4] bad section index[42405] <corrupt> 6: 00000260 0 FUNC GLOBAL DEFAULT 9 _init Any attempt to link with the resulting libffmpegthumbnailer.so will fail. (The a5a5a5a5 number is actually an uninitialized value.) The r255931 commit fixes this by making ld properly handle these so-called 'indirect' symbols, similar to what upstream ld has already implemented. -Dimitry --Apple-Mail=_0239F370-613E-4E66-A73E-9850C6252918 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.20 (Darwin) iEYEARECAAYFAlJJ5lEACgkQsF6jCi4glqPZAgCgxDsEEWhpUs566fhg2gBaLTsX OZ8AoIPUJCWp34NPMKyG/ZZUJKJBD8zR =Vvo3 -----END PGP SIGNATURE----- --Apple-Mail=_0239F370-613E-4E66-A73E-9850C6252918--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E3EA05B2-0E2D-432A-B4F5-1C26E730EFED>