shared object symbol visibility (185 Views)
Reply
Occasional Advisor
chilabot
Posts: 8
Registered: ‎10-22-2012
Message 1 of 6 (185 Views)

shared object symbol visibility

[ Edited ]

I'm trying to compile a C++ shared object, and the weirdest thing happens. Whenever some code is in there, all the symbols from a certain compilation object dissappear. When I remove that code, they appear. For instance:

 

#include <boost/ptr_container/ptr_vector.hpp>

namespace nsp
{

    template <typename Type>
    struct Holder
    {
        boost::ptr_vector<Type> vec;
    };

    class Object { int a; };

    Holder<Object> holder;

    void testIt()
    {
        // holder.vec.push_back(new Object());
    }
}

 

$g++ -shared test.cpp -o test.so -I${BOOST_INCLUDE_GCC}/1.51

 

$ nm test.so | grep testIt | c++filt
[258] | 67118528| 32|FUNC |GLOB |0| .text|nsp::testIt()

 

But if I uncomment the line inside 'testIt', the 'nm' command shows nothing. If there's no 'Holder' template, just the 'vec', the symbols appears. If the type is just an 'int', the symbol appears.

 

What could be the cause of this?

 

$ g++ --version
g++ (GCC) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

$ uname -a
HP-UX rx8km B.11.31 U ia64 2229485251 unlimited-user license

 

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 2 of 6 (169 Views)

Re: shared lib symbol visibility (hidden local symbol)

[ Edited ]

It would be helpful to run nm(1) on the object file instead of a shlib.

 

>If the type is just an 'int', the symbol appears.

 

The template type as in: ?

Holder<int> holder;

Or:

boost::ptr_vector<int> vec;

Please use plain text.
Occasional Advisor
chilabot
Posts: 8
Registered: ‎10-22-2012
Message 3 of 6 (156 Views)

Re: shared lib symbol visibility

>It would be helpful to run nm(1) on an object file instead of a shlib.

 

What should be run on a shlib?

 

>>If the type is just an 'int', the symbol appears.

>The template type as in: ?

>Holder<int> holder;

>Or:

>boost::ptr_vector<int> vec;

 

Holder<int> holder;

 

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 4 of 6 (149 Views)

Re: shared lib symbol visibility (hidden local symbol)

[ Edited ]

>What should be run on a shlib?

 

You already did this.  Now run nm(1) on the object file.

Please use plain text.
Occasional Advisor
chilabot
Posts: 8
Registered: ‎10-22-2012
Message 5 of 6 (146 Views)

Re: shared lib symbol visibility (missing symbol)

I did that and the symbol appears. I tried using the shared object anyways and it worked even thou the nm does not show the symbol. Weird.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,853
Registered: ‎03-06-2006
Message 6 of 6 (144 Views)

Re: shared lib symbol visibility (hidden local symbol)

>I did that and the symbol appears.

 

Can you provide the nm(1) output, perhaps the symbol is only local and so doesn't get put in the shlib symbol table?

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation