public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* rebase addon - Bas and Size listing of dll's without rebasing
@ 2001-12-26 14:01 Ralf Habacker
  2001-12-27 10:22 ` Jason Tishler
  0 siblings, 1 reply; 12+ messages in thread
From: Ralf Habacker @ 2001-12-26 14:01 UTC (permalink / raw)
  To: Cygwin

[-- Attachment #1: Type: text/plain, Size: 4840 bytes --]

Hi,

while porting kde2 the rebase tool solved some problems for me on using libtools libltdl.

In the past I have to use the LTDL_DLOPEN_DEPLIBS in the config.h of libtldl, which enables
loading of all dependency dll's of a lib and because of many dll's used for kde this slow
down application loading significantly. If I haven't used this flag, cygwin tells about a
"... can't remap ..." problem.
After rebasing the dll's from the kdelibs, this error does not happens anymore and I can
reject this config option.

libltdl/config.h
...
/* Define if the OS needs help to load dependent libraries for dlopen(). */
//#define LTDL_DLOPEN_DEPLIBS 1
....

On analysing this problem I added an option "-l" to the rebase tool to list dll's imagebase
and -size without rebasing. It's very interesting to see how MS chooses there Imagebase.

Because I hacked this very quick, I have used simple FILE structure and fopen/fread calls.
Perhaps someone like to change this to iostream functionality.

$ rebase -h
rebase: unknown option -- h
usage: rebase -b BaseAddress [-d] -o Offset <file> ...  rebase <file>
usage: rebase -l <file> ...        list Imagebase and -size of <file>

Example:
$ rebase -l /opt/kde2/bin/*.dll
c:\programme\cygwin\opt\kde2\bin\cygDCOP-1.dll               - ImageBase: 74fb0000 ImageSize:
00026000
c:\programme\cygwin\opt\kde2\bin\cygartsc-0.dll              - ImageBase: 74f80000 ImageSize:
00007000
c:\programme\cygwin\opt\kde2\bin\cygartsflow-0.dll           - ImageBase: 74ee0000 ImageSize:
0007a000
c:\programme\cygwin\opt\kde2\bin\cygartsflow_idl-0.dll       - ImageBase: 74e50000 ImageSize:
0006f000
c:\programme\cygwin\opt\kde2\bin\cygartskde.dll              - ImageBase: 74df0000 ImageSize:
0003f000
c:\programme\cygwin\opt\kde2\bin\cygkICE-0.dll               - ImageBase: 74db0000 ImageSize:
00017000
c:\programme\cygwin\opt\kde2\bin\cygkab-3.dll                - ImageBase: 74d30000 ImageSize:
0005e000
c:\programme\cygwin\opt\kde2\bin\cygkbuildsycoca.dll         - ImageBase: 74cf0000 ImageSize:
0001d000
c:\programme\cygwin\opt\kde2\bin\cygkdecore-3.dll            - ImageBase: 74b30000 ImageSize:
00194000
c:\programme\cygwin\opt\kde2\bin\cygkdefakes-3.dll           - ImageBase: 74b00000 ImageSize:
00007000
c:\programme\cygwin\opt\kde2\bin\cygkdeprint-0.dll           - ImageBase: 74a50000 ImageSize:
00084000
c:\programme\cygwin\opt\kde2\bin\cygkdeprint_management-0.dll - ImageBase: 749b0000
ImageSize: 00075000
c:\programme\cygwin\opt\kde2\bin\cygkdesu-1.dll              - ImageBase: 74960000 ImageSize:
0002d000
c:\programme\cygwin\opt\kde2\bin\cygkdeui-3.dll              - ImageBase: 74750000 ImageSize:
001ee000
c:\programme\cygwin\opt\kde2\bin\cygkfile-3.dll              - ImageBase: 74690000 ImageSize:
0009c000
c:\programme\cygwin\opt\kde2\bin\cygkio-3.dll                - ImageBase: 74590000 ImageSize:
000d2000
c:\programme\cygwin\opt\kde2\bin\cygkjava-1.dll              - ImageBase: 74540000 ImageSize:
00027000
c:\programme\cygwin\opt\kde2\bin\cygkjs-1.dll                - ImageBase: 744d0000 ImageSize:
00044000
c:\programme\cygwin\opt\kde2\bin\cygkmedia2-0.dll            - ImageBase: 74480000 ImageSize:
00025000
c:\programme\cygwin\opt\kde2\bin\cygkmedia2_idl-0.dll        - ImageBase: 74400000 ImageSize:
00054000
c:\programme\cygwin\opt\kde2\bin\cygkmid-0.dll               - ImageBase: 743c0000 ImageSize:
0001b000
c:\programme\cygwin\opt\kde2\bin\cygkonq-3.dll               - ImageBase: 74300000 ImageSize:
0009c000
c:\programme\cygwin\opt\kde2\bin\cygkonqsidebartree_bookmarks-0.dll - ImageBase: 742d0000
ImageSize: 0000e000
c:\programme\cygwin\opt\kde2\bin\cygkparts-1.dll             - ImageBase: 74270000 ImageSize:
00033000
c:\programme\cygwin\opt\kde2\bin\cygkspell-3.dll             - ImageBase: 74220000 ImageSize:
00029000
c:\programme\cygwin\opt\kde2\bin\cygkssl-2.dll               - ImageBase: 741d0000 ImageSize:
0002e000
c:\programme\cygwin\opt\kde2\bin\cygksycoca-3.dll            - ImageBase: 740f0000 ImageSize:
000b9000
c:\programme\cygwin\opt\kde2\bin\cygktexteditor-0.dll        - ImageBase: 740c0000 ImageSize:
0000f000
c:\programme\cygwin\opt\kde2\bin\cygltdl-0.dll               - ImageBase: 74090000 ImageSize:
0000a000
c:\programme\cygwin\opt\kde2\bin\cygmcop-0.dll               - ImageBase: 73f60000 ImageSize:
00101000
c:\programme\cygwin\opt\kde2\bin\cygmcop_mt-0.dll            - ImageBase: 73f30000 ImageSize:
00007000
c:\programme\cygwin\opt\kde2\bin\cygqtmcop-0.dll             - ImageBase: 73ef0000 ImageSize:
0001f000
c:\programme\cygwin\opt\kde2\bin\cygsoundserver_idl-0.dll    - ImageBase: 73e70000 ImageSize:
0005a000
c:\programme\cygwin\opt\kde2\bin\cygxml2-2.dll               - ImageBase: 73dc0000 ImageSize:
00085000
c:\programme\cygwin\opt\kde2\bin\cygxslt-0.dll               - ImageBase: 73d70000 ImageSize:
00021000


Regards
Ralf



[-- Attachment #2: rebase-list-option.dif --]
[-- Type: application/octet-stream, Size: 2399 bytes --]

--- rebase.cc.orig	Mon Dec 24 11:33:46 2001
+++ rebase.cc	Wed Dec 26 19:53:36 2001
@@ -28,6 +28,8 @@
 #include <windows.h>
 #include <imagehlp.h>
 
+#include <stdio.h>
+
 using namespace std;
 
 string PosixToWin32(const string& aPosixPath);
@@ -39,6 +41,7 @@ ULONG theImageBase = 0;
 BOOL theDownFlag = FALSE;
 ULONG theOffset = 0;
 int theArgsIndex = 0;
+int theListFlag = 0; 
 
 void
 main(int argc, char* argv[])
@@ -48,10 +51,20 @@ main(int argc, char* argv[])
 
 	for (int i = theArgsIndex; i < argc; i++)
 	{
+    string aFile = PosixToWin32(argv[i]);
+    if (theListFlag)
+    {
+      long image[60]; 
+      
+      FILE *f = fopen(const_cast<char*>(aFile.c_str()),"r");
+      fread(&image,sizeof(image),1,f);
+      printf("%-60s - ImageBase: %08x ImageSize: %08x\n",aFile.c_str(),image[45],image[52]);
+      fclose(f);
+    }
+    else {
 		if (theDownFlag)
 			aNewImageBase -= theOffset;
 
-		string aFile = PosixToWin32(argv[i]);
 		ULONG anOldImageSize, anOldImageBase, aNewImageSize;
 		ULONG aPrevNewImageBase = aNewImageBase;
 		BOOL aStatus = ReBaseImage(
@@ -82,6 +95,8 @@ main(int argc, char* argv[])
 		if (!theDownFlag)
 			aNewImageBase += theOffset;
 	}
+  }
+  
 
 	exit(0);
 }
@@ -97,7 +112,7 @@ PosixToWin32(const string& aPosixPath)
 void
 ParseArgs(int argc, char* argv[])
 {
-	const char* anOptions = "b:do:";
+  const char* anOptions = "b:do:l:";
 	for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;)
 	{
 		switch (anOption)
@@ -111,6 +126,9 @@ ParseArgs(int argc, char* argv[])
 			case 'o':
 				theOffset = StringToUlong(optarg);
 				break;
+      case 'l':
+        theListFlag = 1;
+        break;
 			default:
 				Usage();
 				exit(1);
@@ -118,12 +136,15 @@ ParseArgs(int argc, char* argv[])
 		}
 	}
 
-	if (theImageBase == 0)
+  if (theImageBase == 0 && !theListFlag)
 	{
 		Usage();
 		exit(1);
 	}
 
+  if (theListFlag)
+    theArgsIndex = optind-1;
+  else 
 	theArgsIndex = optind;
 }
 
@@ -144,6 +165,7 @@ StringToUlong(const string& aString)
 void
 Usage()
 {
-	cerr << "usage: rebase -b BaseAddress [-d] -o Offset ImageFileName ..." << endl;
+  cerr << "usage: rebase -b BaseAddress [-d] -o Offset <file> ...  rebase <file>" << endl;
+  cerr << "usage: rebase -l <file> ...        list Imagebase and -size of <file>" << endl;
 }
 

[-- Attachment #3: rebase.cc --]
[-- Type: application/octet-stream, Size: 4179 bytes --]

/*
 * Copyright (c) 2001 Jason Tishler
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: rebase.cc,v 1.5 2001/12/18 20:21:19 jtishler Exp $
 */

#include <iostream>
#include <sstream>
#include <string>
#include <time.h>
#include <stdlib.h>
#include <getopt.h>
#include <sys/cygwin.h>
#include <windows.h>
#include <imagehlp.h>

#include <stdio.h>

using namespace std;

string PosixToWin32(const string& aPosixPath);
void ParseArgs(int argc, char* argv[]);
unsigned long StringToUlong(const string& aString);
void Usage();

ULONG theImageBase = 0;
BOOL theDownFlag = FALSE;
ULONG theOffset = 0;
int theArgsIndex = 0;
int theListFlag = 0; 

void
main(int argc, char* argv[])
{
  ParseArgs(argc, argv);
  ULONG aNewImageBase = theImageBase;

  for (int i = theArgsIndex; i < argc; i++)
  {
    string aFile = PosixToWin32(argv[i]);
    if (theListFlag)
    {
      long image[60]; 
      
      FILE *f = fopen(const_cast<char*>(aFile.c_str()),"r");
      fread(&image,sizeof(image),1,f);
      printf("%-60s - ImageBase: %08x ImageSize: %08x\n",aFile.c_str(),image[45],image[52]);
      fclose(f);
    }
    else {
    if (theDownFlag)
      aNewImageBase -= theOffset;

    ULONG anOldImageSize, anOldImageBase, aNewImageSize;
    ULONG aPrevNewImageBase = aNewImageBase;
    BOOL aStatus = ReBaseImage(
      const_cast<char*>(aFile.c_str()), // CurrentImageName
      0, // SymbolPath
      TRUE, // fReBase
      FALSE, // fRebaseSysfileOk
      theDownFlag, // fGoingDown
      0, // CheckImageSize
      &anOldImageSize, // OldImageSize
      &anOldImageBase, // OldImageBase
      &aNewImageSize, // NewImageSize
      &aNewImageBase, // NewImageBase
      time(0)); // TimeStamp

    // ReBaseImage seems to never returns false!
    DWORD aStatus2 = GetLastError();
    if (aStatus2 != 0)
    {
      cerr << "ReBaseImage() failed with last error = " <<
        GetLastError() << endl;
      exit(2);
    }
    cout << aFile << hex << ": new base = " <<
      ((theDownFlag) ? aNewImageBase : aPrevNewImageBase) <<
      ", new size = " << aNewImageSize + theOffset << endl;

    if (!theDownFlag)
      aNewImageBase += theOffset;
    }
  }
  

  exit(0);
}

string
PosixToWin32(const string& aPosixPath)
{
  char aWin32Path[MAX_PATH];
  cygwin_conv_to_win32_path(aPosixPath.c_str(), aWin32Path);
  return aWin32Path;
}

void
ParseArgs(int argc, char* argv[])
{
  const char* anOptions = "b:do:l:";
  for (int anOption; (anOption = getopt(argc, argv, anOptions)) != -1;)
  {
    switch (anOption)
    {
      case 'b':
        theImageBase = StringToUlong(optarg);
        break;
      case 'd':
        theDownFlag = TRUE;
        break;
      case 'o':
        theOffset = StringToUlong(optarg);
        break;
      case 'l':
        theListFlag = 1;
        break;
      default:
        Usage();
        exit(1);
        break;
    }
  }

  if (theImageBase == 0 && !theListFlag)
  {
    Usage();
    exit(1);
  }

  if (theListFlag)
    theArgsIndex = optind-1;
  else 
    theArgsIndex = optind;
}

unsigned long
StringToUlong(const string& aString)
{
  stringstream ss;
  unsigned long aUlong;
  string::size_type anIndex = aString.find("0x");
  if (anIndex == 0)
    ss << hex << string(aString, 2, aString.size() - 2);
  else
    ss << aString;
  ss >> aUlong;
  return aUlong;
}

void
Usage()
{
  cerr << "usage: rebase -b BaseAddress [-d] -o Offset <file> ...  rebase <file>" << endl;
  cerr << "usage: rebase -l <file> ...        list Imagebase and -size of <file>" << endl;
}


[-- Attachment #4: Makefile --]
[-- Type: application/octet-stream, Size: 110 bytes --]

rebase: rebase.cc
	g++ -g -o $@ $< -limagehlp
	
install: rebase
	/usr/bin/install rebase.exe /usr/local/bin



[-- Attachment #5: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-26 14:01 rebase addon - Bas and Size listing of dll's without rebasing Ralf Habacker
@ 2001-12-27 10:22 ` Jason Tishler
  2001-12-27 18:34   ` Robert Collins
  2001-12-28  5:48   ` Ralf Habacker
  0 siblings, 2 replies; 12+ messages in thread
