From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 20 21:16:36 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id B1172C8D; Wed, 20 Feb 2013 21:16:36 +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 0E4C5787; Wed, 20 Feb 2013 21:16:35 +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 r1KLGTQe014828; Wed, 20 Feb 2013 23:16:29 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.7.4 kib.kiev.ua r1KLGTQe014828 Received: (from kostik@localhost) by tom.home (8.14.6/8.14.6/Submit) id r1KLGTYu014827; Wed, 20 Feb 2013 23:16:29 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 20 Feb 2013 23:16:29 +0200 From: Konstantin Belousov To: Tijl Coosemans Subject: Re: [patch] Wine DLL base address patches Message-ID: <20130220211629.GR2598@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="3VJSuQsIgdmXj2/q" Content-Disposition: inline In-Reply-To: <51253759.70508@coosemans.org> 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: Damjan Jovanovic , freebsd-emulation@freebsd.org, freebsd-hackers@freebsd.org 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: Wed, 20 Feb 2013 21:16:36 -0000 --3VJSuQsIgdmXj2/q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Feb 20, 2013 at 09:51:37PM +0100, Tijl Coosemans wrote: > 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 po= rt > >> 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. > >=20 > > Unfortunately, it is not safe. MAP_FIXED overrides any previous mappings > > which could exist at the specified address. >=20 > 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 > Index: libexec/rtld-elf/map_object.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- libexec/rtld-elf/map_object.c (revision 246986) > +++ libexec/rtld-elf/map_object.c (working copy) > @@ -175,7 +175,7 @@ map_object(int fd, const char *path, const struct > base_vaddr =3D trunc_page(segs[0]->p_vaddr); > base_vlimit =3D round_page(segs[nsegs]->p_vaddr + segs[nsegs]->p_mem= sz); > mapsize =3D base_vlimit - base_vaddr; > - base_addr =3D hdr->e_type =3D=3D ET_EXEC ? (caddr_t) base_vaddr : NU= LL; > + base_addr =3D (caddr_t) base_vaddr; > =20 > mapbase =3D mmap(base_addr, mapsize, PROT_NONE, MAP_ANON | MAP_PRIVA= TE | > MAP_NOCORE, -1, 0); If this is enough for wine, I definitely have no objection. The typical dso has zero virtual base for the first segment, so the patch should change nothing for dso built without special map file. > Index: Makefile > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- Makefile (revision 312556) > +++ Makefile (working copy) > @@ -28,7 +28,7 @@ > LATEST_LINK=3D wine-devel > CPPFLAGS+=3D -I${LOCALBASE}/include > LDFLAGS+=3D -L${LOCALBASE}/lib > -USE_GCC=3D any > +USE_GCC=3D 4.7 > GNU_CONFIGURE=3D yes > CONFIGURE_ARGS+=3D--verbose --disable-tests \ > --without-alsa --without-capi --without-dbus \ > Index: files/patch-tools-winegcc-utils.h > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- files/patch-tools-winegcc-utils.h (revision 0) > +++ files/patch-tools-winegcc-utils.h (working copy) > @@ -0,0 +1,12 @@ > +--- tools/winegcc/utils.h.orig > ++++ tools/winegcc/utils.h > +@@ -42,7 +42,8 @@ > +=20 > + enum target_platform > + { > +- PLATFORM_UNSPECIFIED, PLATFORM_APPLE, PLATFORM_SOLARIS, PLATFORM_WI= NDOWS, PLATFORM_CYGWIN > ++ PLATFORM_UNSPECIFIED, PLATFORM_APPLE, PLATFORM_FREEBSD, PLATFORM_SO= LARIS, > ++ PLATFORM_WINDOWS, PLATFORM_CYGWIN > + }; > +=20 > + void error(const char* s, ...) DECLSPEC_NORETURN; > Index: files/patch-tools-winegcc-winegcc.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- files/patch-tools-winegcc-winegcc.c (revision 0) > +++ files/patch-tools-winegcc-winegcc.c (working copy) > @@ -0,0 +1,32 @@ > +--- tools/winegcc/winegcc.c.orig > ++++ tools/winegcc/winegcc.c > +@@ -172,6 +172,7 @@ > + { > + { "macos", PLATFORM_APPLE }, > + { "darwin", PLATFORM_APPLE }, > ++ { "freebsd", PLATFORM_FREEBSD }, > + { "solaris", PLATFORM_SOLARIS }, > + { "cygwin", PLATFORM_CYGWIN }, > + { "mingw32", PLATFORM_WINDOWS }, > +@@ -232,6 +233,8 @@ > +=20 > + #ifdef __APPLE__ > + static enum target_platform build_platform =3D PLATFORM_APPLE; > ++#elif defined(__FreeBSD__) > ++static enum target_platform build_platform =3D PLATFORM_FREEBSD; > + #elif defined(__sun) > + static enum target_platform build_platform =3D PLATFORM_SOLARIS; > + #elif defined(__CYGWIN__) > +@@ -1020,6 +1023,12 @@ > + if (opts->strip) > + strarray_add(link_args, "-Wl,-x"); > + break; > ++ case PLATFORM_FREEBSD: > ++ if (opts->image_base) > ++ { > ++ strarray_add(link_args, strmake("-Wl,-Ttext-segment=3D%s", = opts->image_base)); > ++ } > ++ break; > + case PLATFORM_SOLARIS: > + { > + char *mapfile =3D get_temp_file( output_name, ".map" ); --3VJSuQsIgdmXj2/q Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iQIcBAEBAgAGBQJRJT0tAAoJEJDCuSvBvK1BOjwQAIwDtkAYTikXCeL6vsrst7hz 6+VKPQm2wZLO0/VBhpKqYgzhjcynxSTYrmf+DWu3iq4i8S7z37nO0UFNozBCCZhh iHVdXWJ/+NhpBGMVy4b3V88Z6BVvW8i7hZVsX35eiKKLq87hhC9R4rpjEQK9eKgK 10AFW5uNYpmR8IN/qLOXTgMOQ76x8lHrcLdvsw5Pe7WhKX9VGO47CanBm9Ux3cA1 cvmlx8V36W/cATH+dkZ1NgNFtWB2rjL7jp1FR6WOU4K02Jl22ggVVrc6l6E/owdh DTwrkptrL+Fca0vaN+0xYQbJiRcCZ2Z2m4uTaEH3/6bzFnr7s10lRRA5KHElgzps MSoery+hPL2YzfTvaYGIBbA+cciguiwFBVavi8BjrmIwLuRnwznN8JTJNjG4UV0v Wu+BYju5n3jdBlxE+0adZVChioP3f9A0c6xnEoxps4D2ekan9L8Ly1KcjqzHlaJH y2qTCS4xxBLF6JAdX/pQGVaG5a0NfPDyPnK/TPq9dKPLE4uuzBAPq5nscpGpbfh8 9WlFffV4DYuispAcr9ojeOrfikp5yo0WNwRJS34vdw4h/a2jKwbq/qcNOZsbjGS0 8fUIqoQN1ljhW+8fDRxMPrCAyVUYvqZHmHP8mrhCHbzvbPfrZYoA6wTS3l8JoblE b8xJHdk5Lb7jGag5YkLI =kx1j -----END PGP SIGNATURE----- --3VJSuQsIgdmXj2/q--