• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/config/security/security_config.gni")
15
16config("auto_var_init_configs") {
17  if (using_security_flag && !is_mingw) {
18    assert(
19        is_clang,
20        "currently, automatic variable initialization only supported with clang")
21    configs = [ ":auto_var_zero_init_config" ]
22  }
23}
24
25all_security_configs = [ ":auto_var_init_configs" ]
26
27# This config is applied by default to all targets. It sets the compiler flags
28# for automatic variable initialization, or, if no config is set, does nothing.
29config("default_security_configs") {
30  configs = all_security_configs
31}
32
33# Set the uninitialized local variables to pattern.
34config("auto_var_pattern_init_config") {
35  cflags = [ "-ftrivial-auto-var-init=pattern" ]
36}
37
38# Set the uninitialized local variables to zero. But it will be removed from clang int the future.
39# Currently, enabling the config of pattern for all components is impractical and may cause system
40# instability. So on the premise that the system is stable, the config of zero need to be gradually replaced with
41# the config of pattern.
42config("auto_var_zero_init_config") {
43  cflags = [
44    "-ftrivial-auto-var-init=zero",
45    "-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang",
46  ]
47}
48
49# Do not set the uninitialized local variables to any value.
50config("auto_var_uninit_config") {
51  cflags = [ "-ftrivial-auto-var-init=uninitialized" ]
52}
53