From: Jason Tishler @ 2001-12-27 10:22 UTC (permalink / raw)
  To: Ralf Habacker; +Cc: Cygwin

Ralf,

On Wed, Dec 26, 2001 at 09:08:49PM +0100, Ralf Habacker wrote:
> On analysing this problem I added an option "-l" to the rebase tool to
> list dll's imagebase and -size without rebasing. It's very interesting
> to see how MS chooses there Imagebase.

What about the following alternative solution:

    $ objdump -p foo.dll | egrep '(ImageBase|SizeOfImage)'
    ImageBase               68000000
    SizeOfImage             0003f000

> Because I hacked this very quick, I have used simple FILE structure
> and fopen/fread calls.  Perhaps someone like to change this to iostream
> functionality.

At this point, my priorities are:

    1. attempt to contribute rebase to binutils
    2. work on the integration with setup.exe

After the above is completed, then I would entertain adding such an
option if the community deemed it appropriate.  But, wouldn't
implementing it via ReBaseImage()'s fReBase parameter as opposed to
plucking certain bytes out of the executable be a better approach?  I
presume that this is how MS implements their '-s' (just sum image range)
option.

Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-27 10:22 ` Jason Tishler
@ 2001-12-27 18:34   ` Robert Collins
  2002-01-03  5:24     ` Jason Tishler
  2001-12-28  5:48   ` Ralf Habacker
  1 sibling, 1 reply; 12+ messages in thread
