From debbugs-submit-bounces@debbugs.gnu.org Sat Mar 04 04:32:10 2023 Received: (at submit) by debbugs.gnu.org; 4 Mar 2023 09:32:10 +0000 Received: from localhost ([127.0.0.1]:35256 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pYOFM-0003T8-O6 for submit@debbugs.gnu.org; Sat, 04 Mar 2023 04:32:10 -0500 Received: from lists.gnu.org ([209.51.188.17]:37652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pYMrk-0001Cs-MB for submit@debbugs.gnu.org; Sat, 04 Mar 2023 03:03:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pYMri-0004uW-PJ for bug-guile@gnu.org; Sat, 04 Mar 2023 03:03:40 -0500 Received: from gatalith.at ([45.132.245.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pYMrd-0006op-Pb for bug-guile@gnu.org; Sat, 04 Mar 2023 03:03:37 -0500 Received: from yt.nih.at (84-115-227-192.cable.dynamic.surfer.at [84.115.227.192]) by gatalith.at (Postfix) with ESMTPSA id 1AFCB390A44 for ; Sat, 4 Mar 2023 09:03:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gatalith.at; s=dkim; t=1677917005; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Z+mgFQRoF2eXfTT2SdorXQS8ZqS+Cld5Vz58f5CkBH0=; b=Zh+0Zkx7Mn7wjvqd1IKlwYQSnSAYe5swZQ+MdXc2CRRi4tPcB5w2CA56NJLehmKCsRbEpw Wzchw5JQlIQOa5r+SvkngxQsUDb1XA1DJ638YbaUuu2cCINbhRd+agS5f9wl0Ue8GW6Tui bKwriQeMVLXRwFYvp2TLy/Yiyt6XZOg= Date: Sat, 4 Mar 2023 09:02:53 +0100 From: Thomas Klausner To: bug-guile@gnu.org Subject: NetBSD: JIT doesn't work Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Received-SPF: pass client-ip=45.132.245.72; envelope-from=wiz@gatalith.at; helo=gatalith.at X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sat, 04 Mar 2023 04:32:07 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Hi! guile 3.0.9 on NetBSD 10.99.2/amd64 defaults to enabling the JIT, butthen fails to build with: CCLD libguile-3.0.la ld: .libs/libguile_3.0_la-posix.o: in function `scm_tmpnam': /scratch/lang/guile30/work/guile-3.0.9/libguile/posix.c:1757: warning: warning: tmpnam() possibly used unsafely, use mkstemp() or mkdtemp() CCLD guile ld: ./.libs/libguile-3.0.so: warning: warning: tmpnam() possibly used unsafely, use mkstemp() or mkdtemp() GEN guile-procedures.texi allocating JIT code buffer failed: Permission denied jit.c:5896: fatal: assertion failed cat: stdout: Broken pipe [1] Done(1) cat alist.doc array-handle.doc array-map.doc a... | Abort trap (core dumped) GUILE_AUTO_COMPILE=0 ../meta/build-env guild s... gmake[3]: *** [Makefile:4657: guile-procedures.texi] Error 1 The underlying problem is that NetBSD by default has PaX MPROTECT enabled, i.e. a page can not be mapped executable and writable at the same time, which libguile/jit.c tries to do: ret->base = mmap (NULL, ret->size, PROT_EXEC | PROT_READ | PROT_WRITE, flags, -1, 0); On NetBSD (and some other systems) the workaround is to map the page twice - once writable, and once executable. The NetBSD mremap(2) man page describes this and has a complete code example: https://man.netbsd.org/mremap.2 Please add support for this to guile's JIT. Thank you! Thomas (Please note that there currently is a bug in NetBSD when using fork() in such a situation, see https://gnats.netbsd.org/55177 for details. A workaround is to map the page MAP_SHARED even though conceptually MAP_PRIVATE would be correct.)