11cb0ef41Sopenharmony_ci#!/bin/bash
21cb0ef41Sopenharmony_ci# Copyright 2012 the V8 project authors. All rights reserved.
31cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without
41cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are
51cb0ef41Sopenharmony_ci# met:
61cb0ef41Sopenharmony_ci#
71cb0ef41Sopenharmony_ci#     * Redistributions of source code must retain the above copyright
81cb0ef41Sopenharmony_ci#       notice, this list of conditions and the following disclaimer.
91cb0ef41Sopenharmony_ci#     * Redistributions in binary form must reproduce the above
101cb0ef41Sopenharmony_ci#       copyright notice, this list of conditions and the following
111cb0ef41Sopenharmony_ci#       disclaimer in the documentation and/or other materials provided
121cb0ef41Sopenharmony_ci#       with the distribution.
131cb0ef41Sopenharmony_ci#     * Neither the name of Google Inc. nor the names of its
141cb0ef41Sopenharmony_ci#       contributors may be used to endorse or promote products derived
151cb0ef41Sopenharmony_ci#       from this software without specific prior written permission.
161cb0ef41Sopenharmony_ci#
171cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
181cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
191cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
201cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
211cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
221cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
231cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
241cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
251cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
261cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
271cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci# Checks that the number of compilation units having at least one static
301cb0ef41Sopenharmony_ci# initializer in d8 matches the one defined below.
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci# Allow:
331cb0ef41Sopenharmony_ci# _GLOBAL__I_000101
341cb0ef41Sopenharmony_ci# _GLOBAL__sub_I_iostream.cpp
351cb0ef41Sopenharmony_ci# _GLOBAL__sub_I_d8.cc
361cb0ef41Sopenharmony_ci# The first two are needed to set up std::cin/cout/cerr before main() runs.
371cb0ef41Sopenharmony_ci# See https://crbug.com/1177324 for more.
381cb0ef41Sopenharmony_ciexpected_static_init_count=3
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_civ8_root=$(readlink -f $(dirname $BASH_SOURCE)/../)
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_ciif [ -n "$1" ] ; then
431cb0ef41Sopenharmony_ci  d8="${v8_root}/$1"
441cb0ef41Sopenharmony_cielse
451cb0ef41Sopenharmony_ci  d8="${v8_root}/d8"
461cb0ef41Sopenharmony_cifi
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciif [ ! -f "$d8" ]; then
491cb0ef41Sopenharmony_ci  echo "d8 binary not found: $d8"
501cb0ef41Sopenharmony_ci  exit 1
511cb0ef41Sopenharmony_cifi
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_cistatic_inits=$(nm "$d8" | grep _GLOBAL_ | grep _I_ | awk '{ print $NF; }')
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cistatic_init_count=$(echo "$static_inits" | wc -l)
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_ciif [ $static_init_count -gt $expected_static_init_count ]; then
581cb0ef41Sopenharmony_ci  echo "Too many static initializers."
591cb0ef41Sopenharmony_ci  echo "$static_inits"
601cb0ef41Sopenharmony_ci  exit 1
611cb0ef41Sopenharmony_cielse
621cb0ef41Sopenharmony_ci  echo "Static initializer check passed ($static_init_count initializers)."
631cb0ef41Sopenharmony_ci  exit 0
641cb0ef41Sopenharmony_cifi
65