Merge "bp2build; Update handling of linker flags" am: 2649c7913a
am: e6450855c6
am: bb88d20495
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1846573 Change-Id: I6998afd2638ea87773ed52a90b7ec62d5abebc14
This commit is contained in:
@@ -239,9 +239,7 @@ func NewCodegenContext(config android.Config, context android.Context, mode Code
|
|||||||
func propsToAttributes(props map[string]string) string {
|
func propsToAttributes(props map[string]string) string {
|
||||||
var attributes string
|
var attributes string
|
||||||
for _, propName := range android.SortedStringKeys(props) {
|
for _, propName := range android.SortedStringKeys(props) {
|
||||||
if shouldGenerateAttribute(propName) {
|
attributes += fmt.Sprintf(" %s = %s,\n", propName, props[propName])
|
||||||
attributes += fmt.Sprintf(" %s = %s,\n", propName, props[propName])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return attributes
|
return attributes
|
||||||
}
|
}
|
||||||
@@ -422,7 +420,8 @@ func generateBazelTarget(ctx bpToBuildContext, m bp2buildModule) BazelTarget {
|
|||||||
attrs := m.BazelAttributes()
|
attrs := m.BazelAttributes()
|
||||||
props := extractModuleProperties(attrs, true)
|
props := extractModuleProperties(attrs, true)
|
||||||
|
|
||||||
delete(props.Attrs, "bp2build_available")
|
// name is handled in a special manner
|
||||||
|
delete(props.Attrs, "name")
|
||||||
|
|
||||||
// Return the Bazel target with rule class and attributes, ready to be
|
// Return the Bazel target with rule class and attributes, ready to be
|
||||||
// code-generated.
|
// code-generated.
|
||||||
@@ -457,6 +456,10 @@ func generateSoongModuleTarget(ctx bpToBuildContext, m blueprint.Module) BazelTa
|
|||||||
depLabels[qualifiedTargetLabel(ctx, depModule)] = true
|
depLabels[qualifiedTargetLabel(ctx, depModule)] = true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for p, _ := range ignoredPropNames {
|
||||||
|
delete(props.Attrs, p)
|
||||||
|
}
|
||||||
attributes := propsToAttributes(props.Attrs)
|
attributes := propsToAttributes(props.Attrs)
|
||||||
|
|
||||||
depLabelList := "[\n"
|
depLabelList := "[\n"
|
||||||
|
@@ -873,7 +873,7 @@ cc_library {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCcLibraryPackRelocations(t *testing.T) {
|
func TestCcLibraryFeatures(t *testing.T) {
|
||||||
runCcLibraryTestCase(t, bp2buildTestCase{
|
runCcLibraryTestCase(t, bp2buildTestCase{
|
||||||
description: "cc_library pack_relocations test",
|
description: "cc_library pack_relocations test",
|
||||||
moduleTypeUnderTest: "cc_library",
|
moduleTypeUnderTest: "cc_library",
|
||||||
@@ -884,6 +884,7 @@ cc_library {
|
|||||||
name: "a",
|
name: "a",
|
||||||
srcs: ["a.cpp"],
|
srcs: ["a.cpp"],
|
||||||
pack_relocations: false,
|
pack_relocations: false,
|
||||||
|
allow_undefined_symbols: true,
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -893,6 +894,7 @@ cc_library {
|
|||||||
arch: {
|
arch: {
|
||||||
x86_64: {
|
x86_64: {
|
||||||
pack_relocations: false,
|
pack_relocations: false,
|
||||||
|
allow_undefined_symbols: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
@@ -904,25 +906,35 @@ cc_library {
|
|||||||
target: {
|
target: {
|
||||||
darwin: {
|
darwin: {
|
||||||
pack_relocations: false,
|
pack_relocations: false,
|
||||||
|
allow_undefined_symbols: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
include_build_directory: false,
|
include_build_directory: false,
|
||||||
}`,
|
}`,
|
||||||
expectedBazelTargets: []string{`cc_library(
|
expectedBazelTargets: []string{`cc_library(
|
||||||
name = "a",
|
name = "a",
|
||||||
linkopts = ["-Wl,--pack-dyn-relocs=none"],
|
features = [
|
||||||
|
"disable_pack_relocations",
|
||||||
|
"-no_undefined_symbols",
|
||||||
|
],
|
||||||
srcs = ["a.cpp"],
|
srcs = ["a.cpp"],
|
||||||
)`, `cc_library(
|
)`, `cc_library(
|
||||||
name = "b",
|
name = "b",
|
||||||
linkopts = select({
|
features = select({
|
||||||
"//build/bazel/platforms/arch:x86_64": ["-Wl,--pack-dyn-relocs=none"],
|
"//build/bazel/platforms/arch:x86_64": [
|
||||||
|
"disable_pack_relocations",
|
||||||
|
"-no_undefined_symbols",
|
||||||
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
srcs = ["b.cpp"],
|
srcs = ["b.cpp"],
|
||||||
)`, `cc_library(
|
)`, `cc_library(
|
||||||
name = "c",
|
name = "c",
|
||||||
linkopts = select({
|
features = select({
|
||||||
"//build/bazel/platforms/os:darwin": ["-Wl,--pack-dyn-relocs=none"],
|
"//build/bazel/platforms/os:darwin": [
|
||||||
|
"disable_pack_relocations",
|
||||||
|
"-no_undefined_symbols",
|
||||||
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
}),
|
}),
|
||||||
srcs = ["c.cpp"],
|
srcs = ["c.cpp"],
|
||||||
|
@@ -390,15 +390,7 @@ type linkerAttributes struct {
|
|||||||
stripKeepSymbolsList bazel.StringListAttribute
|
stripKeepSymbolsList bazel.StringListAttribute
|
||||||
stripAll bazel.BoolAttribute
|
stripAll bazel.BoolAttribute
|
||||||
stripNone bazel.BoolAttribute
|
stripNone bazel.BoolAttribute
|
||||||
}
|
features bazel.StringListAttribute
|
||||||
|
|
||||||
// FIXME(b/187655838): Use the existing linkerFlags() function instead of duplicating logic here
|
|
||||||
func getBp2BuildLinkerFlags(linkerProperties *BaseLinkerProperties) []string {
|
|
||||||
flags := linkerProperties.Ldflags
|
|
||||||
if !BoolDefault(linkerProperties.Pack_relocations, true) {
|
|
||||||
flags = append(flags, "-Wl,--pack-dyn-relocs=none")
|
|
||||||
}
|
|
||||||
return flags
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// bp2BuildParseLinkerProps parses the linker properties of a module, including
|
// bp2BuildParseLinkerProps parses the linker properties of a module, including
|
||||||
@@ -425,6 +417,8 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
var stripAll bazel.BoolAttribute
|
var stripAll bazel.BoolAttribute
|
||||||
var stripNone bazel.BoolAttribute
|
var stripNone bazel.BoolAttribute
|
||||||
|
|
||||||
|
var features bazel.StringListAttribute
|
||||||
|
|
||||||
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
|
||||||
for config, props := range configToProps {
|
for config, props := range configToProps {
|
||||||
if stripProperties, ok := props.(*StripProperties); ok {
|
if stripProperties, ok := props.(*StripProperties); ok {
|
||||||
@@ -443,6 +437,7 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
|
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
|
||||||
for config, props := range configToProps {
|
for config, props := range configToProps {
|
||||||
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
|
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
|
||||||
|
var axisFeatures []string
|
||||||
|
|
||||||
// Excludes to parallel Soong:
|
// Excludes to parallel Soong:
|
||||||
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
|
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
|
||||||
@@ -474,7 +469,15 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
headerDeps.SetSelectValue(axis, config, hDeps.export)
|
headerDeps.SetSelectValue(axis, config, hDeps.export)
|
||||||
implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
|
implementationHeaderDeps.SetSelectValue(axis, config, hDeps.implementation)
|
||||||
|
|
||||||
linkopts.SetSelectValue(axis, config, getBp2BuildLinkerFlags(baseLinkerProps))
|
linkopts.SetSelectValue(axis, config, baseLinkerProps.Ldflags)
|
||||||
|
if !BoolDefault(baseLinkerProps.Pack_relocations, packRelocationsDefault) {
|
||||||
|
axisFeatures = append(axisFeatures, "disable_pack_relocations")
|
||||||
|
}
|
||||||
|
|
||||||
|
if Bool(baseLinkerProps.Allow_undefined_symbols) {
|
||||||
|
axisFeatures = append(axisFeatures, "-no_undefined_symbols")
|
||||||
|
}
|
||||||
|
|
||||||
if baseLinkerProps.Version_script != nil {
|
if baseLinkerProps.Version_script != nil {
|
||||||
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
|
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
|
||||||
}
|
}
|
||||||
@@ -488,6 +491,10 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
disallowedArchVariantCrt = true
|
disallowedArchVariantCrt = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if axisFeatures != nil {
|
||||||
|
features.SetSelectValue(axis, config, axisFeatures)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -576,6 +583,8 @@ func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module)
|
|||||||
stripKeepSymbolsList: stripKeepSymbolsList,
|
stripKeepSymbolsList: stripKeepSymbolsList,
|
||||||
stripAll: stripAll,
|
stripAll: stripAll,
|
||||||
stripNone: stripNone,
|
stripNone: stripNone,
|
||||||
|
|
||||||
|
features: features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -259,6 +259,8 @@ type bazelCcLibraryAttributes struct {
|
|||||||
Static staticOrSharedAttributes
|
Static staticOrSharedAttributes
|
||||||
|
|
||||||
Strip stripAttributes
|
Strip stripAttributes
|
||||||
|
|
||||||
|
Features bazel.StringListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
type stripAttributes struct {
|
type stripAttributes struct {
|
||||||
@@ -340,6 +342,8 @@ func CcLibraryBp2Build(ctx android.TopDownMutatorContext) {
|
|||||||
Shared: sharedAttrs,
|
Shared: sharedAttrs,
|
||||||
|
|
||||||
Static: staticAttrs,
|
Static: staticAttrs,
|
||||||
|
|
||||||
|
Features: linkerAttrs.features,
|
||||||
}
|
}
|
||||||
|
|
||||||
props := bazel.BazelTargetModuleProperties{
|
props := bazel.BazelTargetModuleProperties{
|
||||||
@@ -2407,6 +2411,8 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
|
|||||||
Cppflags: compilerAttrs.cppFlags,
|
Cppflags: compilerAttrs.cppFlags,
|
||||||
Conlyflags: compilerAttrs.conlyFlags,
|
Conlyflags: compilerAttrs.conlyFlags,
|
||||||
Asflags: asFlags,
|
Asflags: asFlags,
|
||||||
|
|
||||||
|
Features: linkerAttrs.features,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attrs = &bazelCcLibrarySharedAttributes{
|
attrs = &bazelCcLibrarySharedAttributes{
|
||||||
@@ -2435,6 +2441,8 @@ func ccSharedOrStaticBp2BuildMutatorInternal(ctx android.TopDownMutatorContext,
|
|||||||
All: linkerAttrs.stripAll,
|
All: linkerAttrs.stripAll,
|
||||||
None: linkerAttrs.stripNone,
|
None: linkerAttrs.stripNone,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Features: linkerAttrs.features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2464,6 +2472,8 @@ type bazelCcLibraryStaticAttributes struct {
|
|||||||
Cppflags bazel.StringListAttribute
|
Cppflags bazel.StringListAttribute
|
||||||
Conlyflags bazel.StringListAttribute
|
Conlyflags bazel.StringListAttribute
|
||||||
Asflags bazel.StringListAttribute
|
Asflags bazel.StringListAttribute
|
||||||
|
|
||||||
|
Features bazel.StringListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
func CcLibraryStaticBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
@@ -2492,6 +2502,8 @@ type bazelCcLibrarySharedAttributes struct {
|
|||||||
Cppflags bazel.StringListAttribute
|
Cppflags bazel.StringListAttribute
|
||||||
Conlyflags bazel.StringListAttribute
|
Conlyflags bazel.StringListAttribute
|
||||||
Asflags bazel.StringListAttribute
|
Asflags bazel.StringListAttribute
|
||||||
|
|
||||||
|
Features bazel.StringListAttribute
|
||||||
}
|
}
|
||||||
|
|
||||||
func CcLibrarySharedBp2Build(ctx android.TopDownMutatorContext) {
|
func CcLibrarySharedBp2Build(ctx android.TopDownMutatorContext) {
|
||||||
|
@@ -27,6 +27,10 @@ import (
|
|||||||
// This file contains the basic functionality for linking against static libraries and shared
|
// This file contains the basic functionality for linking against static libraries and shared
|
||||||
// libraries. Final linking into libraries or executables is handled in library.go, binary.go, etc.
|
// libraries. Final linking into libraries or executables is handled in library.go, binary.go, etc.
|
||||||
|
|
||||||
|
const (
|
||||||
|
packRelocationsDefault = true
|
||||||
|
)
|
||||||
|
|
||||||
type BaseLinkerProperties struct {
|
type BaseLinkerProperties struct {
|
||||||
// list of modules whose object files should be linked into this module
|
// list of modules whose object files should be linked into this module
|
||||||
// in their entirety. For static library modules, all of the .o files from the intermediate
|
// in their entirety. For static library modules, all of the .o files from the intermediate
|
||||||
@@ -471,7 +475,7 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags {
|
|||||||
|
|
||||||
if linker.useClangLld(ctx) {
|
if linker.useClangLld(ctx) {
|
||||||
flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLldflags}", hod))
|
flags.Global.LdFlags = append(flags.Global.LdFlags, fmt.Sprintf("${config.%sGlobalLldflags}", hod))
|
||||||
if !BoolDefault(linker.Properties.Pack_relocations, true) {
|
if !BoolDefault(linker.Properties.Pack_relocations, packRelocationsDefault) {
|
||||||
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none")
|
flags.Global.LdFlags = append(flags.Global.LdFlags, "-Wl,--pack-dyn-relocs=none")
|
||||||
} else if ctx.Device() {
|
} else if ctx.Device() {
|
||||||
// SHT_RELR relocations are only supported at API level >= 30.
|
// SHT_RELR relocations are only supported at API level >= 30.
|
||||||
|
Reference in New Issue
Block a user