From f7a17daefe6d88a0f2146680288b3b62335d505d Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 3 Oct 2019 15:48:34 -0700 Subject: [PATCH] Use -nostdlib++ instead of -nodefaultlibs Host builds using libc++ used -nodefaultlibs to turn off the default C++ runtime, and then added back all the other necessary libraries. Clang supports -nostdlib++ since https://reviews.llvm.org/D47115 that removes the C++ runtime without affecting the other default libraries. Use -nostdlib++, and remove the lists of default libraries. Test: m checkbuild Change-Id: I722bd6596a1f3f5819f2767c29c0fa1e8b3ec0e8 --- cc/stl.go | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/cc/stl.go b/cc/stl.go index 458129c41..aa34240a0 100644 --- a/cc/stl.go +++ b/cc/stl.go @@ -221,13 +221,13 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { if !ctx.toolchain().Bionic() { flags.CppFlags = append(flags.CppFlags, "-nostdinc++") - flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs") - if ctx.staticBinary() { - flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...) - } else { - flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...) - } + flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") if ctx.Windows() { + if stl.Properties.SelectedStl == "libc++_static" { + // These are transitively needed by libc++_static. + flags.extraLibFlags = append(flags.extraLibFlags, + "-lmsvcrt", "-lucrt") + } // Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj // exception model for 32-bit. if ctx.Arch().ArchType == android.X86 { @@ -260,12 +260,7 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { // None or error. if !ctx.toolchain().Bionic() { flags.CppFlags = append(flags.CppFlags, "-nostdinc++") - flags.extraLibFlags = append(flags.extraLibFlags, "-nodefaultlibs") - if ctx.staticBinary() { - flags.extraLibFlags = append(flags.extraLibFlags, hostStaticGccLibs[ctx.Os()]...) - } else { - flags.extraLibFlags = append(flags.extraLibFlags, hostDynamicGccLibs[ctx.Os()]...) - } + flags.extraLibFlags = append(flags.extraLibFlags, "-nostdlib++") } default: panic(fmt.Errorf("Unknown stl: %q", stl.Properties.SelectedStl)) @@ -273,22 +268,3 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { return flags } - -var hostDynamicGccLibs, hostStaticGccLibs map[android.OsType][]string - -func init() { - hostDynamicGccLibs = map[android.OsType][]string{ - android.Fuchsia: []string{"-lc", "-lunwind"}, - android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}, - android.Darwin: []string{"-lc", "-lSystem"}, - android.Windows: []string{"-Wl,--start-group", "-lmingw32", "-lgcc", "-lgcc_eh", - "-lmoldname", "-lmingwex", "-lmsvcrt", "-lucrt", "-lpthread", - "-ladvapi32", "-lshell32", "-luser32", "-lkernel32", "-lpsapi", - "-Wl,--end-group"}, - } - hostStaticGccLibs = map[android.OsType][]string{ - android.Linux: []string{"-Wl,--start-group", "-lgcc", "-lgcc_eh", "-lc", "-Wl,--end-group"}, - android.Darwin: []string{"NO_STATIC_HOST_BINARIES_ON_DARWIN"}, - android.Windows: []string{"NO_STATIC_HOST_BINARIES_ON_WINDOWS"}, - } -}