【Crhomium】Arm平臺編譯配置

Chromium Arm平臺編譯配置

  • 以下內容以Chromium67爲準。
  • Chromium支持多平臺編譯,如Linux、android、MAC。在編譯時,可以指定cpu類型,如
current_cpu="arm"
# 或
current_cpu="arm64"
  • 當指定cpu類型時,chromium的gn編譯系統便會根據指定的CPU類型,進行設置。
  • 這裏,分析以下當cpu類型爲arm時,chromium的bulid/config模塊,所做的配置。

Arm Config for build

  • 源碼路徑:
    src/build/config/arm.gni
  • Chromium官網鏈接: https://chromium.googlesource.com/chromium/src/+/master/build/config/arm.gni
  • 內容如下:
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/v8_target_cpu.gni")
# These are primarily relevant in current_cpu == "arm" contexts, where
# ARM code is being compiled.  But they can also be relevant in the
# other contexts when the code will change its behavior based on the
# cpu it wants to generate code for.
if (current_cpu == "arm" || v8_current_cpu == "arm") {
  declare_args() {
    # Version of the ARM processor when compiling on ARM. Ignored on non-ARM
    # platforms.
    arm_version = 7
    # The ARM architecture. This will be a string like "armv6" or "armv7-a".
    # An empty string means to use the default for the arm_version.
    arm_arch = ""
    # The ARM floating point hardware. This will be a string like "neon" or
    # "vfpv3". An empty string means to use the default for the arm_version.
    arm_fpu = ""
    # The ARM floating point mode. This is either the string "hard", "soft", or
    # "softfp". An empty string means to use the default one for the
    # arm_version.
    arm_float_abi = ""
    # The ARM variant-specific tuning mode. This will be a string like "armv6"
    # or "cortex-a15". An empty string means to use the default for the
    # arm_version.
    arm_tune = ""
    # Whether to use the neon FPU instruction set or not.
    arm_use_neon = ""
    # Whether to enable optional NEON code paths.
    arm_optionally_use_neon = false
    # Thumb is a reduced instruction set available on some ARM processors that
    # has increased code density.
    arm_use_thumb = true
  }
  assert(arm_float_abi == "" || arm_float_abi == "hard" ||
         arm_float_abi == "soft" || arm_float_abi == "softfp")
  if (arm_use_neon == "") {
    if (current_os == "linux" && target_cpu != v8_target_cpu) {
      # Don't use neon on V8 simulator builds as a default.
      arm_use_neon = false
    } else {
      arm_use_neon = true
    }
  }
  if (arm_version == 6) {
    if (arm_arch == "") {
      arm_arch = "armv6"
    }
    if (arm_tune != "") {
      arm_tune = ""
    }
    if (arm_float_abi == "") {
      arm_float_abi = "softfp"
    }
    if (arm_fpu == "") {
      arm_fpu = "vfp"
    }
    arm_use_thumb = false
    arm_use_neon = false
  } else if (arm_version == 7) {
    if (arm_arch == "") {
      arm_arch = "armv7-a"
    }
    if (arm_tune == "") {
      arm_tune = "generic-armv7-a"
    }
    if (arm_float_abi == "") {
      if (current_os == "android" || target_os == "android") {
        arm_float_abi = "softfp"
      } else if (current_os == "linux" && target_cpu != v8_target_cpu) {
        # Default to the same as Android for V8 simulator builds.
        arm_float_abi = "softfp"
      } else {
        arm_float_abi = "hard"
      }
    }
    if (arm_fpu == "") {
      if (arm_use_neon) {
        arm_fpu = "neon"
      } else {
        arm_fpu = "vfpv3-d16"
      }
    }
  } else if (arm_version == 8) {
    if (arm_arch == "") {
      arm_arch = "armv8-a"
    }
    if (arm_tune == "") {
      arm_tune = "generic-armv8-a"
    }
    if (arm_float_abi == "") {
      if (current_os == "android" || target_os == "android") {
        arm_float_abi = "softfp"
      } else {
        arm_float_abi = "hard"
      }
    }
    if (arm_fpu == "") {
      if (arm_use_neon) {
        arm_fpu = "neon"
      } else {
        arm_fpu = "vfpv3-d16"
      }
    }
  }
} else if (current_cpu == "arm64" || v8_current_cpu == "arm64") {
  # arm64 supports only "hard".
  arm_float_abi = "hard"
  arm_use_neon = true
}
  • 分析:
  1. 首先,如果當前cpu類型爲arm,或者v8當前cpu類型爲arm。定義一系列參數,這些參數爲默認參數。如果之前定義過,便不再定義(比如在編譯時,指定了arm_float_abi(軟/硬浮點))。
  declare_args() {
    # Version of the ARM processor when compiling on ARM. Ignored on non-ARM
    # platforms.
    arm_version = 7

    # The ARM architecture. This will be a string like "armv6" or "armv7-a".
    # An empty string means to use the default for the arm_version.
    arm_arch = ""

    # The ARM floating point hardware. This will be a string like "neon" or
    # "vfpv3". An empty string means to use the default for the arm_version.
    arm_fpu = ""

    # The ARM floating point mode. This is either the string "hard", "soft", or
    # "softfp". An empty string means to use the default one for the
    # arm_version.
    arm_float_abi = ""

    # The ARM variant-specific tuning mode. This will be a string like "armv6"
    # or "cortex-a15". An empty string means to use the default for the
    # arm_version.
    arm_tune = ""

    # Whether to use the neon FPU instruction set or not.
    arm_use_neon = ""

    # Whether to enable optional NEON code paths.
    arm_optionally_use_neon = false

    # Thumb is a reduced instruction set available on some ARM processors that
    # has increased code density.
    arm_use_thumb = true
  }
  1. 之後,就是一系列判斷,對arm類型所要使用的編譯參數進行判斷。關於這些編譯參數的具體含義,可自行百度。
# 軟浮點或硬浮點
arm_float_abi
# arm架構
arm_arch
# 是否使用neno
arm_use_neon
# 是否使用thumb
arm_use_thumb
# fpu類型
arm_fpu
  1. 在定義好一系列編譯參數後,使用arm編譯器進行編譯。

GNI文件,並非編譯文件,而且模板文件。編譯系統如何使用它?
答:在.gn文件中,通過import引入模板文件(有點類型C++的頭文件)中的定義。

  • 例:src/v8/BUILD.gn,在該gn文件開頭,我們可以看到import了arm.gni文件。
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/android/config.gni")
import("//build/config/arm.gni")
import("//build/config/dcheck_always_on.gni")
import("//build/config/host_byteorder.gni")
import("//build/config/jumbo.gni")
import("//build/config/mips.gni")
import("//build/config/sanitizers/sanitizers.gni")
.....
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章