From eefc9e6a624e78e1c1565656f7ec5e0a655590b0 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Fri, 2 Apr 2021 17:36:47 -0400 Subject: [PATCH] Fix note_memtag bionic libraries in mixed builds Required fixes: - Set MakeLinkType for libraries, even in mixed build mode. - Set snapshot header information to empty list, which passes validation logic for depending modules Fixing these libraries also requires a Starlark change to cc_library_static.bzl, which will be submitted separately. Additionally, this adds better error messaging in the event that output files are missing from a mixed-build library. Test: USE_BAZEL_ANALYSIS=1 m libc Test: USE_BAZEL_ANALYSIS=1 m runtime-module-sdk Change-Id: Iad2c4d46359986fb0a43263292a15ed45fabbac7 --- android/bazel.go | 2 -- bazel/cquery/request_type.go | 14 ++++++++++++-- cc/cc.go | 4 ++-- cc/library.go | 17 ++++++++++++++--- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/android/bazel.go b/android/bazel.go index a08da0e7b..b2170be79 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -174,8 +174,6 @@ var ( "liblinker_debuggerd_stub", // ruperts@, cc_library_static, depends on //system/libbase "libbionic_tests_headers_posix", // ruperts@, cc_library_static "libc_dns", // ruperts@, cc_library_static - "note_memtag_heap_async", // cparsons@, cc_library_static - "note_memtag_heap_sync", // cparsons@, cc_library_static } // Used for quicker lookups diff --git a/bazel/cquery/request_type.go b/bazel/cquery/request_type.go index bd1ece177..c4ab36c35 100644 --- a/bazel/cquery/request_type.go +++ b/bazel/cquery/request_type.go @@ -83,7 +83,17 @@ func (g getOutputFilesAndCcObjectFilesType) ParseResult(rawString string) interf splitString := strings.Split(rawString, "|") outputFilesString := splitString[0] ccObjectsString := splitString[1] - outputFiles = strings.Split(outputFilesString, ", ") - ccObjects = strings.Split(ccObjectsString, ", ") + outputFiles = splitOrEmpty(outputFilesString, ", ") + ccObjects = splitOrEmpty(ccObjectsString, ", ") return GetOutputFilesAndCcObjectFiles_Result{outputFiles, ccObjects} } + +// splitOrEmpty is a modification of strings.Split() that returns an empty list +// if the given string is empty. +func splitOrEmpty(s string, sep string) []string { + if len(s) < 1 { + return []string{} + } else { + return strings.Split(s, sep) + } +} diff --git a/cc/cc.go b/cc/cc.go index 0f9a55668..1ce83a95c 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1646,12 +1646,12 @@ func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { c.hideApexVariantFromMake = true } + c.makeLinkType = GetMakeLinkType(actx, c) + if c.maybeGenerateBazelActions(actx) { return } - c.makeLinkType = GetMakeLinkType(actx, c) - ctx := &moduleContext{ ModuleContext: actx, moduleContextImpl: moduleContextImpl{ diff --git a/cc/library.go b/cc/library.go index 50fff7f9d..11b673742 100644 --- a/cc/library.go +++ b/cc/library.go @@ -425,11 +425,14 @@ func (handler *staticLibraryBazelHandler) generateBazelBuildActions(ctx android. if !ok { return ok } - if len(outputPaths) != 1 { + if len(outputPaths) > 1 { // TODO(cparsons): This is actually expected behavior for static libraries with no srcs. // We should support this. - ctx.ModuleErrorf("expected exactly one output file for '%s', but got %s", label, objPaths) + ctx.ModuleErrorf("expected at most one output file for '%s', but got %s", label, objPaths) return false + } else if len(outputPaths) == 0 { + handler.module.outputFile = android.OptionalPath{} + return true } outputFilePath := android.PathForBazelOut(ctx, outputPaths[0]) handler.module.outputFile = android.OptionalPathForPath(outputFilePath) @@ -453,7 +456,15 @@ func (handler *staticLibraryBazelHandler) generateBazelBuildActions(ctx android. Direct(outputFilePath). Build(), }) - handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0])) + if i, ok := handler.module.linker.(snapshotLibraryInterface); ok { + // Dependencies on this library will expect collectedSnapshotHeaders to + // be set, otherwise validation will fail. For now, set this to an empty + // list. + // TODO(cparsons): More closely mirror the collectHeadersForSnapshot + // implementation. + i.(*libraryDecorator).collectedSnapshotHeaders = android.Paths{} + } + return ok }