This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
RE: [patch]: Add MS __ImageBase symbol to 32-bit pe.em
- From: Kai Tietz <Kai dot Tietz at onevision dot com>
- To: Jerker Bäck <jerker dot back at telia dot com>
- Cc: binutils at sourceware dot org
- Date: Sat, 3 Nov 2007 10:58:34 +0100
- Subject: RE: [patch]: Add MS __ImageBase symbol to 32-bit pe.em
> The usual expression is:
>
> #if defined(_M_IA64)
> #pragma section(".base", long, read)
> extern "C" __declspec(allocate(".base"))
> const IMAGE_DOS_HEADER __ImageBase;
> #else
> extern "C" const IMAGE_DOS_HEADER __ImageBase;
> #endif
>
> and used like:
> PIMAGE_DOS_HEADER dhd = &__ImageBase;
> or:
> HINSTANCE hModulehandle = (HINSTANCE)&__ImageBase; // e.g. ATL
>
> Where __ImageBase represents the PE DOS header of a binary. This
> variable is not defined anywhere, nor is it documented. ATL uses
> this method to get the module handle (HINSTANCE) of the current
> process, thus it must always point to the current executable image,
> right? As I understand, using __ImageBase in a DLL, you will get the
> PE header of the executable.
>
> I always thought it was defined by the MS compiler. So this variable
> is valid for mingw also?
The variable is in mingw the ld symbol '__image_base__'. So the definition
for current ld (before this patch) would be something like.
#define __ImageBase _image_base__
extern "C" IMAGE_DOS_HEADER __ImageBase;
One leading underscore needs to be added for gcc, which does not
underscore user-variables.
You can find some more information about this symbol, when you take a look
at the 'delayhlp.cpp' file of the MS include folder.
Cheers,
i.A. Kai Tietz
| (\_/) This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.
------------------------------------------------------------------------------------------
OneVision Software Entwicklungs GmbH & Co. KG
Dr.-Leo-Ritter-StraÃe 9 - 93049 Regensburg
Tel: +49.(0)941.78004.0 - Fax: +49.(0)941.78004.489 - www.OneVision.com
Commerzbank Regensburg - BLZ 750 400 62 - Konto 6011050
Handelsregister: HRA 6744, Amtsgericht Regensburg
KomplementÃrin: OneVision Software Entwicklungs Verwaltungs GmbH
Dr.-Leo-Ritter-StraÃe 9 â 93049 Regensburg
Handelsregister: HRB 8932, Amtsgericht Regensburg - GeschÃftsfÃhrer:
Ulrike DÃhler, Manuela Kluger