HP-UX Reference (11i v2 04/09) - 5 Miscellaneous Topics (vol 9)
p
pthread_stubs(5) pthread_stubs(5)
SHLIB_PATH disabled second
embedded path disabled first Not Defined
shared library list:
dynamic /usr/lib/libpthread.1
dynamic /usr/lib/libc.2
shared library binding:
deferred
global hash table disabled ...
Example 2
Specifying
-lc before -lpthread in threaded applications can cause run-time problems like the follow-
ing because the pthread calls get resolved to stubs in
libc rather than the functions in pthread library.
• Calls to pthread functions fail, due to uninitialized internal structures.
• Calls to gethostbyname(3N) fail and return null.
• Apache webmin and perl DBI applications fail with the following error message:
Can’t load libname .sl for module xxx
: Invalid argument at address
• Calls to shl_load (3X) fail with the following error:
errno 22 (invalid argument)
because the pthread_mutex_lock
stub returns zero.
$ cat a.c
#include <stdio.h>
#include <dl.h>
extern int errno;
main()
{
shl_load("lib_not_found", BIND_DEFERRED, 0);
printf("Error %d, %s\n", errno, strerror(errno));
}
$ cc a.c -lc -lpthread
$ a.out
Error 22, Invalid argument
$ LD_PRELOAD=/usr/lib/libpthread.1 ./a.out
Error 2, No such file or directory
$ cat b.c
#include <stdio.h>
#include <dlfcn.h>
void* handle;
extern int errno;
main()
{
handle = dlopen("lib_not_found", RTLD_LAZY);
printf("Error %d, %s\n", errno, strerror(errno));
if (handle == NULL)
{
printf("Error: %s\n",dlerror());
}
}
$ cc b.c -lc -lpthread
$ a.out
Error 22, Invalid argument
Error:
$ ./a.out
$ LD_PRELOAD=/usr/lib/libpthread.1
HP-UX 11i Version 2: September 2004 − 4 − Hewlett-Packard Company Section 5−−277