Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

weird bug: dylib symbol loading hangs on pthread semaphore



Greetings,


Brief intro:

The set up:
1) three small c++ files. see bellow
2) c++ -dynamiclib -o libfoo.dylib a.o b.o c.o
3) a small program (attached)
lib = dlopen( "libfoo.dylib", RTLD_LAZY | RTLD_GLOBAL);
dlsym( lib, symbol_name);

The Problem:
dlsym hangs. gdb reveal the program is waiting on
#0 0x90034d68 in semaphore_wait_trap ()
#1 0x9000a258 in pthread_mutex_lock ()

The Severity:
I'm porting a large scientific simulation system ( ~1 million lines of code) we
developed at the University of Utah to OSX. The system runs on IRIX (32,64),
Linux and IBM and has many users in the academic world.

Our system depends of shared libraries and dynamic loading.

It took weeks to reduce the problem to these 3 small files...

The Weird:
*Any* change in these files or even changing the linking order of libfoo will
cause the bug to disappear. In particular, it depends on string::operator+()
string::operator!=(), <iostream> and that the bodies of the 'fail()' functions in
classes A and B are *not* defined inside their respected classes.

However we can not rely on this as the system
is very large and is in constant development. One can not be assure when
such a condition will happen.

note also that the problem seems to happen in the initialization of the iostream
even though the code does not depend on iostream at all.

oh, notice that I do *not* explicitly execute any of the code in files a,b and c,
and I do not link with pthread.

Hope someone can look into it or direct me to the appropriate people

take care,

Yarden Livnat
Research Assistance Professor
SCI Institute
University of Utah

More details:

File a.cc:
==========
#include <string>
#include <iostream>

class A {
public:
void fail();
};

void A::fail()
{
std::string s1,s2;
s1+s2;
}

File b.cc:
========
#include <string>
#include <iostream>

class B {
public:
void fail();
};

void B::fail()
{
std::string s1;
s1 != "foo";
}

File c.cc
===============
#include <string>
#include <iostream>

void test()
{
std::string f,h;
if (f+h != "");
}

The test program
==============
#include <iostream>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

int main( int argv, char* argc[] )
{
const char *libname = argv > 1 ? argc[1] : "libfoo.so";
char type, name[100],cmd[80];
void *symbol;

void *lib = dlopen(libname, RTLD_LAZY|RTLD_GLOBAL);
if ( !lib ) {
std::cerr << "could not open lib [" << libname << "] error: " << dlerror() << "\n";
return 0;
}

// I have no idea how to get the list of symbols directly
sprintf(cmd, "nm -gf %s > lib.symbols",libname);
if ( system( cmd ) == -1 ) {
std::cerr << "nm faild\n";
return 0;
}

FILE *file = fopen( "lib.symbols", "r" );
if ( !file ) {
std::cerr << "can not open lib.symbols file\n";
return 0;
}

for (int i=0; !feof(file); i++) {
// read symbol info
if ( fscanf( file, "%*[^A-Z] %c %[^ .\n]", &type, name ) != 2 ) break;

// ignore it is not a defined global symbol
if ( type != 'T' ) continue;
std::cerr << name << "\n";
symbol = dlsym( lib, name );

// never happens
if ( !symbol ) std::cerr << "\tnot found " << dlerror() << "\n";
}
std::cerr << "done\n";
}

==========
system info:
==========

yarden@view:lock$ uname -a
Darwin view.sci.utah.edu 6.2 Darwin Kernel Version 6.2: Tue Nov 5 22:00:03 PST 2002; root:xnu/xnu-344.12.2.obj~1/RELEASE_PPC Power Macintosh powerpc

yarden@view:lock$ c++ --version
c++ (GCC) 3.1 20020420 (prerelease)

============
The gdb output:
============

yarden@view:lock$ make
rm -f *.dylib *.o
g++ -c -o a.o a.cc
g++ -c -o b.o b.cc
g++ -c -o c.o c.cc
c++ -dynamiclib -o libfoo.dylib a.o b.o c.o
./load libfoo.dylib
__Z4testv
^Cmake: *** [all] Interrupt

yarden@view:lock$ gdb load
GNU gdb 5.1-20020408 (Apple version gdb-228) (Sun Jul 14 10:07:24 GMT 2002)
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "powerpc-apple-macos10".
Reading symbols for shared libraries .. done
(gdb) run libfoo.dylib
Starting program: /Users/yarden/lock/load libfoo.dylib
[Switching to process 4711 thread 0xb03]
Reading symbols for shared libraries ... done
Reading symbols for shared libraries . done
__Z4testv
^C
Program received signal SIGINT, Interrupt.
0x90034d68 in semaphore_wait_trap ()
(gdb) where
#0 0x90034d68 in semaphore_wait_trap ()
#1 0x9000a258 in pthread_mutex_lock ()
#2 0x001972ec in std::locale::classic() ()
#3 0x00196b48 in std::locale::locale() ()
#4 0x0018ccf4 in std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(__sFILE*, std::_Ios_Openmode, int) ()
#5 0x00188644 in std::ios_base::Init::_S_ios_create(bool) ()
#6 0x001889c8 in std::ios_base::Init::Init() ()
#7 0x001ae2e4 in __static_initialization_and_destruction_0(int, int) ()
#8 0x001ae348 in _GLOBAL__I__Z4testv ()
#9 0x8fe16350 in __dyld_call_module_initializers_for_library ()
#10 0x8fe160e4 in __dyld_call_module_initializers ()
#11 0x8fe106f0 in __dyld_link_in_need_modules ()
#12 0x8fe1016c in __dyld_bind_lazy_symbol_reference ()
#13 0x8fe00ec0 in __dyld_stub_binding_helper_interface ()
#14 0x00197344 in std::locale::classic() ()
#15 0x00196b48 in std::locale::locale() ()
#16 0x0018ccf4 in std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(__sFILE*, std::_Ios_Openmode, int) ()
#17 0x00188644 in std::ios_base::Init::_S_ios_create(bool) ()
#18 0x001889c8 in std::ios_base::Init::Init() ()
#19 0x001ae1e4 in __static_initialization_and_destruction_0(int, int) ()
#20 0x001ae248 in _GLOBAL__I__ZN1B4failEv ()
#21 0x8fe16350 in __dyld_call_module_initializers_for_library ()
#22 0x8fe160e4 in __dyld_call_module_initializers ()
#23 0x8fe106f0 in __dyld_link_in_need_modules ()
#24 0x8fe1016c in __dyld_bind_lazy_symbol_reference ()
#25 0x8fe00ec0 in __dyld_stub_binding_helper_interface ()
#26 0x0018ccf4 in std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(__sFILE*, std::_Ios_Openmode, int) ()
#27 0x00188644 in std::ios_base::Init::_S_ios_create(bool) ()
#28 0x001889c8 in std::ios_base::Init::Init() ()
#29 0x001ae0e4 in __static_initialization_and_destruction_0(int, int) ()
#30 0x001ae148 in _GLOBAL__I__ZN1A4failEv ()
#31 0x8fe16350 in __dyld_call_module_initializers_for_library ()
#32 0x8fe160e4 in __dyld_call_module_initializers ()
#33 0x8fe106f0 in __dyld_link_in_need_modules ()
#34 0x8fe13d68 in __dyld__dyld_NSLookupSymbolInImage ()
#35 0x0005fd80 in dlsymIntern ()
#36 0x00002a44 in main ()
#37 0x000025e0 in _start (argc=2, argv=0xbffffc34, envp=0xbffffc40) at /SourceCache/Csu/Csu-45/crt.c:267
#38 0x00002460 in start ()
(gdb)
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.