Add temporary workaround for pack_relocations linker flag conversion for bp2build.

Test: added unit test
Test: bazel build //bionic/...
Change-Id: I28217026f5846820ea2cc32cf8790948a54a9365
diff --git a/cc/bp2build.go b/cc/bp2build.go
index 7f2554f..67f88e2 100644
--- a/cc/bp2build.go
+++ b/cc/bp2build.go
@@ -252,6 +252,15 @@
 	versionScript bazel.LabelAttribute
 }
 
+// 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
 // configurable attribute values.
 func bp2BuildParseLinkerProps(ctx android.TopDownMutatorContext, module *Module) linkerAttributes {
@@ -269,7 +278,7 @@
 			libs = android.SortedUniqueStrings(libs)
 			deps = bazel.MakeLabelListAttribute(android.BazelLabelForModuleDeps(ctx, libs))
 
-			linkopts.Value = baseLinkerProps.Ldflags
+			linkopts.Value = getBp2BuildLinkerFlags(baseLinkerProps)
 
 			if baseLinkerProps.Version_script != nil {
 				versionScript.Value = android.BazelLabelForModuleSrcSingle(ctx, *baseLinkerProps.Version_script)
@@ -291,7 +300,7 @@
 			libs = android.SortedUniqueStrings(libs)
 			deps.SetValueForArch(arch.Name, android.BazelLabelForModuleDeps(ctx, libs))
 
-			linkopts.SetValueForArch(arch.Name, baseLinkerProps.Ldflags)
+			linkopts.SetValueForArch(arch.Name, getBp2BuildLinkerFlags(baseLinkerProps))
 
 			if baseLinkerProps.Version_script != nil {
 				versionScript.SetValueForArch(arch.Name,
@@ -312,7 +321,7 @@
 			libs = android.SortedUniqueStrings(libs)
 			deps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, libs))
 
-			linkopts.SetValueForOS(os.Name, baseLinkerProps.Ldflags)
+			linkopts.SetValueForOS(os.Name, getBp2BuildLinkerFlags(baseLinkerProps))
 
 			sharedLibs := baseLinkerProps.Shared_libs
 			dynamicDeps.SetValueForOS(os.Name, android.BazelLabelForModuleDeps(ctx, sharedLibs))