Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: avoid bitcode incompatible flag -Wl,no_pie on darwin/arm #35252

Closed
eliasnaur opened this issue Oct 30, 2019 · 1 comment
Closed

cmd/link: avoid bitcode incompatible flag -Wl,no_pie on darwin/arm #35252

eliasnaur opened this issue Oct 30, 2019 · 1 comment

Comments

@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Oct 30, 2019

CL 201358 removes most of the flags incompatible with -fembed-bitcode on iOS. However, -Wl,no_pie is left for darwin/arm because without it, linking fails:

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _runtime.rodata from /var/folders/qq/qxn86k813bn9fjxydm095rxw0000gp/T/workdir-host-darwin-amd64-zenly-ios/tmp/go-link-225285265/go.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie

This error surprised @cherrymui who

thought we have removed absolute addressing on darwin/arm. Maybe we only did this for normal symbols but we missed runtime.rodata (which is linker generated)? I could take a look. (but probably not so soon...)

@thanm also expressed interest in digging into this:

The "runtime.rodata" thing seems odd -- runtime.rodata is a linker generated symbol, but looking at the linker code it appears to just be a pseudo-symbol that incorporates all of the rodata for the program. I ran a couple of regular builds on Darwin/amd64 with -buildmode=pie and looked over the relocations in the Go object file, and I don't see anything suspicious (although I'm not sure if that says much).

(from the golang-dev thread)

The error above is a build time error so can readily be reproduced on macOS with the following change applied:

diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go
index d5868c9770..78f493ca9f 100644
--- a/src/cmd/link/internal/ld/lib.go
+++ b/src/cmd/link/internal/ld/lib.go
@@ -1206,7 +1206,7 @@ func (ctxt *Link) hostlink() {
        switch ctxt.BuildMode {
        case BuildModeExe:
                if ctxt.HeadType == objabi.Hdarwin {
-                       if ctxt.Arch.Family != sys.ARM64 {
+                       if !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
                                argv = append(argv, "-Wl,-no_pie")
                        }
                        if !ctxt.Arch.InFamily(sys.ARM, sys.ARM64) {
@eliasnaur eliasnaur changed the title cmd/link: avoid bitcode incompatible flag -W,no_pie on darwin/arm cmd/link: avoid bitcode incompatible flag -Wl,no_pie on darwin/arm Oct 30, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 4, 2019

Change https://golang.org/cl/205060 mentions this issue: cmd/link: enable PIE on darwin/arm

@gopherbot gopherbot closed this in d3660e8 Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.