Add Darwin-specific linker file flags

Darwin's ld does not support --version-script, but it does support
-unexported_symbols_list, -force_symbols_not_weak_list, and
-force_symbols_weak_list that all take files as arguments.

Instead of expecting these to be added to the ldflags manually, add
properties for them so that the dependencies are handled appropriately.

Also sanity checks the darwin vs non-darwin usages early, so that the
error message is faster and more obvious.

Change-Id: I42526cc4367b6ea9adfdbb58753e12824e8c321c
diff --git a/cc/cc.go b/cc/cc.go
index e0c62d8..489bffe 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -1068,6 +1068,12 @@
 
 	// local file name to pass to the linker as --version_script
 	Version_script string `android:"arch_variant"`
+	// local file name to pass to the linker as -unexported_symbols_list
+	Unexported_symbols_list string `android:"arch_variant"`
+	// local file name to pass to the linker as -force_symbols_not_weak_list
+	Force_symbols_not_weak_list string `android:"arch_variant"`
+	// local file name to pass to the linker as -force_symbols_weak_list
+	Force_symbols_weak_list string `android:"arch_variant"`
 }
 
 type CCLibrary struct {
@@ -1260,10 +1266,40 @@
 
 	var linkerDeps []string
 
-	if c.LibraryProperties.Version_script != "" {
-		versionScript := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Version_script)
-		sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,--version-script,"+versionScript)
-		linkerDeps = append(linkerDeps, versionScript)
+	if !ctx.Darwin() {
+		if c.LibraryProperties.Version_script != "" {
+			versionScript := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Version_script)
+			sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,--version-script,"+versionScript)
+			linkerDeps = append(linkerDeps, versionScript)
+		}
+		if c.LibraryProperties.Unexported_symbols_list != "" {
+			ctx.PropertyErrorf("unexported_symbols_list", "Only supported on Darwin")
+		}
+		if c.LibraryProperties.Force_symbols_not_weak_list != "" {
+			ctx.PropertyErrorf("force_symbols_not_weak_list", "Only supported on Darwin")
+		}
+		if c.LibraryProperties.Force_symbols_weak_list != "" {
+			ctx.PropertyErrorf("force_symbols_weak_list", "Only supported on Darwin")
+		}
+	} else {
+		if c.LibraryProperties.Version_script != "" {
+			ctx.PropertyErrorf("version_script", "Not supported on Darwin")
+		}
+		if c.LibraryProperties.Unexported_symbols_list != "" {
+			localFile := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Unexported_symbols_list)
+			sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-unexported_symbols_list,"+localFile)
+			linkerDeps = append(linkerDeps, localFile)
+		}
+		if c.LibraryProperties.Force_symbols_not_weak_list != "" {
+			localFile := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Force_symbols_not_weak_list)
+			sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-force_symbols_not_weak_list,"+localFile)
+			linkerDeps = append(linkerDeps, localFile)
+		}
+		if c.LibraryProperties.Force_symbols_weak_list != "" {
+			localFile := filepath.Join(common.ModuleSrcDir(ctx), c.LibraryProperties.Force_symbols_weak_list)
+			sharedFlags.LdFlags = append(sharedFlags.LdFlags, "-Wl,-force_symbols_weak_list,"+localFile)
+			linkerDeps = append(linkerDeps, localFile)
+		}
 	}
 
 	TransformObjToDynamicBinary(ctx, objFiles, deps.SharedLibs, deps.StaticLibs,