Add LLNDK support for the VNDK

Instead of using the NDK headers and libraries, add LL-NDK specific
headers and library stubs for VNDK users. This allows us to provide an
expanded liblog interface.

Test: aosp_arm; m -j
Test: Enable BOARD_VNDK_VERSION on aosp_arm; m -j
Test: Inspect out/soong/build.ninja before/after (w/o vndk)
Change-Id: Ic85f07fa10c695b5baab10c41f5e0ad38700bf3d
This commit is contained in:
Dan Willemsen 2017-03-19 13:44:32 -07:00
parent 86a1c7dd15
commit b916b80bf3
9 changed files with 233 additions and 23 deletions

View File

@ -147,6 +147,8 @@ bootstrap_go_package {
"cc/ndk_headers.go", "cc/ndk_headers.go",
"cc/ndk_library.go", "cc/ndk_library.go",
"cc/ndk_sysroot.go", "cc/ndk_sysroot.go",
"cc/llndk_library.go",
], ],
testSrcs: [ testSrcs: [
"cc/cc_test.go", "cc/cc_test.go",

View File

@ -298,3 +298,19 @@ func (c *stubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkDa
return nil return nil
}) })
} }
func (c *llndkStubDecorator) AndroidMk(ctx AndroidMkContext, ret *android.AndroidMkData) {
ret.Class = "SHARED_LIBRARIES"
ret.Extra = append(ret.Extra, func(w io.Writer, outputFile android.Path) error {
c.libraryDecorator.androidMkWriteExportedFlags(w)
fmt.Fprintln(w, "LOCAL_BUILT_MODULE_STEM := $(LOCAL_MODULE)"+outputFile.Ext())
fmt.Fprintln(w, "LOCAL_STRIP_MODULE := false")
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
fmt.Fprintln(w, "LOCAL_NO_NOTICE_FILE := true")
return nil
})
}

View File

