Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d8c0a50 authored by Pirama Arumuga Nainar's avatar Pirama Arumuga Nainar
Browse files

Revert "Revert "Enable lld for windows""

This reverts commit 61166dc0.

One difference from the earlier change is that import libraries are now
using the '.lib' extension instead of '.a' to prevent clash with
AdbWinApi.a.

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.lib' to lld when linking
libFoo.dll to get lld to generate an import library.  Add libFoo.lib as
an implicit output to the 'ld' build rule.

Rewrite the shared libraries when building a library/binary to use the
import library instead of the DLL.  As a side-effect, this also uses the
newly-created AdbWinApi.lib that's alongside
development/host/windows/prebuilt/usb/AdbWinApi.dll

Test: Run Windows tests (go/android-llvm-windows-testing) and check
absence of regressions.  Also check that the following commands pass:
      $ adb.exe devices
      $ fastboot.exe devices

Change-Id: I34e07d345e0207086ac8e8ea12525d8c322b20fd
parent 81963562
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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...)
+13 −7
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import (
	"strings"

	"github.com/google/blueprint"
	"github.com/google/blueprint/pathtools"

	"android/soong/android"
	"android/soong/cc/config"
@@ -596,7 +597,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++"

@@ -633,7 +634,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, "lib")
		}
		libFlagsList = append(libFlagsList, libFile)
	}

	deps = append(deps, staticLibs...)
@@ -647,6 +652,7 @@ func TransformObjToDynamicBinary(ctx android.ModuleContext,
		Rule:            ld,
		Description:     "link " + outputFile.Base(),
		Output:          outputFile,
		ImplicitOutputs: implicitOutputs,
		Inputs:          objFiles,
		Implicits:       deps,
		Args: map[string]string{
+13 −4
Original line number Diff line number Diff line
@@ -357,9 +357,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...)
@@ -683,6 +684,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, "lib"))

		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
@@ -734,7 +743,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...)
+2 −6
Original line number Diff line number Diff line
@@ -301,10 +301,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)
	}
@@ -358,7 +354,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")
	}

@@ -395,7 +391,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/"