-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/crypto/curve25519: MOVQ global clobbers R15 when dynamically linking #18820
Comments
@agl is the meta owner of all x/crypto. |
These values should be |
I do not believe we have such a mechanism. (Though I would be happy to be proven wrong.) How performance sensitive are these functions? We could push the globals into stack slots at the start. |
I can work around it, I'm sure, but if there's no notion of symbol visibility in Go does that mean that every function call goes via the PLT and every global access goes via the GOT? That does seem at odds with traditional shared-library conventions and unlikely to give good performance. (I would guess that it also means that every function is listed in the dynamic exports table, but that's less crazy in Go since it already has namespaces.) |
I suspect @mwhudson or @ianlancetaylor can give a better answer as they have thought about it more, but my attempt would be: (EDIT) All exported symbols in -buildmode=shared and cgo exports need to exposed so they can be dynamically linked again. Otherwise all unexported symbols like this are hidden (in the "C shared library" sense), unless the //go:cgo_export_static or //go:cgo_export_dynamic directives are used. The toolchain is missing optimizations. |
(If someone can definitively say that we're currently indirecting all global loads and thus need to avoid holding R15 during them I can start on the needed changes. Just want to make sure that this is needed though because it's unexpected to me.) |
In the normal case we do not indirect global loads through R15. However, we do when the code is compiled with the |
@ianlancetaylor and there's no way to avoid the indirection when the symbol cannot be shadowed, like |
That is correct: it applies to every global symbol. There is no way to mark a symbol as hidden. |
Oh, good sleuthing @crawshaw There is one way to make a symbol end up being local to the module being built, which is to use the ·foo<> form. But this is file local, which is not really appropriate here, as far as I can see. |
Perhaps the linker should treat ·foo<> as private symbols when generating
shared libraries.
|
@agl, yes there's no way to avoid the indirection. R15 is clobbered by global references like this, sorry. We should probably fix this for Go 1.8, right? |
It does already. But that doesn't really help here. It would be nice to fix this for 1.8, please. I can carry a fix as a distro patch until 1.8.1 if necessary if the timings don't work out. |
On Jan 30, 2017 6:03 PM, "Michael Hudson-Doyle" <notifications@github.com> wrote:
Perhaps the linker should treat ·foo<> as private symbols when generating
shared libraries.
It does already. But that doesn't really help here.
For private symbols, it could use rip-relative addressing mode to avoid the
indirection through GOT. Or am I missing anything?
|
CL https://golang.org/cl/36359 mentions this issue. |
CL https://golang.org/cl/36412 mentions this issue. |
Fixed in subrepo. CL pending for master. Then have to cherry-pick to release branch. |
Final CL out: https://go-review.googlesource.com/36414 |
CL https://golang.org/cl/36414 mentions this issue. |
…oss of R15 in -dynlink mode Original code fixed in https://go-review.googlesource.com/#/c/36359/. Fixes #18820. Change-Id: I060e6c9d0e312b4fd5d0674aff131055bf5cf61d Reviewed-on: https://go-review.googlesource.com/36412 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Adam Langley <agl@golang.org> Reviewed-on: https://go-review.googlesource.com/36414 Reviewed-by: Austin Clements <austin@google.com>
Fixes golang/go#18820. Change-Id: I4b3a49b3bbbecc4e1008989fefd39da9725a28ea Reviewed-on: https://go-review.googlesource.com/36359 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Adam Langley <agl@golang.org>
Fixes golang/go#18820. Change-Id: I4b3a49b3bbbecc4e1008989fefd39da9725a28ea Reviewed-on: https://go-review.googlesource.com/36359 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Adam Langley <agl@golang.org>
Fixes golang/go#18820. Change-Id: I4b3a49b3bbbecc4e1008989fefd39da9725a28ea Reviewed-on: https://go-review.googlesource.com/36359 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Adam Langley <agl@golang.org>
Fixes golang/go#18820. Change-Id: I4b3a49b3bbbecc4e1008989fefd39da9725a28ea Reviewed-on: https://go-review.googlesource.com/36359 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Adam Langley <agl@golang.org>
Fixes golang/go#18820. Change-Id: I4b3a49b3bbbecc4e1008989fefd39da9725a28ea Reviewed-on: https://go-review.googlesource.com/36359 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Adam Langley <agl@golang.org>
The functions
ladderstep
,mul
, andsquare
load global values.When dynamically linking on amd64, a the load uses R15 as a temporary. Unfortunately, these functions try to use R15 across these loads.
For example,
turns into
MOVQ 0xABCD(IP), DX
typically, but under the compiler's dynamic linking mode it becomesThe unit tests for this package (and crypto/tls which depends on this) hang under -buildmode=shared and fail under -buildmode=plugin:
cc @mwhudson
@bradfitz Any idea who owns this code? I'd like their opinion before touching it.
The text was updated successfully, but these errors were encountered: