Refactor ccDynamic for static binaries

ccLibrary uses ccDynamic for linking shared libraries, but bypasses
it by calling directly into ccBase for static libraries.  Instead of
duplicating the same mess for ccBinary, rename ccDynamic to ccLinked
and add the logic for dealing with static or shared linkage.  This
also allows moving the stl logic out of ccBase and into ccLinked.

Change-Id: Idfa6d86de16911c8851f694d6ed92681c8939281
diff --git a/cc/builder.go b/cc/builder.go
index e7ea73d..4c86110 100644
--- a/cc/builder.go
+++ b/cc/builder.go
@@ -21,10 +21,11 @@
 import (
 	"android/soong/common"
 
-	"github.com/google/blueprint"
-	"github.com/google/blueprint/pathtools"
 	"path/filepath"
 	"strings"
+
+	"github.com/google/blueprint"
+	"github.com/google/blueprint/pathtools"
 )
 
 const (
@@ -185,7 +186,7 @@
 // and shared libraires, to a shared library (.so) or dynamic executable
 func TransformObjToDynamicBinary(ctx common.AndroidModuleContext,
 	objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs []string,
-	crtBegin, crtEnd string, flags builderFlags, outputFile string) {
+	crtBegin, crtEnd string, groupLate bool, flags builderFlags, outputFile string) {
 
 	var ldCmd string
 	if flags.clang {
@@ -218,7 +219,13 @@
 		ldDirs = append(ldDirs, dir)
 	}
 
+	if groupLate {
+		libFlagsList = append(libFlagsList, "-Wl,--start-group")
+	}
 	libFlagsList = append(libFlagsList, lateStaticLibs...)
+	if groupLate {
+		libFlagsList = append(libFlagsList, "-Wl,--end-group")
+	}
 
 	deps := []string{ldCmd}
 	deps = append(deps, sharedLibs...)