]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: avoid use of -T when linking with lld
authorThan McIntosh <thanm@google.com>
Mon, 14 Dec 2020 18:03:06 +0000 (13:03 -0500)
committerThan McIntosh <thanm@google.com>
Fri, 18 Dec 2020 00:16:17 +0000 (00:16 +0000)
When doing external linking on Windows, auto-detect the linker flavor
(bfd vs gold vs lld) and when linking with "lld", avoid the use of
"-T" (linker script), since this option is not supported by lld.
[Note: the Go linker currently employs -T to ensure proper placement
of the .debug_gdb_scripts section, to work around issues in older
versions of binutils; LLD recognizes this section and does place it
properly].

Updates #39326.

Change-Id: I3ea79cdceef2316bf86eccdb60188ac3655264ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/278932
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/lib.go

index f3c301cc9b56539558d91bffa5be64bf17a3b590..833b3eb9db6639205e015eb595002a189333e5ed 100644 (file)
@@ -1560,10 +1560,22 @@ func (ctxt *Link) hostlink() {
                checkStatic(p)
        }
        if ctxt.HeadType == objabi.Hwindows {
+               // Determine which linker we're using. Add in the extldflags in
+               // case used has specified "-fuse-ld=...".
+               cmd := exec.Command(*flagExtld, *flagExtldflags, "-Wl,--version")
+               usingLLD := false
+               if out, err := cmd.CombinedOutput(); err == nil {
+                       if bytes.Contains(out, []byte("LLD ")) {
+                               usingLLD = true
+                       }
+               }
+
                // use gcc linker script to work around gcc bug
                // (see https://golang.org/issue/20183 for details).
-               p := writeGDBLinkerScript()
-               argv = append(argv, "-Wl,-T,"+p)
+               if !usingLLD {
+                       p := writeGDBLinkerScript()
+                       argv = append(argv, "-Wl,-T,"+p)
+               }
                // libmingw32 and libmingwex have some inter-dependencies,
                // so must use linker groups.
                argv = append(argv, "-Wl,--start-group", "-lmingwex", "-lmingw32", "-Wl,--end-group")