X-Spam-Check-By: sourceware.org Message-ID: <45AD1E15.31F06B43@dessent.net> Date: Tue, 16 Jan 2007 10:48:53 -0800 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Cygwin Python/PIL TCL/TK fork rebase solution References: <87ejpvluvj DOT fsf AT superfluity DOT lefae DOT org> <3D1F5241A4BA56B7EBA1D30B AT qjunbur DOT quns DOT cam DOT ac DOT uk> <45ACC59F DOT 397A6589 AT dessent DOT net> <45ACCBEF DOT 49170261 AT dessent DOT net> <20070116175838 DOT GB14405 AT trixie DOT casa DOT cgf DOT cx> <87zm8ihmhd DOT fsf AT superfluity DOT lefae DOT org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Ross Patterson wrote: > I'd still like to understand how one chooses base address and offset > values for rebase, seeing as I was just shooting in the dark until > something said "OWW!" :) Well normally you don't really choose anything. There are two ways to assign the base address. And again keep in mind that for a lot of users, this won't matter; it tends to only comes into play in the presence of dynamically loaded modules. If you run rebaseall, it just takes a list of all known Cygwin DLLs on the system (based on the /etc/setup/*.lst.gz files created by setup) and starting at some address near the top of memory (currently 0x70000000 but this might have been 0x68000000 in the recent past) it assigns them in back to back slots, in descending order. This should fix most problems as it ensures that every known DLL loads to a unique spot in virtual memory. But it requires the user to run rebaseall, which in turn requires that all DLLs be not in use so they can be modified, and it requires that once this has been done the first that it be repeated any time a new DLL-containing package is installed. It also fails if the program you're running tries to use a DLL not known by setup.exe, such as a user-compiled binary, or something that loads a DLL not managed by setup.exe. In that case you're supposed to supply a list of any such extra DLLs to rebaseall with -T so that it can include them in the assignment. In other words, this is the "guarantee that it works but requires a lot of effort" method. The other way, which is a lot better in general, is to just let the linker assign a base address it when it creates the DLL. If you pass --enable-auto-image-base to ld (thus, "-Wl,--enable-auto-image-base" as option to gcc/g++) then it will use a hash function to assign the base address based on the filename of the DLL. That function is currently: static unsigned long compute_dll_image_base (const char *ofile) { unsigned long hash = strhash (ofile); return 0x61300000 + ((hash << 16) & 0x0FFC0000); } ..which means it will end up somewhere between 0x61300000 and 0x712C0000. This does not guarantee that there are no overlapping DLLs since it's only just a simple hash, but it is much more convenient as the package creator can do this once when compiling the package and it will be set for all users. I don't know whether ld defaults to --enable-auto-image-base being enabled or not, but I do know that if you use e.g. libtool it will automatically add this option for you. Ideally, if all packages were compiled this way we would not need rebase/rebaseall at all. Brian -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/