[Bug c++/36820] New: Exception can't be catched when --version-script is used

alexi dot zuo at gmail dot com gcc-bugzilla@gcc.gnu.org
Mon Jul 14 08:25:00 GMT 2008


In my project, we have 3 components: test,libbar.so and libfoo.so. libbar.so
depends on libfoo.so,and test depends on the two .so. In libfoo.so, I throw an
exception, but libbar.so can't catch it.

----exception.h------
#ifndef __EXCEPTION_H
#define __EXCEPTION_H

#include <string>
class ebase
{
public:
   virtual std::string getmsg() =0;
};


class echild:public ebase
{
private:
    std::string m_s;
public:
    echild(const std::string& s)
    {
        m_s=s;
    }
    virtual std::string getmsg()
    {
        return m_s;
    }
};

#endif

------foo.cpp----------
#include "exception.h"
void check_exception()
{
  throw echild("check_insert: something happened");
}

------bar.cpp----------
#include "exception.h"
#include "foo.h"

extern "C" void test()
{
    try
   {
        check_exception();      
   }
   catch(ebase &e)
   {
         //exception should be catched here
        printf("really good\n");

   }
}

---------test.cpp--------
#include "foo.h"
#include <iostream>

extern "C" void test();

int main()
{
   test();
   return 0;
}

----------libbar.ver----------
VERSION_1.0
{
  global:
     test;
  local: 
     *;
};


----------Makfile-----------
All:
   g++ -g -shared -fPIC -c -o foo.o foo.cpp
   g++ -g -shared -fPIC -c -o error.o error.cpp
   g++ -g -shared -fPIC -o libfoo.so foo.o error.o
   g++ -g -shared -fPIC -c -o bar.o bar.cpp
   g++ -g -shared -fPIC -o libbar.so -Xlinker --version-script --Xlinker
./libbar.ver -L./ -lfoo bar.o
   g++ -g  -L. test.cpp -lbar -o test

clean:
   rm libfoo.so libbar.so foo.o test 

test() should print out "really good", but it prints out "unknown exception"
instead.The output is:

"terminate called after throwing an instance of 'echild'"
Aborted

There are a lot of discussion about the exception defintion. Since all
defintion is in the .h file and all functions are inline functions, it may be a
problem.(See http://gcc.gnu.org/faq.html#vtables). 

But if I don't use --version-script, nothing is wrong.Another workaround
solution is defining a non-inline virtual function for class ebase. So what the
hell is the real problem? 

Thanks,

Alexi


-- 
           Summary: Exception can't be catched when --version-script is used
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexi dot zuo at gmail dot com
 GCC build triplet: X86 32bit Redhat Enterprise Linux AS release 4
  GCC host triplet: X86 32bit Redhat Enterprise Linux AS release 4
GCC target triplet: X86 32bit Redhat Enterprise Linux AS release 4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36820



More information about the Gcc-bugs mailing list