From dd5655b3a4487b612ce2f35109f1bf6b9e25f3f8 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 17 Feb 2022 11:16:08 -0800 Subject: [PATCH] Export sanitizer paths to Make system/core/rootdir/Android.mk writes a list of sanitizer libraries to sanitizer.libraries.txt, and assumes that they are installed with the same name as the module. The next patch renames the module to be the same for all architectures while keeping the installed name as is. Collect the output file names of the libraries to export to make. Bug: 220019988 Test: m out/target/produuct/coral/system/etc/sanitizer.libraries.txt Change-Id: Idc51c2ad6f914977a286fe4e2fcb457bc1229339 --- cc/makevars.go | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/cc/makevars.go b/cc/makevars.go index b7aaaad0b..bb8d61830 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -259,14 +259,43 @@ func makeVarsToolchain(ctx android.MakeVarsContext, secondPrefix string, }, " ")) if target.Os.Class == android.Device { - ctx.Strict(secondPrefix+"ADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.AddressSanitizerRuntimeLibrary(toolchain), ".so")) - ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_RUNTIME_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerRuntimeLibrary(toolchain), ".so")) - ctx.Strict(secondPrefix+"HWADDRESS_SANITIZER_STATIC_LIBRARY", strings.TrimSuffix(config.HWAddressSanitizerStaticLibrary(toolchain), ".a")) - ctx.Strict(secondPrefix+"UBSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), ".so")) - ctx.Strict(secondPrefix+"UBSAN_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), ".a")) - ctx.Strict(secondPrefix+"TSAN_RUNTIME_LIBRARY", strings.TrimSuffix(config.ThreadSanitizerRuntimeLibrary(toolchain), ".so")) - ctx.Strict(secondPrefix+"SCUDO_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoRuntimeLibrary(toolchain), ".so")) - ctx.Strict(secondPrefix+"SCUDO_MINIMAL_RUNTIME_LIBRARY", strings.TrimSuffix(config.ScudoMinimalRuntimeLibrary(toolchain), ".so")) + sanitizerVariables := map[string]string{ + "ADDRESS_SANITIZER_RUNTIME_LIBRARY": config.AddressSanitizerRuntimeLibrary(toolchain), + "HWADDRESS_SANITIZER_RUNTIME_LIBRARY": config.HWAddressSanitizerRuntimeLibrary(toolchain), + "HWADDRESS_SANITIZER_STATIC_LIBRARY": config.HWAddressSanitizerStaticLibrary(toolchain), + "UBSAN_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerRuntimeLibrary(toolchain), + "UBSAN_MINIMAL_RUNTIME_LIBRARY": config.UndefinedBehaviorSanitizerMinimalRuntimeLibrary(toolchain), + "TSAN_RUNTIME_LIBRARY": config.ThreadSanitizerRuntimeLibrary(toolchain), + "SCUDO_RUNTIME_LIBRARY": config.ScudoRuntimeLibrary(toolchain), + "SCUDO_MINIMAL_RUNTIME_LIBRARY": config.ScudoMinimalRuntimeLibrary(toolchain), + } + + for variable, value := range sanitizerVariables { + ctx.Strict(secondPrefix+variable, value) + } + + sanitizerLibs := android.SortedStringValues(sanitizerVariables) + var sanitizerLibStems []string + ctx.VisitAllModules(func(m android.Module) { + if !m.Enabled() { + return + } + + ccModule, _ := m.(*Module) + if ccModule == nil || ccModule.library == nil || !ccModule.library.shared() { + return + } + + if android.InList(strings.TrimPrefix(ctx.ModuleName(m), "prebuilt_"), sanitizerLibs) && + m.Target().Os == target.Os && m.Target().Arch.ArchType == target.Arch.ArchType { + outputFile := ccModule.outputFile + if outputFile.Valid() { + sanitizerLibStems = append(sanitizerLibStems, outputFile.Path().Base()) + } + } + }) + sanitizerLibStems = android.SortedUniqueStrings(sanitizerLibStems) + ctx.Strict(secondPrefix+"SANITIZER_STEMS", strings.Join(sanitizerLibStems, " ")) } // This is used by external/gentoo/...