]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: exit early when -d is used on libc platforms
authorCherry Mui <cherryyz@google.com>
Fri, 19 Nov 2021 21:36:03 +0000 (16:36 -0500)
committerCherry Mui <cherryyz@google.com>
Sat, 20 Nov 2021 00:32:49 +0000 (00:32 +0000)
On platforms where we use libc for syscalls, we dynamically link
with libc and therefore dynamic linking cannot be disabled. Exit
early when -d is specified.

Update #42459.

Change-Id: I05abfe111df723b5ee512ceafef734e3804dd0a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/365658
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/ld/target.go
src/cmd/link/internal/ld/xcoff.go

index a1d86965e434bb99f6eb1e68522debd3fd07f0c1..26f9db8ec410bf3dbc5a2265c51cc95d6700863d 100644 (file)
@@ -172,6 +172,10 @@ func Main(arch *sys.Arch, theArch Arch) {
                usage()
        }
 
+       if *FlagD && ctxt.UsesLibc() {
+               Exitf("dynamic linking required on %s; -d flag cannot be used", buildcfg.GOOS)
+       }
+
        checkStrictDups = *FlagStrictDups
 
        if !buildcfg.Experiment.RegabiWrappers {
index f68de8fff13fa83411c3208f5cae16631217631b..58d45d1504677376163e563bb35c95d47969501e 100644 (file)
@@ -185,3 +185,13 @@ func (t *Target) mustSetHeadType() {
 func (t *Target) IsBigEndian() bool {
        return t.Arch.ByteOrder == binary.BigEndian
 }
+
+func (t *Target) UsesLibc() bool {
+       t.mustSetHeadType()
+       switch t.HeadType {
+       case objabi.Haix, objabi.Hdarwin, objabi.Hopenbsd, objabi.Hsolaris, objabi.Hwindows:
+               // platforms where we use libc for syscalls.
+               return true
+       }
+       return false
+}
index aba6138c834adca7c09bb56d2f40cb94aba0edb1..aaddf19d16a730f417f1ce9905d4700dca45912c 100644 (file)
@@ -1290,10 +1290,6 @@ func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader
 }
 
 func (ctxt *Link) doxcoff() {
-       if *FlagD {
-               // All XCOFF files have dynamic symbols because of the syscalls.
-               Exitf("-d is not available on AIX")
-       }
        ldr := ctxt.loader
 
        // TOC