1#!/usr/bin/perl 2 3# Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions 7# are met: 8# 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15# its contributors may be used to endorse or promote products derived 16# from this software without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29# "check-for-weak-vtables" script for WebKit Open Source Project 30 31# Intended to be invoked from an Xcode build step to check if there are 32# any weak vtables in a target. 33 34use warnings; 35use strict; 36 37use File::Basename; 38 39sub touch($); 40 41my $arch = $ENV{'CURRENT_ARCH'}; 42my $configuration = $ENV{'CONFIGURATION'}; 43my $target = $ENV{'TARGET_NAME'}; 44my $variant = $ENV{'CURRENT_VARIANT'}; 45my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'}; 46my $debugRoot = $ENV{'WEBKIT_DEBUG_ROOT'}; 47 48$arch = $ENV{'NATIVE_ARCH'} if !$arch; # for Xcode 2.1, which does not have CURRENT_ARCH 49$variant = "normal" if !$variant; # for Xcode 2.1, which does not have CURRENT_VARIANT 50 51my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}"; 52 53my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . ".timestamp"; 54my $buildTimestampAge = -M $buildTimestampPath; 55my $executablePathAge = -M $executablePath; 56 57my $sawError = 0; 58 59if (!defined $executablePathAge || !defined $buildTimestampAge || $executablePathAge > $buildTimestampAge) { 60 if (!open NM, "(nm -m '$executablePath' | c++filt | sed 's/^/STDOUT:/') 2>&1 |") { 61 print "ERROR: Could not open $executablePath\n"; 62 $sawError = 1; 63 next; 64 } 65 my @weakVTableClasses = (); 66 while (<NM>) { 67 if (/^STDOUT:/) { 68 push @weakVTableClasses, $1 if /weak external vtable for (.*)$/; 69 } else { 70 print STDERR if $_ ne "nm: no name list\n"; 71 } 72 } 73 close NM; 74 if (@weakVTableClasses) { 75 my $shortName = $executablePath; 76 $shortName =~ s/.*\///; 77 78 print "ERROR: $shortName has a weak vtable in it ($executablePath)\n"; 79 print "ERROR: Fix by making sure the first virtual function in each of these classes is not an inline:\n"; 80 for my $class (sort @weakVTableClasses) { 81 print "ERROR: class $class\n"; 82 } 83 $sawError = 1; 84 } 85} 86 87if ($sawError and !$coverageBuild) { 88 unlink $executablePath; 89 exit 1; 90} 91 92touch($buildTimestampPath); 93 94exit 0; 95 96sub touch($) 97{ 98 my ($path) = @_; 99 open(TOUCH, ">", $path) or die "$!"; 100 close(TOUCH); 101} 102