From patchwork Tue Jun 20 16:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 110618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3805453vqr; Tue, 20 Jun 2023 09:58:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ59TPkuqqBm9BL9X56c/nMEeFILOKns/L08xMHDjDdMkhHjmPXAufH0WT38tmYnWERduJIy X-Received: by 2002:a17:907:a429:b0:989:15f0:3180 with SMTP id sg41-20020a170907a42900b0098915f03180mr2672183ejc.76.1687280318930; Tue, 20 Jun 2023 09:58:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687280318; cv=none; d=google.com; s=arc-20160816; b=ldQeNzRP24IVc37cov/OP0FpnmBHL081bcV0mPZ/SRqUl/Y+WbE9BuP7ENlY/LcuUf BKUyLC9fI9ZhSwJeYiF8RyAZxrHTZujMHcKW887AnG1maS4Ti+QskuoCW61ZXNgUfsSA v6qY+1ud3OV75Cj3oVkWvZ8Reu19rgtQtD9RIcO+sDQTIokDJta5DXRDn+f7cn3fbFUL hNoPNDzs1xHSPc+a1q3nznV/rSmyTpaq0Yfzj7A8IXXDz4ylVBDg3XWLXg7bKib/IlZv /qrXaZAIfSsdlrSMBHekSoUbsA9EO0OFJESgRQVbv+bSB43sjyoxKze8Zqi0bTFaDnf+ Q5bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:cc:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=GHKDlIE34poHyGI5z+F++uLKg3BJ4CVdh94GpCiqK+M=; b=XFFT8X5DFUa5W1bXJvosUWdYmU3GgYRVL/FVK/KpL6z/nAOhw/j1HjoPBgdlop3ucV Q8uEak1ehu9uHej1UvlGHp45dg0qg3/0qLFxmvAJiDn7K58G3isd4l7ruOFtorY3rcq/ kToWYdQF8DXnV2Z13Hzj4FkDNIyfyMAQqOL2oqSPWLrhMEdIne867wLVDQzkSuO+S/h0 xzs6JsDDcGVuwRSLJR12DvO4OrwzwP63oS1Q3r/tgEmPB2VOOIOai2xauU7SFmeNGrCw vfOxfgWk57LE20axoCj9cMPUPA+HnGxpJZXFPS+ppxvjF1Ou9X8vCKJyIHqC0JNLBTpB IvIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XF4oHyaO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c1-20020a17090654c100b00988812e1529si1439126ejp.396.2023.06.20.09.58.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 09:58:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XF4oHyaO; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 759AD3858414 for ; Tue, 20 Jun 2023 16:58:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 759AD3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687280317; bh=GHKDlIE34poHyGI5z+F++uLKg3BJ4CVdh94GpCiqK+M=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=XF4oHyaORtZY7TtNSZJ5Z8UBR1xS3qABGiHWkeQTkXWSvu1J55XYm30i40EOm9gxV bokA4TAZ1dwJePb1C8cFeEZVQ3c3xgKiSW/zzDQGcgvrKzi0WkbbhJkyONaTSCW7Kv JuqWindU56IDalZLYtU8gp82yjbDsWP7/o69gmpw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id BCB433858431 for ; Tue, 20 Jun 2023 16:57:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCB433858431 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-668723729c5so1868468b3a.3 for ; Tue, 20 Jun 2023 09:57:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687280272; x=1689872272; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=GHKDlIE34poHyGI5z+F++uLKg3BJ4CVdh94GpCiqK+M=; b=OGfNjOMLfL82rUYhoD+yGb1Xa497bs87YDgX7/Gj+OYnLeUX6Ti0EJMKTMrOScFDNz dpHs5RnDRcoaPZFh5Sc226WzYQe5UGqkPwDZnmgrNfKqHlQJT/fByWZxjnHofTqpmi6c dLSX4BQjGkRDQfghDSKIvY0m3AmKDg0QRN3MYIQwRHFyboGTk1c1bxGNilE01S6UnhzT AaZdDj0Coy0FgI4CpHF3aYNnswXvGG7aMIQoREmjWSfEILB6z1YkP9xALPd7nahVZtNa 0OyAUZLVScf7JrOuaC7ixF5iKYq2cyc+Ub1eVr7c+EaDeJblcTsgJRHaMl54rXst4JeH NlKA== X-Gm-Message-State: AC+VfDzRwVw296Dyief3ao8RD+zgIq1/PuD4p6Lqtd5Z5KDb8IZW1dTe sq5RRdba0FiHjwYJjlfEF8qlLHwlMuas5QqlMrLKFXVcM85R0RISODE= X-Received: by 2002:a05:6a20:a199:b0:11f:245d:159b with SMTP id r25-20020a056a20a19900b0011f245d159bmr8640807pzk.17.1687280272256; Tue, 20 Jun 2023 09:57:52 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 20 Jun 2023 09:57:41 -0700 Message-ID: Subject: libgo patch committed: Use a C function to call mmap To: gcc-patches , gofrontend-dev Cc: =?utf-8?q?S=C3=B6ren_Tempel?= X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769241647721672063?= X-GMAIL-MSGID: =?utf-8?q?1769241647721672063?= This libgo patches changes the runtime pacakge to use a C function to call mmap. The final argument to mmap, of type off_t, varies. In https://go.dev/cl/445375 (https://gcc.gnu.org/pipermail/gcc-patches/2022-October/604158.html) we changed it to always use the C off_t type, but that broke 32-bit big-endian Linux systems. On those systems, using the C off_t type requires calling the mmap64 function. In C this is automatically handled by the file. In Go, we would have to change the magic //extern comment to call mmap64 when appropriate. Rather than try to get that right, we instead go through a C function that uses C implicit type conversions to pick the right type. This fixes https://gcc.gnu.org/PR110297. Bootstrapped and tested on x86_64-pc-linux-gnu and powerpc-pc-linux-gnu (32-bit and 64-bit). Committed to trunk and GCC 13 branch. Ian 55557f5a6c8a27190daf9daadf5e9f14ef5f4ece diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 1191a8d663d..dbb2d68f909 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -a3a3c3a2d1bc6a8ca51b302d08c94ef27cdd8f0f +6a1d165c2218cd127ee937a1f45599075762f716 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/Makefile.am b/libgo/Makefile.am index 207d5a98127..920f8cc7071 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -462,6 +462,7 @@ runtime_files = \ runtime/go-memclr.c \ runtime/go-memmove.c \ runtime/go-memequal.c \ + runtime/go-mmap.c \ runtime/go-nanotime.c \ runtime/go-now.c \ runtime/go-nosys.c \ diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go index 1e84f4f5c56..e7b51ff37cc 100644 --- a/libgo/go/runtime/mem_gccgo.go +++ b/libgo/go/runtime/mem_gccgo.go @@ -14,8 +14,8 @@ import ( //go:linkname sysAlloc //go:linkname sysFree -//extern mmap -func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off _libgo_off_t_type) unsafe.Pointer +//extern __go_mmap +func sysMmap(addr unsafe.Pointer, n uintptr, prot, flags, fd int32, off uintptr) 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, _libgo_off_t_type(off)) + p := sysMmap(addr, n, prot, flags, fd, off) if uintptr(p) == _MAP_FAILED { return nil, errno() } diff --git a/libgo/runtime/go-mmap.c b/libgo/runtime/go-mmap.c new file mode 100644 index 00000000000..b2327ba68f5 --- /dev/null +++ b/libgo/runtime/go-mmap.c @@ -0,0 +1,21 @@ +/* go-mmap.c -- functions for calling C mmap functions. + + Copyright 2023 The Go Authors. All rights reserved. + Use of this source code is governed by a BSD-style + license that can be found in the LICENSE file. */ + +#include "config.h" + +#include +#include + +/* The exact C function to call varies between mmap and mmap64, and + the size of the off_t argument also varies. Here we provide a + function that Go code can call with consistent types. */ + +void * +__go_mmap(void *addr, uintptr_t length, int32_t prot, int32_t flags, + int32_t fd, uintptr_t offset) +{ + return mmap(addr, length, prot, flags, fd, offset); +} diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h index b3dc4fd2414..699770d53ad 100644 --- a/libgo/runtime/runtime.h +++ b/libgo/runtime/runtime.h @@ -355,9 +355,6 @@ bool runtime_notetsleepg(Note*, int64) // false - timeout /* * low level C-called */ -#define runtime_mmap mmap -#define runtime_munmap munmap -#define runtime_madvise madvise #define runtime_memclr(buf, size) __builtin_memset((buf), 0, (size)) #define runtime_getcallerpc() __builtin_return_address(0)