3 # Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
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.
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.
29 # "check-for-exit-time-destructors" script for WebKit Open Source Project
31 # Intended to be invoked from an Xcode build step to check if there are
32 # any exit-time destructors in a target.
40 sub printFunctions($$);
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'};
49 $arch = $ENV{'NATIVE_ARCH'} if !$arch; # for Xcode 2.1, which does not have CURRENT_ARCH
50 $variant = "normal" if !$variant; # for Xcode 2.1, which does not have CURRENT_VARIANT
52 my $executablePath = "$ENV{'TARGET_BUILD_DIR'}/$ENV{'EXECUTABLE_PATH'}";
54 my $buildTimestampPath = $ENV{'TARGET_TEMP_DIR'} . "/" . basename($0) . ".timestamp";
55 my $buildTimestampAge = -M $buildTimestampPath;
56 my $scriptAge = -M $0;
58 my $list = $ENV{"LINK_FILE_LIST_${variant}_${arch}"};
60 if (!open LIST, $list) {
61 print "ERROR: Could not open $list\n";
71 for my $file (sort @files) {
72 if (defined $buildTimestampAge && $buildTimestampAge < $scriptAge) {
73 my $fileAge = -M $file;
74 next if defined $fileAge && $fileAge > $buildTimestampAge;
76 if (!open NM, "(nm '$file' | sed 's/^/STDOUT:/') 2>&1 |") {
77 print "ERROR: Could not open $file\n";
82 my $shortName = $file;
83 $shortName =~ s/.*\///;
87 # With GC logging enabled Heap.o may contain finalizers, so we ignore them.
88 $sawAtExit = 1 if (/___cxa_atexit/ && ($shortName ne "Heap.o"));
90 print STDERR if $_ ne "nm: no name list\n";
94 next unless $sawAtExit;
96 $sawError = 1 if printFunctions($shortName, $file);
99 if ($sawError and !$coverageBuild) {
100 print "ERROR: Use DEFINE_STATIC_LOCAL from <wtf/StdLibExtras.h>\n";
101 unlink $executablePath;
105 touch($buildTimestampPath);
111 open(TOUCH, ">", $path) or die "$!";
118 if (!open FILT, "c++filt $symbol |") {
119 print "ERROR: Could not open c++filt\n";
128 sub printFunctions($$)
130 my ($shortName, $path) = @_;
131 if (!open OTOOL, "otool -tV '$path' |") {
132 print "WARNING: Could not open $path\n";
136 my $currentSymbol = "";
138 $currentSymbol = $1 if /^(\w+):$/;
139 next unless $currentSymbol;
140 $functions{demangle($currentSymbol)} = 1 if /___cxa_atexit/;
144 for my $function (sort keys %functions) {
146 print "ERROR: $shortName has exit time destructors in it! ($path)\n";
149 print "ERROR: In function $function\n";