static linking

New Message Reply Date view Thread view Subject view Author view

Michael Jones (mtj++at++isdn-celeste.corp.sgi.com)
Tue, 7 May 1996 20:19:07 -0700


Scott McMillan guesses:
| I am guessing that even in libpfdu.a's version of pfLoadFile it is
| doing a dlsym and dlopen after it parses the filename and then
| dynamically linking in the appropriate loader...(it defeats the purpose
| of linking statically, IMHO).
|
| With this assumption, what I have to do to get around this is to bypass
| the pfdLoadFile function, parse the input file names myself, call the
| appropriate loader directly (e.g., pfdLoadFile_iv) using a case/switch
| or whatever, and make sure that during the link phase, I include every
| static libpfdb library that I account for in my case statement (e.g.,
| libpfiv.a).
|
| Am I right?

No.

| If so, couldn't this have been done in libpfdu.a, in the first place?

Well, take a look at the source code shipped in pfdLoadFile.c:

    /* is the loader for this file type linked into the executable ? */
    cDSO = &DSO[PF_MIN2(nDSOs, MAX_DSO_COUNT-1)];
    cDSO->dso = dlopen(NULL, RTLD_LAZY);
    if (cDSO->dso != NULL)
    {
        cDSO->initConverter = (initFunc) dlsym(cDSO->dso, initFuncName);
        cDSO->loadFile = (loadFunc) dlsym(cDSO->dso, loadFuncName);
        cDSO->storeFile = (storeFunc) dlsym(cDSO->dso, storeFuncName);
        cDSO->convertTo = (convertToFunc) dlsym(cDSO->dso, convertToFuncName);
        cDSO->convertFrom = (convertFromFunc) dlsym(cDSO->dso, convertFromFuncName);
        cDSO->setMode = (setConverterModeFunc) dlsym(cDSO->dso, setConverterModeFuncName);
        cDSO->getMode = (getConverterModeFunc) dlsym(cDSO->dso, getConverterModeFuncName);
        cDSO->setAttr = (setConverterAttrFunc) dlsym(cDSO->dso, setConverterAttrFuncName);
        cDSO->getAttr = (getConverterAttrFunc) dlsym(cDSO->dso, getConverterAttrFuncName);
        cDSO->setVal = (setConverterValFunc) dlsym(cDSO->dso, setConverterValFuncName);
        cDSO->getVal = (getConverterValFunc) dlsym(cDSO->dso, getConverterValFuncName);
        if (cDSO->initConverter != NULL)
        {
            (*cDSO->initConverter)();
        }
        if (cDSO->loadFile != NULL)
        {
            cDSO->name = strdup(ext);
            return cDSO;
        }
    }

What's happening is that the NULL argument to dlopen() means open the
current executable and the the dlsym() calls look for the functions
in the executable. If you linked it in, then it will be found and
remembered.

Michael Jones

Be seeing you, Phone:415.390.1455 Fax:415.965.2658 M/S:8U-590
Michael T. Jones Silicon Graphics, Advanced Graphics Division
mtj++at++sgi.com 2011 N. Shoreline Blvd., Mtn. View, CA 94039-7311

"Competition is a by-product of productive work, not its goal. A
creative man is motivated by the desire to achieve, not by the desire
to beat others." -Ayn Rand


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:52:52 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.