cmd/link: plugin support on darwin/amd64

This CL turns some special section marker symbols into real symbols
laid out in the sections they mark. This is to deal with the fact
that dyld on OS X resolves the section marker symbols in any dlopen-ed
Go program to the original section marker symbols in the host program.

More details in a comment in cmd/link/internal/ld/data.go.

Change-Id: Ie9451cfbf06d0bdcccb9959219c791b829f3f771
Reviewed-on: https://go-review.googlesource.com/29394
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David Crawshaw 2016-09-19 14:13:07 -04:00
parent 26a6131bac
commit 73e7a569b4
5 changed files with 127 additions and 15 deletions

View file

@ -954,7 +954,12 @@ func (l *Link) hostlink() {
switch Headtype {
case obj.Hdarwin:
argv = append(argv, "-Wl,-no_pie,-headerpad,1144")
argv = append(argv, "-Wl,-headerpad,1144")
if l.DynlinkingGo() {
argv = append(argv, "-Wl,-flat_namespace")
} else {
argv = append(argv, "-Wl,-no_pie")
}
case obj.Hopenbsd:
argv = append(argv, "-Wl,-nopie")
case obj.Hwindows:
@ -986,11 +991,20 @@ func (l *Link) hostlink() {
// non-closeable: a dlclose will do nothing.
argv = append(argv, "-shared", "-Wl,-z,nodelete")
}
case BuildmodeShared, BuildmodePlugin:
case BuildmodeShared:
if UseRelro() {
argv = append(argv, "-Wl,-z,relro")
}
argv = append(argv, "-shared")
case BuildmodePlugin:
if Headtype == obj.Hdarwin {
argv = append(argv, "-dynamiclib")
} else {
if UseRelro() {
argv = append(argv, "-Wl,-z,relro")
}
argv = append(argv, "-shared")
}
}
if Iself && l.DynlinkingGo() {