Supporting changes for CFI toolchain features
Mostly exporting variables to Bazel, but also allowlisting a BUILD file. Bug: 251217226 Test: Unit tests Change-Id: Id87015a3cd5d970700c4058ec989bb0c14c36bcb
This commit is contained in:
parent
a22c4b6a79
commit
391a25d7fa
5 changed files with 33 additions and 9 deletions
|
@ -388,6 +388,8 @@ var (
|
||||||
"external/protobuf":/* recursive = */ false,
|
"external/protobuf":/* recursive = */ false,
|
||||||
"external/python/absl-py":/* recursive = */ true,
|
"external/python/absl-py":/* recursive = */ true,
|
||||||
|
|
||||||
|
"external/compiler-rt/lib/cfi":/* recursive = */ false,
|
||||||
|
|
||||||
// this BUILD file is globbed by //external/icu/icu4c/source:icu4c_test_data's "data/**/*".
|
// this BUILD file is globbed by //external/icu/icu4c/source:icu4c_test_data's "data/**/*".
|
||||||
"external/icu/icu4c/source/data/unidata/norm2":/* recursive = */ false,
|
"external/icu/icu4c/source/data/unidata/norm2":/* recursive = */ false,
|
||||||
|
|
||||||
|
|
|
@ -313,6 +313,8 @@ var (
|
||||||
"device/",
|
"device/",
|
||||||
"vendor/",
|
"vendor/",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VersionScriptFlagPrefix = "-Wl,--version-script,"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BazelCcToolchainVars generates bzl file content containing variables for
|
// BazelCcToolchainVars generates bzl file content containing variables for
|
||||||
|
@ -401,6 +403,8 @@ func init() {
|
||||||
exportedVars.ExportString("ExperimentalCStdVersion", ExperimentalCStdVersion)
|
exportedVars.ExportString("ExperimentalCStdVersion", ExperimentalCStdVersion)
|
||||||
exportedVars.ExportString("ExperimentalCppStdVersion", ExperimentalCppStdVersion)
|
exportedVars.ExportString("ExperimentalCppStdVersion", ExperimentalCppStdVersion)
|
||||||
|
|
||||||
|
exportedVars.ExportString("VersionScriptFlagPrefix", VersionScriptFlagPrefix)
|
||||||
|
|
||||||
// Everything in these lists is a crime against abstraction and dependency tracking.
|
// Everything in these lists is a crime against abstraction and dependency tracking.
|
||||||
// Do not add anything to this list.
|
// Do not add anything to this list.
|
||||||
commonGlobalIncludes := []string{
|
commonGlobalIncludes := []string{
|
||||||
|
|
11
cc/linker.go
11
cc/linker.go
|
@ -15,11 +15,12 @@
|
||||||
package cc
|
package cc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"android/soong/android"
|
|
||||||
"android/soong/cc/config"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"android/soong/android"
|
||||||
|
"android/soong/cc/config"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
)
|
)
|
||||||
|
@ -542,13 +543,13 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
ctx.PropertyErrorf("version_script", "Not supported on Darwin")
|
||||||
} else {
|
} else {
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
"-Wl,--version-script,"+versionScript.String())
|
config.VersionScriptFlagPrefix+versionScript.String())
|
||||||
flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path())
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, versionScript.Path())
|
||||||
|
|
||||||
if linker.sanitize.isSanitizerEnabled(cfi) {
|
if linker.sanitize.isSanitizerEnabled(cfi) {
|
||||||
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath)
|
cfiExportsMap := android.PathForSource(ctx, cfiExportsMapPath+"/"+cfiExportsMapFilename)
|
||||||
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
flags.Local.LdFlags = append(flags.Local.LdFlags,
|
||||||
"-Wl,--version-script,"+cfiExportsMap.String())
|
config.VersionScriptFlagPrefix+cfiExportsMap.String())
|
||||||
flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap)
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, cfiExportsMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,14 +62,18 @@ var (
|
||||||
"-fast-isel=false",
|
"-fast-isel=false",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cfiBlocklistPath = "external/compiler-rt/lib/cfi"
|
||||||
|
cfiBlocklistFilename = "cfi_blocklist.txt"
|
||||||
cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso",
|
cfiCflags = []string{"-flto", "-fsanitize-cfi-cross-dso",
|
||||||
"-fsanitize-ignorelist=external/compiler-rt/lib/cfi/cfi_blocklist.txt"}
|
"-fsanitize-ignorelist=" + cfiBlocklistPath + "/" + cfiBlocklistFilename}
|
||||||
// -flto and -fvisibility are required by clang when -fsanitize=cfi is
|
// -flto and -fvisibility are required by clang when -fsanitize=cfi is
|
||||||
// used, but have no effect on assembly files
|
// used, but have no effect on assembly files
|
||||||
cfiAsflags = []string{"-flto", "-fvisibility=default"}
|
cfiAsflags = []string{"-flto", "-fvisibility=default"}
|
||||||
cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
|
cfiLdflags = []string{"-flto", "-fsanitize-cfi-cross-dso", "-fsanitize=cfi",
|
||||||
"-Wl,-plugin-opt,O1"}
|
"-Wl,-plugin-opt,O1"}
|
||||||
cfiExportsMapPath = "build/soong/cc/config/cfi_exports.map"
|
cfiExportsMapPath = "build/soong/cc/config"
|
||||||
|
cfiExportsMapFilename = "cfi_exports.map"
|
||||||
|
cfiAssemblySupportFlag = "-fno-sanitize-cfi-canonical-jump-tables"
|
||||||
|
|
||||||
intOverflowCflags = []string{"-fsanitize-ignorelist=build/soong/cc/config/integer_overflow_blocklist.txt"}
|
intOverflowCflags = []string{"-fsanitize-ignorelist=build/soong/cc/config/integer_overflow_blocklist.txt"}
|
||||||
|
|
||||||
|
@ -388,6 +392,18 @@ func init() {
|
||||||
exportedVars.ExportStringListStaticVariable("HostOnlySanitizeFlags", hostOnlySanitizeFlags)
|
exportedVars.ExportStringListStaticVariable("HostOnlySanitizeFlags", hostOnlySanitizeFlags)
|
||||||
exportedVars.ExportStringList("DeviceOnlySanitizeFlags", deviceOnlySanitizeFlags)
|
exportedVars.ExportStringList("DeviceOnlySanitizeFlags", deviceOnlySanitizeFlags)
|
||||||
|
|
||||||
|
// Leave out "-flto" from the slices exported to bazel, as we will use the
|
||||||
|
// dedicated LTO feature for this
|
||||||
|
exportedVars.ExportStringList("CfiCFlags", cfiCflags[1:])
|
||||||
|
exportedVars.ExportStringList("CfiAsFlags", cfiAsflags[1:])
|
||||||
|
exportedVars.ExportStringList("CfiLdFlags", cfiLdflags[1:])
|
||||||
|
|
||||||
|
exportedVars.ExportString("CfiBlocklistPath", cfiBlocklistPath)
|
||||||
|
exportedVars.ExportString("CfiBlocklistFilename", cfiBlocklistFilename)
|
||||||
|
exportedVars.ExportString("CfiExportsMapPath", cfiExportsMapPath)
|
||||||
|
exportedVars.ExportString("CfiExportsMapFilename", cfiExportsMapFilename)
|
||||||
|
exportedVars.ExportString("CfiAssemblySupportFlag", cfiAssemblySupportFlag)
|
||||||
|
|
||||||
android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider)
|
android.RegisterMakeVarsProvider(pctx, cfiMakeVarsProvider)
|
||||||
android.RegisterMakeVarsProvider(pctx, hwasanMakeVarsProvider)
|
android.RegisterMakeVarsProvider(pctx, hwasanMakeVarsProvider)
|
||||||
}
|
}
|
||||||
|
@ -810,7 +826,7 @@ func (s *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
flags.Local.CFlags = append(flags.Local.CFlags, cfiCflags...)
|
flags.Local.CFlags = append(flags.Local.CFlags, cfiCflags...)
|
||||||
flags.Local.AsFlags = append(flags.Local.AsFlags, cfiAsflags...)
|
flags.Local.AsFlags = append(flags.Local.AsFlags, cfiAsflags...)
|
||||||
if Bool(s.Properties.Sanitize.Config.Cfi_assembly_support) {
|
if Bool(s.Properties.Sanitize.Config.Cfi_assembly_support) {
|
||||||
flags.Local.CFlags = append(flags.Local.CFlags, "-fno-sanitize-cfi-canonical-jump-tables")
|
flags.Local.CFlags = append(flags.Local.CFlags, cfiAssemblySupportFlag)
|
||||||
}
|
}
|
||||||
// Only append the default visibility flag if -fvisibility has not already been set
|
// Only append the default visibility flag if -fvisibility has not already been set
|
||||||
// to hidden.
|
// to hidden.
|
||||||
|
|
|
@ -91,6 +91,7 @@ function create_mock_soong {
|
||||||
symlink_directory prebuilts/go
|
symlink_directory prebuilts/go
|
||||||
symlink_directory prebuilts/build-tools
|
symlink_directory prebuilts/build-tools
|
||||||
symlink_directory prebuilts/clang/host
|
symlink_directory prebuilts/clang/host
|
||||||
|
symlink_directory external/compiler-rt
|
||||||
symlink_directory external/go-cmp
|
symlink_directory external/go-cmp
|
||||||
symlink_directory external/golang-protobuf
|
symlink_directory external/golang-protobuf
|
||||||
symlink_directory external/starlark-go
|
symlink_directory external/starlark-go
|
||||||
|
|
Loading…
Reference in a new issue