From owner-svn-src-head@FreeBSD.ORG Mon Sep 30 21:00:12 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 8C4D4D40; Mon, 30 Sep 2013 21:00:12 +0000 (UTC) (envelope-from dim@FreeBSD.org) Received: from tensor.andric.com (tensor.andric.com [IPv6:2001:7b8:3a7:1:2d0:b7ff:fea0:8c26]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1A9C8253A; Mon, 30 Sep 2013 21:00:12 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7::a9cb:6a3f:5290:e31d] (unknown [IPv6:2001:7b8:3a7:0:a9cb:6a3f:5290:e31d]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 532A45C44; Mon, 30 Sep 2013 23:00:07 +0200 (CEST) From: Dimitry Andric Content-Type: multipart/signed; boundary="Apple-Mail=_0239F370-613E-4E66-A73E-9850C6252918"; protocol="application/pgp-signature"; micalg=pgp-sha1 Message-Id: Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: svn commit: r255931 - head/contrib/binutils/bfd Date: Mon, 30 Sep 2013 22:59:54 +0200 References: <201309282303.r8SN3foW022674@svn.freebsd.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org In-Reply-To: <201309282303.r8SN3foW022674@svn.freebsd.org> X-Mailer: Apple Mail (2.1510) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Sep 2013 21:00:12 -0000 --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 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 : 10 INTERNAL [: = a4] bad section index[42405] 4: a5a5a5a5 0xa5a5a5a5 COMMON : 10 INTERNAL [: = a4] bad section index[42405] 5: a5a5a5a5 0xa5a5a5a5 COMMON : 10 INTERNAL [: = a4] bad section index[42405] 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--