Blame SOURCES/dummylib.sh

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