Re: [go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Dan Kortschak
Yes, that's understood. I'm just responding to the notion that it's a
bug for a package author to expect the compiler to do the right thing.

On Tue, 2018-08-14 at 15:56 -0700, Ian Lance Taylor wrote:
> On Tue, Aug 14, 2018 at 3:49 PM, Dan Kortschak
>  wrote:
> > 
> > 
> > This ignores the possibility that more than one alignment-sensitive
> > field might be needed. Requiring that they all be up front,
> > potentially
> > degrading readability flies in the face of the design principles of
> > the
> > language. This kind foot-gun in other languages is why many people
> > choose Go.
> Yes.  It's a bug.  It's listed as a bug at the bottom of
> https://golang.org/pkg/sync/atomic.  The problem is that we haven't
> figured out the right way to fix it.  It may require a language
> change.  Or see https://golang.org/issue/19057 .
> 
> Ian
> 
> 
> > 
> > On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
> > > 
> > > It’s a bug in the library if it uses 64 bit atomic operations
> > > without
> > > ensuring 64 bit alignment. Putting the alignment-required field
> > > at
> > > the top of the struct is the traditional method.
> > > 
> > > //jb
> > --
> > You received this message because you are subscribed to the Google
> > Groups "golang-nuts" group.
> > To unsubscribe from this group and stop receiving emails from it,
> > send an email to golang-nuts+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Ian Lance Taylor
On Tue, Aug 14, 2018 at 3:49 PM, Dan Kortschak
 wrote:
>
> This ignores the possibility that more than one alignment-sensitive
> field might be needed. Requiring that they all be up front, potentially
> degrading readability flies in the face of the design principles of the
> language. This kind foot-gun in other languages is why many people
> choose Go.

Yes.  It's a bug.  It's listed as a bug at the bottom of
https://golang.org/pkg/sync/atomic.  The problem is that we haven't
figured out the right way to fix it.  It may require a language
change.  Or see https://golang.org/issue/19057 .

Ian


> On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
>> It’s a bug in the library if it uses 64 bit atomic operations without
>> ensuring 64 bit alignment. Putting the alignment-required field at
>> the top of the struct is the traditional method.
>>
>> //jb
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Dan Kortschak
This ignores the possibility that more than one alignment-sensitive
field might be needed. Requiring that they all be up front, potentially
degrading readability flies in the face of the design principles of the
language. This kind foot-gun in other languages is why many people
choose Go.

On Tue, 2018-08-14 at 06:49 +, Jakob Borg wrote:
> It’s a bug in the library if it uses 64 bit atomic operations without
> ensuring 64 bit alignment. Putting the alignment-required field at
> the top of the struct is the traditional method.
> 
> //jb

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Jakob Borg
It’s a bug in the library if it uses 64 bit atomic operations without ensuring 
64 bit alignment. Putting the alignment-required field at the top of the struct 
is the traditional method.

//jb

On 14 Aug 2018, at 08:45, Stephan Mühlstrasser 
mailto:stephan.muehlstras...@gmail.com>> wrote:

Am Montag, 13. August 2018 23:47:11 UTC+2 schrieb Dave Cheney:
I don’t think that will help. The problem is not cross compilation. The problem 
is when run in a 32bit environment the offset of that field is not guaranteed 
to be aligned to 8 bytes. You’ve got a 50/50 chance that each allocation will 
be properly aligned.

That sounds like a pretty severe compiler bug then. This makes it more or less 
impossible to use any third-party libraries with Go on ARM unless you check 
them and all their dependencies whether they use sync/atomic. Apparently the 
Google Cloud Go APIs fall into this category and should not be used on ARM 
32-bit.

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-14 Thread Stephan Mühlstrasser
Am Montag, 13. August 2018 23:47:11 UTC+2 schrieb Dave Cheney:
>
> I don’t think that will help. The problem is not cross compilation. The 
> problem is when run in a 32bit environment the offset of that field is not 
> guaranteed to be aligned to 8 bytes. You’ve got a 50/50 chance that each 
> allocation will be properly aligned.


That sounds like a pretty severe compiler bug then. This makes it more or 
less impossible to use any third-party libraries with Go on ARM unless you 
check them and all their dependencies whether they use sync/atomic. 
Apparently the Google Cloud Go APIs fall into this category and should not 
be used on ARM 32-bit.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-13 Thread Dave Cheney
I don’t think that will help. The problem is not cross compilation. The problem 
is when run in a 32bit environment the offset of that field is not guaranteed 
to be aligned to 8 bytes. You’ve got a 50/50 chance that each allocation will 
be properly aligned. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-13 Thread Philip Chapman
Another option may be to run 32 bit raspberian OS and compile in a virtual
machine and compile it there, perhaps.  VirtualBox comes to mind.

On Mon, Aug 13, 2018 at 1:52 PM, Stephan Mühlstrasser <
stephan.muehlstras...@gmail.com> wrote:

>
> Am Montag, 13. August 2018 22:36:56 UTC+2 schrieb Dave Cheney:
>>
>> No, it’s not a cross compilation issue. Well, yes and no, the rpi is a 32
>> bit platform so some structures have a different size causing the offset of
>> the field to be 32 but aligned, not the required 64 bit aligned.
>>
>> The play example shows the address of the field is not aligned on a 8
>> byte boundary.
>>
>
> Ah, I didn't recognize that the number in the play example is the
> problematic address from the stack trace.
>
> Short version, move the field to the top of the structure which is
>> guaranteed to be properly aligned.
>
>
> Ok, thank you. I now realized that I would have to change structures in
> third party software, so this is probably not a reasonable approach. I will
> have to live with the fact that I have to compile on the Raspberry Pi
> itself, and I hope that the compiler bug will not manifest itself there.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Philip A. Chapman
Java Software Development
Enterprise, Web, and Desktop

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-13 Thread Stephan Mühlstrasser

Am Montag, 13. August 2018 22:36:56 UTC+2 schrieb Dave Cheney:
>
> No, it’s not a cross compilation issue. Well, yes and no, the rpi is a 32 
> bit platform so some structures have a different size causing the offset of 
> the field to be 32 but aligned, not the required 64 bit aligned. 
>
> The play example shows the address of the field is not aligned on a 8 byte 
> boundary. 
>

Ah, I didn't recognize that the number in the play example is the 
problematic address from the stack trace.

Short version, move the field to the top of the structure which is 
> guaranteed to be properly aligned.


Ok, thank you. I now realized that I would have to change structures in 
third party software, so this is probably not a reasonable approach. I will 
have to live with the fact that I have to compile on the Raspberry Pi 
itself, and I hope that the compiler bug will not manifest itself there.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-13 Thread Dave Cheney
No, it’s not a cross compilation issue. Well, yes and no, the rpi is a 32 bit 
platform so some structures have a different size causing the offset of the 
field to be 32 but aligned, not the required 64 bit aligned. 

The play example shows the address of the field is not aligned on a 8 byte 
boundary. 

Short version, move the field to the top of the structure which is guaranteed 
to be properly aligned. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-13 Thread Stephan Mühlstrasser
Am Sonntag, 12. August 2018 23:30:22 UTC+2 schrieb Dave Cheney:
>
> This is likely to be issue https://github.com/golang/go/issues/599 
> 
> , https://play.golang.org/p/zZm-6zWwFoi
>
>  
Thanks for the diagnosis, this looks like the issue I'm seeing, although I 
don't understand how the example on play.golang.org 
 is related. The example does not 
crash if I run a cross-compiled binary on the Raspberry Pi and it prints 
the correct result "false".

So do I understand it correctly that this is a bug that is exclusive to the 
cross compiler? The native compiler on the Raspberry Pi apparently is able 
to compile the code correctly?

And is it possible to work around the bug, for example by adding padding or 
by re-arranging the problematic structure?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[go-nuts] Re: Cross-compiled program for Raspberry Pi crashes

2018-08-12 Thread Dave Cheney
This is likely to be 
issue https://github.com/golang/go/issues/599, 
https://play.golang.org/p/zZm-6zWwFoi

On Monday, 13 August 2018 01:29:43 UTC+10, Stephan Mühlstrasser wrote:
>
> Hi,
>
> I'm developing my first Go program that is supposed to upload files into a 
> Google Cloud Storage bucket from a Raspberry Pi 1. It uses the 
> https://github.com/blackjack/webcam library to grab a picture from an USB 
> camera.
>
> I can compile the program on the Raspberry Pi itself with Go 1.7.4 that 
> comes with Raspbian, and then it works as expected. However compilation on 
> the Raspberry Pi is slow and it even sometimes fails because of memory 
> shortage. Therefore I want to cross-compile on Windows.
>
> When I cross-compile the exact same source on Windows for ARM with Go 
> 1.10.3, then this binary crashes at some point on the Raspberry Pi with a 
> segmentation fault:
>
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x1 addr=0x4 pc=0x11520]
>
>
> goroutine 8 [running]:
> sync/atomic.addUint64(0x1236210c, 0x8a75f371, 0xa3f9cbd6, 0xdcd30e9, 
> 0xda39e1c1)
> C:/Go/src/sync/atomic/64bit_arm.go:31 +0x4c
> go.opencensus.io/trace.(*defaultIDGenerator).NewSpanID(0x123620f0, 0x0, 
> 0x0)
> E:/Users/stm/go/src/go.opencensus.io/trace/trace.go:483 +0x50
> go.opencensus.io/trace.startSpanInternal(0x123202d0, 0x22, 0x0, 0x0, 0x0, 
> 0x0, 0x0, 0x0, 0x0, 0x0, ...)
> E:/Users/stm/go/src/go.opencensus.io/trace/trace.go:196 +0x7c
> go.opencensus.io/trace.StartSpan(0x4c4128, 0x12795c60, 0x123202d0, 0x22, 
> 0x123798ec, 0x2, 0x2, 0x10, 0x40, 0x58f74)
> E:/Users/stm/go/src/go.opencensus.io/trace/trace.go:162 +0x128
> ...
>
> I'm a Go newbie, and therefore I'm not sure how to interpret this. May 
> this be a bug in the Go cross-compiler, or may this be a bug in the program 
> that only manifests itself when the program is cross-compiled with the 
> newer compiler on Windows?  How can I analyze this?
>
> Thanks
> Stephan
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.