am cfafe554: Merge "Fix building static host executables."

* commit 'cfafe554c0852f5b2c05e5d895b47d032daeec2e':
  Fix building static host executables.
diff --git a/core/cxx_stl_setup.mk b/core/cxx_stl_setup.mk
index 0f574d2..c1ce6e1 100644
--- a/core/cxx_stl_setup.mk
+++ b/core/cxx_stl_setup.mk
@@ -10,6 +10,11 @@
         # Platform code. Select the appropriate STL.
         ifndef USE_MINGW
             my_cxx_stl := libc++
+            ifdef LOCAL_IS_HOST_MODULE
+                ifneq (,$(BUILD_HOST_static))
+                    my_cxx_stl := libc++_static
+                endif
+            endif
         else
             # libc++ is not supported on mingw.
             my_cxx_stl := libstdc++
@@ -33,7 +38,8 @@
     ifdef LOCAL_IS_HOST_MODULE
         my_cppflags += -nostdinc++
         my_ldflags += -nodefaultlibs
-        my_ldlibs += -lc -lm -lpthread
+        my_ldlibs += -lpthread -lm
+        my_ldlibs += -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
     endif
 else ifneq ($(filter $(my_cxx_stl),stlport stlport_static),)
     ifndef LOCAL_IS_HOST_MODULE
@@ -61,7 +67,8 @@
 else ifeq ($(my_cxx_stl),none)
     ifdef LOCAL_IS_HOST_MODULE
         my_cppflags += -nostdinc++
-        my_ldflags += -nodefaultlibs -lc -lm
+        my_ldflags += -nodefaultlibs
+        my_ldlibs += -lm -Wl,--start-group -lgcc -lgcc_eh -lc -Wl,--end-group
     endif
 else
     $(error $(my_cxx_stl) is not a supported STL.)