2016-07-30 03:48:20 +08:00
|
|
|
// 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
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"android/soong/android"
|
2021-02-18 16:21:34 +08:00
|
|
|
"android/soong/bazel"
|
2016-07-30 03:48:20 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// Objects (for crt*.o)
|
|
|
|
//
|
|
|
|
|
|
|
|
func init() {
|
2018-10-03 13:25:58 +08:00
|
|
|
android.RegisterModuleType("cc_object", ObjectFactory)
|
Add SDK member support for cc_object.
Test: m nothing
Test: Add
sdk {
name: "runtime-module-sdk",
native_shared_libs: [
"libc",
"libdl",
"libm",
"ld-android",
],
native_objects: [
"crtbegin_dynamic",
"crtbegin_static",
"crtend_android",
],
}
to bionic/apex/Android.bp. Then:
build/soong/scripts/build-aml-prebuilts.sh runtime-module-sdk
Take the generated runtime-module-sdk-current.zip and unzip into a
master-art tree without bionic/, edit the generated Android.bp to
extend cc_prebuilt_* modules with:
nocrt: true,
stl: "none",
system_shared_libs: [],
apex_available: ["//apex_available:anyapex"],
recovery_available: true,
vendor_available: true,
ramdisk_available: true,
Then "m com.android.art.debug". This passes Soong but fails in the
build step because more members are required.
Bug: 148934017
Change-Id: I2ab8f6aadb1440b325697cae4a8ed761c62d15d2
2020-03-11 06:37:59 +08:00
|
|
|
android.RegisterSdkMemberType(ccObjectSdkMemberType)
|
2021-02-18 16:21:34 +08:00
|
|
|
|
|
|
|
android.RegisterBp2BuildMutator("cc_object", ObjectBp2Build)
|
Add SDK member support for cc_object.
Test: m nothing
Test: Add
sdk {
name: "runtime-module-sdk",
native_shared_libs: [
"libc",
"libdl",
"libm",
"ld-android",
],
native_objects: [
"crtbegin_dynamic",
"crtbegin_static",
"crtend_android",
],
}
to bionic/apex/Android.bp. Then:
build/soong/scripts/build-aml-prebuilts.sh runtime-module-sdk
Take the generated runtime-module-sdk-current.zip and unzip into a
master-art tree without bionic/, edit the generated Android.bp to
extend cc_prebuilt_* modules with:
nocrt: true,
stl: "none",
system_shared_libs: [],
apex_available: ["//apex_available:anyapex"],
recovery_available: true,
vendor_available: true,
ramdisk_available: true,
Then "m com.android.art.debug". This passes Soong but fails in the
build step because more members are required.
Bug: 148934017
Change-Id: I2ab8f6aadb1440b325697cae4a8ed761c62d15d2
2020-03-11 06:37:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var ccObjectSdkMemberType = &librarySdkMemberType{
|
|
|
|
SdkMemberTypeBase: android.SdkMemberTypeBase{
|
|
|
|
PropertyName: "native_objects",
|
|
|
|
SupportsSdk: true,
|
|
|
|
},
|
|
|
|
prebuiltModuleType: "cc_prebuilt_object",
|
|
|
|
linkTypes: nil,
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type objectLinker struct {
|
2016-07-30 08:28:03 +08:00
|
|
|
*baseLinker
|
2016-07-30 03:48:20 +08:00
|
|
|
Properties ObjectLinkerProperties
|
|
|
|
}
|
|
|
|
|
2021-02-23 05:13:50 +08:00
|
|
|
type objectBazelHandler struct {
|
|
|
|
bazelHandler
|
|
|
|
|
|
|
|
module *Module
|
|
|
|
}
|
|
|
|
|
|
|
|
func (handler *objectBazelHandler) generateBazelBuildActions(ctx android.ModuleContext, label string) bool {
|
2021-03-04 05:40:52 +08:00
|
|
|
bazelCtx := ctx.Config().BazelContext
|
|
|
|
objPaths, ok := bazelCtx.GetOutputFiles(label, ctx.Arch().ArchType)
|
|
|
|
if ok {
|
|
|
|
if len(objPaths) != 1 {
|
|
|
|
ctx.ModuleErrorf("expected exactly one object file for '%s', but got %s", label, objPaths)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
handler.module.outputFile = android.OptionalPathForPath(android.PathForBazelOut(ctx, objPaths[0]))
|
|
|
|
}
|
|
|
|
return ok
|
2021-02-23 05:13:50 +08:00
|
|
|
}
|
|
|
|
|
2019-08-17 03:25:06 +08:00
|
|
|
type ObjectLinkerProperties struct {
|
|
|
|
// list of modules that should only provide headers for this module.
|
|
|
|
Header_libs []string `android:"arch_variant,variant_prepend"`
|
|
|
|
|
|
|
|
// names of other cc_object modules to link into this module using partial linking
|
|
|
|
Objs []string `android:"arch_variant"`
|
|
|
|
|
|
|
|
// if set, add an extra objcopy --prefix-symbols= step
|
|
|
|
Prefix_symbols *string
|
|
|
|
|
|
|
|
// if set, the path to a linker script to pass to ld -r when combining multiple object files.
|
|
|
|
Linker_script *string `android:"path,arch_variant"`
|
2020-07-16 04:33:30 +08:00
|
|
|
|
|
|
|
// Indicates that this module is a CRT object. CRT objects will be split
|
|
|
|
// into a variant per-API level between min_sdk_version and current.
|
|
|
|
Crt *bool
|
2019-08-17 03:25:06 +08:00
|
|
|
}
|
|
|
|
|
2020-03-12 05:45:49 +08:00
|
|
|
func newObject() *Module {
|
|
|
|
module := newBaseModule(android.HostAndDeviceSupported, android.MultilibBoth)
|
|
|
|
module.sanitize = &sanitize{}
|
|
|
|
module.stl = &stl{}
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
2019-03-27 01:39:49 +08:00
|
|
|
// cc_object runs the compiler without running the linker. It is rarely
|
|
|
|
// necessary, but sometimes used to generate .s files from .c files to use as
|
|
|
|
// input to a cc_genrule module.
|
2018-10-03 13:25:58 +08:00
|
|
|
func ObjectFactory() android.Module {
|
2020-03-12 05:45:49 +08:00
|
|
|
module := newObject()
|
2016-07-30 08:28:03 +08:00
|
|
|
module.linker = &objectLinker{
|
2019-09-27 03:24:45 +08:00
|
|
|
baseLinker: NewBaseLinker(module.sanitize),
|
2016-07-30 08:28:03 +08:00
|
|
|
}
|
|
|
|
module.compiler = NewBaseCompiler()
|
2021-02-23 05:13:50 +08:00
|
|
|
module.bazelHandler = &objectBazelHandler{module: module}
|
2018-10-26 01:53:44 +08:00
|
|
|
|
|
|
|
// Clang's address-significance tables are incompatible with ld -r.
|
|
|
|
module.compiler.appendCflags([]string{"-fno-addrsig"})
|
|
|
|
|
Add SDK member support for cc_object.
Test: m nothing
Test: Add
sdk {
name: "runtime-module-sdk",
native_shared_libs: [
"libc",
"libdl",
"libm",
"ld-android",
],
native_objects: [
"crtbegin_dynamic",
"crtbegin_static",
"crtend_android",
],
}
to bionic/apex/Android.bp. Then:
build/soong/scripts/build-aml-prebuilts.sh runtime-module-sdk
Take the generated runtime-module-sdk-current.zip and unzip into a
master-art tree without bionic/, edit the generated Android.bp to
extend cc_prebuilt_* modules with:
nocrt: true,
stl: "none",
system_shared_libs: [],
apex_available: ["//apex_available:anyapex"],
recovery_available: true,
vendor_available: true,
ramdisk_available: true,
Then "m com.android.art.debug". This passes Soong but fails in the
build step because more members are required.
Bug: 148934017
Change-Id: I2ab8f6aadb1440b325697cae4a8ed761c62d15d2
2020-03-11 06:37:59 +08:00
|
|
|
module.sdkMemberTypes = []android.SdkMemberType{ccObjectSdkMemberType}
|
2021-02-18 16:21:34 +08:00
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
return module.Init()
|
|
|
|
}
|
|
|
|
|
2021-02-18 16:21:34 +08:00
|
|
|
// For bp2build conversion.
|
|
|
|
type bazelObjectAttributes struct {
|
2021-03-15 18:02:43 +08:00
|
|
|
Srcs bazel.LabelListAttribute
|
2021-03-24 22:04:33 +08:00
|
|
|
Hdrs bazel.LabelListAttribute
|
2021-03-15 18:02:43 +08:00
|
|
|
Deps bazel.LabelListAttribute
|
2021-02-24 20:20:12 +08:00
|
|
|
Copts bazel.StringListAttribute
|
2021-03-24 22:14:47 +08:00
|
|
|
Asflags []string
|
2021-02-18 16:21:34 +08:00
|
|
|
Local_include_dirs []string
|
|
|
|
}
|
|
|
|
|
|
|
|
type bazelObject struct {
|
|
|
|
android.BazelTargetModuleBase
|
|
|
|
bazelObjectAttributes
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *bazelObject) Name() string {
|
|
|
|
return m.BaseModuleName()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *bazelObject) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
|
|
|
|
|
|
|
|
func BazelObjectFactory() android.Module {
|
|
|
|
module := &bazelObject{}
|
|
|
|
module.AddProperties(&module.bazelObjectAttributes)
|
|
|
|
android.InitBazelTargetModule(module)
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
// ObjectBp2Build is the bp2build converter from cc_object modules to the
|
|
|
|
// Bazel equivalent target, plus any necessary include deps for the cc_object.
|
|
|
|
func ObjectBp2Build(ctx android.TopDownMutatorContext) {
|
|
|
|
m, ok := ctx.Module().(*Module)
|
2021-03-10 15:05:59 +08:00
|
|
|
if !ok || !m.ConvertWithBp2build(ctx) {
|
2021-02-18 16:21:34 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// a Module can be something other than a cc_object.
|
|
|
|
if ctx.ModuleType() != "cc_object" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.compiler == nil {
|
|
|
|
// a cc_object must have access to the compiler decorator for its props.
|
|
|
|
ctx.ModuleErrorf("compiler must not be nil for a cc_object module")
|
|
|
|
}
|
|
|
|
|
2021-02-24 20:20:12 +08:00
|
|
|
// Set arch-specific configurable attributes
|
2021-03-24 22:04:33 +08:00
|
|
|
copts, srcs, hdrs := bp2BuildParseCompilerProps(ctx, m)
|
2021-02-18 16:21:34 +08:00
|
|
|
var localIncludeDirs []string
|
2021-03-24 22:14:47 +08:00
|
|
|
var asFlags []string
|
2021-02-18 16:21:34 +08:00
|
|
|
for _, props := range m.compiler.compilerProps() {
|
|
|
|
if baseCompilerProps, ok := props.(*BaseCompilerProperties); ok {
|
|
|
|
localIncludeDirs = baseCompilerProps.Local_include_dirs
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-19 04:56:36 +08:00
|
|
|
if c, ok := m.compiler.(*baseCompiler); ok && c.includeBuildDirectory() {
|
|
|
|
localIncludeDirs = append(localIncludeDirs, ".")
|
|
|
|
}
|
|
|
|
|
2021-03-15 18:02:43 +08:00
|
|
|
var deps bazel.LabelListAttribute
|
2021-02-23 13:46:47 +08:00
|
|
|
for _, props := range m.linker.linkerProps() {
|
|
|
|
if objectLinkerProps, ok := props.(*ObjectLinkerProperties); ok {
|
2021-03-15 18:02:43 +08:00
|
|
|
deps = bazel.MakeLabelListAttribute(
|
|
|
|
android.BazelLabelForModuleDeps(ctx, objectLinkerProps.Objs))
|
2021-02-23 13:46:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 22:14:47 +08:00
|
|
|
productVariableProps := android.ProductVariableProperties(ctx)
|
|
|
|
if props, exists := productVariableProps["Asflags"]; exists {
|
|
|
|
// TODO(b/183595873): consider deduplicating handling of product variable properties
|
|
|
|
for _, prop := range props {
|
|
|
|
flags, ok := prop.Property.([]string)
|
|
|
|
if !ok {
|
|
|
|
ctx.ModuleErrorf("Could not convert product variable asflag property")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// TODO(b/183595873) handle other product variable usages -- as selects?
|
|
|
|
if newFlags, subbed := bazel.TryVariableSubstitutions(flags, prop.ProductConfigVariable); subbed {
|
|
|
|
asFlags = append(asFlags, newFlags...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO(b/183595872) warn/error if we're not handling product variables
|
|
|
|
|
2021-02-24 20:20:12 +08:00
|
|
|
for arch, p := range m.GetArchProperties(&BaseCompilerProperties{}) {
|
|
|
|
if cProps, ok := p.(*BaseCompilerProperties); ok {
|
2021-03-15 18:02:43 +08:00
|
|
|
srcs.SetValueForArch(arch.Name, android.BazelLabelForModuleSrcExcludes(ctx, cProps.Srcs, cProps.Exclude_srcs))
|
2021-02-24 20:20:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 16:21:34 +08:00
|
|
|
attrs := &bazelObjectAttributes{
|
2021-03-15 18:02:43 +08:00
|
|
|
Srcs: srcs,
|
2021-03-24 22:04:33 +08:00
|
|
|
Hdrs: hdrs,
|
2021-02-23 13:46:47 +08:00
|
|
|
Deps: deps,
|
2021-03-24 22:04:33 +08:00
|
|
|
Copts: copts,
|
2021-03-24 22:14:47 +08:00
|
|
|
Asflags: asFlags,
|
2021-02-18 16:21:34 +08:00
|
|
|
Local_include_dirs: localIncludeDirs,
|
|
|
|
}
|
|
|
|
|
2021-02-20 00:06:17 +08:00
|
|
|
props := bazel.BazelTargetModuleProperties{
|
|
|
|
Rule_class: "cc_object",
|
|
|
|
Bzl_load_location: "//build/bazel/rules:cc_object.bzl",
|
|
|
|
}
|
2021-02-18 16:21:34 +08:00
|
|
|
|
2021-02-20 00:06:17 +08:00
|
|
|
ctx.CreateBazelTargetModule(BazelObjectFactory, m.Name(), props, attrs)
|
2021-02-18 16:21:34 +08:00
|
|
|
}
|
|
|
|
|
2016-07-30 03:48:20 +08:00
|
|
|
func (object *objectLinker) appendLdflags(flags []string) {
|
2017-09-28 08:01:44 +08:00
|
|
|
panic(fmt.Errorf("appendLdflags on objectLinker not supported"))
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
2016-08-02 04:20:05 +08:00
|
|
|
func (object *objectLinker) linkerProps() []interface{} {
|
2016-07-30 03:48:20 +08:00
|
|
|
return []interface{}{&object.Properties}
|
|
|
|
}
|
|
|
|
|
2016-08-02 04:20:05 +08:00
|
|
|
func (*objectLinker) linkerInit(ctx BaseModuleContext) {}
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-12-14 09:06:13 +08:00
|
|
|
func (object *objectLinker) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
2019-07-18 19:31:26 +08:00
|
|
|
deps.HeaderLibs = append(deps.HeaderLibs, object.Properties.Header_libs...)
|
2016-07-30 03:48:20 +08:00
|
|
|
deps.ObjFiles = append(deps.ObjFiles, object.Properties.Objs...)
|
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2019-08-17 03:25:06 +08:00
|
|
|
func (object *objectLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Global.LdFlags = append(flags.Global.LdFlags, ctx.toolchain().ToolchainClangLdflags())
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2019-08-17 03:25:06 +08:00
|
|
|
if lds := android.OptionalPathForModuleSrc(ctx, object.Properties.Linker_script); lds.Valid() {
|
2019-11-05 01:37:55 +08:00
|
|
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-T,"+lds.String())
|
2019-08-17 03:25:06 +08:00
|
|
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, lds.Path())
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
func (object *objectLinker) link(ctx ModuleContext,
|
2016-09-27 08:33:01 +08:00
|
|
|
flags Flags, deps PathDeps, objs Objects) android.Path {
|
2016-07-30 03:48:20 +08:00
|
|
|
|
2016-09-27 08:33:01 +08:00
|
|
|
objs = objs.Append(deps.Objs)
|
2016-07-30 03:48:20 +08:00
|
|
|
|
|
|
|
var outputFile android.Path
|
2017-09-19 13:47:20 +08:00
|
|
|
builderFlags := flagsToBuilderFlags(flags)
|
|
|
|
|
2019-10-18 19:39:56 +08:00
|
|
|
if len(objs.objFiles) == 1 && String(object.Properties.Linker_script) == "" {
|
2016-09-27 08:33:01 +08:00
|
|
|
outputFile = objs.objFiles[0]
|
2017-09-19 13:47:20 +08:00
|
|
|
|
2017-11-08 02:57:05 +08:00
|
|
|
if String(object.Properties.Prefix_symbols) != "" {
|
2017-09-19 13:47:20 +08:00
|
|
|
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
2020-11-24 06:02:44 +08:00
|
|
|
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), outputFile,
|
2017-09-19 13:47:20 +08:00
|
|
|
builderFlags, output)
|
|
|
|
outputFile = output
|
|
|
|
}
|
2016-07-30 03:48:20 +08:00
|
|
|
} else {
|
|
|
|
output := android.PathForModuleOut(ctx, ctx.ModuleName()+objectExtension)
|
|
|
|
outputFile = output
|
2017-09-19 13:47:20 +08:00
|
|
|
|
2017-11-08 02:57:05 +08:00
|
|
|
if String(object.Properties.Prefix_symbols) != "" {
|
2017-09-19 13:47:20 +08:00
|
|
|
input := android.PathForModuleOut(ctx, "unprefixed", ctx.ModuleName()+objectExtension)
|
2020-11-24 06:02:44 +08:00
|
|
|
transformBinaryPrefixSymbols(ctx, String(object.Properties.Prefix_symbols), input,
|
2017-09-19 13:47:20 +08:00
|
|
|
builderFlags, output)
|
|
|
|
output = input
|
|
|
|
}
|
|
|
|
|
2020-11-24 06:02:44 +08:00
|
|
|
transformObjsToObj(ctx, objs.objFiles, builderFlags, output, flags.LdFlagsDeps)
|
2016-07-30 03:48:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx.CheckbuildFile(outputFile)
|
|
|
|
return outputFile
|
|
|
|
}
|
2019-01-31 11:21:23 +08:00
|
|
|
|
|
|
|
func (object *objectLinker) unstrippedOutputFilePath() android.Path {
|
|
|
|
return nil
|
|
|
|
}
|
2019-03-26 01:21:31 +08:00
|
|
|
|
|
|
|
func (object *objectLinker) nativeCoverage() bool {
|
|
|
|
return true
|
|
|
|
}
|
2019-08-09 13:44:36 +08:00
|
|
|
|
|
|
|
func (object *objectLinker) coverageOutputFilePath() android.OptionalPath {
|
|
|
|
return android.OptionalPath{}
|
|
|
|
}
|
2020-06-01 22:23:05 +08:00
|
|
|
|
|
|
|
func (object *objectLinker) object() bool {
|
|
|
|
return true
|
|
|
|
}
|
2020-07-16 04:33:30 +08:00
|
|
|
|
|
|
|
func (object *objectLinker) isCrt() bool {
|
|
|
|
return Bool(object.Properties.Crt)
|
|
|
|
}
|