From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 21 15:44:46 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 01C7D854; Thu, 21 Feb 2013 15:44:46 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) by mx1.freebsd.org (Postfix) with ESMTP id 50442EA1; Thu, 21 Feb 2013 15:44:45 +0000 (UTC) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.6/8.14.6) with ESMTP id r1LFiYXN039698; Thu, 21 Feb 2013 17:44:34 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r1LFiYXN039698 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r1LFiXAl039697; Thu, 21 Feb 2013 17:44:33 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 21 Feb 2013 17:44:33 +0200 From: Konstantin Belousov To: Damjan Jovanovic Subject: Re: [patch] Wine DLL base address patches Message-ID: <20130221154433.GY2598@kib.kiev.ua> References: <20130220154855.GF2598@kib.kiev.ua> <51253759.70508@coosemans.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/TIhMU+9tW3Jkwla" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on tom.home Cc: freebsd-hackers@freebsd.org, freebsd-emulation@freebsd.org, Tijl Coosemans X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Feb 2013 15:44:46 -0000 --/TIhMU+9tW3Jkwla Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 21, 2013 at 12:57:45AM +0200, Damjan Jovanovic wrote: > On Wed, Feb 20, 2013 at 10:51 PM, Tijl Coosemans wro= te: > > On 20-02-2013 16:48, Konstantin Belousov wrote: > >> On Wed, Feb 20, 2013 at 05:29:01PM +0200, Damjan Jovanovic wrote: > >>> Hi > >>> > >>> Wine needs some of its libraries to be loaded at specific base > >>> addresses (https://wiki.freebsd.org/Wine), something FreeBSD currently > >>> lacks. > >>> > >>> I've written a patch to the dynamic loader (/libexec/ld-elf.so.1) that > >>> loads libraries at their preferred base addresses > >>> (http://www.freebsd.org/cgi/query-pr.cgi?pr=3D176216), as well as a p= ort > >>> of Prelink to FreeBSD which Wine uses to set base addresses > >>> (http://www.freebsd.org/cgi/query-pr.cgi?pr=3D176283). Both work :-), > >>> the changed dynamic loader doesn't show any problems in a few days of > >>> testing, and prelink works with the --reloc-only option as used by > >>> Wine. > >>> > >>> Please review/test/comment/commit. > >> > >> Unfortunately, it is not safe. MAP_FIXED overrides any previous mappin= gs > >> which could exist at the specified address. > > > > I've simplified the rtld patch to a single line. The second patch makes > > Wine use -Ttext-segment linker flag instead of prelink. This requires > > binutils from ports, but it's easier than porting prelink. > > >=20 > All of that occurred to me as well. >=20 > The problem with that one-line rtld patch is that loading an > application will now fail if any of its libraries cannot be loaded at > their requested address. But this is intended behaviour. Also, the default virtaddr base for the shared libraries is 0, so the existing binaries should be not affected. >=20 > The problem with -Ttext-segment (and isn't it just -Ttext?) is that it > doesn't seem to work: the base_vaddr seen by rtld will remain 0, and > the address listed in /proc/.../map is different from what it should > be. Also run "readelf -l" on a library compiled that way and compare > with the output of one run through "prelink --reloc-only", you'll see > the lowest VirtAddr and PhysAddr in LOAD headers change only with > prelink. I really ported prelink because there was no other choice. The -Ttext-segment does work. As indicated by Tijl, you need recent binutils. I just verified that ld 2.32.1 obeys -Ttext-segment. You can also take a look at the default linker script to see how -Ttext-segment is used, look for SEGMENT_START("text-segment"). >=20 > See my attached test cases, and examine the contents of /proc/.../map > while they run. --/TIhMU+9tW3Jkwla Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRJkDhAAoJEJDCuSvBvK1BKgcQAJAGi3YIrhLO5X1hPmFxn5Ju NpRg/BqS3HHb1U3r5DaR1Vr3M/6ACmx6ZQIySHpTysADdwqPw3b3k+mtSl8bOfmW 45XQWn1jgiYJ22PiCoVTYF8DJFWZ+2onLJuevJ+xRielZx2Pz1KTztc+IhXY6PUv NXZ+1/zINvt0e8bFwVt9WLdazAj15/FRmDkKSRf+oKlq5YMsbqAppv7UZRDqUhsI AdsbVEbilLIfuqPuR+M9+iJMaIt5oF3InHwX6msy15dEnn/xdI6d3fMcyhdkp+nP rC+LT1ggD+TQaAXH1LqZTZfPCSS9mv7NhqCYaUemKjZbeVsIZU+P4p+tWWqjdBQd qEyEctToB6ONkptqZ2tqiPaN3OopVEdJzrab4Ovgfy0a62lBfiXcTKEQZgL2ezGW UpLItTHWt+lwcG+dLCECKPnzH4v79Kz9sIYcDn1J3gJ0rx1l2jobwaMQymspUK6z 70V5aVZ4OE2xFPTYabl6YAVDzRvtO7bhOubM11GHlv1+WVwPRQwb4dpebGKzASd3 oe/Uuy4GJCr0ZwGEMovtSP3XowVDCJ69o/G3MJCAhL4ztd4+6hQgnN+ytNDvdzVA EsOT+WKf/USCUA5CXsdaExnDPeY5AtryQ6E0g0cr/5phJbizEmVqT5VQs7FhZEi4 2L9nvFIcKb185sYmMtb+ =76XR -----END PGP SIGNATURE----- --/TIhMU+9tW3Jkwla--