From: Robert Collins @ 2001-12-27 18:34 UTC (permalink / raw)
  To: Jason Tishler, Ralf Habacker; +Cc: Cygwin


===
----- Original Message -----
From: "Jason Tishler" <jason@tishler.net>
> After the above is completed, then I would entertain adding such an
> option if the community deemed it appropriate.  But, wouldn't
> implementing it via ReBaseImage()'s fReBase parameter as opposed to
> plucking certain bytes out of the executable be a better approach?  I
> presume that this is how MS implements their '-s' (just sum image
range)
> option.

IMO we should be using bfd not the MS helper libraries - in the long
term. Otherwise one cannot do any of this as part of a cross compile or
cross-manipulation toolkit.

Rob


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-27 10:22 ` Jason Tishler
  2001-12-27 18:34   ` Robert Collins
@ 2001-12-28  5:48   ` Ralf Habacker
  2001-12-28 10:24     ` Christopher Faylor
  1 sibling, 1 reply; 12+ messages in thread
From: Ralf Habacker @ 2001-12-28  5:48 UTC (permalink / raw)
  To: Cygwin

> -----Original Message-----
> From: Jason Tishler [mailto:jason@tishler.net]
> Sent: Thursday, December 27, 2001 7:05 PM
> To: Ralf Habacker
> Cc: Cygwin
> Subject: Re: rebase addon - Bas and Size listing of dll's without
> rebasing
>
>
> Ralf,
>
> On Wed, Dec 26, 2001 at 09:08:49PM +0100, Ralf Habacker wrote:
> > On analysing this problem I added an option "-l" to the rebase tool to
> > list dll's imagebase and -size without rebasing. It's very interesting
> > to see how MS chooses there Imagebase.
>
> What about the following alternative solution:
>
>     $ objdump -p foo.dll | egrep '(ImageBase|SizeOfImage)'
>     ImageBase               68000000
>     SizeOfImage             0003f000

