1#!/bin/sh 2 3objdir="$1" 4 5num_errors=0 6 7check_syms() { 8 global_count=0 9 entry_count=0 10 while read value type name; do 11 if [ $value = "U" ]; then 12 name=$type 13 # undefined symbols must start with double-underscore 14 if [ $(expr $name : '\(..\)') != "__" ]; then 15 echo -e "$(basename $file):\tError: undefined reference $name doesn't start with \"__\"." 16 num_errors=$(($num_errors + 1)) 17 fi 18 continue 19 fi 20 21 case "$type" in 22 W) 23 entry_count=$(($entry_count + 1)) 24 ;; 25 *) 26 entry_count=$(($entry_count + 1)) 27 if [ "$(expr $name : '\(..\)')" != "__" ]; then 28 global_count=$(($global_count + 1)) 29 fi 30 ;; 31 esac 32 done 33 if [ $entry_count -gt 1 -a $global_count -gt 0 ]; then 34 echo -e "$(basename $file):\tError: detected $global_count strong " \ 35 "global and $entry_count entry-points." 36 num_errors=$(($num_errors + 1)) 37 fi 38} 39 40check_file() { 41 file=$1 42 size=$(readelf -S $file | \ 43 (sz=0; while read line; do 44 if echo $line | fgrep -q " .rodata"; then 45 read sz rest 46 break 47 fi 48 done; 49 printf "%d" 0x$sz)) 50 51 summands=$(readelf -s $file | fgrep " OBJECT " | tr -s ' ' | 52 cut -f4 -d' ' | sed 's,$,+,')0 53 sum=$(($summands)) 54 if [ $sum != $size ]; then 55 echo -e "$(basename $file):\tError: sum of objects=$sum bytes, .rodata size=$size bytes" 56 num_errors=$(($num_errors + 1)) 57 fi 58 59 tmp=$(tempfile -p syms) 60 nm -g $file > $tmp 61 check_syms < $tmp 62} 63 64do_checks() { 65 echo "Note: 1 error expected in w_tgammal.o due to 64-byte alignment-padding." 66 while read func_pattern src_file dst_file; do 67 if [ "$(expr $dst_file : '.*\(S\)$')" = "S" ]; then 68 objfile=$(expr $dst_file : '\(.*\)[.]S$') 69 check_file $objdir/$objfile.o 70 fi 71 done 72} 73 74do_checks < import_file_list 75 76if [ $num_errors -gt 0 ]; then 77 echo "FAILURE: Detected $num_errors error(s)." 78 exit 1 79fi 80echo SUCCESS 81exit 0 82