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