Subject: SIGSEGV and memory (was: Strange goings on)
From: [email-masked] (Keet / Foxbird)

10 Mar 1998 23:02:01 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
To: Sergey Okhapkin <[email-masked]>,
        "[email-masked]" <[email-masked]>

At 11:07 AM 3/10/98 +0300, Sergey Okhapkin wrote:
>Trap is somewhere in newlib's code. For example, string manipulation 
>functions may trap when NULL pointer is passed as an argument. Check it! 
>Gdb's "backtrace" command will help you.

Okay, I decided to try this thing out again, and for some odd reason the
windowed version of GDB freezes.. so I ran the console version and got the
program running and hit SIGSEGV again in the _size_of_stack_reserve__ ()
function.. so I did backtrace and bt and everything else I could think of
and I get: 

#0  0x10047c70 in _size_of_stack_reserve__ ()
Cannot access memory at address 0x2000000.

So appearently there isn't much more to go on than that. From B18, I get
the following info in response to my 'invalid file format' and this might
explain some of it:

The executable you sent me has a bss section (unitialized data) size of
3,523,560 bytes. This seems huge. Is your program using all that static
data as uninitialized arrays?

In any case, windows gets confused, because the extended header tells it that
the heap reserve size is only 1,048,576 (1MB) standard size. Maybe the reason
for this problem is that the linker doesn't extend the size of the heap
reserve
size to the sum of the bss +data sections. Your initialized data section is
small (5K or so).

I cc this message to Ian Taylor at cygnus. He will be more able to see why
this
link is failing. Appended is the description of the executable as given by
my tools:

Dump of file XSW.EXE (420119 bytes)

File Header
  Machine:                      014C (i386)
  Number of Sections:           6
  TimeDateStamp:                34F364F3  (Wed Feb 25 01:25:23 1998)
  PointerToSymbolTable:         00379904
  NumberOfSymbols:              00001806
  String Table File Offset      412412
  SizeOfOptionalHeader:         00E0
  Characteristics:              0107
    RELOCS_STRIPPED
    EXECUTABLE_IMAGE
    LINE_NUMS_STRIPPED
    32BIT_MACHINE

Optional Header
  Magic                              0x10b        267
  linker version                     2.55
  size of code                       0x58E00      364032
  size of initialized data           0x2200       8704
  size of uninitialized data         0x35C400     3523584
  entrypoint RVA                     0x1000       4096
  base of code                       0x1000       4096
  base of data                       0x5A000      368640
  image base                         0x400000     4194304
  section align                      0x1000       4096
  file align                         0x200        512
  required OS version                4.00
  image version                      1.00
  subsystem version                  4.00
  Win32 Version                      0x0
  size of image                      0x3BC000     3915776
  size of headers                    0x400        1024
  checksum                           0x0
  Subsystem                          0x3 (Windows character)
  DLL flags                          0x0
  stack reserve size                 0x2000000    33554432
  stack commit size                  0x1000       4096
  heap reserve size                  0x100000     1048576   <<<<<look here
  heap commit size                   0x1000       4096
  loader flags                       0x0
  RVAs & sizes                       0x10

Data Directory
  EXPORT       rva: 0x0         size:        0
  IMPORT       rva: 0x3B9000    size:     2700
  RESOURCE     rva: 0x0         size:        0
  EXCEPTION    rva: 0x0         size:        0
  SECURITY     rva: 0x0         size:        0
  BASERELOC    rva: 0x0         size:        0
  DEBUG        rva: 0x0         size:        0
  COPYRIGHT    rva: 0x0         size:        0
  GLOBALPTR    rva: 0x0         size:        0
  TLS          rva: 0x0         size:        0
  LOAD_CONFIG  rva: 0x0         size:        0
  unused       rva: 0x0         size:        0
  unused       rva: 0x0         size:        0
  unused       rva: 0x0         size:        0
  unused       rva: 0x0         size:        0
  unused       rva: 0x0         size:        0

Section Table
  01 .text      VirtSize: 00363576  VirtAddr:  00004096 0x00001000
    raw data offs: 01024 raw data size: 364032
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$60000020
      CODE  MEM_EXECUTE  MEM_READ

  02 .bss       VirtSize: 03523560  VirtAddr:  00368640 0x0005a000
    raw data offs: 00000 raw data size: 00000
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$C0000080
      UNINITIALIZED_DATA  MEM_READ  MEM_WRITE

  03 .data      VirtSize: 00005284  VirtAddr:  03895296 0x003b7000
    raw data offs: 365056 raw data size: 05632
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$C0000040
      INITIALIZED_DATA  MEM_READ  MEM_WRITE

  04 .idata     VirtSize: 00002700  VirtAddr:  03903488 0x003b9000
    raw data offs: 370688 raw data size: 03072
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$C0000040
      INITIALIZED_DATA  MEM_READ  MEM_WRITE

  05 .stab      VirtSize: 00002232  VirtAddr:  03907584 0x003ba000
    raw data offs: 373760 raw data size: 02560
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$00000202
      LNK_INFO

  06 .stabstr   VirtSize: 00003215  VirtAddr:  03911680 0x003bb000
    raw data offs: 376320 raw data size: 03584
    relocation offs: 00000000  relocations:   00000000
    line # offs:     00000000  line #'s:      00000000
    characteristics: 0x$00000202
      LNK_INFO

