Add CFI flags to Compile Action

Bug: 261733820
Test: Unit Tests
Change-Id: I7c7cb8ab07da2c66df5d69e1e4af3337e3b24e6d
This commit is contained in:
Trevor Radcliffe
2023-06-01 21:12:08 +00:00
parent 3bc9c57dc4
commit f1836e4728

View File

@@ -64,13 +64,14 @@ var (
cfiBlocklistPath = "external/compiler-rt/lib/cfi"
cfiBlocklistFilename = "cfi_blocklist.txt"
cfiEnableFlag = "-fsanitize=cfi"
cfiCrossDsoFlag = "-fsanitize-cfi-cross-dso"
cfiCflags = []string{"-flto", cfiCrossDsoFlag,
"-fsanitize-ignorelist=" + cfiBlocklistPath + "/" + cfiBlocklistFilename}
// -flto and -fvisibility are required by clang when -fsanitize=cfi is
// used, but have no effect on assembly files
cfiAsflags = []string{"-flto", "-fvisibility=default"}
cfiLdflags = []string{"-flto", cfiCrossDsoFlag, "-fsanitize=cfi",
cfiLdflags = []string{"-flto", cfiCrossDsoFlag, cfiEnableFlag,
"-Wl,-plugin-opt,O1"}
cfiExportsMapPath = "build/soong/cc/config"
cfiExportsMapFilename = "cfi_exports.map"
@@ -395,8 +396,8 @@ func init() {
// Leave out "-flto" from the slices exported to bazel, as we will use the
// dedicated LTO feature for this. For C Flags and Linker Flags, also leave
// out the cross DSO flag which will be added separately by transitions.
exportedVars.ExportStringList("CfiCFlags", cfiCflags[2:])
// out the cross DSO flag which will be added separately under the correct conditions.
exportedVars.ExportStringList("CfiCFlags", append(cfiCflags[2:], cfiEnableFlag))
exportedVars.ExportStringList("CfiLdFlags", cfiLdflags[2:])
exportedVars.ExportStringList("CfiAsFlags", cfiAsflags[1:])