This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


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

crash using _environ from libmsvcrt20/40.a


Hello all,

I'm using cygwin 1.1.4, and I've run into trouble accessing _environ
from libmsvcrt40.a (or libmsvcrt20.a - I don't know what the difference
is).
The demonstration code is trivial:
=============================================
main.c:

extern char **_environ;
int main(void)
{
  while (*_environ)
    printf("%s\n", *_environ++);
  return 0;
}
=============================================
Build command:

gcc main.c -lmsvcrt40 -Wl,-Map,link.map
=============================================
00401044 <_main>:
  401044:	55                   	push   %ebp
  401045:	89 e5                	mov    %esp,%ebp
  401047:	83 ec 08             	sub    $0x8,%esp
  40104a:	e8 99 00 00 00       	call   4010e8 <___main>
  40104f:	90                   	nop    
  401050:	a1 88 10 40 00       	mov    0x401088,%eax
  401055:	83 38 00             	cmpl   $0x0,(%eax)

It's the cmpl that causes STATUS_ACCESS_VIOLATION. 
eax=0x40c425ff
I'm just guessing, but it looks like the value loaded into eax isn't
correct. Changing eax to 0x4040c4 (the place in memory shifted over a
couple of bytes) makes the cmpl succeed. (but a similiar problem happens
at a subsequent instruction).

objdump says that 0x401088 is _environ:

00401088 <__environ>:
  401088:	ff 25 c4 40 40 00    	jmp    *0x4040c4
  40108e:	90                   	nop    
  40108f:	90                   	nop    

From the link map:

 .text          0x00401088        0x8 /usr/lib/libmsvcrt40.a(ds00128.o)
                0x00401088                _environ

 .idata$5       0x004040c4        0x4 /usr/lib/libmsvcrt40.a(ds00128.o)
                0x004040c4                _imp___environ


The real motivation here is that I was mixing msvc and gcc objects, with
references to _environ coming out of the msvc objects. I linked in
libmsvcrt40.a, but the program fails. Then I noticed that even reduced
to a single file it still fails using only the cygwin toolchain. Using
only msvc, this example program works however.

Any clues as to what's gone wrong and how it can be fixed? Has the
linker done something wrong, is the the code in the import libraries at
fault? Or do I need to use some different build flags?
Thanks.

Nigel

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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