|
Lines 1-163
a/Tools/Scripts/check-for-global-initializers_sec1
|
| 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 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-global-initializers" script for WebKit Open Source Project |
| 30 |
|
| 31 |
# Intended to be invoked from an Xcode build step to check if there are |
| 32 |
# any global initializers in a target. |
| 33 |
|
| 34 |
use warnings; |
| 35 |
use strict; |
| 36 |
|
| 37 |
use File::Basename; |
| 38 |
|
| 39 |
sub touch($); |
| 40 |
sub demangle($); |
| 41 |
|
| 42 |
my $arch = $ENV{'CURRENT_ARCH'}; |
| 43 |
my $configuration = $ENV{'CONFIGURATION'}; |
| 44 |
my $target = $ENV{'TARGET_NAME'}; |
| 45 |
my $variant = $ENV{'CURRENT_VARIANT'}; |
| 46 |
my $coverageBuild = $ENV{'WEBKIT_COVERAGE_BUILD'}; |
| 47 |
my $debugRoot = $ENV{'WEBKIT_DEBUG_ROOT'}; |
| 48 |
|
| 49 |
my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}"; |
| 50 |
|
| 51 |
my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . ".timestamp"; |
| 52 |
my $buildTimestampAge = -M $buildTimestampPath; |
| 53 |
my $scriptAge = -M $0; |
| 54 |
|
| 55 |
my $list = $ENV{"LINK_FILE_LIST_${variant}_${arch}"}; |
| 56 |
|
| 57 |
if (!open LIST, $list) { |
| 58 |
print "ERROR: Could not open $list\n"; |
| 59 |
exit 1; |
| 60 |
} |
| 61 |
|
| 62 |
my @files = <LIST>; |
| 63 |
chomp @files; |
| 64 |
close LIST; |
| 65 |
|
| 66 |
my $sawError = 0; |
| 67 |
|
| 68 |
for my $file (sort @files) { |
| 69 |
if (defined $buildTimestampAge && $buildTimestampAge < $scriptAge) { |
| 70 |
my $fileAge = -M $file; |
| 71 |
next if defined $fileAge && $fileAge > $buildTimestampAge; |
| 72 |
} |
| 73 |
if (!open NM, "(nm '$file' | sed 's/^/STDOUT:/') 2>&1 |") { |
| 74 |
print "ERROR: Could not open $file\n"; |
| 75 |
$sawError = 1; |
| 76 |
next; |
| 77 |
} |
| 78 |
my $sawGlobal = 0; |
| 79 |
my @globals; |
| 80 |
while (<NM>) { |
| 81 |
if (/^STDOUT:/) { |
| 82 |
my $line = $_; |
| 83 |
if ($line =~ /__GLOBAL__I(.+)$/) { |
| 84 |
$sawGlobal = 1; |
| 85 |
push(@globals, demangle($1)); |
| 86 |
} |
| 87 |
} else { |
| 88 |
print STDERR if $_ ne "nm: no name list\n"; |
| 89 |
} |
| 90 |
} |
| 91 |
close NM; |
| 92 |
if ($sawGlobal) { |
| 93 |
my $shortName = $file; |
| 94 |
$shortName =~ s/.*\///; |
| 95 |
|
| 96 |
# Special cases for files that have initializers in debug builds. |
| 97 |
if ($configuration eq "Debug" or $variant eq "debug" or $debugRoot) { |
| 98 |
if ($target eq "JavaScriptCore") { |
| 99 |
next if $shortName eq "AllInOneFile.o"; |
| 100 |
next if $shortName eq "Opcode.o"; |
| 101 |
next if $shortName eq "Structure.o"; |
| 102 |
next if $shortName eq "nodes.o"; |
| 103 |
} |
| 104 |
if ($target eq "WebCore") { |
| 105 |
next if $shortName eq "BidiRun.o"; |
| 106 |
next if $shortName eq "CachedPage.o"; |
| 107 |
next if $shortName eq "CachedResource.o"; |
| 108 |
next if $shortName eq "FEGaussianBlur.o"; |
| 109 |
next if $shortName eq "Frame.o"; |
| 110 |
next if $shortName eq "JSCustomSQLTransactionCallback.o"; |
| 111 |
next if $shortName eq "JSLazyEventListener.o"; |
| 112 |
next if $shortName eq "Node.o"; |
| 113 |
next if $shortName eq "Page.o"; |
| 114 |
next if $shortName eq "Range.o"; |
| 115 |
next if $shortName eq "RenderObject.o"; |
| 116 |
next if $shortName eq "SubresourceLoader.o"; |
| 117 |
next if $shortName eq "XMLHttpRequest.o"; |
| 118 |
} |
| 119 |
if ($target eq "WebKit") { |
| 120 |
next if $shortName eq "HostedNetscapePluginStream.o"; |
| 121 |
next if $shortName eq "NetscapePluginInstanceProxy.o"; |
| 122 |
} |
| 123 |
if ($target eq "WebKit2") { |
| 124 |
next if $shortName eq "WebContext.o"; |
| 125 |
next if $shortName eq "WebFrame.o"; |
| 126 |
next if $shortName eq "WebPage.o"; |
| 127 |
next if $shortName eq "WebPageProxy.o"; |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
print "ERROR: $shortName has one or more global initializers in it! ($file), near @globals\n"; |
| 132 |
$sawError = 1; |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
if ($sawError and !$coverageBuild) { |
| 137 |
unlink $executablePath; |
| 138 |
exit 1; |
| 139 |
} |
| 140 |
|
| 141 |
touch($buildTimestampPath); |
| 142 |
exit 0; |
| 143 |
|
| 144 |
sub touch($) |
| 145 |
{ |
| 146 |
my ($path) = @_; |
| 147 |
open(TOUCH, ">", $path) or die "$!"; |
| 148 |
close(TOUCH); |
| 149 |
} |
| 150 |
|
| 151 |
sub demangle($) |
| 152 |
{ |
| 153 |
my ($symbol) = @_; |
| 154 |
if (!open FILT, "c++filt $symbol |") { |
| 155 |
print "ERROR: Could not open c++filt\n"; |
| 156 |
return; |
| 157 |
} |
| 158 |
my $result = <FILT>; |
| 159 |
close FILT; |
| 160 |
chomp $result; |
| 161 |
return $result; |
| 162 |
} |
| 163 |
|