@ -638,7 +638,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
variantNdkLibs := []string{} variantNdkLibs := []string{}
variantLateNdkLibs := []string{} variantLateNdkLibs := []string{}
if ctx.sdk() || ctx.vndk() { if ctx.Os() == android.Android {
version := ctx.sdkVersion() version := ctx.sdkVersion()
// Rewrites the names of shared libraries into the names of the NDK // Rewrites the names of shared libraries into the names of the NDK
@ -655,12 +655,14 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
variantLibs := []string{} variantLibs := []string{}
nonvariantLibs := []string{} nonvariantLibs := []string{}
for _, entry := range list { for _, entry := range list {
if inList(entry, ndkPrebuiltSharedLibraries) { if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
if !inList(entry, ndkMigratedLibs) { if !inList(entry, ndkMigratedLibs) {
nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version) nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
} else { } else {
variantLibs = append(variantLibs, entry+ndkLibrarySuffix) variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
} }
} else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
} else { } else {
nonvariantLibs = append(nonvariantLibs, entry) nonvariantLibs = append(nonvariantLibs, entry)
} }

View File

@ -205,7 +205,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
} }
} }
if ctx.sdk() || ctx.vndk() { if ctx.sdk() {
// The NDK headers are installed to a common sysroot. While a more // The NDK headers are installed to a common sysroot. While a more
// typical Soong approach would be to only make the headers for the // typical Soong approach would be to only make the headers for the
// library you're using available, we're trying to emulate the NDK // library you're using available, we're trying to emulate the NDK
@ -233,6 +233,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+legacyIncludes) flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+legacyIncludes)
} }
if ctx.vndk() {
flags.GlobalFlags = append(flags.GlobalFlags,
"-D__ANDROID_API__=__ANDROID_API_FUTURE__", "-D__ANDROID_VNDK__")
}
instructionSet := compiler.Properties.Instruction_set instructionSet := compiler.Properties.Instruction_set
if flags.RequiredInstructionSet != "" { if flags.RequiredInstructionSet != "" {
instructionSet = flags.RequiredInstructionSet instructionSet = flags.RequiredInstructionSet
@ -412,7 +417,7 @@ func (compiler *baseCompiler) hasSrcExt(ext string) bool {
var gnuToCReplacer = strings.NewReplacer("gnu", "c") var gnuToCReplacer = strings.NewReplacer("gnu", "c")
func ndkPathDeps(ctx ModuleContext) android.Paths { func ndkPathDeps(ctx ModuleContext) android.Paths {
if ctx.sdk() || ctx.vndk() { if ctx.sdk() {
// The NDK sysroot timestamp file depends on all the NDK sysroot files // The NDK sysroot timestamp file depends on all the NDK sysroot files
// (headers and libraries). // (headers and libraries).
return android.Paths{getNdkSysrootTimestampFile(ctx)} return android.Paths{getNdkSysrootTimestampFile(ctx)}

View File

@ -178,6 +178,13 @@ func VndkLibraries() []string {
return []string{} return []string{}
} }
// This needs to be kept up to date with the list in system/core/rootdir/etc/ld.config.txt:
// [vendor]
// namespace.default.link.system.shared_libs
func LLndkLibraries() []string {
return []string{"libc", "libm", "libdl", "liblog", "ld-android"}
}
func replaceFirst(slice []string, from, to string) { func replaceFirst(slice []string, from, to string) {
if slice[0] != from { if slice[0] != from {
panic(fmt.Errorf("Expected %q, found %q", from, to)) panic(fmt.Errorf("Expected %q, found %q", from, to))

169
cc/llndk_library.go Normal file
View File

@ -0,0 +1,169 @@
// Copyright 2017 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
import (
"path/filepath"
"strings"
"github.com/google/blueprint"
"android/soong/android"
)
var (
llndkLibrarySuffix = ".llndk"
)
// Creates a stub shared library based on the provided version file.
//
// The name of the generated file will be based on the module name by stripping
// the ".llndk" suffix from the module name. Module names must end with ".llndk"
// (as a convention to allow soong to guess the LL-NDK name of a dependency when
// needed). "libfoo.llndk" will generate "libfoo.so".
//
// Example:
//
// llndk_library {
// name: "libfoo.llndk",
// symbol_file: "libfoo.map.txt",
// export_include_dirs: ["include_vndk"],
// }
//
type llndkLibraryProperties struct {
// Relative path to the symbol map.
// An example file can be seen here: TODO(danalbert): Make an example.
Symbol_file string
// Whether to export any headers as -isystem instead of -I. Mainly for use by
// bionic/libc.
Export_headers_as_system bool
// Which headers to process with versioner. This really only handles
// bionic/libc/include right now.
Export_preprocessed_headers []string
// Whether the system library uses symbol versions.
Unversioned bool
}
type llndkStubDecorator struct {
*libraryDecorator
Properties llndkLibraryProperties
exportHeadersTimestamp android.OptionalPath
versionScriptPath android.ModuleGenPath
}
func (stub *llndkStubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
if !strings.HasSuffix(ctx.ModuleName(), llndkLibrarySuffix) {
ctx.ModuleErrorf("llndk_library modules names must be suffixed with %q\n",
llndkLibrarySuffix)
}
objs, versionScript := compileStubLibrary(ctx, flags, stub.Properties.Symbol_file, "current", "--vndk")
stub.versionScriptPath = versionScript
return objs
}
func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
return Deps{}
}
func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
stub.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(),
llndkLibrarySuffix)
return stub.libraryDecorator.linkerFlags(ctx, flags)
}
func (stub *llndkStubDecorator) processHeaders(ctx ModuleContext, srcHeaderDir string, outDir android.ModuleGenPath) android.Path {
srcDir := android.PathForModuleSrc(ctx, srcHeaderDir)
srcFiles := ctx.Glob(filepath.Join(srcDir.String(), "**/*.h"), nil)
var installPaths []android.WritablePath
for _, header := range srcFiles {
headerDir := filepath.Dir(header.String())
relHeaderDir, err := filepath.Rel(srcDir.String(), headerDir)
if err != nil {
ctx.ModuleErrorf("filepath.Rel(%q, %q) failed: %s",
srcDir.String(), headerDir, err)
continue
}
installPaths = append(installPaths, outDir.Join(ctx, relHeaderDir, header.Base()))
}
return processHeadersWithVersioner(ctx, srcDir, outDir, srcFiles, installPaths)
}
func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
objs Objects) android.Path {
if !stub.Properties.Unversioned {
linkerScriptFlag := "-Wl,--version-script," + stub.versionScriptPath.String()
flags.LdFlags = append(flags.LdFlags, linkerScriptFlag)
}
if len(stub.Properties.Export_preprocessed_headers) > 0 {
genHeaderOutDir := android.PathForModuleGen(ctx, "include")
var timestampFiles android.Paths
for _, dir := range stub.Properties.Export_preprocessed_headers {
timestampFiles = append(timestampFiles, stub.processHeaders(ctx, dir, genHeaderOutDir))
}
includePrefix := "-I "
if stub.Properties.Export_headers_as_system {
includePrefix = "-isystem "
}
stub.reexportFlags([]string{includePrefix + " " + genHeaderOutDir.String()})
stub.reexportDeps(timestampFiles)
}
if stub.Properties.Export_headers_as_system {
stub.exportIncludes(ctx, "-isystem")
stub.libraryDecorator.flagExporter.Properties.Export_include_dirs = []string{}
}
return stub.libraryDecorator.link(ctx, flags, deps, objs)
}
func newLLndkStubLibrary() (*Module, []interface{}) {
module, library := NewLibrary(android.DeviceSupported)
library.BuildOnlyShared()
module.stl = nil
module.sanitize = nil
library.StripProperties.Strip.None = true
stub := &llndkStubDecorator{
libraryDecorator: library,
}
module.compiler = stub
module.linker = stub
module.installer = nil
return module, []interface{}{&stub.Properties, &library.MutatedProperties, &library.flagExporter.Properties}
}
func llndkLibraryFactory() (blueprint.Module, []interface{}) {
module, properties := newLLndkStubLibrary()
return android.InitAndroidArchModule(module, android.DeviceSupported,
android.MultilibBoth, properties...)
}
func init() {
android.RegisterModuleType("llndk_library", llndkLibraryFactory)
}

View File

@ -58,6 +58,7 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("BOARD_VNDK_VERSION", "") ctx.Strict("BOARD_VNDK_VERSION", "")
} }
ctx.Strict("VNDK_LIBRARIES", strings.Join(config.VndkLibraries(), " ")) ctx.Strict("VNDK_LIBRARIES", strings.Join(config.VndkLibraries(), " "))
ctx.Strict("LLNDK_LIBRARIES", strings.Join(config.LLndkLibraries(), " "))
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", asanCflags) ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS", asanCflags)
ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", asanLdflags) ctx.Strict("ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS", asanLdflags)

View File

@ -204,6 +204,10 @@ func (m *preprocessedHeaderModule) GenerateAndroidBuildActions(ctx android.Modul
ctx.ModuleErrorf("glob %q matched zero files", m.properties.From) ctx.ModuleErrorf("glob %q matched zero files", m.properties.From)
} }
processHeadersWithVersioner(ctx, fromSrcPath, toOutputPath, srcFiles, installPaths)
}
func processHeadersWithVersioner(ctx android.ModuleContext, srcDir, outDir android.Path, srcFiles android.Paths, installPaths []android.WritablePath) android.Path {
// The versioner depends on a dependencies directory to simplify determining include paths // The versioner depends on a dependencies directory to simplify determining include paths
// when parsing headers. This directory contains architecture specific directories as well // when parsing headers. This directory contains architecture specific directories as well
// as a common directory, each of which contains symlinks to the actually directories to // as a common directory, each of which contains symlinks to the actually directories to
@ -239,10 +243,12 @@ func (m *preprocessedHeaderModule) GenerateAndroidBuildActions(ctx android.Modul
ImplicitOutputs: installPaths, ImplicitOutputs: installPaths,
Args: map[string]string{ Args: map[string]string{
"depsPath": depsPath.String(), "depsPath": depsPath.String(),
"srcDir": fromSrcPath.String(), "srcDir": srcDir.String(),
"outDir": toOutputPath.String(), "outDir": outDir.String(),
}, },
}) })
return timestampFile
} }
func preprocessedNdkHeadersFactory() (blueprint.Module, []interface{}) { func preprocessedNdkHeadersFactory() (blueprint.Module, []interface{}) {

View File

@ -30,10 +30,10 @@ var (
genStubSrc = pctx.AndroidStaticRule("genStubSrc", genStubSrc = pctx.AndroidStaticRule("genStubSrc",
blueprint.RuleParams{ blueprint.RuleParams{
Command: "$toolPath --arch $arch --api $apiLevel $in $out", Command: "$toolPath --arch $arch --api $apiLevel $vndk $in $out",
Description: "genStubSrc $out", Description: "genStubSrc $out",
CommandDeps: []string{"$toolPath"}, CommandDeps: []string{"$toolPath"},
}, "arch", "apiLevel") }, "arch", "apiLevel", "vndk")
ndkLibrarySuffix = ".ndk" ndkLibrarySuffix = ".ndk"
@ -241,28 +241,20 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) {
ndkMigratedLibs = append(ndkMigratedLibs, name) ndkMigratedLibs = append(ndkMigratedLibs, name)
} }
func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects { func compileStubLibrary(ctx ModuleContext, flags Flags, symbolFile, apiLevel, vndk string) (Objects, android.ModuleGenPath) {
arch := ctx.Arch().ArchType.String() arch := ctx.Arch().ArchType.String()
if !strings.HasSuffix(ctx.ModuleName(), ndkLibrarySuffix) { stubSrcPath := android.PathForModuleGen(ctx, "stub.c")
ctx.ModuleErrorf("ndk_library modules names must be suffixed with %q\n", versionScriptPath := android.PathForModuleGen(ctx, "stub.map")
ndkLibrarySuffix) symbolFilePath := android.PathForModuleSrc(ctx, symbolFile)
}
libName := strings.TrimSuffix(ctx.ModuleName(), ndkLibrarySuffix)
fileBase := fmt.Sprintf("%s.%s.%s", libName, arch, c.properties.ApiLevel)
stubSrcName := fileBase + ".c"
stubSrcPath := android.PathForModuleGen(ctx, stubSrcName)
versionScriptName := fileBase + ".map"
versionScriptPath := android.PathForModuleGen(ctx, versionScriptName)
c.versionScriptPath = versionScriptPath
symbolFilePath := android.PathForModuleSrc(ctx, c.properties.Symbol_file)
ctx.ModuleBuild(pctx, android.ModuleBuildParams{ ctx.ModuleBuild(pctx, android.ModuleBuildParams{
Rule: genStubSrc, Rule: genStubSrc,
Outputs: []android.WritablePath{stubSrcPath, versionScriptPath}, Outputs: []android.WritablePath{stubSrcPath, versionScriptPath},
Input: symbolFilePath, Input: symbolFilePath,
Args: map[string]string{ Args: map[string]string{
"arch": arch, "arch": arch,
"apiLevel": c.properties.ApiLevel, "apiLevel": apiLevel,
"vndk": vndk,
}, },
}) })
@ -280,7 +272,17 @@ func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) O
subdir := "" subdir := ""
srcs := []android.Path{stubSrcPath} srcs := []android.Path{stubSrcPath}
return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil) return compileObjs(ctx, flagsToBuilderFlags(flags), subdir, srcs, nil), versionScriptPath
}
func (c *stubDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
if !strings.HasSuffix(ctx.ModuleName(), ndkLibrarySuffix) {
ctx.ModuleErrorf("ndk_library modules names must be suffixed with %q\n",
ndkLibrarySuffix)
}
objs, versionScript := compileStubLibrary(ctx, flags, c.properties.Symbol_file, c.properties.ApiLevel, "")
c.versionScriptPath = versionScript
return objs
} }
func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { func (linker *stubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {