Bug 3713 - Dynamic-list-cpp-typeinfo doesn't handle correctly static variables in a class
Summary: Dynamic-list-cpp-typeinfo doesn't handle correctly static variables in a class
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.17
: P1 critical
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-12-13 12:00 UTC by Guillaume Lazzara
Modified: 2007-01-04 18:42 UTC (History)
3 users (show)

See Also:
Host:
Target: Any
Build:
Last reconfirmed:


Attachments
A small example to reproduce the bug (747 bytes, application/gzip)
2006-12-13 12:02 UTC, Guillaume Lazzara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume Lazzara 2006-12-13 12:00:33 UTC
I have the following:
- A library called toto.so where the object Toto is implemented:

class Toto
{
        public:
                Toto();
                static Toto *instance() { return self; }

        private:
                static Toto *self;
};

- A main.cpp linked against toto.so:
int main()
{
    Toto tmp;
    std::cout << "Main: Toto::instance() == " << tmp.instance() << std::endl;
    return 0;
}

If I build everything like this:
g++ -shared -fPIC -Wl,--dynamic-list-cpp-typeinfo toto.cpp -o libtoto.so
g++ -Wl,--dynamic-list-cpp-typeinfo main.cpp -L. -ltoto

The toto::instance() function returns 0 in the main function.

However, if I build without --dynamic-list-cpp-typeinfo, the toto::instance()
function returns the correct value.

I compiled natively on Linux I386 and I cross compiled for ARM. 
I got the same results on both architectures.
Comment 1 Guillaume Lazzara 2006-12-13 12:02:00 UTC
Created attachment 1461 [details]
A small example to reproduce the bug
Comment 2 H.J. Lu 2007-01-04 14:21:38 UTC
As documented, --dynamic-list-cpp-typeinfo only does "Provide the builtin dynamic
list for C++ runtime type identification". You need to use  --dynamic-list= to
add additional symbols to dynamic list.
Comment 3 Simon Hausmann 2007-01-04 17:36:21 UTC
Is there a way to automatically include all symbols in a list file 
for --dynamic-list for which the linker of a separate program would generate 
copy relocations?

If not would you accept an enhancement request for the linker to support 
something like that?

Because as it stands right now --dynamic-list-typeinfo is not very useful for 
C++ libraries (such as Qt or KDE) because of this very problem, which is a pity 
since the --dynamic-list feature is otherwise very attractive.
Comment 4 H.J. Lu 2007-01-04 17:57:33 UTC
(In reply to comment #3)
> Is there a way to automatically include all symbols in a list file 
> for --dynamic-list for which the linker of a separate program would generate 
> copy relocations?
> 
> If not would you accept an enhancement request for the linker to support 
> something like that?
> 

Yes, please be specific about what you want.

Comment 5 Simon Hausmann 2007-01-04 18:42:20 UTC
Thanks for the quick reply.

I have tried to elaborate on the problem now in bug #3831 .