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/cgo: use C exact-width integer types to represent Go types #29907

Closed
wants to merge 1 commit into from

Conversation

phst
Copy link
Contributor

@phst phst commented Jan 23, 2019

The exact-width integer types are required to use two’s complement
representation and may not have padding bits, cf. §7.20.1.1/1 in the C11
standard or https://en.cppreference.com/w/c/types/integer. This ensures that
they have the same domain and representation as the corresponding Go types.

Fixes #29878

@googlebot googlebot added the cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label Jan 23, 2019
@gopherbot
Copy link

This PR (HEAD: f243e24) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/159258 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 1c1ebe3) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/159258 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Philipp Stephani:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 2:

R=go1.13


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Emmanuel Odeke:

Patch Set 2: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 2:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=eec656d3


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 2:

Build is still in progress...
This change failed on freebsd-amd64-12_0:
See https://storage.googleapis.com/go-build-log/eec656d3/freebsd-amd64-12_0_2a75ce0f.log

Consult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR (HEAD: 71dac4a) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/159258 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

This PR (HEAD: d8a401b) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/159258 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Philipp Stephani:

Patch Set 4:

I've moved the test to the misc/cgo directory, I hope they now pass.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Tobias Klauser:

Patch Set 4: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 4:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=50991e3d


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 4:

Build is still in progress...
This change failed on linux-386:
See https://storage.googleapis.com/go-build-log/50991e3d/linux-386_9d65ed80.log

Consult https://build.golang.org/ to see whether it's a new failure. Other builds still in progress; subsequent failure notices suppressed until final report.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 4: TryBot-Result-1

2 of 19 TryBots failed:
Failed on linux-386: https://storage.googleapis.com/go-build-log/50991e3d/linux-386_9d65ed80.log
Failed on windows-386-2008: https://storage.googleapis.com/go-build-log/50991e3d/windows-386-2008_3eaa6aa1.log

Consult https://build.golang.org/ to see whether they are new failures.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 4:

Trybot failures look real.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Philipp Stephani:

Patch Set 4:

Patch Set 4:

Trybot failures look real.

Yes, agreed. This is because C and Go disagree about the alignment of (u)int64 on 32-bit x86.
I'm wondering why goTypes has a fixed alignment of 8; IIUC the actual alignment on 32-bit systems is 4. Should I fix this in goTypes by using unsafe.Alignof(int64(0)) etc.?


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 4:

Trybot failures look real.

Yes, agreed. This is because C and Go disagree about the alignment of (u)int64 on 32-bit x86.
I'm wondering why goTypes has a fixed alignment of 8; IIUC the actual alignment on 32-bit systems is 4. Should I fix this in goTypes by using unsafe.Alignof(int64(0)) etc.?

