IY92889: EARLY DESTRUCT OF .SO USING 8.0.0.5 RUNTIME

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • When using any runtimes after the 8.0.0.0 one, there seems to be
    a incorrect loading of certain libraries (.so) leading to an
    incorrect output at execution time of the application.
    
    ===========Compile Command=========================
    xlC_r  -g  -bcheck=all *.cpp -c
    xlC_r  -G  -Wl,-bernotok -L. -g -o libA.so A.o
    xlC_r  -G  -Wl,-bernotok -L. -g -o libB.so B.o -lA
    xlC_r  -brtl -L. -g  -o m m.o -lB -lA
    xlC_r  -g  -bcheck=all -o D.o -c D.cpp
    xlC_r  -G  -Wl,-bernotok -L. -g -o libD.so D.o -lA
    ===================================================
    
    
    ==========Start of m.cpp===================
    #include <iostream>
    #include <dlfcn.h>
    class B {
    public:
           static int dosomething();
    };
    
    
    class A {
    public:
           static A*instance();
           static void destroyinstance();
           int doit();
    private:
           A();
           ~A();
           static A* instance_;
           int count_;
    };
    
    
    void doit()
    {
           void * h = dlopen("libD.so", RTLD_GLOBAL|RTLD_NOW);
           if (h) {
                  dlclose(h);
           } else {
                  std::cerr << "dlopen failed:" << dlerror() <<
    std::endl;
           }
    }
    
    int main(int argc, char *arv[])
    {
           B::dosomething();
           A* a = A::instance();
           doit();
           a->doit();
    
           doit();
           a->doit();
    
           doit();
           a->doit();
    
           doit();
           a->doit();
    
           doit();
           a->doit();
    
           doit();
           a->doit();
    
           return 0;
    }
    
    ===========End of m.cpp=================
    
    ==========start of A.cpp===============
    #include <iostream>
    
    class A {
    public:
           static A*instance();
           static void destroyinstance();
           int doit();
    private:
           A();
           ~A();
           static A* instance_;
           int count_;
    };
    
    
    class AHolder {
    public:
           AHolder(A*a) : mya(a) {}
           ~AHolder() { mya=0; A::destroyinstance(); }
           A*mya;
    };
    
    AHolder myholder(A::instance());
    
     A*A::instance_ = 0;
    
    A::A()
           : count_(0)
    {
           std::cerr << "A::A" << std::endl;
    }
    
    A::~A()
    {
           std::cerr << "A::~A" << std::endl;
    
    }
    
    int A::doit()
    {
           count_++;
    
           std::cerr << "A::doit " << this << " " << this->count_ <<
    std::endl;
           return 0;
    }
    
    void A::destroyinstance()
    {
           std::cerr << "A::destroyinstance" << std::endl;
           delete instance_;
           instance_ = 0;
    }
    
    A* A::instance()
    {
           if (instance_) {
                  return instance_;
           }
    
           instance_ = new A;
           return instance_;
    }
    ================End of A.cpp===================
    
    ================Start of B.cpp================
    
    class B {
    public:
           static int dosomething();
    };
    
    
    class A {
    public:
           static A*instance();
           static void destroyinstance();
           int doit();
    private:
           A();
           ~A();
           static A* instance_;
           int count_;
    };
    
    
    int B::dosomething()
    {
           A::instance()->doit();
           return 0;
    }
    ================End of B.cpp===================
    
    ================Start of D.cpp================
    class A;
    
    class D {
    public:
           static int dosomething();
           D();
           ~D();
           A*mya;
    };
    
    
    class A {
    public:
           static A*instance();
           static void destroyinstance();
           int doit();
    private:
           A();
           ~A();
           static A* instance_;
           int count_;
    };
    
    
    D dinstance;
    
    D::D() {
           mya = A::instance();
           mya->doit();
    }
    
    D::~D() {
           mya = 0;
    }
    ================End of D.cpp==================
    
    
    ===== ACTUAL OUTPUT:
    A::A
    A::doit 2018bff8 1
    A::doit 2018bff8 2
    A::doit 2018bff8 3
    A::doit 2018bff8 4
    A::destroyinstance
    A::~A
    Segmentation fault(coredump)
    
    
    
    ===== EXPECTED OUTPUT:
    A::A
    A::doit 2017fff8 1
    A::doit 2017fff8 2
    A::doit 2017fff8 3
    A::doit 2017fff8 4
    A::doit 2017fff8 5
    A::doit 2017fff8 6
    A::doit 2017fff8 7
    A::doit 2017fff8 8
    A::doit 2017fff8 9
    A::doit 2017fff8 10
    A::doit 2017fff8 11
    A::doit 2017fff8 12
    A::doit 2017fff8 13
    A::destroyinstance
    A::~A
    

Local fix

  • n/a
    

Problem summary

  • User of applications that have libC.a loaded prior during
    static initialization, and whose application calls dlopen and
    dlclose.
    
    When libC.a is loaded prior to entering into main via static
    intitializations, the use count on libC.a is incorrect and may
    be unloaded too soon if a call to dlclose in made on a library
    that is dependent upon libC.a
    

Problem conclusion

  • Keep track of the use counts for libraries loaded during static
    initialization correctly.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IY92889

  • Reported component name

    XLC C++ AIX

  • Reported component ID

    5724M1200

  • Reported release

    800

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2006-12-15

  • Closed date

    2007-01-08

  • Last modified date

    2007-08-02

  • APAR is sysrouted FROM one or more of the following:

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XLC C++ AIX

  • Fixed component ID

    5724M1200

Applicable component levels

  • R800 PSY U812643

       UP07/08/02 I 1000



Rate this page:

(0 users)Average rating

Add comments

Document information


More support for:

XL C/C++
Compiler

Software version:

8.0

Reference #:

IY92889

Modified date:

2007-08-02

Translate my page

Machine Translation

Content navigation