From 09aa390eeed1f380ac7925ce4bcc5058f35b9619 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Thu, 20 May 2004 13:58:49 +0000 Subject: [PATCH] Initial revision --- admin/bcheck.pl | 156 +++++++++++++++++++++ admin/deps.am | 19 +++ admin/nmcheck | 371 +++++++++++++++++++++++++++++++++++++++++++++++++ admin/oldinclude.m4.in | 192 +++++++++++++++++++++++++ 4 files changed, 738 insertions(+) create mode 100644 admin/bcheck.pl create mode 100644 admin/deps.am create mode 100755 admin/nmcheck create mode 100644 admin/oldinclude.m4.in diff --git a/admin/bcheck.pl b/admin/bcheck.pl new file mode 100644 index 0000000..46485e5 --- /dev/null +++ b/admin/bcheck.pl @@ -0,0 +1,156 @@ +#!/usr/bin/perl -w + +use DB_File; +use Fcntl ':flock'; + +if (!defined($ARGV[0])) { + print "usage: requires .class dump as parameter!\n"; + exit; +} + +sub bailout +{ + untie %bcheckdb if(defined(%bcheckdb)); + + if(defined(MYLOCK)) { + flock MYLOCK, LOCK_UN; + close(MYLOCK); + } + + print @_; + exit 5; +} + +sub ask_user +{ + my ($dbkey, $dbchunk) = @_; + + if (defined($ENV{"BCHECK_UPDATE"})) { + $bcheckdb{$dbkey} = $dbchunk; + return; + } + + &bailout("BC problem detected") if (! -t STDIN); + + print "(I)gnore / (Q)uit / (U)pdate: "; + + my $key; + while(defined(read STDIN, $key, 1)) { + $key = lc($key); + + print "got: >$key<\n"; + + return if ($key eq 'i'); + + &bailout("BC problem. aborted") if ($key eq 'q'); + + if ($key eq 'u') { + $bcheckdb{$dbkey} = $dbchunk; + return; + } + print "\n(I)gnore / (Q)uit / (U)pdate: "; + } +} + +sub diff_chunk($$) +{ + my ($oldl, $newl) = @_; + my @old = split /^/m, $oldl; + my @new = split /^/m, $newl; + my $haschanges = 0; + my $max = $#old > $#new ? $#old : $#new; + + die "whoops. key different" if ($old[0] ne $new[0]); + + if ($#old != $#new) { + warn ("Structural difference.\n"); + print @old; + print "-----------------------------------------------\n"; + print @new; + $haschanges = 1; + return $haschanges; + } + + print $old[0]; + + my ($class) = ($old[0] =~ /^(?:Class |Vtable for )(\S+)/); + + my $c = 1; + while ($c < $max) { + my ($o, $n) = ($old[$c], $new[$c]); + chomp $o; + chomp $n; + $c++; + next if ($o eq $n); + + if(defined($class) and $n =~ /^(\d+\s+)\w+(::\S+\s*.*)$/) { + next if ($n eq "$1$class$2"); + } + + $haschanges = 1; + + print "-$o\n+$n\n\n"; + } + + return $haschanges; +} + +local $dblock = $ENV{"HOME"} . "/bcheck.lock"; +my $dbfile = $ENV{"HOME"} . "/bcheck.db"; +my $cdump = $ARGV[0]; + +die "file $cdump is not readable: $!" if (! -f $cdump); + +# make sure the advisory lock exists +open(MYLOCK, ">$dblock"); +print MYLOCK ""; + +flock MYLOCK, LOCK_EX; + +tie %bcheckdb, 'DB_File', $dbfile; + +my $chunk = ""; + +open (IN, "<$cdump") or die "cannot open $cdump: $!"; +while () { + + chop; + + s/0x[0-9a-fA-F]+/0x......../g; + s/base size=/size=/g; + s/base align=/align=/g; + + $chunk .= $_ . "\n"; + + if(/^\s*$/) { + my @lines = split /^/m, $chunk; + my $key = $lines[0]; + chomp $key; + + if($key !~ // && + $key !~ //) { + if(defined($bcheckdb{$key})) { + my $dbversion = $bcheckdb{$key}; + + if($dbversion ne $chunk) { + &ask_user($key, $chunk) if(&diff_chunk($dbversion, $chunk)); + } + } + else { + $bcheckdb{$key} = $chunk; + print "NEW: $key\n"; + } + } + + $chunk = ""; + next; + } + +} +close(IN); + +untie %bcheckdb; +flock MYLOCK, LOCK_UN; +close(MYLOCK); + +exit 0; diff --git a/admin/deps.am b/admin/deps.am new file mode 100644 index 0000000..8f83a96 --- /dev/null +++ b/admin/deps.am @@ -0,0 +1,19 @@ +$(top_srcdir)/acinclude.m4: $(top_srcdir)/admin/acinclude.m4.in $(top_srcdir)/admin/libtool.m4.in $(top_srcdir)/admin/cvs.sh + @cd $(top_srcdir) && $(SHELL) admin/cvs.sh acinclude_m4 + +$(top_srcdir)/configure.in: $(top_srcdir)/subdirs $(top_srcdir)/configure.files $(top_srcdir)/admin/cvs.sh + @cd $(top_srcdir) && $(SHELL) admin/cvs.sh configure_in + +$(top_srcdir)/configure.files: $(top_srcdir)/subdirs $(CONF_FILES) + @cd $(top_srcdir) && $(SHELL) admin/cvs.sh configure.files $(top_srcdir)/admin/cvs.sh + +$(top_srcdir)/Makefile.am: $(top_srcdir)/Makefile.am.in $(top_srcdir)/subdirs $(top_srcdir)/admin/cvs.sh + @cd $(top_srcdir) && $(SHELL) admin/cvs.sh Makefile_am + +$(top_srcdir)/subdirs: $(top_srcdir)/Makefile.am.in $(top_srcdir)/admin/cvs.sh + @cd $(top_srcdir) && $(SHELL) admin/cvs.sh subdirs + +# defining default rules for files that may not be present +$(top_srcdir)/Makefile.am.in: +$(CONF_FILES): + diff --git a/admin/nmcheck b/admin/nmcheck new file mode 100755 index 0000000..1544713 --- /dev/null +++ b/admin/nmcheck @@ -0,0 +1,371 @@ +#!/usr/bin/perl -w + +# Check namespace cleanness of a library. +# Allowed symbols are passed as arguments. +# They may have trailing * = wildcard. +# Wildcards may be also specified as *::* (e.g. K*::* for all KDE classes) +# Symbols are listed as full function unmangled names without arguments, +# e.g. 'foo bar* nspace::*' allows foo(), foo(int), bar(), barbar() +# and all symbols in namespace/class nspace. +# If an argument has comma in it, it's a filename of a file containing +# allowed symbols, one per line. + + +$thisProg = "$0"; # This programs name + +$library = ""; +$allowed_symbols = ""; +$debug = 0; +$allowed_weak = ""; +$weak_specified = 0; + +while( defined( $ARGV[ 0 ] )) +{ + $_ = shift; + if( /^--verbose$|^-v$/ ) + { + $debug = 1; + } + elsif( /^--help$|^-h$/ ) + { + print STDOUT "Usage $thisProg [OPTION] ... library [allowed symbols] ...\n", + "\n", + "Check if the given library has only allowed public symbols.\n", + "\n", + " --allowweak=[symbol] allow only these weak symbols\n", + " -v, --verbose verbosely list files processed\n", + " -h, --help print this help, then exit\n"; + exit 0; + } + elsif( /^--allowweak=(.*)$/ ) + { + $allowed_weak .= " " . $1; + $weak_specified = 1; + } + elsif( /^--allowweak$/ ) # simply list all weak + { + $allowed_weak .= " "; + $weak_specified = 1; + } + elsif( /^--*/ ) + { + die "Invalid argument!\n"; + } + else + { + if( ! $library ) + { + $library = $_; + } + else + { + $allowed_symbols .= " " . $_; + } + } +} + +if( ! $weak_specified ) +{ + $allowed_weak = "*"; + # allow all weak symbols by default + # instances of templates and similar stuff - unfortunately includes also things from other libraries, + # so it cannot be on by default +} + +print STDERR "library:" . $library . "\n" if $debug; +print STDERR "allowed_symbols:" . $allowed_symbols . "\n" if $debug; +print STDERR "allowed_weak:" . $allowed_weak . "\n" if $debug; + +$default_symbols = "_fini _init"; # system symbols +# on my system, every .so has : +# A _DYNAMIC +# A _GLOBAL_OFFSET_TABLE_ +# A __bss_start +# A _edata +# A _end +# T _fini +# T _init +# no need to list A symbols in $default_symbols + +print STDERR "default_symbols: " . $default_symbols . "\n" if $debug; + +print STDOUT "Namespace cleanness check for " . $library . " :\n"; + +$lib_file = ""; +if( $library =~ /\.la$/ ) +{ + # get the real library file from .la + open( FILEIN, $library ) || die "Couldn't open $! !\n"; + while( $line = ) + { + if( $line =~ /library_names=\'([^ ]*).*/o ) + { + $lib_file = $1; + } + } + close( FILEIN ); + if( ! $lib_file ) + { + print STDERR "Library file not found in .la file!\n"; + exit 1; + } + my $libpath = $library; + $libpath =~ s%[^/]*$%%; + if( -e $libpath . ".libs/" . $lib_file ) + { + $lib_file = $libpath . ".libs/" . $lib_file; + } + else + { + $lib_file = $libpath . $lib_file; + } +} +else +{ + $lib_file = $library; +} + +print STDERR "libfile: ". $lib_file . "\n" if $debug; + +$allowed_symbols .= " " . $default_symbols; + +sub process_symbols($\@\%\@); + +@wildcards = (); +%exacts = (); +@regwildcards = (); +process_symbols( $allowed_symbols, @wildcards, %exacts, @regwildcards ); +@weak_wildcards = (); +%weak_exacts = (); +@weak_regwildcards = (); +process_symbols( $allowed_weak, @weak_wildcards, %weak_exacts, @weak_regwildcards ); + +# grep is for stripping not exported symbols, which don't have address (=first column) +$nm_command = "nm -BDCg " . $lib_file . " | grep -v '^ ' |"; + +# TODO how portable is this nmcheck stuff? + +print STDERR "nm command:" . $nm_command . "\n" if $debug; + +open( FILEIN, $nm_command ) || die "nm command failed\n"; + +my $exit_code = 0; + +while( $line = ) +{ + my $type; + my $symbol; + if( $line =~ /^[^ ]* (.) (.*)$/o ) + { + $type = $1; + $symbol = $2; + } + else + { + die "Invalid line: " . $line . "\n"; + } + + print STDERR "Type: " . $type . " , symbol: " . $symbol . "\n" if $debug; + if( $type eq "A" ) + { # these should be system symbols, so ignore them + next; + } + + my $orig_symbol = $symbol; + + if( $symbol =~ /\(anonymous namespace\)/o ) + { # TODO tell to prefer named namespaces? (shorter symbols) + next; + } + + # strip prefixes + # the :: appending is to make "CLASS::*" work also for "vtable for CLASS" + $symbol =~ s/^typeinfo for (.*)$/$1::/o; + $symbol =~ s/^typeinfo fn for (.*)$/$1::/o; + $symbol =~ s/^typeinfo name for (.*)$/$1::/o; + $symbol =~ s/^vtable for (.*)$/$1::/o; + $symbol =~ s/^guard variable for (.*)$/$1::/o; + $symbol =~ s/^reference temporary for (.*)$/$1::/o; + $symbol =~ s/^VTT for (.*)$/$1::/o; + $symbol =~ s/^virtual thunk \[[^\]]*\] to (.*)$/$1::/o; + $symbol =~ s/^non-virtual thunk \[[^\]]*\] to (.*)$/$1::/o; + $symbol =~ s/^covariant return thunk \[[^\]]*\] to (.*)$/$1::/o; + $symbol =~ s/^construction vtable thunk for (.*)$/$1::/o; + $symbol =~ s/^construction vtable for .*-in-(.*) [0-9]*$/$1::/o; + + # templates seem to have also return types mangled in their name, and nm prints it too + # they have also template arguments in the symbol + # get rid of both of those + while( $symbol =~ /<.*>/o ) + { + $symbol =~ s/<[^<>]*>//o; # strip innermost <> + } + if( $symbol !~ /operator\(\)/o ) + { + $symbol =~ s/ ?\(.*\).*$//o; # strip () and all after it + } + else + { + $symbol =~ s/(^|:| )operator\(\) ?\(.*\).*$//o; # strip () and all after it + } + $symbol =~ s/\[.*\] *$//o; # strip [in-charge] etc. + if( $symbol =~ /(^|:| )operator /o ) + { + $symbol =~ s/.* ([^\s]*)operator /$1/o; # strip everything before 'X::operator blah' + } + else + { + $symbol =~ s/.* ([^\s]+) *$/$1/o; # get last word (strip return type) + } + + # print STDERR "Processed symbol: " . $symbol . "\n" if $debug; + + my $found = 0; + if( $exacts{ $symbol } ) + { + $found = 1; + } + if( ! $found ) + { + for my $wild ( @wildcards ) + { + if( index( $symbol, $wild ) == 0 ) + { + $found = 1; + last; + } + } + } + if( ! $found ) + { + for my $wild ( @regwildcards ) + { + if( $symbol =~ /^$wild$/ ) + { + $found = 1; + last; + } + } + } + if( ( ! $found ) && ( $type eq "W" || $type eq "V" )) + { + if( $weak_exacts{ $symbol } ) + { + $found = 1; + } + if( ! $found ) + { + for my $wild ( @weak_wildcards ) + { + if( index( $symbol, $wild ) == 0 ) + { + $found = 1; + last; + } + } + } + if( ! $found ) + { + for my $wild ( @weak_regwildcards ) + { + if( $symbol =~ /^$wild$/ ) + { + $found = 1; + last; + } + } + } + } + + if( ! $found ) + { + print STDERR "Public symbol " . $orig_symbol . " is not allowed!\n"; + $exit_code = 1; + } +} + +close( FILEIN ); + +print STDOUT $exit_code == 0 ? "OK\n" : "FAILED\n"; + +exit $exit_code; + +sub process_symbols($\@\%\@) +{ + my $allowed_symbols = $_[ 0 ]; + my $wildcards_ref = $_[ 1 ]; + my $exacts_ref = $_[ 2 ]; + my $regwildcards_ref = $_[ 3 ]; + + $allowed_symbols =~ s/^ *//o; # strip whitespace + $allowed_symbols =~ s/ *$//o; + + if( $allowed_symbols eq "NONE" ) + { + $allowed_symbols = ""; + } + + my @symbols1 = split( ' ', $allowed_symbols ); + my $i = 0; + my @symbols2 = (); + while( defined( $symbols1[ $i ] )) + { + my $symbol = $symbols1[ $i ]; + if( $symbol =~ /\./ ) # dot in name -> file + { + open( SYMIN, $symbol ) || die ( "Cannot open file " . $symbol . "!" ); + while( $line = ) + { + $line =~ s/^\s*//o; # strip whitespace + $line =~ s/\s*$//o; + if( $line !~ /^$/o # empty line + && $line !~ /^\s*#/ ) # comment line starting with # + { + $symbols2[ $#symbols2 + 1 ] = $line; + } + } + close( SYMIN ); + } + else + { + $symbols2[ $#symbols2 + 1 ] = $symbol; + } + $i++; + } + $i = 0; + while( defined( $symbols2[ $i ] )) + { + my $symbol = $symbols2[ $i ]; + if( $symbol =~ /__/ + || $symbol =~ /^_[A-Z]/ ) + { # ISO C++ 2.10.2 + die "Symbols containing a double underscore or beginning with an underscore and an upper-case letter are reserved!\n"; + } + elsif( $symbol eq "main" + || $symbol eq "main*" ) + { + die "Symbol main is not allowed!\n"; + } + if( $symbol =~ /^([^\*]*)\*$/o # trailing * without any * before it + && $symbol !~ /operator\*$/o ) + { + print STDERR "wildcard:" . $symbol . "\n" if $debug; + $wildcards_ref->[ $#{$wildcards_ref} + 1 ] = $1; + } + elsif( $symbol =~ /\*$/o + && ( $symbol =~ /\*::/o || $symbol =~ /::\*/o ) + && $symbol !~ /^\*/o + && $symbol !~ /operator\*$/o ) + { + print STDERR "regwildcard:" . $symbol . "\n" if $debug; + $symbol =~ s/\*/\.\*/go; # change * to .* (regexp) + $regwildcards_ref->[ $#{$regwildcards_ref} + 1 ] = $symbol; + } + else + { + print STDERR "exact:" . $symbol . "\n" if $debug; + $exacts_ref->{ $symbol } = 1; + } + $i++; + } +} diff --git a/admin/oldinclude.m4.in b/admin/oldinclude.m4.in new file mode 100644 index 0000000..e5eb176 --- /dev/null +++ b/admin/oldinclude.m4.in @@ -0,0 +1,192 @@ +### -*- autoconf -*- + +dnl This file is part of the KDE libraries/packages +dnl Copyright (C) 1997 Janos Farkas (chexum@shadow.banki.hu) +dnl (C) 1997,98,99 Stephan Kulow (coolo@kde.org) + +dnl This file is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Library General Public +dnl License as published by the Free Software Foundation; either +dnl version 2 of the License, or (at your option) any later version. + +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Library General Public License for more details. + +dnl You should have received a copy of the GNU Library General Public License +dnl along with this library; see the file COPYING.LIB. If not, write to +dnl the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +dnl Boston, MA 02111-1307, USA. + +AC_DEFUN([KDE_CHECK_MICO], +[ +AC_REQUIRE([KDE_CHECK_LIBDL]) +AC_REQUIRE([KDE_MISC_TESTS]) +AC_MSG_CHECKING(for MICO) + +if test -z "$MICODIR"; then + kde_micodir=/usr/local + else + kde_micodir="$MICODIR" +fi + +AC_ARG_WITH(micodir, + [ --with-micodir=micodir where mico is installed ], + kde_micodir=$withval, + kde_micodir=$kde_micodir +) + +AC_CACHE_VAL(kde_cv_mico_incdir, +[ + mico_incdirs="$kde_micodir/include /usr/include /usr/local/include /usr/local/include /opt/local/include $kde_extra_includes" +AC_FIND_FILE(CORBA.h, $mico_incdirs, kde_cv_mico_incdir) + +]) +kde_micodir=`echo $kde_cv_mico_incdir | sed -e 's#/include##'` + +if test ! -r $kde_micodir/include/CORBA.h; then + AC_MSG_ERROR([No CORBA.h found, specify another micodir]) +fi + +AC_MSG_RESULT($kde_micodir) + +MICO_INCLUDES=-I$kde_micodir/include +AC_SUBST(MICO_INCLUDES) +MICO_LDFLAGS=-L$kde_micodir/lib +AC_SUBST(MICO_LDFLAGS) +micodir=$kde_micodir +AC_SUBST(micodir) + +AC_MSG_CHECKING([for MICO version]) +AC_CACHE_VAL(kde_cv_mico_version, +[ +AC_LANG_C +cat >conftest.$ac_ext < +#include +int main() { + + printf("MICO_VERSION=%s\n",MICO_VERSION); + return (0); +} +EOF +ac_compile='${CC-gcc} $CFLAGS $MICO_INCLUDES conftest.$ac_ext -o conftest' +if AC_TRY_EVAL(ac_compile); then + if eval `./conftest 2>&5`; then + kde_cv_mico_version=$MICO_VERSION + else + AC_MSG_ERROR([your system is not able to execute a small application to + find MICO version! Check $kde_micodir/include/mico/version.h]) + fi +else + AC_MSG_ERROR([your system is not able to compile a small application to + find MICO version! Check $kde_micodir/include/mico/version.h]) +fi +]) + +dnl installed MICO version +mico_v_maj=`echo $kde_cv_mico_version | sed -e 's/^\(.*\)\..*\..*$/\1/'` +mico_v_mid=`echo $kde_cv_mico_version | sed -e 's/^.*\.\(.*\)\..*$/\1/'` +mico_v_min=`echo $kde_cv_mico_version | sed -e 's/^.*\..*\.\(.*\)$/\1/'` + +if test "x$1" = "x"; then + req_version="2.3.0" +else + req_version=$1 +fi + +dnl required MICO version +req_v_maj=`echo $req_version | sed -e 's/^\(.*\)\..*\..*$/\1/'` +req_v_mid=`echo $req_version | sed -e 's/^.*\.\(.*\)\..*$/\1/'` +req_v_min=`echo $req_version | sed -e 's/^.*\..*\.\(.*\)$/\1/'` + +if test "$mico_v_maj" -lt "$req_v_maj" || \ + ( test "$mico_v_maj" -eq "$req_v_maj" && \ + test "$mico_v_mid" -lt "$req_v_mid" ) || \ + ( test "$mico_v_mid" -eq "$req_v_mid" && \ + test "$mico_v_min" -lt "$req_v_min" ) + +then + AC_MSG_ERROR([found MICO version $kde_cv_mico_version but version $req_version \ +at least is required. You should upgrade MICO.]) +else + AC_MSG_RESULT([$kde_cv_mico_version (minimum version $req_version, ok)]) +fi + +LIBMICO="-lmico$kde_cv_mico_version $LIBCRYPT $LIBSOCKET $LIBDL" +AC_SUBST(LIBMICO) +if test -z "$IDL"; then + IDL='$(kde_bindir)/cuteidl' +fi +AC_SUBST(IDL) +IDL_DEPENDENCIES='$(kde_includes)/CUTE.h' +AC_SUBST(IDL_DEPENDENCIES) + +idldir="\$(includedir)/idl" +AC_SUBST(idldir) + +]) + +AC_DEFUN([KDE_CHECK_MINI_STL], +[ +AC_REQUIRE([KDE_CHECK_MICO]) + +AC_MSG_CHECKING(if we use mico's mini-STL) +AC_CACHE_VAL(kde_cv_have_mini_stl, +[ +AC_LANG_SAVE +AC_LANG_CPLUSPLUS +kde_save_cxxflags="$CXXFLAGS" +CXXFLAGS="$CXXFLAGS $MICO_INCLUDES" +AC_TRY_COMPILE( +[ +#include +], +[ +#ifdef HAVE_MINI_STL +#error "nothing" +#endif +], +kde_cv_have_mini_stl=no, +kde_cv_have_mini_stl=yes) +CXXFLAGS="$kde_save_cxxflags" +AC_LANG_RESTORE +]) + +if test "x$kde_cv_have_mini_stl" = "xyes"; then + AC_MSG_RESULT(yes) + $1 +else + AC_MSG_RESULT(no) + $2 +fi +]) + +]) + +AC_DEFUN([KDE_CHECK_ANSI], +[ +]) + +AC_DEFUN([KDE_CHECK_INSURE], +[ + AC_ARG_ENABLE(insure, [ --enable-insure use insure++ for debugging [default=no]], + [ + if test $enableval = "no"; dnl + then ac_use_insure="no" + else ac_use_insure="yes" + fi + ], [ac_use_insure="no"]) + + AC_MSG_CHECKING(if we will use Insure++ to debug) + AC_MSG_RESULT($ac_use_insure) + if test "$ac_use_insure" = "yes"; dnl + then CC="insure"; CXX="insure"; dnl CFLAGS="$CLAGS -fno-rtti -fno-exceptions "???? + fi +]) + +AC_DEFUN([KDE_CHECK_NEWLIBS], +[ + +]) -- 2.11.4.GIT