This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: Symbol visibility revised
On Mon, May 01, 2000 at 11:29:35PM +0200, Martin v. Loewis wrote:
> > Basically, the function pointer should work as usual if there is
> > only one definition of the STV_PROTECTED symbol.
>
> In my patch, the function pointer works as you'd expect. I eliminate
> relocations involving the PLT, not those involving the GOT. I said
> this could be done, but I didn't do it. Now it seems it is not a good
> idea to do it, but to rely on the dynamic linker for protected data
> instead.
>
> > Here is the testcase.
>
> I can't see how this is relevant to protected symbols. I get failures
> for bar and foobar. The bar failure is due to -Bsymbolic, not due to
> .protected (at least under my current patch); removing -Bsymbolic
> makes it pass. The foobar failure is not a failure at all: There are
> two definitions of bar(), and the dynamic linker correctly choses the
> one in the executable. The abort is because the one in the libfoo.so
> is not called - but it should not be called, so the test case is
> bogus.
>
Ooops. Here is a new testcase. As you can see,
# ./foobar
Hello from bar.c: 0x80485bc
Hello from foo.c: 0x80485bc
Wrong function calld
zsh: 21309 abort ./foobar
It is a tricky problem. I am not sure if we can do it without support
from the dynamic linker.
H.J.
---
#!/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-05-01 17:18 PDT by <hjl@osmium.su.varesearch.com>.
# Source directory was `/home/hjl/bugs/gas/protected'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 58 -rw-r--r-- bar.c
# 244 -rw-r--r-- foo.c
# 124 -rw-r--r-- main.c
# 712 -rw-r--r-- Makefile
#
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 _sh21312; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
fi
# ============= bar.c ==============
if test -f 'bar.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'bar.c' '(file already exists)'
else
$echo 'x -' extracting 'bar.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'bar.c' &&
void
bar ()
{
X printf ("Hello from bar.c: %p\n", bar);
}
SHAR_EOF
(set 20 00 05 01 16 39 54 'bar.c'; eval "$shar_touch") &&
chmod 0644 'bar.c' ||
$echo 'restore of' 'bar.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 'bar.c:' 'MD5 check failed'
f0ddc307a39012f21670d47f36f60b06 bar.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'bar.c'`"
test 58 -eq "$shar_count" ||
$echo 'bar.c:' 'original size' '58,' 'current size' "$shar_count!"
fi
fi
# ============= foo.c ==============
if test -f 'foo.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'foo.c' '(file already exists)'
else
$echo 'x -' extracting 'foo.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'foo.c' &&
static int called = 0;
X
void
bar ()
{
X called = 1;
X printf ("Hello from foo.c: %p\n", bar);
}
X
void *
foo ()
{
X void (*b) () = bar;
X (*b) ();
X if (!called)
X {
X printf ("Wrong function calld\n");
X abort ();
X }
X return b;
}
SHAR_EOF
(set 20 00 05 01 16 57 41 'foo.c'; eval "$shar_touch") &&
chmod 0644 'foo.c' ||
$echo 'restore of' 'foo.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 'foo.c:' 'MD5 check failed'
6755f30cd08d8e3e9966374be816b0e4 foo.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'foo.c'`"
test 244 -eq "$shar_count" ||
$echo 'foo.c:' 'original size' '244,' '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' &&
#include <stdlib.h>
X
void * foo ();
void bar ();
X
int
main ()
{
X bar ();
X if (bar != foo ())
X abort ();
X
X return 0;
}
SHAR_EOF
(set 20 00 05 01 16 39 20 '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'
2c6acd8d5b43c31c3253598eb079a63f main.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main.c'`"
test 124 -eq "$shar_count" ||
$echo 'main.c:' 'original size' '124,' 'current size' "$shar_count!"
fi
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
$echo 'x -' extracting 'Makefile' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CFLAGS=-O -B./
#LDFLAGS=-Wl,-Bsymbolic
X
PROGS= foo bar foobar
X
all: $(PROGS)
X for f in $(PROGS); do echo "Running: $$f"; ./$$f; \
X if [ $$? != 0 ]; then echo Failed; fi; done
X
foo: libfoo.so main.c
X $(CC) -o $@ $(CFLAGS) $^ -Wl,-rpath,.
X
foobar: libbar.so bar.c main.c
X $(CC) -o $@ $(CFLAGS) $^ -Wl,-rpath,.
X
bar: libbar.so main.c
X $(CC) -o $@ $(CFLAGS) $^ -Wl,-rpath,.
X
libfoo.so: foo.o
X $(CC) -shared -o $@ $(CFLAGS) $^
X
libbar.so: bar.o
X $(CC) $(LDFLAGS) -shared -o $@ $(CFLAGS) $^
X
libfoo.so: foo.o
X
foo.o: foo.c
X $(CC) -c $^
X
bar.o: bar.s
X $(CC) -c $^
X
bar.s: foo.c
X $(CC) -S -o $@ -fPIC $(CFLAGS) $^
X echo ".protected bar" >> $@
X
clean:
X rm -f $(PROGS) *.so *.o *.s
X
X
shar:
X shar *.c Makefile > bug.shar
SHAR_EOF
(set 20 00 05 01 16 38 23 'Makefile'; eval "$shar_touch") &&
chmod 0644 'Makefile' ||
$echo 'restore of' 'Makefile' '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 'Makefile:' 'MD5 check failed'
e817a28777472bb0c9fa1f1c28061386 Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
test 712 -eq "$shar_count" ||
$echo 'Makefile:' 'original size' '712,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh21312
exit 0