From: Nigel Stephens Date: Tue, 20 Sep 94 16:06:12 +0100 To: Cuthalion / Sliced Bread Cc: S_Eckart AT lis DOT e-technik DOT tu-muenchen DOT de, djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: strange linker behavior References: <199409201040 DOT GAA22528 AT max DOT tiac DOT net> Cuthalion / Sliced Bread (enrico AT max DOT tiac DOT net) writes: > SE> int delay; > SE> > SE> main() > SE> { > SE> printf("%d\n",delay); > SE> } > SE> > SE> I would have expected to get a 0 as output, and in fact this was the > SE> case until v1.11m5. The current version prints a large negative > SE> number... > I don't think that there's any provision in the C language for what > uninitialized variables > start out as. delay could end up as anything! The C language does specify that all such variables should have the value zero. This problem *may* be due to the following bug in GO32, which I found causes random "DPMI: not enough memory" errors. In some cases GO32 calculates the wrong starting address for the .bss segment (due to the linker rounding it up to the next 8 byte boundary). This causes the last few bytes of the bss segment remain uninitialised. For me the final last variable in .bss is often _stklen, and if this is non-zero when running under DPMI then the _setstack() routine (called by the startup code) attempts to allocate a vast stack, which of course fails and gives the above error. It is possible that for other programs other variables will not be completely zeroed. Use "nm -n" to see which variables are at the end of .bss. The following patches to go32 1.12m1 fix the above problem, together with the following minor cosmetic changes: 1) Correct the final character of the "topline" info. 2) When "meminfo" is set, display the amount of conventional memory available, as well as the extended/vcpi memory. 3) Indicate when GO32 does not have enough conventional memory available (as opposed to extended, etc) _________________________________________________________________________ Nigel Stephens, Algorithmics Ltd, 3 Drayton Park, London, N5 1NU, England phone: +44 71 700 3301 fax: +44 71 700 3400 email: nigel AT algor DOT co DOT uk *** 1.3 1994/09/07 17:48:05 --- paging.c 1994/09/20 14:06:54 *************** *** 104,110 **** "emu" }; #endif ! static char achar[MAX_AREA] = "tdbmsg?e"; word32 far *pd = 0; word8 pd_seg[1024]; --- 104,110 ---- "emu" }; #endif ! static char achar[MAX_AREA] = "tdbmsg??e"; word32 far *pd = 0; word8 pd_seg[1024]; *************** *** 495,503 **** if (debug_mode) fprintf(stderr, "%ld+", aouthdr.dsize); ! areas[A_bss].first_addr = areas[A_data].last_addr + 1; areas[A_bss].foffset = -1; areas[A_bss].last_addr = areas[A_bss].first_addr + aouthdr.bsize - 1; if (debug_mode) fprintf(stderr, "%ld = %ld\n", aouthdr.bsize, aouthdr.tsize+aouthdr.dsize+aouthdr.bsize); --- 495,507 ---- if (debug_mode) fprintf(stderr, "%ld+", aouthdr.dsize); ! if (filehdr.f_magic == 0x14c) ! areas[A_bss].first_addr = scnhdr[2].s_vaddr + ARENA; ! else ! areas[A_bss].first_addr = areas[A_data].last_addr + 1; areas[A_bss].foffset = -1; areas[A_bss].last_addr = areas[A_bss].first_addr + aouthdr.bsize - 1; + if (debug_mode) fprintf(stderr, "%ld = %ld\n", aouthdr.bsize, aouthdr.tsize+aouthdr.dsize+aouthdr.bsize); *** 1.3 1994/09/07 17:48:05 --- valloc.c 1994/09/07 17:51:18 *************** *** 186,195 **** intr(0x21, &r); /* lol == size of largest free memory block */ lol = r.r_bx; /* printf("max pages is %u\n", lol); */ if (lol < 8*256) { ! fprintf(stderr, "Error: not enough memory to run go32!\n"); exit(1); } --- 186,198 ---- intr(0x21, &r); /* lol == size of largest free memory block */ lol = r.r_bx; + if (show_memory_info) + fprintf(stderr, "Conventional memory available: %ld Kb\n", + lol * 16L / 1024L); /* printf("max pages is %u\n", lol); */ if (lol < 8*256) { ! fprintf(stderr, "Error: not enough conventional memory to run go32!\n"); exit(1); }