Blame SOURCES/dummylib.sh

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