From: winalski@adserv.enet.dec.com (Paul S. Winalski)
Subject: Re: VMS shareable images q.- Please help
Reply-To: winalski@adserv.enet.dec.com (Paul S. Winalski)
Organization: Digital Equipment Corporation, Nashua NH
Date: Tue, 29 Sep 1992 19:28:14 GMT


NOTE: I am cross-posting this to comp.lang.fortran since that's where the
original posting was, but I don't follow that group.  Please send any follow-ups
either to comp.os.vms or mail them to winalski@tle.enet.dec.com.

In article <1992Sep28.153400.1@slacvx.slac.stanford.edu>,
fairfield@slacvx.slac.stanford.edu writes:
|>
|>   We recently experienced a problem with our shareable images in the
|>VAX/VMS system. In my group we are writing applications for polymerization
|>reactors (using VAX FORTRAN); all of the low and middle level stuff is
|>organized in shareable images. A few months ago some of us added C
|>allocation/deallocation etc routines in the libraries of our package.
|>Creating shareable images for our libraries was still not a problem and
|>we were using the C rtl as a shareable when linking (i.e. the options
|>file for linking to produce a shareable was containing the line:
|>SYS$SHARE:VAXCRTL.EXE/SHARE
|>and everything was working fine... till I figured out that we cannot ship
|>our product to our sponsors since if they do not have the VAX C compiler
|>the references of our executables and shareables to the VAXCRTL.EXE will
|>crash the program. So we decided to use the library VAXCRTL.OLB instead.

VAXCRTL.EXE ships as part of VMS, not with the VAX C compiler.  Your sponsors
shouldn't need VAX C installed on their systems for your program to work.  In
what way is the program "crashing"?

You should never have to link against the .OLB version of the VAX C RTL unless
you're writing inner-mode code.

|>Well,we did that and we got errors like the one in the example follows.
|>TO demonstrate the problem, I use
|>	test0.for              \  will be used together
|>	test1.c                /
|>	test2.c			- will become a shareable using test2.com
|>
|>===========================================================================
|>
|>test2.c
|>---------
|>#include <stdio.h>
|>
|>void myprint(double *y)
|>{
|>   printf("\n\t\t This is: %g", *y);
|>   return;
|>}
|>
|>test1.c
|>-------
|>#include <math.h>
|>#include <stdio.h>
|>
|>void calc(double *x, double *y)
|>{
|>  *y = sqrt(*x);
|>  printf("\n\n\t Square-root calculation completed");
|>  return;
|>}
|>
|>test0.for
|>---------
|>	program test0
|>	double precision x,y
|>
|>	x = 10.0
|>	call calc(x, y)
|>	call myprint(y)
|>	end
|>
|>==============================================================================
|>
|>Now , I use the following test2.com procedure to generate the shareable:
|>
|>test2.com
|>---------
|>$ cc/NoOpt test2.c
|>$ link/nodebug/shareable=test2.exe -
|>   test2.obj, -
|>   sys$library:vaxcrtl.olb/library, -
|>   sys$input/option
|>UNIVERSAL = myprint
|>$ exit
|>
|>and with
|>@TEST2.COM
|>voila I have the test2.exe shareable image. Ok, I use the test0.com to
|>build the final executable:
|>
|>test0.com
|>---------
|>$ fortran test0.for
|>$ cc/NoOptimize test1.c
|>$ link/exec=test0.exe -
|>     test0.obj, test1.obj, sys$library:vaxcrtl.olb/library, -
|>     sys$input/option
|>dsk$user:[dafniotis.fortran.scratch]test2.exe/share
|>$ exit
|>
|>and using
|>@TEST0.COM
|>
|>I get the error:
|>%LINK-E-OUTSIMG, attempted store location %X0000A024 is outside image binary
|>(%X00000000 to %X00000000)
|>     in psect STDIN module C$VAXCIO file SYS$COMMON:[SYSLIB]VAXCRTL.OLB
|>
|>
|>As you might have guessed the %X0000A024 appears in the map of the TEST2
|>shareable image (test2.exe) for the psect STDIN. I have tried several
|>solutions (using CLUSTER, declaring STDIN with LCL attribute etc) to no
|>effect. Of course the easy solution would be to let out of the TEST0.COM
|>the reference to the C RTL library, finding out the references the linker
|>did not resolve (from the C RTL), then going to the TEST2.COM and force
|>the linker to include the necessary modules from the VAXCRTL.OLB and declare
|>the unresolved references as UNIVERSAL for the TEST2.EXE. Indeed this worked,
|>but it is MESSY!
|>
|>  PLEASE HELP! What am I doing wrong?

The problem here is that the module C$VAXCIO in VAXCRTL.OLB initializes the
variable stdin, and that module (C$VAXCIO) is already part of your test2.exe
shareable image.  The Linker has correctly resolved stdin against the version
in your shareable image, but it complains about the attempted initialization.

There are only two solutions:  (1) avoid any use of stdio routines (such as
printf) outside of your shareable image, or (2) link against VAXCRTL.EXE
instead of VAXCRTL.OLB.  (2) is the preferred solution.  As I stated above,
this shouldn't cause you any problems in bringing your programs to other
VMS systems.

--PSW