[comp.sys.apollo] Shared library madness

mse@ttsi.lonestar.org (Mark Evans) (06/29/91)

I need help from the experts in understanding some real crazy
happenings in my 400S system, DomainOS SR10.3.4 (PSK8 + PSK8X
+ misc patches installed).  I ran into this problem when 
rebuilding epoch that I can demonstrate with the following 
simple program:

    int initialized;
    main()
    {
	initialized++;
	printf("%d\n", initialized);
    }

If I build this as follows:

    cc -c foo.c
    ld /usr/lib/crt0.o foo.o -lc

I get an ld warning:
    ld warning: Symbol initialized will link to shared library
    
When I run a.out, I get the following output:

    65537
    
For reasons I don't understand, 'initialized' gets resolved
to a shared library even though it is defined in my program.
Running esa confirms that 'initialized' is somewhere out
there in the installed library.  Now hold onto your seat.
This is all predicated on being in the DM environment.  If I
switch over to the X environment (ala borrow mode) and run
esa, 'initialized' is not found and the example above loads
normally and produces the expected output (1) when run.  What
in the heck is going on?

I discovered through experimentation that explicitly initializing
'initialized' to 0 when defined causes this variable to go from a
common section to data section (revealed by nm) and the problem 
goes away.  Can you explain why the compiler (cc 6.7) 
discriminates initialized globals from uninitialized globals?

Anyway, I'm curious.  How can I find out what shared library
'initialized' is in?  I tried running nm on all the files
indicated by llib -a but initialized didn't show up in the 
output.

Please tell me I'm not going crazy.

-- 
Mark S. Evans                 Tandem Telecommunications Systems Inc.
Phone: 214-516-6201           850 E. Central Parkway
Fax:   214-516-6801           Plano, TX 75074
Mail:  mse@ttsi.lonestar.org