Message ID | 20220929144912.21826-1-soeren@soeren-tempel.net |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2655A385781D for <patchwork@sourceware.org>; Thu, 29 Sep 2022 14:49:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2655A385781D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664462994; bh=A0RJm5cPXZ9icaQEOX8GKk9T4F1EsGYxaIFf1n96vv8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=oxlazq/MhZHTOdDZRvrnq0MgW2eEcTL9r84Y+KvycesBwFzgY6FTOsdXhLydTDx9o 9dVfRqcFxB5mwTfSOlrch8z5Z/EhBgPNSGzOxw80LYr/0p89q2vQI2pbs5so1uJaGc CJP4e0s4zTvuoqGldD0jTgpKnUuAPccnnB1VlkMg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from magnesium.8pit.net (magnesium.8pit.net [45.76.88.171]) by sourceware.org (Postfix) with ESMTPS id 99EAD3858D39; Thu, 29 Sep 2022 14:49:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99EAD3858D39 Received: from localhost (<unknown> [2a02:8109:3b40:22d0:58e3:25c5:db0:24db]) by magnesium.8pit.net (OpenSMTPD) with ESMTPSA id 7cba108a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:YES); Thu, 29 Sep 2022 16:49:21 +0200 (CEST) To: iant@golang.org Subject: [PATCH] libgo: use _off_t for mmap offset argument Date: Thu, 29 Sep 2022 16:49:12 +0200 Message-Id: <20220929144912.21826-1-soeren@soeren-tempel.net> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: soeren--- via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: soeren@soeren-tempel.net Cc: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
libgo: use _off_t for mmap offset argument
|
|
Commit Message
Li, Pan2 via Gcc-patches
Sept. 29, 2022, 2:49 p.m. UTC
From: Sören Tempel <soeren@soeren-tempel.net> On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a 64-bit type on 64-bit systems by default. However, on systems using musl libc off_t is unconditionally a 64-bit type. As such, it is insufficient to use a uintptr type for the mmap offset parameter. Presently, the (incorrect) mmap declaration causes a libgo run-time failure on 32-bit musl systems (fatal error: runtime: cannot allocate memory). This commit fixes this run-time error. Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> --- This implements what has been proposed by Ian in a GitHub comment https://github.com/golang/go/issues/51280#issuecomment-1046322011 I don't have access to a 32-bit glibc system to test this on but this does seem to work fine on 32-bit and 64-bit musl systems. libgo/go/runtime/mem_gccgo.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Comments
PING. soeren@soeren-tempel.net wrote: > From: Sören Tempel <soeren@soeren-tempel.net> > > On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a > 64-bit type on 64-bit systems by default. However, on systems using musl > libc off_t is unconditionally a 64-bit type. As such, it is insufficient > to use a uintptr type for the mmap offset parameter. > > Presently, the (incorrect) mmap declaration causes a libgo run-time > failure on 32-bit musl systems (fatal error: runtime: cannot allocate > memory). This commit fixes this run-time error. > > Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> > --- > This implements what has been proposed by Ian in a GitHub comment > https://github.com/golang/go/issues/51280#issuecomment-1046322011 > > I don't have access to a 32-bit glibc system to test this on but > this does seem to work fine on 32-bit and 64-bit musl systems. > > libgo/go/runtime/mem_gccgo.go | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go > index fa3389d8..07bf325a 100644 > --- a/libgo/go/runtime/mem_gccgo.go > +++ b/libgo/go/runtime/mem_gccgo.go > @@ -15,7 +15,7 @@ import ( > //go:linkname sysFree > > //extern mmap > -func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) unsafe.Pointer > +func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off _off_t) unsafe.Pointer > > //extern munmap > func munmap(addr unsafe.Pointer, length uintptr) int32 > @@ -38,7 +38,7 @@ func init() { > } > > func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (unsafe.Pointer, int) { > - p := sysMmap(addr, n, prot, flags, fd, off) > + p := sysMmap(addr, n, prot, flags, fd, _off_t(off)) > if uintptr(p) == _MAP_FAILED { > return nil, errno() > }
On Sat, Oct 22, 2022 at 6:45 AM Sören Tempel <soeren@soeren-tempel.net> wrote: > > PING. > > soeren@soeren-tempel.net wrote: > > From: Sören Tempel <soeren@soeren-tempel.net> > > > > On glibc-based systems, off_t is a 32-bit type on 32-bit systems and a > > 64-bit type on 64-bit systems by default. However, on systems using musl > > libc off_t is unconditionally a 64-bit type. As such, it is insufficient > > to use a uintptr type for the mmap offset parameter. > > > > Presently, the (incorrect) mmap declaration causes a libgo run-time > > failure on 32-bit musl systems (fatal error: runtime: cannot allocate > > memory). This commit fixes this run-time error. > > > > Signed-off-by: Sören Tempel <soeren@soeren-tempel.net> > > --- > > This implements what has been proposed by Ian in a GitHub comment > > https://github.com/golang/go/issues/51280#issuecomment-1046322011 > > > > I don't have access to a 32-bit glibc system to test this on but > > this does seem to work fine on 32-bit and 64-bit musl systems. Thanks. Committed as follows using _libgo_off_t_type to avoid the confusion between off_t and off64_t. Sorry for the delay. Ian 11a5fc0c76aedb100b5d7ecc7dd4bed33d850bb8 diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 5b95b38a541..7e531c3f90b 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -6c188108858e3ae8c8ea8e4cc55427d8cf01bbc8 +5e658f4659c551330ea68f5667e4f951b218f32d The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go index fa3389d857e..1e84f4f5c56 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( //go:linkname sysFree //extern mmap -func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) unsafe.Pointer +func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off _libgo_off_t_type) unsafe.Pointer //extern munmap func munmap(addr unsafe.Pointer, length uintptr) int32 @@ -38,7 +38,7 @@ func init() { } func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (unsafe.Pointer, int) { - p := sysMmap(addr, n, prot, flags, fd, off) + p := sysMmap(addr, n, prot, flags, fd, _libgo_off_t_type(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() } @@ -47,6 +47,7 @@ func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (u // Don't split the stack as this method may be invoked without a valid G, which // prevents us from allocating more stack. +// //go:nosplit func sysAlloc(n uintptr, sysStat *sysMemStat) unsafe.Pointer { p, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, mmapFD, 0) @@ -165,6 +166,7 @@ func sysHugePage(v unsafe.Pointer, n uintptr) { // Don't split the stack as this function may be invoked without a valid G, // which prevents us from allocating more stack. +// //go:nosplit func sysFree(v unsafe.Pointer, n uintptr, sysStat *sysMemStat) { sysStat.add(-int64(n))
diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go index fa3389d8..07bf325a 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -15,7 +15,7 @@ import ( //go:linkname sysFree //extern mmap -func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) unsafe.Pointer +func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off _off_t) unsafe.Pointer //extern munmap func munmap(addr unsafe.Pointer, length uintptr) int32 @@ -38,7 +38,7 @@ func init() { } func mmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) (unsafe.Pointer, int) { - p := sysMmap(addr, n, prot, flags, fd, off) + p := sysMmap(addr, n, prot, flags, fd, _off_t(off)) if uintptr(p) == _MAP_FAILED { return nil, errno() }