|
|
6693b3 |
#!/bin/sh
|
|
|
6693b3 |
if [ $# -lt 3 ]; then echo Usage: dummylib.sh orig_lib_path dummy_lib_path mapfile; exit 1; fi
|
|
|
6693b3 |
TMPDIR=`mktemp -d dummylib.sh.XXXXXX` || exit 1
|
|
|
6693b3 |
F=`file -L $1`
|
|
|
6693b3 |
C=
|
|
|
6693b3 |
S=8
|
|
|
6693b3 |
case "$F" in
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*x86-64*) C=-m64;;
|
|
|
6693b3 |
*ELF\ 32-bit*shared\ object*80?86*) C=-m32; S=4;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*PowerPC*) C=-m64;;
|
|
|
6693b3 |
*ELF\ 32-bit*shared\ object*PowerPC*) C=-m32; S=4;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*cisco*) C=-m64;;
|
|
|
6693b3 |
*ELF\ 32-bit*shared\ object*cisco*) C=-m32; S=4;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*IA-64*) C=;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*Alpha*) C=;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*390*) C=-m64;;
|
|
|
6693b3 |
*ELF\ 32-bit*shared\ object*390*) C=-m31; S=4;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*SPARC*) C=-m64;;
|
|
|
6693b3 |
*ELF\ 32-bit*shared\ object*SPARC*) C=-m32; S=4;;
|
|
|
6693b3 |
*ELF\ 64-bit*shared\ object*Alpha*) C=;;
|
|
|
6693b3 |
esac
|
|
|
6693b3 |
readelf -Ws $1 | awk '
|
|
|
6693b3 |
/\.dynsym.* contains/ { start=1 }
|
|
|
6693b3 |
/^$/ { start=0 }
|
|
|
6693b3 |
/ UND / { next }
|
|
|
6693b3 |
/@/ { if (start) {
|
|
|
6693b3 |
fn=$8
|
|
|
6693b3 |
intfn="HACK" hack+0
|
|
|
6693b3 |
hack++
|
|
|
6693b3 |
if ($4 ~ /FUNC/) { print ".text"; size=16; print ".type " intfn ",@function" }
|
|
|
6693b3 |
else if ($4 ~ /OBJECT/) { print ".data"; size=$3; print ".type " intfn ",@object" }
|
|
|
6693b3 |
else if ($4 ~ /NOTYPE/) { print ".data"; size=$3 }
|
|
|
6693b3 |
else exit(1);
|
|
|
6693b3 |
print ".globl " intfn
|
|
|
6693b3 |
if ($5 ~ /WEAK/) { print ".weak " intfn }
|
|
|
6693b3 |
else if ($5 !~ /GLOBAL/) exit(1);
|
|
|
6693b3 |
print intfn ": .skip " size
|
|
|
6693b3 |
print ".size " intfn "," size
|
|
|
6693b3 |
print ".symver " intfn "," fn
|
|
|
6693b3 |
} }
|
|
|
6693b3 |
' > $TMPDIR/lib.s || exit
|
|
|
6693b3 |
soname=`readelf -Wd $1 | grep SONAME | sed 's/^.*\[//;s/\].*$//'`
|
|
|
6693b3 |
gcc $C -shared -Wl,-soname,$soname,-version-script,$3 \
|
|
|
6693b3 |
-o $2 $TMPDIR/lib.s -nostdlib
|
|
|
6693b3 |
strip $2
|
|
|
6693b3 |
rm -rf $TMPDIR
|