-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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/internal/ld: Passing incorrect offset to codesign.Sign
#59555
Comments
Previously, codesign.Sign was called with Segtext.Fileoff and Segtext.Filelen. However, both variables are being changed in the course of asmbMacho and point to the __text section at the time codesign.Sign is called, instead of the whole __TEXT segment. Therefore, a stored local variable, which already existed and holds the correct length is used. The offset is always 0. Fixes golang#59555
Change https://go.dev/cl/484015 mentions this issue: |
@golang/compiler - already has a proposed fix, just needs to be eyeballed to be sure it is really a bug. |
The code is actually intended to use the segment's values, not the section's, as The For consistency, maybe we'll change the linker to use the values matching the Mach-O segment, one day. Thanks. |
Previously, codesign.Sign was called with Segtext.Fileoff and Segtext.Filelen. However, both variables do not contain the complete __TEXT segment, as it excludes padding and header. Therefore, we now store a reference to the complete segment in mstext when it is created and pass its offset (which should always be 0) and filesize to codesign.Sign. Fixes golang#59555
As requested per @dmitshur: There was an ongoing discussion about this issue in https://go-review.googlesource.com/c/go/+/484015 and the consensus was that the values were changed to match the Mach-O segment. |
Reopening to track submission of CL 484015 which will resolve this. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The internal function
asmbMacho
which creates the mach-o header passes incorrect values to thecodesign
package here:go/src/cmd/link/internal/ld/macho.go
Line 871 in 5a962bf
What did you expect to see?
codesign.Sign
expects the offset and size of the executable segment.What did you see instead?
Instead, only the values of the
__text
section are passed.It seems this gets sort of fixed in the end because
codesign.Sign
gets executed again in theRewrite
function ofcmd/internal/buildid
and this time, the correct values are passed.go/src/cmd/internal/buildid/rewrite.go
Lines 107 to 112 in 1635205
Possible fix
The fix is quite easy, the local variable
v
withinasmbMacho
already holds the exec file size and the offset should be 0.I am not an expert on the buildid, but does this rewrite always happen? Or just under special circumstances?
The text was updated successfully, but these errors were encountered: