Re: missing symbols with bobcat C++ library on armel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, May 25, 2011 at 11:12:02AM -0700, Ian Lance Taylor wrote:
> "Frank B. Brokken" <f.b.brokken@xxxxxx> writes:
> 
> > Dear Ian Lance Taylor, you wrote:
> >
> >> This approach will only work if you guarantee that every piece of code
> >> that creates a new MultiStreambuf includes that header file.
> >
> > I'm not sure if I follow you here. All MultiStreambuf sources include the
> > above header, and no other (external to MultiStreambuf) functions need/have
> > access to MultiStreambuf's private members. 
> >
> > So I guess you do not mean by 'creates a new MultiStreambuf' constructions
> > like:
> >     void fun()
> >     {
> >         MultiStreambuf ms;
> >         MultiStreambuf *msp = new MultiStreambuf;
> >     }
> 
> That is pretty much exactly what I do mean, actually.  There is some
> more information at
> 
> http://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Vague-Linkage.html
> 
> Note specifically: "Make sure that any inline virtuals are declared
> inline in the class body, even if they are not defined there."  You
> aren't currently doing that.  It's possible that that by itself might
> fix this problem; I'm not sure.

Nevertheless, I'm also wondering also about another situation, which
might occur (or is it the same ?):

the function "overflow" is defined already as protected in the
base-class std::streambuf, from which MultiStreambuf is derived
(public).

Now, what would happen if (on armel):
 - your MultiStreambuf-class and all derived classes ONLY call
   "this->overflow" in situations where g++ can guarantee that "this" is
   a MultiStreambuf, and thus inline the code
   ==> it is possible to generate the library without exporting
   "MultiStreambuf::overflow"
   (i'm not sure: would that be OK from G++, or a violation of the
   standard?)
 - but when the library is used, an object of type MultiStreambuf is
   used through the std::streambuf - interface, such that a call to
   overflow is generated -- which can't be satisfied due to the missing
   exported function.

In fact, I tried a minimal example of this situation, where I also get
an error on amd64 (Debian, g++-4.4.5) with the following code:

base.h:
class Base{ // base class defining an inline virtual function as public
  public:
    inline virtual int operator()()const{ return 2; }
    int get2()const{ return this->operator()(); }
    virtual ~Base(){};
};

derived.h:
#include "base.h" // derived class, defining the function as private &
	// using it only once
class Derived : public Base{
  public:
    ~Derived(){}
    int get()const;
  private:
    inline virtual int operator()()const;
};

derived.cc: 
#include "derived.h" // separate compile unit, where the type of "this"
		    // is well-defined ==> operator() can be inlined
int Derived::get()const{  	 return this->operator()();}
int Derived::operator()()const{  return 4;	}

test.cc:
#include "derived.h"	// access the virtual function of Derived
			// through "get2"
#include <iostream>
int main(){
  Base *b = new Derived();
  std::cout << b->get2() << std::endl;
}

Compiling with "g++ test.cc derived.cc" gives a warning:
warning: inline function âvirtual int Derived::operator()() constâ used but never defined
and a linker error:
/tmp/ccU781xY.o:(.rodata._ZTV7Derived[vtable for Derived]+0x10): undefined reference to `Derived::operator()() const'


Maybe in the MultiStreambuf-case something similar is happen?

Axel


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux