Specifying a base address
Tue Nov 30 23:39:00 GMT 1999
Thanks Mumit. That worked.
A few comments:
- I'm using 'libtool' to build my binaries. I don't have much of a choice
because it's an integral part of the project that I'm working on.
Unfortunately, 'libtool' has a bad bug where it strips certain command line
switches on the final link. This seems to include the -Wl switch, which is
- The reason I asked this question to begin with was because of a strange
thing I was seeing in 'gdb' (both Cygwin and Mingw32 versions). I have an .exe
binary that ends up explicitly loading 2 DLLs, both of which had the same base
image addresses, by default. The problem that I saw is that after the second
DLL loads and relocates, the symbol names in the stack were corrupt. The
symbols names for the first DLL were coming out of the address space of the
second DLL. Thus, I wanted to change the image base address before the DLLs
were automatically relocated to verify that this would resolve the problem in
'gdb', and it did. I don't know if I really care about always building with
the base address explicitly set.
- Prior to posting the question, I DID TRY to find documentation on ld. The
web pages on Cygwin's site don't cover any i386pe specific options. However, I
did do a 'ld --help', and I really must have been blind because I now see
the --image-base switch, although it somehow eluded me before. Thanks again.
- About EDITBIN. I just did something wrong when I tried before. When I tried
again, it worked.... sort of... First of all, I DID use the /rebase option. I
can't tell which option to use if that's not the one. After using /rebase, I
was able to get the base address to change, but this messed up things in 'gdb'
even worse. 'gdb' was unable to read any symbols from any DLL that I loaded
whose address was not the original before EDITBIN (i.e. 0x10000000). So I
really don't know what to think about this.
> -----Original Message-----
> From: Mumit Khan [ mailto:email@example.com ]
> Sent: Thursday, November 04, 1999 9:30 PM
> To: Jon Leichter
> Cc: firstname.lastname@example.org
> Subject: Re: Specifying a base address
> "Jon Leichter" <email@example.com> writes:
> > Forgive me if this has been asked before. I searched the archives
> but didn't
> > come up with an answer.
> > With the Cygwin set of compiler utilities, how does one go about
> setting the
> > base image address for a DLL?
> Pass the --image-base=<BASE_ADDR> to the linker. If you're using GCC to
> create the DLL, use -Wl,--image-base=<BASE_ADDR>
> $ gcc -Wl,--image-base=0x66000000 [... rest ...]
> > Is there a particular tool that I can use to change the base image address
> > after the DLL is built? For instance, MSVC provides a tool called
> EDITBIN tha
> > t
> > does just that. (By the way, I tried to use EDITBIN on a DLL that
> I built wit
> > h
> > gcc, and EDITBIN failed).
> EDITBIN has always worked for me, so perhaps something is wrong with the
> DLL (eg,. due to a bug in the linker)? There's also REBASE, but I've never
> used it.
> > If there is no tool, is there a way to specify the base address
> at link time?
> > Do I need to provide a .def file for this?
> You can use a .DEF file, but I prefer either (1) using dllwrap, which
> takes an --image-base parameter, and if not supplied, creates an image
> base by hashing the output filename, or (2) supply -Wl,--image-base to
> GCC or --image-base to the linker. See the documentation on the linker
> (ld) for more info.
Want to unsubscribe from this list?
Send a message to firstname.lastname@example.org
More information about the Cygwin