Block CFI on static libraries
Bug: 295805467
Test: Unit tests and inspecting generated BUILD files
Change-Id: I1bbd2f48ad384e0b5b6f7cc1458b12ded2748e8f
diff --git a/cc/Android.bp b/cc/Android.bp
index c32d854..8f6709f 100644
--- a/cc/Android.bp
+++ b/cc/Android.bp
@@ -30,6 +30,7 @@
"cc.go",
"ccdeps.go",
"check.go",
+ "constants.go",
"coverage.go",
"gen.go",
"generated_cc_library.go",
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 7f78e28..bbdf672 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -1953,9 +1953,9 @@
sanitizerCompilerInputs.SetSelectValue(bazel.SanitizersEnabledAxis, bazel.SanitizersEnabled, bazel.MakeLabelListFromTargetNames([]string{*blocklist}))
}
if sanitizerProps.Sanitize.Cfi != nil && !proptools.Bool(sanitizerProps.Sanitize.Cfi) {
- features = append(features, "-android_cfi")
+ features = append(features, "-"+cfiFeatureName)
} else if proptools.Bool(sanitizerProps.Sanitize.Cfi) {
- features = append(features, "android_cfi")
+ features = append(features, cfiFeatureName)
if proptools.Bool(sanitizerProps.Sanitize.Config.Cfi_assembly_support) {
features = append(features, "android_cfi_assembly_support")
}
diff --git a/cc/constants.go b/cc/constants.go
new file mode 100644
index 0000000..f188d4e
--- /dev/null
+++ b/cc/constants.go
@@ -0,0 +1,19 @@
+// Copyright 2016 Google Inc. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package cc
+
+var (
+ cfiFeatureName = "android_cfi"
+)
diff --git a/cc/library.go b/cc/library.go
index 2d4d604..c5a9222 100644
--- a/cc/library.go
+++ b/cc/library.go
@@ -331,6 +331,7 @@
sharedFeatures.DeduplicateAxesFromBase()
staticFeatures := baseAttributes.features.Clone().Append(staticAttrs.Features)
staticFeatures.DeduplicateAxesFromBase()
+ staticFeatures.RemoveFromAllConfigs(cfiFeatureName)
staticCommonAttrs := staticOrSharedAttributes{
Srcs: *srcs.Clone().Append(staticAttrs.Srcs),
@@ -2946,6 +2947,9 @@
features := baseAttributes.features.Clone().Append(libSharedOrStaticAttrs.Features)
features.DeduplicateAxesFromBase()
+ if isStatic {
+ features.RemoveFromAllConfigs(cfiFeatureName)
+ }
commonAttrs := staticOrSharedAttributes{
Srcs: compilerAttrs.srcs,