bp2build; Update handling of linker flags
Test: build/bazel/ci/bp2build.sh
Bug: 197920036
Change-Id: I6e3100574fa0e40bcd8cf0e6af0efd3310aa41bf
diff --git a/cc/bp2build.go b/cc/bp2build.go
index ebba9d1..f3c999d 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -373,15 +373,7 @@
stripKeepSymbolsList bazel.StringListAttribute
stripAll bazel.BoolAttribute
stripNone bazel.BoolAttribute
-}
-
-// 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
+ features bazel.StringListAttribute
}
// bp2BuildParseLinkerProps parses the linker properties of a module, including
@@ -408,6 +400,8 @@
var stripAll bazel.BoolAttribute
var stripNone bazel.BoolAttribute
+ var features bazel.StringListAttribute
+
for axis, configToProps := range module.GetArchVariantProperties(ctx, &StripProperties{}) {
for config, props := range configToProps {
if stripProperties, ok := props.(*StripProperties); ok {
@@ -426,6 +420,7 @@
for axis, configToProps := range module.GetArchVariantProperties(ctx, &BaseLinkerProperties{}) {
for config, props := range configToProps {
if baseLinkerProps, ok := props.(*BaseLinkerProperties); ok {
+ var axisFeatures []string
// Excludes to parallel Soong:
// https://cs.android.com/android/platform/superproject/+/master:build/soong/cc/linker.go;l=247-249;drc=088b53577dde6e40085ffd737a1ae96ad82fc4b0
@@ -457,7 +452,15 @@
headerDeps.SetSelectValue(axis, config, hDeps.export)
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 {
versionScript.SetSelectValue(axis, config, android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script))
}
@@ -471,6 +474,10 @@
disallowedArchVariantCrt = true
}
}
+
+ if axisFeatures != nil {
+ features.SetSelectValue(axis, config, axisFeatures)
+ }
}
}
}
@@ -559,6 +566,8 @@
stripKeepSymbolsList: stripKeepSymbolsList,
stripAll: stripAll,
stripNone: stripNone,
+
+ features: features,
}
}