1
0
mirror of https://github.com/golang/go synced 2024-09-23 23:20:14 -06:00

cmd/link: exit early when -d is used on libc platforms

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>
This commit is contained in:
Cherry Mui 2021-11-19 16:36:03 -05:00
parent b31dda8a2a
commit 57aba325c8
3 changed files with 14 additions and 4 deletions

View 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 {

View 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
}

View 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