cmd/go, cmd/link: enable buildmode=pie on darwin/amd64

Change some configurations to enable the feature. Also add the test.
This CL doesn't include internal linking support which is tentatively
disabled due to #18968. We could do that another day.

Fixes #21220

Change-Id: I601d2d78446d36332acc70be0d5b9461ac635208
Reviewed-on: https://go-review.googlesource.com/54790
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-08-05 18:25:26 +09:00 committed by Ian Lance Taylor
parent 9fbc06e6aa
commit b7c600d6ba
5 changed files with 75 additions and 6 deletions

View file

@ -1095,7 +1095,7 @@ func (l *Link) hostlink() {
argv = append(argv, "-Wl,-headerpad,1144")
if l.DynlinkingGo() {
argv = append(argv, "-Wl,-flat_namespace")
} else if !SysArch.InFamily(sys.ARM64) {
} else if !SysArch.InFamily(sys.ARM64) && Buildmode != BuildmodePIE {
argv = append(argv, "-Wl,-no_pie")
}
case objabi.Hopenbsd:
@ -1114,10 +1114,13 @@ func (l *Link) hostlink() {
argv = append(argv, "-Wl,-pagezero_size,4000000")
}
case BuildmodePIE:
if UseRelro() {
argv = append(argv, "-Wl,-z,relro")
// ELF.
if Headtype != objabi.Hdarwin {
if UseRelro() {
argv = append(argv, "-Wl,-z,relro")
}
argv = append(argv, "-pie")
}
argv = append(argv, "-pie")
case BuildmodeCShared:
if Headtype == objabi.Hdarwin {
argv = append(argv, "-dynamiclib")