This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
absolute syms in shared libs
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sources dot redhat dot com
- Date: Fri, 4 Oct 2002 11:34:37 +0930
- Subject: absolute syms in shared libs
Consider the following
cat > lib1.s <<EOF
.text
jmp foo
EOF
cat > lib2.s <<EOF
.global foo
foo = 0x12345678
EOF
as -o lib1.o lib1.s
as -o lib2.o lib2.s
ld -shared -o lib2.so lib2.o
ld -shared -o lib1.so lib1.o
This gives us lib1.so with a reloc against foo, an absolute sym
defined in lib2.so. Loading both shared libs thus allows jumping
to an absolute location in memory even when the libs are loaded
at arbitrary locations.
Question: Why can't we do this with a single shared lib? (Ignoring
the fact that jumping to absolute locations in memory might not be
a good idea!)
cat > lib.s <<EOF
.global foo
foo = 0x12345678
.text
jmp foo
EOF
as -o lib.o lib.s
ld -shared -o lib.so lib.o
readelf -r lib.so
There are no relocations in this file.
Oops, our "jmp foo" goes to the shared lib load address + 0x12345678.
This can be fixed, but I'm just wondering whether it's wise to
change the current ld behaviour. Opinions?
--
Alan Modra
IBM OzLabs - Linux Technology Centre