This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Re: The problem with linkonce sections in ELF
On Thu, Feb 03, 2000 at 11:09:24PM -0500, Ian Lance Taylor wrote:
> For some reason, linker decides to strip the input relocation
> section, .rel.gnu.linkonce.t._._19srvr_message_list_c.
>
> The linker always strips all input relocation sections. That is
> correct behaviour.
>
> I still don't understand what the actual problem is.
>
> Ian
Ian,
Here is a testcase for ELF/i386. With my patch, I got:
# make
gcc -c -o foo.o foo.c
gcc -c -o test.o test.c
gcc -shared -Wl,-Bsymbolic -Wl,--noinhibit-exec -o libtest.so test.o test1.o
gcc -o foo foo.o -Wl,-rpath,. -L. -ltest
./foo
test1
Without my patch, I got:
gcc -c -o foo.o foo.c
gcc -c -o test.o test.c
gcc -shared -Wl,-Bsymbolic -Wl,--noinhibit-exec -o libtest.so test.o test1.o
gcc -o foo foo.o -Wl,-rpath,. -L. -ltest
./foo
make: *** [all] Illegal instruction
If you take a look at the sections in libtest.so, you will find out
the .rel.text section is not there.
Thanks.
--
H.J. Lu (hjl@gnu.org)
---
#!/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-02-04 09:35 PST by <hjl@osmium.su.varesearch.com>.
# Source directory was `/home/hjl/bugs/gas/symbolic3'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 356 -rw-r--r-- Makefile
# 84 -rw-r--r-- foo.c
# 154 -rw-r--r-- test.c
# 69 -rw-r--r-- test1.c
#
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 _sh07589; then
$echo 'x -' 'creating lock directory'
else
$echo 'failed to create lock directory'
exit 1
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= #-fPIC
SHLIBLDFLAGS= -Wl,-Bsymbolic -Wl,--noinhibit-exec
LDFLAGS=
X
CC=gcc -B./
X
all: foo
X ./foo
X
%.o: %.c
X $(CC) -c $(CFLAGS) -o $@ $<
X
libtest.so: test.o test1.o
X $(CC) -shared $(SHLIBLDFLAGS) -o $@ $^
X
foo: foo.o libtest.so
X $(CC) $(LDFLAGS) -o $@ $< -Wl,-rpath,. -L. -ltest
X
clean:
X rm -f *~ *.so *.o *.s foo
X
shar:
X shar Makefile *.c > l.shar
SHAR_EOF
(set 20 00 02 04 09 35 11 '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'
44d0ec785cc89022c29102b2a58cb81b Makefile
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
test 356 -eq "$shar_count" ||
$echo 'Makefile:' 'original size' '356,' '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' &&
extern void test1 (const char *);
X
int
main ()
{
X test1 ("test1\n");
X return 0;
}
SHAR_EOF
(set 20 00 02 04 09 34 49 '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'
40378e9d69d9da3257e2e96b059ded66 foo.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'foo.c'`"
test 84 -eq "$shar_count" ||
$echo 'foo.c:' 'original size' '84,' 'current size' "$shar_count!"
fi
fi
# ============= test.c ==============
if test -f 'test.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'test.c' '(file already exists)'
else
$echo 'x -' extracting 'test.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'test.c' &&
extern void foo (const char *);
X
void test1 (const char *) __attribute__ ((section(".gnu.linkonce.t.test1")));
X
void
test1 (const char *s)
{
X foo (s);
}
SHAR_EOF
(set 20 00 02 04 09 34 59 'test.c'; eval "$shar_touch") &&
chmod 0644 'test.c' ||
$echo 'restore of' 'test.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 'test.c:' 'MD5 check failed'
c554c01521000d8bc8b149a85949fe71 test.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'test.c'`"
test 154 -eq "$shar_count" ||
$echo 'test.c:' 'original size' '154,' 'current size' "$shar_count!"
fi
fi
# ============= test1.c ==============
if test -f 'test1.c' && test "$first_param" != -c; then
$echo 'x -' SKIPPING 'test1.c' '(file already exists)'
else
$echo 'x -' extracting 'test1.c' '(text)'
sed 's/^X//' << 'SHAR_EOF' > 'test1.c' &&
#include <stdio.h>
X
void
foo (const char *s)
{
X printf ("%s", s);
}
SHAR_EOF
(set 20 00 02 04 09 31 28 'test1.c'; eval "$shar_touch") &&
chmod 0644 'test1.c' ||
$echo 'restore of' 'test1.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 'test1.c:' 'MD5 check failed'
e1bb251bf0c0aeadd8b70d2ce528325d test1.c
SHAR_EOF
else
shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'test1.c'`"
test 69 -eq "$shar_count" ||
$echo 'test1.c:' 'original size' '69,' 'current size' "$shar_count!"
fi
fi
rm -fr _sh07589
exit 0