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


Hi Pedro,

> 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.

AFAIC read your version is correct. There must be two underscores in the 
header and therefore three in ld. I took a look at the MS headers (as 
Jerker did) and MS defines it with two underscores 8|
I will add the same issue to pep.em, too. Because I defined it there 
false, too.

> > 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
I can just tell, that for the x86_64 version underscores are generated for 
symbols. And this target has the same base (for this configuration) as the 
32-bit version. So IMHO there are underscores.

ChangleLog for /ld/emultempl:

2007-11-02  Kai Tietz  <kai.tietz@onevision.com>

        * emultempl/pe.em: (init): Add __ImageBase symbol.
        (MSIMAGEBASEOFF): New.
        (set_pe_name): Keep __image_base and __ImageBase value synch.
        (_set_symbols): Likewise.
        * emultempl/pep.em: Likewise.

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

Attachment: imagebase32.txt
Description: Text document


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