From a403cc72549e421cb92801a3694f5427497c2f0d Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Wed, 8 Aug 2018 10:28:12 -0700 Subject: [PATCH 1/2] Change STL for Windows to libc++. - Stop including libstdc++ headers. - '-pthread' and 'static-libgcc' are unused when we pass -nodefaultlibs. We didn't pass -nodefaultlibs for libstdc++. - Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj exception model for 32-bit. - Disable visibility annotations for libcxx and libcxxabi since we are only going to support these as static libraries. - Use Win32 threads. MinGW pthreads throws an error when building libcxx since it's pthread_mutex_initializer is not constant (needs a cast). - Link libgcc_eh, which needs pthread, which in turn depends on kernel32. Wrap the libraries with --start-group and --end-group and remove duplicates. Test: Build and test Windows binaries under Wine. Change-Id: I8be51b004585e11ef51b7d5012f2a51330d1260f --- cc/config/x86_windows_host.go | 18 ++++-------------- cc/stl.go | 27 +++++++++++++++++++++------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 988ba0363..8bbda3146 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -47,18 +47,11 @@ var ( "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include", } - windowsClangCppflags = []string{ - "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3", - "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/backward", - } + windowsClangCppflags = []string{} - windowsX86ClangCppflags = []string{ - "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}/32", - } + windowsX86ClangCppflags = []string{} - windowsX8664ClangCppflags = []string{ - "-isystem ${WindowsGccRoot}/${WindowsGccTriple}/include/c++/4.8.3/${WindowsGccTriple}", - } + windowsX8664ClangCppflags = []string{} windowsLdflags = []string{ "--enable-stdcall-fixup", @@ -80,14 +73,13 @@ var ( "-m32", "-Wl,--large-address-aware", "-L${WindowsGccRoot}/${WindowsGccTriple}/lib32", - "-static-libgcc", } windowsX86ClangLdflags = append(ClangFilterUnknownCflags(windowsX86Ldflags), []string{ "-B${WindowsGccRoot}/${WindowsGccTriple}/bin", "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32", "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32", "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32", - "-pthread", + // Bug: http://b/109759970 - WAR until issue with ld.bfd's // inability to handle Clang-generated section names is fixed. "-Wl,--allow-multiple-definition", @@ -97,7 +89,6 @@ var ( windowsX8664Ldflags = []string{ "-m64", "-L${WindowsGccRoot}/${WindowsGccTriple}/lib64", - "-static-libgcc", "-Wl,--high-entropy-va", } windowsX8664ClangLdflags = append(ClangFilterUnknownCflags(windowsX8664Ldflags), []string{ @@ -105,7 +96,6 @@ var ( "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3", "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3", "-B${WindowsGccRoot}/${WindowsGccTriple}/lib64", - "-pthread", }...) windowsX8664ClangLldflags = ClangFilterUnknownLldflags(windowsX8664ClangLdflags) diff --git a/cc/stl.go b/cc/stl.go index f44902e0b..8eee6124d 100644 --- a/cc/stl.go +++ b/cc/stl.go @@ -81,9 +81,9 @@ func (stl *stl) begin(ctx BaseModuleContext) { } } else if ctx.Windows() { switch s { - case "libc++", "libc++_static", "libstdc++", "": - // libc++ is not supported on mingw - return "libstdc++" + case "libc++", "libc++_static", "": + // Only use static libc++ for Windows. + return "libc++_static" case "none": return "" default: @@ -177,6 +177,20 @@ func (stl *stl) flags(ctx ModuleContext, flags Flags) Flags { } else { flags.LdFlags = append(flags.LdFlags, hostDynamicGccLibs[ctx.Os()]...) } + if ctx.Windows() { + // Use SjLj exceptions for 32-bit. libgcc_eh implements SjLj + // exception model for 32-bit. + if ctx.Arch().ArchType == android.X86 { + flags.CppFlags = append(flags.CppFlags, "-fsjlj-exceptions") + } + flags.CppFlags = append(flags.CppFlags, + // Disable visiblity annotations since we're using static + // libc++. + "-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS", + "-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS", + // Use Win32 threads in libc++. + "-D_LIBCPP_HAS_THREAD_API_WIN32") + } } else { if ctx.Arch().ArchType == android.Arm { flags.LdFlags = append(flags.LdFlags, "-Wl,--exclude-libs,libunwind_llvm.a") @@ -213,9 +227,10 @@ func init() { hostDynamicGccLibs = map[android.OsType][]string{ android.Linux: []string{"-lgcc_s", "-lgcc", "-lc", "-lgcc_s", "-lgcc"}, android.Darwin: []string{"-lc", "-lSystem"}, - android.Windows: []string{"-lmingw32", "-lgcc", "-lmoldname", "-lmingwex", "-lmsvcr110", - "-lmsvcrt", "-ladvapi32", "-lshell32", "-luser32", "-lkernel32", "-lmingw32", - "-lgcc", "-lmoldname", "-lmingwex", "-lmsvcrt"}, + android.Windows: []string{"-Wl,--start-group", "-lmingw32", "-lgcc", "-lgcc_eh", + "-lmoldname", "-lmingwex", "-lmsvcr110", "-lmsvcrt", "-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"}, From 8fd5a9695947f7855e3f13fab5a07c346150a6ef Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Mon, 8 Oct 2018 18:14:52 -0700 Subject: [PATCH 2/2] Remove --allow-multiple-definitions for 32-bit Windows Bug: http://b/109759970 Bug: http://b/91353691 There are no multiple-defintion errors after switching to clang-r339409 and libc++. Test: m native-host-cross Change-Id: I5576b3894ed1d88c9b2e5f4d92e1d3bfadfb029b --- cc/config/x86_windows_host.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cc/config/x86_windows_host.go b/cc/config/x86_windows_host.go index 8bbda3146..6300a1bcf 100644 --- a/cc/config/x86_windows_host.go +++ b/cc/config/x86_windows_host.go @@ -79,10 +79,6 @@ var ( "-B${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32", "-L${WindowsGccRoot}/lib/gcc/${WindowsGccTriple}/4.8.3/32", "-B${WindowsGccRoot}/${WindowsGccTriple}/lib32", - - // Bug: http://b/109759970 - WAR until issue with ld.bfd's - // inability to handle Clang-generated section names is fixed. - "-Wl,--allow-multiple-definition", }...) windowsX86ClangLldflags = ClangFilterUnknownLldflags(windowsX86ClangLdflags)