From: "jonathan forbes" <jonathan.forbes@canrem.com>
Subject: sas/c 6.1 -large libs
Reply-To: "jonathan forbes" <jonathan.forbes@canrem.com>
Organization: Canada Remote Systems
Distribution: comp
Date: 1 Jan 93 22:47:11 EST

I have been experimenting with SAS/C 6.1's support for making shared
libraries (with one global data area).

Although everything seems to work just fine for small libraries (tiny
ones which I tried for testing), for a large library (final output size
about 85K) I have run into some problems.

For the past couple of years, I haven't used the SAS/C shared library
support modules (LIBINIT.O, LIBENT.O) but rather have continued to
expand upon the output of a rather ancient librarymaker program [I
stopped using the librarymaker over a year ago since it couldn't handle
> 128 functions in a library, but it was easy enough to see what it was
doing and just add things to it manually].

The reason I'd like to use the SAS/C supported method is that it seems
to produce a smaller output file size; perhaps because A4 is being
loaded off A6 (the librarybase pointer) instead of LEA _LinkerDB, or
maybe just more efficient startup code (LibInit, LibOpen, etc.)  Plus,
I would feel more comfortable doing it in the SAS/C supported way.

Now, the problem is that many functions simply hang when called.  In
order to try to narrow down the problem, I took one particular routine
(let's call it "MyTestRoutine") and made it an almost do-nothing
routine:

void __asm MyTestRoutine(register __a0 UBYTE *Str)
{
   strcpy(Str, "This is a test");
}

(I'm compiling with SAVEDS, LIBCODE, NOSTKCHK and various other
options).

I then wrote a small test program which opened the library, called the
routine with a pointer to a blank string, and then printed what it got.
Most of the time I got garbage back, and the times I didn't get garbage,
my test program just hung after calling the routine.

I disassembled the library routine, and it looked just fine.

So, thinking it might be the size of my library, I replaced most of the
library functions with empty functions, and somewhere around the 27-35K
range of output file size, it no longer hung [but it didn't output the
correct string either].

I also tried creating a completely new library with just one routine
(the one above), and it worked fine.

The big library has about 170 routines in it, so I don't know if this is
a problem for SAS/C.

I also have some assembly language routines which are linked in, and
which use global data, but they do it in the proper way:

LEA _LinkerDB(a6),a4

[saving a4 first, of course]

I did some poking around in LIBINIT.O, and although I didn't understand
everything there, it does seem to be doing some kind of relocation;
perhaps it's choking when relocating the assembly language routines?

I'm extremely doubtful it's a problem of SAS/C 6.1, because I've found
that errors which seem like compiler errors generally aren't, but I'm
rather confused about where the problem might be.

Even stranger, the test program never hangs it Enforcer and MungWall are
run in the background [although it still doesn't produce the correct
output].

Basically, the thing which confuses me the most, is that a simple jump
to a library function which does a strcpy simply doesn't work.  On the
other hand, everything is fine and dandy if I use the old librarymaker
method.

Any help would be much appreciated.
--
Canada Remote Systems  - Toronto, Ontario
World's Largest PCBOARD System - 416-629-7000/629-7044