From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 22 03:19:58 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 0E0D496C; Fri, 22 Feb 2013 03:19:58 +0000 (UTC) (envelope-from damjan.jov@gmail.com) Received: from mail-la0-x22d.google.com (la-in-x022d.1e100.net [IPv6:2a00:1450:4010:c03::22d]) by mx1.freebsd.org (Postfix) with ESMTP id 515AE164; Fri, 22 Feb 2013 03:19:57 +0000 (UTC) Received: by mail-la0-f45.google.com with SMTP id er20so194404lab.4 for ; Thu, 21 Feb 2013 19:19:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=JlLvC+nxR8zbR2y3F7fyMqF8yQ1IOKkZvdEr8S0v5H8=; b=S9DUfDlrMIcbxw1FpwNY09qqzz4nvq3eRK5MVA7bsQj19wTXiVKuRkui1azXYp6xU/ W4CO8wWZ1sSPSj+xmggDn8jR/JvaUSxtCLTz7CD3BzII79hilWDGmbsJTzsEjmepig+d sPh8KqPiujd7166x+94VoSkARkKoRLNHgUjczsrnJZ14/clH2341628Bg427GVM7GC01 1F99qrDK2/HgAei58Q/ZpuJBjTeopSvSTm6XMprmpxLVh5GIghTXd4HoBX3mKN4iTec7 cgMGMHwZ/zc5LwbjVQZYAu6YoS29J0kjjTas9PWEZpPheW3uR9aYSXBhcLtUc5r8ku2B 2QRQ== X-Received: by 10.152.108.203 with SMTP id hm11mr376132lab.4.1361503195441; Thu, 21 Feb 2013 19:19:55 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.20.138 with HTTP; Thu, 21 Feb 2013 19:19:35 -0800 (PST) In-Reply-To: <20130221154433.GY2598@kib.kiev.ua> References: <20130220154855.GF2598@kib.kiev.ua> <51253759.70508@coosemans.org> <20130221154433.GY2598@kib.kiev.ua> From: Damjan Jovanovic Date: Fri, 22 Feb 2013 05:19:35 +0200 Message-ID: Subject: Re: [patch] Wine DLL base address patches To: Konstantin Belousov Content-Type: text/plain; charset=ISO-8859-1 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: Fri, 22 Feb 2013 03:19:58 -0000 On Thu, Feb 21, 2013 at 5:44 PM, Konstantin Belousov wrote: > On Thu, Feb 21, 2013 at 12:57:45AM +0200, Damjan Jovanovic wrote: >> On Wed, Feb 20, 2013 at 10:51 PM, 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=176216), as well as a port >> >>> of Prelink to FreeBSD which Wine uses to set base addresses >> >>> (http://www.freebsd.org/cgi/query-pr.cgi?pr=176283). 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 mappings >> >> 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. >> > >> >> All of that occurred to me as well. >> >> 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. In that case, and since failing to load a library only causes the process to exit when starting up and not when it calls dlopen(), I approve. >> >> 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"). > My apologies: I confused -Ttext which is documented but doesn't work, with -Ttext-segment which is undocumented in FreeBSD 9.1 and might work. I would test it further, but -CURRENT doesn't installworld (ERROR: Required auditdistd user is missing, see /usr/src/UPDATING.) and I am away until next week. Prelink is now in Ports. What I'd recommend is checking if the binaries are the same, and if not, doing a diff between "readelf -a" outputs of the prelinked binary vs -Ttext-segmented binary. Also run this a few times and make sure the address is what's expected: #include #include int main(int argc, char **argv) { printf("%p\n", LoadLibrary("KERNEL32")); return 0; } mingw32-gcc hello.c -o hello.exe wine hello.exe