Try it with a recent objdump and a dll with auto-import variables and you will see that
objdump crashes. :-(

>
> > Because I hacked this very quick, I have used simple FILE structure
> > and fopen/fread calls.  Perhaps someone like to change this to iostream
> > functionality.
>
> At this point, my priorities are:
>
>     1. attempt to contribute rebase to binutils
>     2. work on the integration with setup.exe
>
> After the above is completed, then I would entertain adding such an
> option if the community deemed it appropriate.  But, wouldn't
> implementing it via ReBaseImage()'s fReBase parameter as opposed to
> plucking certain bytes out of the executable be a better approach?  I
> presume that this is how MS implements their '-s' (just sum image range)
> option.

I have done this, because I doesn't know any other way to do this, especially because of the
objdump bug.
There may be better solutions for this.

Ralf


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-28  5:48   ` Ralf Habacker
@ 2001-12-28 10:24     ` Christopher Faylor
  2001-12-29  3:22       ` Ralf Habacker
  0 siblings, 1 reply; 12+ messages in thread
From: Christopher Faylor @ 2001-12-28 10:24 UTC (permalink / raw)
  To: cygwin

On Fri, Dec 28, 2001 at 12:50:07PM +0100, Ralf Habacker wrote:
>> -----Original Message-----
>> From: Jason Tishler [mailto:jason@tishler.net]
>> On Wed, Dec 26, 2001 at 09:08:49PM +0100, Ralf Habacker wrote:
>> > On analysing this problem I added an option "-l" to the rebase tool to
>> > list dll's imagebase and -size without rebasing. It's very interesting
>> > to see how MS chooses there Imagebase.
>>
>> What about the following alternative solution:
>>
>>     $ objdump -p foo.dll | egrep '(ImageBase|SizeOfImage)'
>>     ImageBase               68000000
>>     SizeOfImage             0003f000
>
>Try it with a recent objdump and a dll with auto-import variables and you will see that
>objdump crashes. :-(

Seems to work fine with the distributed version of binutils.  I tried
this with cygncurses6.dll.

Regardless, if there is a problem in objdump then it obviously needs to
be fixed.  Adding an option to some other program because objdump is broken
is not the way to approach this, IMO.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-28 10:24     ` Christopher Faylor
@ 2001-12-29  3:22       ` Ralf Habacker
  2002-01-03  9:25         ` Ralf Habacker
  0 siblings, 1 reply; 12+ messages in thread
From: Ralf Habacker @ 2001-12-29  3:22 UTC (permalink / raw)
  To: cygwin

> -----Original Message-----
> From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com]On Behalf
> Of Christopher Faylor
> Sent: Friday, December 28, 2001 6:55 PM
> To: cygwin@cygwin.com
> Subject: Re: rebase addon - Bas and Size listing of dll's without
> rebasing
>
>
> On Fri, Dec 28, 2001 at 12:50:07PM +0100, Ralf Habacker wrote:
> >> -----Original Message-----
> >> From: Jason Tishler [mailto:jason@tishler.net]
> >> On Wed, Dec 26, 2001 at 09:08:49PM +0100, Ralf Habacker wrote:
> >> > On analysing this problem I added an option "-l" to the rebase tool to
> >> > list dll's imagebase and -size without rebasing. It's very interesting
> >> > to see how MS chooses there Imagebase.
> >>
> >> What about the following alternative solution:
> >>
> >>     $ objdump -p foo.dll | egrep '(ImageBase|SizeOfImage)'
> >>     ImageBase               68000000
> >>     SizeOfImage             0003f000
> >
> >Try it with a recent objdump and a dll with auto-import variables and you will see that
> >objdump crashes. :-(
>
> Seems to work fine with the distributed version of binutils.  I tried
> this with cygncurses6.dll.

Hmmh, because for kde I currently need a patched ld (the problem with linking static
libraries to multiple dll's) I update periodically my source with the archive. I will verify,
may be I have overseen something.

> Regardless, if there is a problem in objdump then it obviously needs to
> be fixed.  Adding an option to some other program because objdump is broken
> is not the way to approach this, IMO.

You're right. I have reported this bug very early in the time the auto-import problem was
introduced, but was not able to understand the bfd lib so that I could fix it by myself.

Ralf

> cgf
>
> --
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> Bug reporting:         http://cygwin.com/bugs.html
> Documentation:         http://cygwin.com/docs.html
> FAQ:                   http://cygwin.com/faq/
>
>


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-27 18:34   ` Robert Collins
@ 2002-01-03  5:24     ` Jason Tishler
  2002-01-03  5:27       ` Robert Collins
  0 siblings, 1 reply; 12+ messages in thread
From: Jason Tishler @ 2002-01-03  5:24 UTC (permalink / raw)
  To: Robert Collins; +Cc: Ralf Habacker, Cygwin

Rob,

On Fri, Dec 28, 2001 at 11:06:35AM +1100, Robert Collins wrote:
> ----- Original Message -----
> From: "Jason Tishler" <jason@tishler.net>
> > After the above is completed, then I would entertain adding such an
> > option if the community deemed it appropriate.  But, wouldn't
> > implementing it via ReBaseImage()'s fReBase parameter as opposed to
> > plucking certain bytes out of the executable be a better approach?  I
> > presume that this is how MS implements their '-s' (just sum image
> range)
> > option.
> 
> IMO we should be using bfd not the MS helper libraries - in the long
> term. Otherwise one cannot do any of this as part of a cross compile or
> cross-manipulation toolkit.

Good point.

I'm willing to do the right thing, but that is going to take longer given
the ramp up necessary for me learn about binutils' configury/make, bfd,
etc.  However, I would like to get a rebase solution into setup.exe ASAP.
Is a two prong approach acceptable?  In the short term, add rebase to
winsup/utils, integrate directly into setup.exe, etc.  In the long term,
add rebase to binutils, integrate with ld, etc.

Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2002-01-03  5:24     ` Jason Tishler
@ 2002-01-03  5:27       ` Robert Collins
  2002-01-04  6:10         ` Jason Tishler
  0 siblings, 1 reply; 12+ messages in thread
From: Robert Collins @ 2002-01-03  5:27 UTC (permalink / raw)
  To: Jason Tishler; +Cc: Ralf Habacker, Cygwin

----- Original Message -----
From: "Jason Tishler" <jason@tishler.net>
> > IMO we should be using bfd not the MS helper libraries - in the long
> > term. Otherwise one cannot do any of this as part of a cross compile
or
> > cross-manipulation toolkit.
>
> Good point.
>
> I'm willing to do the right thing, but that is going to take longer
given
> the ramp up necessary for me learn about binutils' configury/make,
bfd,
> etc.  However, I would like to get a rebase solution into setup.exe
ASAP.
> Is a two prong approach acceptable?  In the short term, add rebase to
> winsup/utils, integrate directly into setup.exe, etc.  In the long
term,
> add rebase to binutils, integrate with ld, etc.

Yes. In fact it's probably a requirement, as setup.exe cannot get too
big.

Does the MS solution need .dll's not present on win95a ?

Rob


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: rebase addon - Bas and Size listing of dll's without rebasing
  2001-12-29  3:22       ` Ralf Habacker
@ 2002-01-03  9:25         ` Ralf Habacker
  2002-01-03 13:42           ` Robert Collins
  0 siblings, 1 reply; 12+ messages in thread
From: Ralf Habacker @ 2002-01-03  9:25 UTC (permalink / raw)
  To: Cygwin

[-- Attachment #1: Type: text/plain, Size: 4142 bytes --]

> > On Fri, Dec 28, 2001 at 12:50:07PM +0100, Ralf Habacker wrote:
> > >> -----Original Message-----
> > >> From: Jason Tishler [mailto:jason@tishler.net]
> > >> On Wed, Dec 26, 2001 at 09:08:49PM +0100, Ralf Habacker wrote:
> > >> > On analysing this problem I added an option "-l" to the rebase tool to
> > >> > list dll's imagebase and -size without rebasing. It's very interesting
> > >> > to see how MS chooses there Imagebase.
> > >>
> > >> What about the following alternative solution:
> > >>
> > >>     $ objdump -p foo.dll | egrep '(ImageBase|SizeOfImage)'
> > >>     ImageBase               68000000
> > >>     SizeOfImage             0003f000
> > >
> > >Try it with a recent objdump and a dll with auto-import variables and you will see that
> > >objdump crashes. :-(
> >
> > Seems to work fine with the distributed version of binutils.  I tried
> > this with cygncurses6.dll.

Yes this work, because this lib provides an auto-importable var. But try a lib which depends
on this lib, than objdump will fail with a segment violation.
This is an example from cygkdecore-3.dll (the kdecore dll of kde 2.2.1) which uses
qt-2.3.dll, which exports such auto-importable vars
....
 001530b4       0017dfd4 00000000 00000000 0018814c 00002b13

        DLL Name: qt-2-3.dll
        vma:  Hint/Ord Member-Name
        180554    842  _7QString$null

Program received signal SIGSEGV, Segmentation fault.
bfd_getl32 (addr=0xa011928 "®þ\"") at libbfd.c:1059
1059    libbfd.c: No such file or directory.
        in libbfd.c
(gdb) bt
#0  bfd_getl32 (addr=0xa011928 "®þ\"") at libbfd.c:1059
#1  0x0045bccf in _bfd_pe_print_private_bfd_data_common (abfd=0xa011928,
    vfile=0x6109f25c) at peigen.c:1846
#2  0x0043cc94 in pe_print_private_bfd_data (abfd=0xa011928, vfile=0x6109f25c)
    at peicode.h:365
#3  0x0040557d in dump_bfd_private_header (abfd=0xa011928) at ./objdump.c:2029
#4  0x00405693 in dump_bfd (abfd=0xa011928) at ./objdump.c:2059
#5  0x0040591c in display_bfd (abfd=0xa011928) at ./objdump.c:2140
#6  0x00405a75 in display_file (
    filename=0x22feae "/opt/kde2/bin/cygkdecore-3.dll", target=0x0)
    at ./objdump.c:2195
#7  0x004074a6 in main (argc=3, argv=0xa0118c8) at ./objdump.c:2942
#8  0x61003f6e in dll_crt0_1 () at ../../../src/winsup/cygwin/dcrt0.cc:769
#9  0x61004262 in _dll_crt0 () at ../../../src/winsup/cygwin/dcrt0.cc:863
#10 0x610042a1 in dll_crt0 (uptr=0x0)
    at ../../../src/winsup/cygwin/dcrt0.cc:876
#11 0x00487bcf in cygwin_crt0 ()
#12 0x0040103d in mainCRTStartup ()
#13 0x77e892a6 in _system_dlls__ ()

0xa011928:      0x0022feae
0xa01192c:      0x00440fd4
0xa011930:      0x0a011764
0xa011934:      0x00000001
0xa011938:      0x00000001
0xa01193c:      0x0a011928
0xa011940:      0x0a011928
0xa011944:      0x00184600
0xa011948:      0x00000000
0xa01194c:      0x00000000
0xa011950:      0x00000000
0xa011954:      0x00000000
0xa011958:      0x00000001
0xa01195c:      0x00000001
0xa011960:      0x00000133
0xa011964:      0x00000000

The following is an extract of a debugging session.

(gdb) c
Continuing.
        The Import Address Table is identical

 001530b4       0017dfd4 00000000 00000000 0018814c 00002b13

        DLL Name: qt-2-3.dll
        vma:  Hint/Ord Member-Name
        180554    842  _7QString$null
Breakpoint 6, pe_print_idata (abfd=0xa011928, vfile=0x6109f25c)
    at peigen.c:1222
1222          if (hint_addr != first_thunk && time_stamp == 0)
(gdb) n
1227              idx2 = first_thunk - adj;
(gdb)
1224              int differ = 0;
(gdb)
1227              idx2 = first_thunk - adj;
(gdb)
1229              for (j = 0; j < datasize; j += 4)
(gdb)
1233                  bfd_vma hint_member = 0;
(gdb)
1236                  if (hint_addr != 0)
(gdb)
1237                    hint_member = bfd_get_32 (abfd, data + idx + j);
(gdb)
1238                  iat_member = bfd_get_32 (abfd, data + idx2 + j);
(gdb)
Program received signal SIGSEGV, Segmentation fault.
bfd_getl32 (addr=0xa011928 "®þ\"") at libbfd.c:1059
1059      v |= (unsigned long) addr[1] << 8;

Appended is a little testapp, that shows the bug with ncurses6.

May be that helps identifing the bug.

Regards Ralf

[-- Attachment #2: objdumptest.tar.bz2 --]
[-- Type: application/octet-stream, Size: 477 bytes --]

[-- Attachment #3: Type: text/plain, Size: 214 bytes --]

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2002-01-03  9:25         ` Ralf Habacker
@ 2002-01-03 13:42           ` Robert Collins
  2002-01-04  6:18             ` Jason Tishler
  0 siblings, 1 reply; 12+ messages in thread
From: Robert Collins @ 2002-01-03 13:42 UTC (permalink / raw)
  To: Cygwin, Jason Tishler

Ah-ha!

Jason, heres a thought: what if MS's rebase is trashing the non-standard
auto-export address offset information...


Rob



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2002-01-03  5:27       ` Robert Collins
@ 2002-01-04  6:10         ` Jason Tishler
  0 siblings, 0 replies; 12+ messages in thread
From: Jason Tishler @ 2002-01-04  6:10 UTC (permalink / raw)
  To: Robert Collins; +Cc: Ralf Habacker, Cygwin

Rob,

On Fri, Jan 04, 2002 at 12:27:12AM +1100, Robert Collins wrote:
> Does the MS solution need .dll's not present on win95a ?

The following:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/imagehlp_1hut.asp

seems to indicate that use of imagehlp.dll is OK even on Windows 95.
Specifically, it states:

    Requirements:
        ...
        Windows 95/98/Me: Included in Windows 95 and later.
        ...

Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: rebase addon - Bas and Size listing of dll's without rebasing
  2002-01-03 13:42           ` Robert Collins
@ 2002-01-04  6:18             ` Jason Tishler
  0 siblings, 0 replies; 12+ messages in thread
From: Jason Tishler @ 2002-01-04  6:18 UTC (permalink / raw)
  To: Robert Collins; +Cc: Cygwin

Rob,

On Fri, Jan 04, 2002 at 08:42:32AM +1100, Robert Collins wrote:
> Jason, heres a thought: what if MS's rebase is trashing the non-standard
> auto-export address offset information...

I don't think so -- at least for the following example:

    $ gcc -shared -Wl,--enable-auto-image-base build/temp.cygwin-1.3.6-i686-2.2/_cursesmodule.o -L/usr/local/lib -L.  -lncurses -lpython2.2 -o build/lib.cygwin-1.3.6-i686-2.2/_curses.dll
    Warning: resolving _stdscr by linking to __imp__stdscr (auto-import)
    Warning: resolving _LINES by linking to __imp__LINES (auto-import)
    Warning: resolving _COLS by linking to __imp__COLS (auto-import)
    Warning: resolving _newscr by linking to __imp__newscr (auto-import)
    Warning: resolving _COLORS by linking to __imp__COLORS (auto-import)
    Warning: resolving _COLOR_PAIRS by linking to __imp__COLOR_PAIRS (auto-import)
    $ cd build/lib.cygwin-1.3.6-i686-2.2
    $ objdump -p _curses.dll | fgrep ImageBase
    ImageBase               6ba40000
    $ rebase -d -b 0x68000000 -o 0x10000 _curses.dll
    _curses.dll: new base = 67fc0000, new size = 40000
    $ objdump -p _curses.dll | fgrep ImageBase                                   
    ImageBase               67fc0000

So, it appears that cygcurl-2.dll is not tolerating a rebase for other
reasons.

Jason

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2002-01-04 14:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-26 14:01 rebase addon - Bas and Size listing of dll's without rebasing Ralf Habacker
2001-12-27 10:22 ` Jason Tishler
2001-12-27 18:34   ` Robert Collins
2002-01-03  5:24     ` Jason Tishler
2002-01-03  5:27       ` Robert Collins
2002-01-04  6:10         ` Jason Tishler
2001-12-28  5:48   ` Ralf Habacker
2001-12-28 10:24     ` Christopher Faylor
2001-12-29  3:22       ` Ralf Habacker
2002-01-03  9:25         ` Ralf Habacker
2002-01-03 13:42           ` Robert Collins
2002-01-04  6:18             ` Jason Tishler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).