How are you deciding what go/types uses for the alignment (I didn't look at your code)? When I run this:

fmt.Println(unsafe.Alignof(int64(0)))
sizes := types.SizesFor("gc", "386")
fmt.Println(sizes.Alignof(types.Universe.Lookup("int64").Type()))

it prints 4 as I expect.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Philipp Stephani:

Patch Set 4:

Patch Set 4:

Trybot failures look real.

Yes, agreed. This is because C and Go disagree about the alignment of (u)int64 on 32-bit x86.
I'm wondering why goTypes has a fixed alignment of 8; IIUC the actual alignment on 32-bit systems is 4. Should I fix this in goTypes by using unsafe.Alignof(int64(0)) etc.?

How are you deciding what go/types uses for the alignment (I didn't look at your code)? When I run this:

fmt.Println(unsafe.Alignof(int64(0)))
sizes := types.SizesFor("gc", "386")
fmt.Println(sizes.Alignof(types.Universe.Lookup("int64").Type()))

it prints 4 as I expect.

What I mean are the alignment settings in the goTypes map in https://go.googlesource.com/go/+/refs/tags/go1.12.1/src/cmd/cgo/out.go#1375. They set the alignment to 8 unconditionally for the 64-bit types. I'm not quite sure what the Size and Align members of these map values refer to; should they match the actual size and alignment on the target architecture?


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 4:

Trybot failures look real.

Yes, agreed. This is because C and Go disagree about the alignment of (u)int64 on 32-bit x86.
I'm wondering why goTypes has a fixed alignment of 8; IIUC the actual alignment on 32-bit systems is 4. Should I fix this in goTypes by using unsafe.Alignof(int64(0)) etc.?

How are you deciding what go/types uses for the alignment (I didn't look at your code)? When I run this:

fmt.Println(unsafe.Alignof(int64(0)))
sizes := types.SizesFor("gc", "386")
fmt.Println(sizes.Alignof(types.Universe.Lookup("int64").Type()))

it prints 4 as I expect.

What I mean are the alignment settings in the goTypes map in https://go.googlesource.com/go/+/refs/tags/go1.12.1/src/cmd/cgo/out.go#1375. They set the alignment to 8 unconditionally for the 64-bit types. I'm not quite sure what the Size and Align members of these map values refer to; should they match the actual size and alignment on the target architecture?

The only place where that table is used, (*Package).cgoType, adjusts the alignment so that it does not exceed the target pointer size. That is supposed to make the result match what the compiler does.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

The exact-width integer types are required to use two’s complement
representation and may not have padding bits, cf. §7.20.1.1/1 in the C11
standard or https://en.cppreference.com/w/c/types/integer.  This ensures that
they have the same domain and representation as the corresponding Go types.

Fixes golang#29878
@gopherbot
Copy link

This PR (HEAD: 546a2cc) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/159258 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

Message from Philipp Stephani:

Patch Set 4:

Patch Set 4:

Trybot failures look real.

Yes, agreed. This is because C and Go disagree about the alignment of (u)int64 on 32-bit x86.
I'm wondering why goTypes has a fixed alignment of 8; IIUC the actual alignment on 32-bit systems is 4. Should I fix this in goTypes by using unsafe.Alignof(int64(0)) etc.?

How are you deciding what go/types uses for the alignment (I didn't look at your code)? When I run this:

fmt.Println(unsafe.Alignof(int64(0)))
sizes := types.SizesFor("gc", "386")
fmt.Println(sizes.Alignof(types.Universe.Lookup("int64").Type()))

it prints 4 as I expect.

What I mean are the alignment settings in the goTypes map in https://go.googlesource.com/go/+/refs/tags/go1.12.1/src/cmd/cgo/out.go#1375. They set the alignment to 8 unconditionally for the 64-bit types. I'm not quite sure what the Size and Align members of these map values refer to; should they match the actual size and alignment on the target architecture?

The only place where that table is used, (*Package).cgoType, adjusts the alignment so that it does not exceed the target pointer size. That is supposed to make the result match what the compiler does.

OK, I've pushed a change making a similar adjustment. (Though I guess in the long run it'd be better to use the go/types package to reduce duplication.)


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 5: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 5:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=977bd5d7


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

Message from Gobot Gobot:

Patch Set 5: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Mar 18, 2019
The exact-width integer types are required to use two’s complement
representation and may not have padding bits, cf. §7.20.1.1/1 in the C11
standard or https://en.cppreference.com/w/c/types/integer.  This ensures that
they have the same domain and representation as the corresponding Go types.

Fixes #29878

Change-Id: Ie8a51e91666dfd89731c7859abe47356c94ca1be
GitHub-Last-Rev: 546a2cc
GitHub-Pull-Request: #29907
Reviewed-on: https://go-review.googlesource.com/c/go/+/159258
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@gopherbot
Copy link

Message from Ian Lance Taylor:

Patch Set 5: Code-Review+2

Thanks.

RELNOTES=yes


Please don’t reply on this GitHub thread. Visit golang.org/cl/159258.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

This PR is being closed because golang.org/cl/159258 has been merged.

@gopherbot gopherbot closed this Mar 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants