]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: enable PIE on darwin/arm
authorCherry Zhang <cherryyz@google.com>
Sun, 3 Nov 2019 22:04:28 +0000 (17:04 -0500)
committerCherry Zhang <cherryyz@google.com>
Mon, 4 Nov 2019 15:18:34 +0000 (15:18 +0000)
We used to pass -no_pie to external linker on darwin/arm, which
is incompatible with -fembed-bitcode. CL 201358 attempted to
remove the -no_pie flag, but it resulted the darwin linker to
complain about absolute addressing in TEXT segment.

On darwin/arm, we already get away from absolute addressing in
the TEXT section. The complained absolute addressing is in
RODATA, which was embedded in the TEXT segment. This CL moves
RODATA to the DATA segment, like what we already did on ARM64
and on AMD64 in c-archive/c-shared buildmodes for the same reason.
So there is no absolute addressing in the TEXT segment, which
allows us to remove -no_pie flag.

Fixes #35252.
Updates #32963.

Change-Id: Id6e3a594cb066d257d4f58fadb4a3ee4672529f7
Reviewed-on: https://go-review.googlesource.com/c/go/+/205060
Reviewed-by: Elias Naur <mail@eliasnaur.com>
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/macho.go

index 9d99aa6f28b895ced9baebd24186b372480f0b09..f1b190deafaacf1024edcbf3ff0d7c58700d898c 100644 (file)
@@ -1209,10 +1209,8 @@ func (ctxt *Link) hostlink() {
        switch ctxt.BuildMode {
        case BuildModeExe:
                if ctxt.HeadType == objabi.Hdarwin {
-                       if ctxt.Arch.Family != sys.ARM64 {
-                               argv = append(argv, "-Wl,-no_pie")
-                       }
                        if !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
+                               argv = append(argv, "-Wl,-no_pie")
                                argv = append(argv, "-Wl,-pagezero_size,4000000")
                        }
                }
index e9e48768c14d3312b93f1ab4a7f5d80ad6fcda83..8756da4fd8c87dd007f3ce97c122b3fe7c00cda7 100644 (file)
@@ -488,9 +488,9 @@ func machoshbits(ctxt *Link, mseg *MachoSeg, sect *sym.Section, segname string)
 
        var msect *MachoSect
        if sect.Rwx&1 == 0 && segname != "__DWARF" && (ctxt.Arch.Family == sys.ARM64 ||
-               (ctxt.Arch.Family == sys.AMD64 && ctxt.BuildMode != BuildModeExe) ||
-               (ctxt.Arch.Family == sys.ARM && ctxt.BuildMode != BuildModeExe)) {
-               // Darwin external linker on arm64 and on amd64 and arm in c-shared/c-archive buildmode
+               ctxt.Arch.Family == sys.ARM ||
+               (ctxt.Arch.Family == sys.AMD64 && ctxt.BuildMode != BuildModeExe)) {
+               // Darwin external linker on arm and arm64, and on amd64 in c-shared/c-archive buildmode
                // complains about absolute relocs in __TEXT, so if the section is not
                // executable, put it in __DATA segment.
                msect = newMachoSect(mseg, buf, "__DATA")