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/compile: support -buildmode=pie on OpenBSD #59866

Open
catinello opened this issue Apr 27, 2023 · 9 comments
Open

cmd/compile: support -buildmode=pie on OpenBSD #59866

catinello opened this issue Apr 27, 2023 · 9 comments
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-OpenBSD
Milestone

Comments

@catinello
Copy link

What version of Go are you using (go version)?

$ go version go1.20.1 openbsd/amd64

Does this issue reproduce with the latest release?

Yes, I think so.

What operating system and processor architecture are you using (go env)?

OpenBSD 7.3 on amd64

What did you do?

I tried to build a PIE binary with -buildmode=pie

What did you expect to see?

I was expecting to build a binary with PIE enabled.

What did you see instead?

-buildmode=pie not supported on openbsd/amd64

Is there any particular reason that buildmode=pie is not supported on openbsd? Building with that buildmode returns that the buildmode=pie is not supported.

clang on OpenBSD/amd64 defaults and produces PIE static/dynamic binaries without issue. But even external linking in Go suppresses PIE with LDFlags -Wl,-nopie. You can append -Wl,-pie through -extldflags option, the result will be expectedly an invalid function entry symbol table or a segmentation fault.

I could not find an open issue that works on this or explains the situation for the missing support. There are some that are years old and closed or some old mailing list entries. I get that openbsd is a secondary port, but why is there not even an issue that addresses the state/progress and situation?

I'm just genuinely interested to see progress at this.

Thank you.

@bcmills bcmills changed the title openbsd / buildmode=pie cmd/compile: support -buildmode=pie on OpenBSD Apr 27, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 27, 2023
@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed compiler/runtime Issues related to the Go compiler and/or runtime. labels Apr 27, 2023
@bcmills bcmills added this to the Backlog milestone Apr 27, 2023
@bcmills
Copy link
Contributor

bcmills commented Apr 27, 2023

(attn @golang/openbsd)

@qbit
Copy link
Member

qbit commented Apr 27, 2023

Around 2020-02-01 I started working on PIE mode for Go amd64. Here is the diff.

I got everything working:

  • It is able to produce binaries.
  • Tests pass.

However, about 50% of the time binaries produced with it die with a SIGSEGV. Interestingly it works fine on single CPU machines.

@catinello
Copy link
Author

catinello commented Apr 27, 2023

Awesome! Your patch allows/fixes the necessary flags as it seems. Does the patch work against 1.20.1 that is currently in ports? Did you try with 7.3 yet? mmap/mprotect was SMP unlocked.

@qbit
Copy link
Member

qbit commented Apr 27, 2023

I haven't updated the patch to work with newer Go versions.

@catinello
Copy link
Author

Is there more information somewhere? Why was PIE disabled in the first place? There must be a reason?

The patch definitely needs some work and I doubt that enabling the flags will just make everything work.

@catinello
Copy link
Author

catinello commented Apr 29, 2023

I think I found the origin in #17847

But could DT_TEXTREL really be the issue here? OpenBSD builds PIE by default and Go does call the external linker on OpenBSD.

Maybe this was just collateral damage?

@qbit
Copy link
Member

qbit commented May 3, 2023

The patch definitely needs some work and I doubt that enabling the flags will just make everything work.

Indeed it did with with enabling the flags .. just inconsistently on MP machines. The bins were PIE and ran as expected on single proc machines.

I can't speak to why it was disabled in the first place.

@ikmckenz
Copy link

Also running into this issue

gopherbot pushed a commit that referenced this issue Mar 16, 2024
The PIE buildmode works correctly on openbsd/arm64, hence enable it.

Updates #59866

Change-Id: I2f3c2839893659391539fafa12891d64f867e189
Reviewed-on: https://go-review.googlesource.com/c/go/+/570375
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
@gopherbot
Copy link

Change https://go.dev/cl/570375 mentions this issue: cmd/dist,cmd/link: enable PIE buildmode on openbsd/arm64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-OpenBSD
Projects
None yet
Development

No branches or pull requests

5 participants