diff mbox series

libgo: Don't assume sys.GoarchAmd64 == 64-bit pointer

Message ID 20180929234408.8367-1-hjl.tools@gmail.com
State New
Headers show
Series libgo: Don't assume sys.GoarchAmd64 == 64-bit pointer | expand

Commit Message

H.J. Lu Sept. 29, 2018, 11:44 p.m. UTC
On x86-64, sys.GoarchAmd64 == 1 for -mx32.  But -mx32 has 32-bit
pointer, not 64-bit.  There is

// _64bit = 1 on 64-bit systems, 0 on 32-bit systems
_64bit = 1 << (^uintptr(0) >> 63) / 2

We should check both _64bit and sys.GoarchAmd64.

	PR go/87470
	* go/runtime/malloc.go (arenaBaseOffset): Also check _64bit.
---
 libgo/go/runtime/malloc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ian Lance Taylor Sept. 30, 2018, 4:01 a.m. UTC | #1
"H.J. Lu" <hjl.tools@gmail.com> writes:

> On x86-64, sys.GoarchAmd64 == 1 for -mx32.  But -mx32 has 32-bit
> pointer, not 64-bit.  There is
>
> // _64bit = 1 on 64-bit systems, 0 on 32-bit systems
> _64bit = 1 << (^uintptr(0) >> 63) / 2
>
> We should check both _64bit and sys.GoarchAmd64.

Thanks, but I think the correct fix is to set GOARCH to amd64p32 when
using x32.  I'm trying that to see if it will work out.

Ian
H.J. Lu Sept. 30, 2018, 12:02 p.m. UTC | #2
On Sat, Sep 29, 2018 at 9:01 PM Ian Lance Taylor <ian@airs.com> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> > On x86-64, sys.GoarchAmd64 == 1 for -mx32.  But -mx32 has 32-bit
> > pointer, not 64-bit.  There is
> >
> > // _64bit = 1 on 64-bit systems, 0 on 32-bit systems
> > _64bit = 1 << (^uintptr(0) >> 63) / 2
> >
> > We should check both _64bit and sys.GoarchAmd64.
>
> Thanks, but I think the correct fix is to set GOARCH to amd64p32 when
> using x32.  I'm trying that to see if it will work out.
>

My understanding is amd64p32 == NaCl.  But x32 != NaCl.
Ian Lance Taylor Oct. 1, 2018, 2:05 p.m. UTC | #3
"H.J. Lu" <hjl.tools@gmail.com> writes:

> On Sat, Sep 29, 2018 at 9:01 PM Ian Lance Taylor <ian@airs.com> wrote:
>>
>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>
>> > On x86-64, sys.GoarchAmd64 == 1 for -mx32.  But -mx32 has 32-bit
>> > pointer, not 64-bit.  There is
>> >
>> > // _64bit = 1 on 64-bit systems, 0 on 32-bit systems
>> > _64bit = 1 << (^uintptr(0) >> 63) / 2
>> >
>> > We should check both _64bit and sys.GoarchAmd64.
>>
>> Thanks, but I think the correct fix is to set GOARCH to amd64p32 when
>> using x32.  I'm trying that to see if it will work out.
>>
>
> My understanding is amd64p32 == NaCl.  But x32 != NaCl.

For Go, GOARCH=amd64p32 GOOS=nacl is NaCl.  But logically amd64p32 means
amd64 with 32-bit pointers, so it may be possible to repurpose
GOARCH=amd64p32 GOOS=linux for x32.

Ian
diff mbox series

Patch

diff --git a/libgo/go/runtime/malloc.go b/libgo/go/runtime/malloc.go
index ac4759ffbf1..c3445387057 100644
--- a/libgo/go/runtime/malloc.go
+++ b/libgo/go/runtime/malloc.go
@@ -306,7 +306,7 @@  const (
 	//
 	// On other platforms, the user address space is contiguous
 	// and starts at 0, so no offset is necessary.
-	arenaBaseOffset uintptr = sys.GoarchAmd64 * (1 << 47)
+	arenaBaseOffset uintptr = _64bit * sys.GoarchAmd64 * (1 << 47)
 
 	// Max number of threads to run garbage collection.
 	// 2, 3, and 4 are all plausible maximums depending