Solaris 2.5 dynamic loader questions

Solaris 2.5 dynamic loader questions

Post by ke.. » Sat, 06 Apr 1996 04:00:00



I have a couple questions about Solaris 2.5 shared libraries.  Please

been kind of flaky lately.

1) I have a program prog and 2 shared libraries, small.so and big.so.
Under 2.5 if libraries are loaded in the order small and then big,
they load ok.  If they are loaded in the order big and then small,
I get this error from dlopen:

Dynamic loading error: ld.so.1: prog: fatal: file=small.so:
relocation [R_SPARC_WDISP22] value 0x25fadb (symbol `_cerror') does not fit.

If I use exactly the same program and shared libraries under 2.4 the
loading order doesn't matter.  It seems to me that either

A) the dynamic loader under 2.5 has a bug; or

B) this really does exceed 22 bits of relocation and I am probably
just missing the error on 2.4 because some system libraries are
smaller, or perhaps fewer of them are loaded or they are loaded in a
different order, bringing the address within range.  The code size
alone of big.so is 5,999,472.  2**22 is 4,194,304.  So it is entirely
believable that a 22 bit relocaton field has been exceeded.  (Probably
you can actually handle offsets bigger than 2**22 because they are
going to be at least word aligned, but maybe you need 1 bit for the
sign.  Just guessing about this.)

If it is B), is this related to compiling -pic vs. -PIC?  The
description of these on the CC man page doesn't make it clear whether
this is related.  I can't recompile small.so -PIC since it is a 3rd
party library.  The supplier of this library has been extremely
uncooperative in the past about fixing serious bugs in their products
and I don't think it is worthwhile asking them to build it
differently.  Also, I can't just load small.so first since it depends
on other optional software being present on the system.  The scenario
described above is actually a simplified version of the environment.

Note for gcc users: -pic and -PIC are the same as -fpic and -fPIC.

2) If you have a function f() defined in so.so, and you load so.so
from program basef, and basef also defines a function f(), which is
used?  It appears from the program below that the function in basef is
preferred.

I ask this because small.so (from question 1) is actually quite large itself
(almost 400K of code) because it statically links in and defines _cerror and
most of the rest of libc.  They apparently statically linked it in
thinking it would take precedence over the versions of libc routines
in programs using small.so.  So they have wasted a lot of memory in
small.so with versions of system routines that will never get called.

makefile

all:    basef baseh so.so

basef:  base.cc
        CC -g -o basef base.cc -R. -ldl

baseh:  base.cc
        CC -g -DH -o baseh base.cc -R. -ldl

so.so:  so.cc
        CC -PIC -g -G -o so.so so.cc

clean:
        rm -f base.o basef baseh so.so

base.cc

#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>

#ifdef H
#define f h
#endif

extern "C"
    {
    void f();
    void g();
    }

void error(char *str)
    {
    printf("%s\n", str);
    exit(1);
    }

void f()
    {
    printf("Base function called\n");
    }

int main()
    {
    void *handle;
    void *addr;

    f();
    handle = dlopen("so.so", RTLD_NOW | RTLD_GLOBAL);
    if (!handle)
        error("Couldn't open shared library ./so.so");
    addr = dlsym(handle, "g");
    if (!addr)
        error("Couldn't find func g() in so.so");
    ((void (*)())addr)();
    }

so.cc

#include <stdio.h>
extern "C"
    {
    void f();
    void g();
    }

void f()
    {
    printf("function f() in shared lib called\n");
    }

void g()
    {
    f();
    }

--

Belmont Research
84 Sherman St.
Cambridge, Mass. 02140
617-868-6878

 
 
 

Solaris 2.5 dynamic loader questions

Post by Casper H.S. Dik - Network Security Engine » Wed, 10 Apr 1996 04:00:00



}1) I have a program prog and 2 shared libraries, small.so and big.so.
}Under 2.5 if libraries are loaded in the order small and then big,
}they load ok.  If they are loaded in the order big and then small,
}I get this error from dlopen:
}Dynamic loading error: ld.so.1: prog: fatal: file=small.so:
}relocation [R_SPARC_WDISP22] value 0x25fadb (symbol `_cerror') does not fit.
}If I use exactly the same program and shared libraries under 2.4 the
}loading order doesn't matter.

It isn't related to pic vs PIC (you'd geta GOT overflow).
It's because of:

Quote:}I ask this because small.so (from question 1) is actually quite large itself
}(almost 400K of code) because it statically links in and defines _cerror and
}most of the rest of libc.  They apparently statically linked it in
}thinking it would take precedence over the versions of libc routines
}in programs using small.so.  So they have wasted a lot of memory in
}small.so with versions of system routines that will never get called.

You statically link libc.a to a *dynamic* object, so your small.so contains
unresolved absolute references that need to be resolved at execution
time.  This fails as some of those references need to get resolved
to symbols *outside* the shared object.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

1. FS: Solaris 2.5 Desktop (CDE) and/or Solaris 2.5 Server Packages for x86 desktops

 Hi All,

  Just wanted to pass on some excellent deals on Solaris 2.5.1 software with
the WABI user interface for x86 machines. The WABI allows you to run many
Windows 3.1 applications on a UNIX box, giving you the best of both worlds.  
Imagine, running MS OFFICE components like, MS Word for Windows, Excel,
Powerpoint, and interfacing with the functionality of UNIX at the same time.

For a limited time, John Cristy, at Executive Tools, Inc.,
is offering:

  Solaris 2.5.1 User Desktop package for $175.00
  Solaris 2.5.1 Application Server package for $395.00

Ref URL http://www.etools.com for full information and additional products.  

They also have a student special (99.00 + shipping)(yes, you read that
right, Solaris 2.5.1 user desktop for $99.00).

Mention my name, Bob Fahey, and he will throw in the Java Workshop for
$85.00. Mention my name anyway, as he wants to know what the response is to
this.
If asked where you heard this, tell them not just the web, but the Newsgroup
you read it on.  Thanks.

The Executive Tools web site URL http://www.etools.com also has some
excellent links to other Solaris and Sun information pages.


 Executive Tools is not associated with this posting, so, if you have any

 replies, good or bad!

--
//signed//

URL http://www.3lefties.com/users/faheyb.html
Famous quote by daughter Elizabeth, "If I was them cows, I'd run away!"

2. Broadcasting WHO info across my lan, why?

3. Dynamic Dialin Solaris 2.5 PPP?

4. How to query Linux version info from C/C++?

5. solaris 2.5 and PPP using dynamic addressing

6. exception from shared library

7. Solaris 2.5 PPP / Dynamic IP / Routing Issues

8. Probleme mit IPCHAINS

9. Solaris 2.5 PPP dynamic ip

10. Sparc10 solaris 2.5 to Sparc20 solaris 2.6 migration question

11. Solaris 2.3 NIS+ Upgrade to Solaris 2.5 NIS+ Question!

12. how to install solaris 2.5 x86 to 2.5 gig WD HD

13. Solaris 2.5 & NeWSprint 2.5