Imports Table size:3072
  offset 370688 libX11.dll
  Hint/Name Table: 003B9088
  TimeDateStamp:   00000000
  ForwarderChain:  00000000
  First thunk RVA: 003B9214 (delta: 396 0x18c) 
  Ordn  Name
    11  XAllocColor 3b939c
   106  XDisplayName 3b93ac
   116  XDrawArc 3b93bc
   120  XDrawLine 3b93c8
   122  XDrawPoint 3b93d4
   124  XDrawRectangle 3b93e4
   127  XDrawString 3b93f8
   156  XFillArc 3b9408
   158  XFillPolygon 3b9414
   159  XFillRectangle 3b9424
   169  XFreeColormap 3b9438
   180  XFreePixmap 3b9448
   265  XLoadQueryFont 3b9458
   274  XMapRaised 3b946c
   275  XMapSubwindows 3b947c
   276  XMapWindow 3b9490
   283  XMoveWindow 3b94a0
   290  XOpenDisplay 3b94b0
   293  XParseColor 3b94c0
   294  XParseGeometry 3b94d0
   317  XQueryPointer 3b94e4
   323  XReadBitmapFileData 3b94f4
   348  XSelectInput 3b950c
   366  XSetFont 3b951c
   368  XSetForeground 3b9528
    40  XCheckTypedEvent 3b953c
   392  XSetStandardProperties 3b9550
   409  XSetWindowBackground 3b956c
   410  XSetWindowBackgroundPixmap 3b9584
   447  XUnmapSubwindows 3b95a4
   448  XUnmapWindow 3b95b8
    47  XClearWindow 3b95c8
    49  XCloseDisplay 3b95d8
    62  XCreateBitmapFromData 3b95e8
    64  XCreateFontCursor 3b9600
    75  XCreateSimpleWindow 3b9614
    76  XCreateWindow 3b962c
    89  XDefineCursor 3b963c
    98  XDestroyWindow 3b964c

  offset 370708 libXext.dll
  Hint/Name Table: 003B912C
  TimeDateStamp:   00000000
  ForwarderChain:  00000000
  First thunk RVA: 003B92B8 (delta: 396 0x18c) 
  Ordn  Name
    11  XShapeCombineMask 3b9660

  offset 370728 libXpm.dll
  Hint/Name Table: 003B9138
  TimeDateStamp:   00000000
  ForwarderChain:  00000000
  First thunk RVA: 003B92C4 (delta: 396 0x18c) 
  Ordn  Name
    12  XpmCreatePixmapFromData 3b9674
    28  XpmReadFileToPixmap 3b9690

  offset 370748 cygwin.dll
  Hint/Name Table: 003B9148
  TimeDateStamp:   00000000
  ForwarderChain:  00000000
  First thunk RVA: 003B92D4 (delta: 396 0x18c) 
  Ordn  Name
    25  __errno 3b96a8
   501  access 3b96b4
   518  atexit 3b96c0
   521  atoi 3b96cc
   522  atol 3b96d4
   526  bzero 3b96dc
   544  close 3b96e4
   560  cygwin32_connect 3b96ec
   566  cygwin32_gethostbyname 3b9700
   582  cygwin32_recv 3b971c
   584  cygwin32_select 3b972c
   589  cygwin32_socket 3b9740
   597  dll_crt0__FP11per_process 3b9754
   619  exit 3b9770
   627  fclose 3b9778
   628  fcntl 3b9784
   639  fgets 3b978c
   640  fileno 3b9794
   648  fopen 3b97a0
   649  fork 3b97a8
   651  fprintf 3b97b0
   653  fputs 3b97bc
   655  free 3b97c4
   662  fstat 3b97cc
   675  getcwd 3b97d4
   679  getenv 3b97e0
   695  getpid 3b97ec
   703  gettimeofday 3b97f8
   711  htons 3b9808
   766  malloc 3b9810
   802  perror 3b981c
   807  printf 3b9828
   823  realloc 3b9834
   882  signal 3b9840
   903  sprintf 3b984c
   908  sscanf 3b9858
   913  strchr 3b9864
   914  strcmp 3b9870
   916  strcpy 3b987c
   921  strlen 3b9888
   926  strncpy 3b9894
   931  strstr 3b98a0
   944  system 3b98ac
   976  usleep 3b98b8
   986  wait3 3b98c4
   994  write 3b98cc

  offset 370768 kernel32.dll
  Hint/Name Table: 003B9208
  TimeDateStamp:   00000000
  ForwarderChain:  00000000
  First thunk RVA: 003B9394 (delta: 396 0x18c) 
  Ordn  Name
   236  GetModuleHandleA 3b98d4

-----------

Anyone out there have any help to offer on this? Is there an .exe editor or
something I can use to play with it and see what becomes of it. Thanks a
million for any replies.

\---------------------------------------------\
 \  Keet  |  [email-masked]            \
  \---------------------------------------------\
   \ http://localsonly.wilmington.net/~keetnet/  \-\
    \---------------------------------------------\ \
       \ Visit MoonGlow MUCK at moonglow.dyn.ml.org  \
        \ on port 8888, or visit our webpage at:      \
      /--\ http://www.moonglow.dyn.ml.org              \
     /    \---------------------------------------------\
    / Furry Code 1.2:                             /
   / FAFCF6fmsw A-- C- D+ H++ M+++ P+ R+         /
  / T++++ W Z Sm++ RL# a# cn++ d+ e# f++++ h#   /
 / iwf++>+++ p* sm#                            /
/---------------------------------------------/
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".