This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
dlopen issue with RTLD_LAZY...
- To: <gcc-bugs at gcc dot gnu dot org>
- Subject: dlopen issue with RTLD_LAZY...
- From: <tracy at col dot hp dot com>
- Date: Tue, 29 Aug 2000 10:15:21 -0600
- Cc: "Tracy at Cos dot Agilent. Com" <tracy at cos dot agilent dot com>
To whom it may concern,
Thanks for taking the time to look at this issue! I'm Tracy
Vandeventer and I am trying to port an application from HPUX to
Linux (YEA!!). This application contains over 10 executables and
~140 shared libraries with a total of ~1.4 million lines of code.
My problem is that I have a shared library that has some
unresolved symbols. I want to be able to load this library
and not have it fail because of unresolved symbols. ( at some
point in the future the symbols will be resolved, but.. I'm not
done with all the porting...)
The problem is that the dlopen library call has a parameter flags
with a possible value being RTLD_LAZY. When I uses this flag the
dlopen call still fails with unresolved symbols, when it should
just load the library and resolve what it can and then return.
The following code snippet demostrates the problem...
When you execute the main executable - a message is printed that
shows the failed dlopen call. This call should NOT fail...
These files are located in the shar at the end of this message:
readme - this file
main.c - the main program that loads the library and then
makes a call into the library - note that the unresolved
symbol is not needed for the call...
lib1.c - the library code with an unresolved symbol
m - a quick script that builds the library, the
executable, and then executes the program
lib1.so- the library binary
main - the executable binary
>g++ -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)
**** note the specs file is located below....
>ld --version
GNU ld 2.9.5
Copyright 1997 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms
of
the GNU General Public License. This program has absolutely no
warranty.
Supported emulations:
elf_i386
i386linux
Again thanks for all your help ...
tracy@cos.agilent.com
______________________________________________________________________
Tracy Vandeventer e-mail: tracy_vandeventer@agilent.com
Agilent Technologies USmail: 1900 Garden of the Gods Road
R&D Digital Design PGU PO Box 2197
Phone : (719) 590-2640 Colorado Springs, CO 80901-2197
______________________________________________________________________
> cat /usr/lib/gcc-lib/i386-linux/2.95.2/specs
*asm:
%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}
*asm_final:
%|
*cpp:
%(cpp_cpu) %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__}
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
*cc1:
%(cc1_cpu) %{profile:-p}
*cc1plus:
*endfile:
%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s
*link:
-m elf_i386 %{shared:-shared} %{!shared: %{!ibcs: %{!static:
%{rdynamic:-export-dynamic} %{!dynamic-linker:-dynamic-linker
/lib/ld-linux.so.2}} %{static:-static}}}
*lib:
%{shared: -lc} %{!shared: %{mieee-fp:-lieee} %{pthread:-lpthread}
%{profile:-lc_p} %{!profile: -lc}}
*libgcc:
-lgcc
*startfile:
%{!shared: %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s}
%{!p:%{profile:gcrt1.o%s} %{!profile:crt1.o%s}}}} crti.o%s
%{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}
*switches_need_spaces:
*signed_char:
%{funsigned-char:-D__CHAR_UNSIGNED__}
*predefines:
-D__ELF__ -Dunix -D__i386__ -Dlinux -Asystem(posix)
*cross_compile:
0
*version:
2.95.2
*multilib:
. ;
*multilib_defaults:
*multilib_extra:
*multilib_matches:
*linker:
collect2
*cpp_486:
%{!ansi:-Di486} -D__i486 -D__i486__
*cpp_586:
%{!ansi:-Di586 -Dpentium} -D__i586 -D__i586__ -D__pentium -D__pentium__
*cpp_k6:
%{!ansi:-Di586 -Dk6} -D__i586 -D__i586__ -D__k6 -D__k6__
*cpp_686:
%{!ansi:-Di686 -Dpentiumpro} -D__i686 -D__i686__ -D__pentiumpro -D__penti
umpro__
*cpp_cpu_default:
*cpp_cpu:
-Acpu(i386) -Amachine(i386) %{!ansi:-Di386} -D__i386 -D__i386__
%{mcpu=i486:%(cpp_486)} %{m486:%(cpp_486)} %{mpentium:%(cpp_586)}
%{mcpu=pentium:%(cpp_586)} %{mpentiumpro:%(cpp_686)}
%{mcpu=pentiumpro:%(cpp_686)} %{mcpu=k6:%(cpp_k6)}
%{!mcpu*:%{!m486:%{!mpentium*:%(cpp_cpu_default)}}}
*cc1_cpu:
%{!mcpu*: %{m386:-mcpu=i386 -march=i386} %{m486:-mcpu=i486 -march=i486}
%{mpentium:-mcpu=pentium} %{mpentiumpro:-mcpu=pentiumpro}}
*link_command:
%{!fsyntax-only: %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A}
%{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}
%{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static:} %{L*} %D %o
%{!nostdlib:%{!nodefaultlibs:%G %L %G}}
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*}
}}}}}}
******** end of specs file
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-08-24 09:10 MDT by <tracy@krackle>.
# Source directory was `/home/tracy/test/shl/bug'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 4854 -rw-r--r-- readme
# 428 -rw-r--r-- main.c
# 194 -rw-r--r-- lib1.c
# 214 -rwxr-xr-x m
# 6159 -rwxr-xr-x lib1.so
# 6027 -rwxr-xr-x main
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
set `$dir/gettext --version 2>&1`
if test "$3" = GNU
then
gettext_dir=$dir
fi
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f
200112312359.59 -a -f $$.touch; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f
123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f
1231235901 -a -f $$.touch; then
shar_touch='touch -am $3$4$5$6$2 "$8"'
else
shar_touch=:
echo
$echo 'WARNING: not restoring timestamps. Consider getting and'
$echo "installing GNU \`touch', distributed in GNU File Utilities..."
echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh01344; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= readme ==============
if test -f 'readme' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'readme' '(file already exists)'
else
$echo 'x -' extracting 'readme' '(binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
readme.dat
SHAR_EOF
(set 20 00 08 24 09 10 08 'readme'; eval "$shar_touch") &&
chmod 0644 'readme' ||
$echo 'restore of' 'readme' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'readme:' 'MD5 check failed'
3b1ec7f953cbeedd1937eaf6d62c8a79 readme
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'readme'`"
test 4854 -eq "$shar_count" ||
$echo 'readme:' 'original size' '4854,' 'current size' "$shar_count!"
fi
fi
# ============= main.c ==============
if test -f 'main.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'main.c' '(file already exists)'
else
$echo 'x -' extracting 'main.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
X
X
#include <dlfcn.h>
#include <stdio.h>
X
void main()
{
X void * handle ;
X
X handle = dlopen( "lib1.so", RTLD_LAZY ) ;
X if ( ! handle ) {
X fprintf( stderr, "dlopen - %s\n", dlerror() ) ;
X exit( 1 ) ;
X }
X
X int (*mymain)() ;
X char *err ;
X
X mymain = (int (*)())dlsym( handle, "meth1_2" ) ;
X if (( err = dlerror()) != NULL ) {
X fprintf( stderr, "dlsym - %s\n", err ) ;
X exit(1 ) ;
X }
X
X (*mymain)() ;
X
X dlclose( handle ) ;
}
SHAR_EOF
(set 20 00 08 24 08 47 43 'main.c'; eval "$shar_touch") &&
chmod 0644 'main.c' ||
$echo 'restore of' 'main.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'main.c:' 'MD5 check failed'
83d4f242c73c33880d91a0f605a5234b main.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main.c'`"
test 428 -eq "$shar_count" ||
$echo 'main.c:' 'original size' '428,' 'current size' "$shar_count!"
fi
fi
# ============= lib1.c ==============
if test -f 'lib1.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'lib1.c' '(file already exists)'
else
$echo 'x -' extracting 'lib1.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'lib1.c' &&
X
X
#include <stdio.h>
X
extern int meth1_4() ;
X
X
int meth1_1()
{
X printf( "in method 1-1\n" ) ;
X return 1 ;
}
X
X
int meth1_2()
{
X return meth1_1() ;
}
X
X
int meth1_3()
{
X return meth1_4() ;
}
X
SHAR_EOF
(set 20 00 08 24 08 47 43 'lib1.c'; eval "$shar_touch") &&
chmod 0644 'lib1.c' ||
$echo 'restore of' 'lib1.c' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'lib1.c:' 'MD5 check failed'
f8e730ef3080c35dae43bd7a8cb7319d lib1.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'lib1.c'`"
test 194 -eq "$shar_count" ||
$echo 'lib1.c:' 'original size' '194,' 'current size' "$shar_count!"
fi
fi
# ============= m ==============
if test -f 'm' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'm' '(file already exists)'
else
$echo 'x -' extracting 'm' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'm' &&
#!/bin/bash -p
X
echo "g++ -shared -o lib1.so lib1.c"
g++ -shared -o lib1.so lib1.c
echo
X
echo "g++ -o main main.c -ldl"
g++ -o main main.c -ldl
echo
X
export LD_LIBRARY_PATH=.
X
echo executing...
echo
X
main
echo
X
SHAR_EOF
(set 20 00 08 24 08 47 43 'm'; eval "$shar_touch") &&
chmod 0755 'm' ||
$echo 'restore of' 'm' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'm:' 'MD5 check failed'
31a418333e37d589851d84d0d79ca33e m
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'm'`"
test 214 -eq "$shar_count" ||
$echo 'm:' 'original size' '214,' 'current size' "$shar_count!"
fi
fi
# ============= lib1.so ==============
if test -f 'lib1.so' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'lib1.so' '(file already exists)'
else
$echo 'x -' extracting 'lib1.so' '(binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
lib1.so
SHAR_EOF
(set 20 00 08 24 08 54 11 'lib1.so'; eval "$shar_touch") &&
chmod 0755 'lib1.so' ||
$echo 'restore of' 'lib1.so' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'lib1.so:' 'MD5 check failed'
41209bdb6d7f3ffd804092e651610b88 lib1.so
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'lib1.so'`"
test 6159 -eq "$shar_count" ||
$echo 'lib1.so:' 'original size' '6159,' 'current size' "$shar_count!"
fi
fi
# ============= main ==============
if test -f 'main' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'main' '(file already exists)'
else
$echo 'x -' extracting 'main' '(binary)'
sed 's/^X//' << 'SHAR_EOF' | uudecode &&
main.dat
SHAR_EOF
(set 20 00 08 24 08 54 11 'main'; eval "$shar_touch") &&
chmod 0755 'main' ||
$echo 'restore of' 'main' 'failed'
if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
&& ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
md5sum -c << SHAR_EOF >/dev/null 2>&1 \
|| $echo 'main:' 'MD5 check failed'
ce8b8d0815e0bf37e3f09ab887cba941 main
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main'`"
test 6027 -eq "$shar_count" ||
$echo 'main:' 'original size' '6027,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh01344
exit 0