# ispic(): checks whether a binary object, either a .o or a .so file, has # only PIC code in it. It can also inspect .o files within a .a archive. # Written by Sam Hocevar 2004/10/28 ispic() { ispic_internal() { if objdump --headers --private-headers -T "$1" | grep -q TEXTREL; then echo -e "$2"': \x1b[31mhas non-PIC code\x1b[0m' else echo -e "$2"': \x1b[32mPIC\x1b[0m' fi } for x in $*; do TMPFILE="`tempfile -s .so`" case "$x" in *.a) echo "$x: archive" TMPOFILE="`tempfile -s .o`" for o in `ar t "$x"`; do ar p "$x" "$o" >| "$TMPOFILE" ispic "$TMPOFILE" | sed 's .*: \ \ '"$o"': ' done rm -f "$TMPOFILE" ;; *.o|*.so|*.so.*) case "$x" in *.so|*.so.*) ispic_internal "$x" "$x" ;; *.o) if gcc "$x" -shared -o "$TMPFILE" 2>&1 | grep -q relocation; then echo -e "$x"': \x1b[31mbad reloc, non-PIC code\x1b[0m' else ispic_internal "$TMPFILE" "$x" fi ;; esac ;; esac rm -f "$TMPFILE" done }