diff options
author | Pirama Arumuga Nainar <pirama@google.com> | 2019-02-28 15:52:05 -0800 |
---|---|---|
committer | Pirama Arumuga Nainar <pirama@google.com> | 2019-03-20 21:07:47 +0000 |
commit | 3c21c0b1d9bab0d51100ca03aa157a1d8545c2ea (patch) | |
tree | f249d66cfe8c40623633602c9dcb72a4364d8661 /cc | |
parent | 967511a4e844e439ab18cf0e77f2d406cc88d3be (diff) | |
download | build_soong-3c21c0b1d9bab0d51100ca03aa157a1d8545c2ea.tar.gz build_soong-3c21c0b1d9bab0d51100ca03aa157a1d8545c2ea.tar.bz2 build_soong-3c21c0b1d9bab0d51100ca03aa157a1d8545c2ea.zip |
Enable lld for windows
Bug: http://b/110800681
The following flags that the binutils linkers support are not available
in lld for Windows:
-soname
--no-undefined
-rpath
Windows also uses "import libraries", which are stub libraries used only
for linking. The binutils linkers accepted a DLL and treated them as an
import library. But lld issues the following error:
lld-link: error: ...DLL: bad file type. Did you specify a DLL instead
of an import library?
To resolve this, pass '-out-implib=libFoo.a' to lld when linking
libFoo.dll. Add libFoo.a as an implicit output to the 'ld' build rule.
Rewrite the shared libraries for a library/binary to use the import
library instead of the DLL. As a side-effect, this also (correctly)
uses the AdbWinApi.a that's alongside
development/host/windows/prebuilt/usb/AdbWinApi.dll
Test: Run Windows tests (go/android-llvm-windows-testing) and check
absence of regressions.
Change-Id: I15a178589aa6882caa6e7e38650cc6ef48109764
Diffstat (limited to 'cc')
-rw-r--r-- | cc/binary.go | 2 | ||||
-rw-r--r-- | cc/builder.go | 20 | ||||
-rw-r--r-- | cc/library.go | 17 | ||||
-rw-r--r-- | cc/linker.go | 8 |
4 files changed, 29 insertions, 18 deletions
diff --git a/cc/binary.go b/cc/binary.go index cae1739b..7f7c6008 100644 --- a/cc/binary.go +++ b/cc/binary.go @@ -384,7 +384,7 @@ func (binary *binaryDecorator) link(ctx ModuleContext, TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, linkerDeps, deps.CrtBegin, deps.CrtEnd, true, - builderFlags, outputFile) + builderFlags, outputFile, nil) objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) diff --git a/cc/builder.go b/cc/builder.go index 97ae8060..dab887c4 100644 --- a/cc/builder.go +++ b/cc/builder.go @@ -26,6 +26,7 @@ import ( "strings" "github.com/google/blueprint" + "github.com/google/blueprint/pathtools" "android/soong/android" "android/soong/cc/config" @@ -597,7 +598,7 @@ func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P // and shared libraries, to a shared library (.so) or dynamic executable func TransformObjToDynamicBinary(ctx android.ModuleContext, objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths, - crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) { + crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath, implicitOutputs android.WritablePaths) { ldCmd := "${config.ClangBin}/clang++" @@ -634,7 +635,11 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext, } for _, lib := range sharedLibs { - libFlagsList = append(libFlagsList, lib.String()) + libFile := lib.String() + if ctx.Windows() { + libFile = pathtools.ReplaceExtension(libFile, "a") + } + libFlagsList = append(libFlagsList, libFile) } deps = append(deps, staticLibs...) @@ -645,11 +650,12 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext, } ctx.Build(pctx, android.BuildParams{ - Rule: ld, - Description: "link " + outputFile.Base(), - Output: outputFile, - Inputs: objFiles, - Implicits: deps, + Rule: ld, + Description: "link " + outputFile.Base(), + Output: outputFile, + ImplicitOutputs: implicitOutputs, + Inputs: objFiles, + Implicits: deps, Args: map[string]string{ "ldCmd": ldCmd, "crtBegin": crtBegin.String(), diff --git a/cc/library.go b/cc/library.go index 8b666ed1..7216832c 100644 --- a/cc/library.go +++ b/cc/library.go @@ -347,9 +347,10 @@ func (library *libraryDecorator) linkerFlags(ctx ModuleContext, flags Flags) Fla ) } } else { - f = append(f, - "-shared", - "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) + f = append(f, "-shared") + if !ctx.Windows() { + f = append(f, "-Wl,-soname,"+libName+flags.Toolchain.ShlibSuffix()) + } } flags.LdFlags = append(f, flags.LdFlags...) @@ -673,6 +674,14 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, outputFile := android.PathForModuleOut(ctx, fileName) ret := outputFile + var implicitOutputs android.WritablePaths + if ctx.Windows() { + importLibraryPath := android.PathForModuleOut(ctx, pathtools.ReplaceExtension(fileName, "a")) + + flags.LdFlags = append(flags.LdFlags, "-Wl,--out-implib="+importLibraryPath.String()) + implicitOutputs = append(implicitOutputs, importLibraryPath) + } + builderFlags := flagsToBuilderFlags(flags) // Optimize out relinking against shared libraries whose interface hasn't changed by @@ -724,7 +733,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, TransformObjToDynamicBinary(ctx, objs.objFiles, sharedLibs, deps.StaticLibs, deps.LateStaticLibs, deps.WholeStaticLibs, - linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile) + linkerDeps, deps.CrtBegin, deps.CrtEnd, false, builderFlags, outputFile, implicitOutputs) objs.coverageFiles = append(objs.coverageFiles, deps.StaticLibObjs.coverageFiles...) objs.coverageFiles = append(objs.coverageFiles, deps.WholeStaticLibObjs.coverageFiles...) diff --git a/cc/linker.go b/cc/linker.go index fd958ba8..179a9985 100644 --- a/cc/linker.go +++ b/cc/linker.go @@ -290,10 +290,6 @@ func (linker *baseLinker) useClangLld(ctx ModuleContext) bool { if ctx.Darwin() { return false } - // http://b/110800681 - lld cannot link Android's Windows modules yet. - if ctx.Windows() { - return false - } if linker.Properties.Use_clang_lld != nil { return Bool(linker.Properties.Use_clang_lld) } @@ -347,7 +343,7 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { // darwin defaults to treating undefined symbols as errors flags.LdFlags = append(flags.LdFlags, "-Wl,-undefined,dynamic_lookup") } - } else if !ctx.Darwin() { + } else if !ctx.Darwin() && !ctx.Windows() { flags.LdFlags = append(flags.LdFlags, "-Wl,--no-undefined") } @@ -384,7 +380,7 @@ func (linker *baseLinker) linkerFlags(ctx ModuleContext, flags Flags) Flags { flags.LdFlags = append(flags.LdFlags, proptools.NinjaAndShellEscapeList(linker.Properties.Ldflags)...) - if ctx.Host() { + if ctx.Host() && !ctx.Windows() { rpath_prefix := `\$$ORIGIN/` if ctx.Darwin() { rpath_prefix = "@loader_path/" |