Blame SOURCES/dummylib.sh

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