This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch]: Add MS __ImageBase symbol to 32-bit pe.em


Kai Tietz wrote:
Hi Pedro,

Kai Tietz wrote:

> +#define MSIMAGEBASEOFF 2
> + D(ImageBase,"__ImageBase", NT_EXE_IMAGE_BASE),
> D(SectionAlignment,"__section_alignment__",
PE_DEF_SECTION_ALIGNMENT),
 >    D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
 >    D(MajorOperatingSystemVersion,"__major_os_version__", 4),
 > @@ -374,6 +376,8 @@ set_pe_name (char *name, long val)
 >     {
 >       init[i].value = val;
 >       init[i].inited = 1;
 > +     if (strcmp (name,"__image_base__") == 0)
 > +       set_pe_name ("__ImageBase", val);
 >

Shouldn't it be ___ImageBase (3 underscores) on i386 9x/NT
Windows, as opposed to x64, which I think I've read that it
is not underscored?  This file is also used for arm-wince,
which is not underscored.  (Although this __ImageBase thing
isn't as useful in Windows CE, because HMODULE == base address
isn't true there.)

You may use U take care of the differences between targets,
it's defined in the top of pe.em:

#define U(S) ${INITIAL_SYMBOL_CHAR} S

Where INITIAL_SYMBOL_CHAR is "_" in i386.

Like so:
+       set_pe_name (U ("__ImageBase"), val);



The symbol is defined by MS as 'extern IMAGE_DOS_HEADER _ImageBase'. So the name is correct. I will add the U.

Where is that documented? It wouldn't be the first time MS docs wheren't exactly in line with reality...

Did you try it? This doesn't build here with MSVC2005.

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

EXTERN_C IMAGE_DOS_HEADER _ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&_ImageBase)

int _tmain(int argc, _TCHAR* argv[])
{
    printf ("%p\n", HINST_THISCOMPONENT);
    return 0;
}

>Linking...
>main.obj : error LNK2001: unresolved external symbol __ImageBase

But, two underscores on __ImageBase on the C/C++ side links correctly.

For Windows CE and arm-wince __image_base__ is invalid too (the same thing as for _ImageBase).

I know. It hasn't bothered me enough yet to fix it ;)


No, for x64 it is underscored, too.

Humm, this is what I remembered reading: http://lists-archives.org/mingw-users/07903-leading-underscore-or-not.html

Cheers,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]