public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: bkoz@gcc.gnu.org
To: alian@cpan.org, bkoz@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
	gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: libstdc++/6062: Coredump when use dlsym with C++ objects with gcc3
Date: Wed, 03 Apr 2002 18:49:00 -0000	[thread overview]
Message-ID: <20020404024947.5739.qmail@sources.redhat.com> (raw)

Synopsis: Coredump when use dlsym with C++ objects with gcc3

Responsible-Changed-From-To: unassigned->bkoz
Responsible-Changed-By: bkoz
Responsible-Changed-When: Wed Apr  3 18:49:47 2002
Responsible-Changed-Why:
    Mine.
State-Changed-From-To: open->closed
State-Changed-By: bkoz
State-Changed-When: Wed Apr  3 18:49:47 2002
State-Changed-Why:
    This is not a bug. Instead, there are several errors in both the C++ code and the usage of the dynamic loader. I'm including the fixes sources, output from gcc-3.1 on linux, and the modified shell script used to build it.
    
    best,
    benjamin
    
    build.sh:
    c++ -rdynamic -g -fPIC -Wall -shared tc_lib2.cc -o libtc2.so 
    c++ -rdynamic -g -fPIC -Wall tc_prog.cc -L. -ltc2 -ldl -o prog
    
    
    #include <stdio.h>
    
    namespace TestN 
    {
      class Interface 
        {
        public:
          void fcn2(void); 
        };
    }
    
    tc_lib2.cc:
    
    #include "tc_lib2.h"
    
    extern "C" 
    {
      TestN::Interface*
      InstanceFactory()
      { return new TestN::Interface(); }
    }
    
    namespace TestN 
    {
      void 
      Interface::fcn2(void) 
      { printf("in fcn2\n"); }
    }
    
    
    tc_prog.cc:
    #include <dlfcn.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    #include "tc_lib2.h"
    
    int main() 
    {
      TestN::Interface* instance;
      void *lib;
      
      cout << "in fcn1, dlopening lib2..." << endl;
    
      //  int flag = DL_LAZY; // bsd
      // int flag = RTLD_NOW; // linux
      int flag = RTLD_LAZY; // linux try 2
      lib = dlopen("libtc2.so", flag); 
      if (!lib)
        {
          cout << "can't dlopen lib2: " << dlerror() << endl;
          exit(2);
        }
      
      printf("dlsymming instance...\n");
      instance = (TestN::Interface*) dlsym(lib, "InstanceFactory");
      const char* msg = dlerror();
      if (msg != NULL) 
        {
          cout << "can't dlsym instance: " << msg << endl;
          exit(3);
        }
      
      printf("calling fcn2...\n");
      instance->fcn2();
      printf("back from fcn2\n");
    
      dlclose(lib);
      return 0;
    }
    
    
    
    %./prog
    in fcn1, dlopening lib2...
    dlsymming instance...
    calling fcn2...
    in fcn2
    back from fcn2
    
    
    I'm not quite sure why this was coring for you before. At first I thought it might be that NULL string, but of course, that was not it as...
    
    
    
    #include <iostream.h>
    
    int main()
    {
      cout << "testing..." << NULL << endl;
      return 0;
    }
    
    
    is totally fine.
    
    At this point, I don't really care either.
    
    best,
    benjamin

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6062


             reply	other threads:[~2002-04-04  2:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-03 18:49 bkoz [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-03-26  6:16 alian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020404024947.5739.qmail@sources.redhat.com \
    --to=bkoz@gcc.gnu.org \
    --cc=alian@cpan.org \
    --cc=gcc-bugs@gcc.gnu.org \
    --cc=gcc-gnats@gcc.gnu.org \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=nobody@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).