Skip to content

Commit 57aba32

Browse files
committed
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 <[email protected]> Run-TryBot: Cherry Mui <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent b31dda8 commit 57aba32

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/cmd/link/internal/ld/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func Main(arch *sys.Arch, theArch Arch) {
172172
usage()
173173
}
174174

175+
if *FlagD && ctxt.UsesLibc() {
176+
Exitf("dynamic linking required on %s; -d flag cannot be used", buildcfg.GOOS)
177+
}
178+
175179
checkStrictDups = *FlagStrictDups
176180

177181
if !buildcfg.Experiment.RegabiWrappers {

src/cmd/link/internal/ld/target.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,13 @@ func (t *Target) mustSetHeadType() {
185185
func (t *Target) IsBigEndian() bool {
186186
return t.Arch.ByteOrder == binary.BigEndian
187187
}
188+
189+
func (t *Target) UsesLibc() bool {
190+
t.mustSetHeadType()
191+
switch t.HeadType {
192+
case objabi.Haix, objabi.Hdarwin, objabi.Hopenbsd, objabi.Hsolaris, objabi.Hwindows:
193+
// platforms where we use libc for syscalls.
194+
return true
195+
}
196+
return false
197+
}

src/cmd/link/internal/ld/xcoff.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,6 @@ func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader
12901290
}
12911291

12921292
func (ctxt *Link) doxcoff() {
1293-
if *FlagD {
1294-
// All XCOFF files have dynamic symbols because of the syscalls.
1295-
Exitf("-d is not available on AIX")
1296-
}
12971293
ldr := ctxt.loader
12981294

12991295
// TOC

0 commit comments

Comments
 (0)