GNU bug report logs - #41994
Emacs on Apple ARM devices

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>; dated Mon, 22 Jun 2020 00:03:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 22 Jun 2020 00:02:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jun 21 20:02:12 2020
Received: from localhost ([127.0.0.1]:32861 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jn9ub-0007U6-D1
	for submit <at> debbugs.gnu.org; Sun, 21 Jun 2020 20:02:12 -0400
Received: from lists.gnu.org ([209.51.188.17]:34038)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <rlndkfmn+emacs@HIDDEN>) id 1jn8DM-0004qf-OP
 for submit <at> debbugs.gnu.org; Sun, 21 Jun 2020 18:13:28 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:48560)
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <rlndkfmn+emacs@HIDDEN>)
 id 1jn8DM-0005KV-I2
 for bug-gnu-emacs@HIDDEN; Sun, 21 Jun 2020 18:13:24 -0400
Received: from mail-lj1-x234.google.com ([2a00:1450:4864:20::234]:33384)
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <rlndkfmn+emacs@HIDDEN>)
 id 1jn8DH-0006aF-NT
 for bug-gnu-emacs@HIDDEN; Sun, 21 Jun 2020 18:13:24 -0400
Received: by mail-lj1-x234.google.com with SMTP id s1so17168033ljo.0
 for <bug-gnu-emacs@HIDDEN>; Sun, 21 Jun 2020 15:13:18 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=sender:from:subject:to:message-id:date:user-agent:mime-version
 :content-language;
 bh=lRFyMqITH93BDcBO8NCEwPrvNhxeUzPLvsRisFOt2jQ=;
 b=JOJbk9+0XC7OeSgOJl/OH+9NnKNr5cLFLtLjkYh6o2gtmDS29sdp1VOrzYWZkOXZuh
 FY0jp8OXYYfhslsS74S3SaNy/pkXRzQNNl/MRPvr+zHB9V1npxLF3LYwFCHYAaiiKAkb
 GB6iRdb16Qc64Jnvu9CTPZ8Qn0ImP0j6Uxx7Mblzsxy7EdzlMue8OSWT8vxR3falH0xQ
 WT8ysRxo9CUnrMyD1KfIwwSBkorl4wMdfiZ+ByOp51T8/J/DpY7KMrC2tlgcoz/TKrpT
 9dq9g6OyDQoQ0RjUwEafXfSCR89pExYUp4LvHFHLz+rBD0ZPd7JNN1WcP2yIM7Cn6+ZS
 WDIQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:sender:from:subject:to:message-id:date
 :user-agent:mime-version:content-language;
 bh=lRFyMqITH93BDcBO8NCEwPrvNhxeUzPLvsRisFOt2jQ=;
 b=Ia2PpRIlOBZkzpGoUwsowtI+V7w41nmfe8Tw/WSXvxCWjLlFDwg7XvUZqrYmdKoEU0
 jSLh6igSDMmIPHNGdk7PqtW/f6VFqYCS3Hu9IQPnqLWxXN4T6zm8BotRxR4PJ6dfwENL
 STsTrwVTQPtzU5FJHgemqwbPrf5M5NTWpdF2KoCsvLwNd1iTkhKZs7eNJJSgRyybDlWv
 jc8WcuI0/BtCSWE5c1WmZ4uA0HF3rBFYHq1Du4O/XsGhbt+LZoZ1H0mamxo+9yzi4jxi
 Lun4dQumFkVfjVb7CgRst6EZZ0ybSs0iJ+kEdsXxShZbx4BkRMmFinSwx9+EHmXC1IQk
 qscg==
X-Gm-Message-State: AOAM5335dpy2pTWFXxfnxTRYIHqJtB2s3pNooENCheAqiHjP84uRaEZ3
 x0OnO0+ZA0WXqhFBVIgX2lR00yTBUYw=
X-Google-Smtp-Source: ABdhPJwuDZIlSNFuKTXgQt4GkdPVg7EsOEwb1Z7nzBmXkaos5plFLHI4mF56z79+EJFCSTkZWVHrtw==
X-Received: by 2002:a2e:86cc:: with SMTP id n12mr6573281ljj.400.1592777596972; 
 Sun, 21 Jun 2020 15:13:16 -0700 (PDT)
Received: from [192.168.1.11] (ti0149q161-3298.bb.online.no. [84.202.230.10])
 by smtp.gmail.com with ESMTPSA id
 s62sm2027997lja.100.2020.06.21.15.13.15 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Sun, 21 Jun 2020 15:13:15 -0700 (PDT)
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Subject: Emacs on Apple ARM devices
To: bug-gnu-emacs@HIDDEN
Message-ID: <ad8d2628-98fb-4bdb-3fec-c64bfaec94f3@HIDDEN>
Date: Mon, 22 Jun 2020 00:13:15 +0200
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
 Thunderbird/68.8.0
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------58C4D5B7A8BB366E981EAB46"
Content-Language: en-US
Received-SPF: pass client-ip=2a00:1450:4864:20::234;
 envelope-from=rlndkfmn+emacs@HIDDEN; helo=mail-lj1-x234.google.com
X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache.
 That's all we know.
X-Spam_score_int: -15
X-Spam_score: -1.6
X-Spam_bar: -
X-Spam_report: (-1.6 / 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, FREEMAIL_FROM=0.001,
 FROM_LOCAL_NOVOWEL=0.5, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN
X-Spam_action: no action
X-Spam-Score: 1.2 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview: Code generation on Apple's ARM devices is mostly similar to
 MacOS, except that they expect a code signature section, which to avoid wasting
 too many bytes, are not aligned on page size as with code, b [...] 
 Content analysis details:   (1.2 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.5 FROM_LOCAL_NOVOWEL     From: localpart has series of non-vowel
 letters
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (rlndkfmn+emacs[at]gmail.com)
 1.0 SPF_SOFTFAIL           SPF: sender does not match SPF record (softfail)
 -0.0 RCVD_IN_MSPIKE_H4      RBL: Very Good reputation (+4)
 [209.51.188.17 listed in wl.mailspike.net]
 -2.3 RCVD_IN_DNSWL_MED      RBL: Sender listed at https://www.dnswl.org/,
 medium trust [209.51.188.17 listed in list.dnswl.org]
 -0.0 RCVD_IN_MSPIKE_WL      Mailspike good senders
 2.0 SPOOFED_FREEMAIL       No description available.
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sun, 21 Jun 2020 20:02:08 -0400
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.8 (-)

This is a multi-part message in MIME format.
--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

Code generation on Apple's ARM devices is mostly similar to MacOS, 
except that they expect a code signature section, which to avoid 
wasting too many bytes, are not aligned on page size as with code, 
but rather to nearest 16 bytes. In addition, the ARM compiler will 
also emit some relative pointer relocation records, which it seems 
can be safely ignored as sections aren't rearranged.

This changeset implements those changes on the Mach-O dumper so 
that Emacs can be compiled for ARM devices. With the ongoing 
convergence between the MacOS and iOS platform, and the increasing 
importance of code-signing in later MacOS versions, I think it 
could be nice to mainline these changes.

Since these sections do not occur in current MacOS builds - 
otherwise they would generate errors for being unknown - the 
changes should not impact existing places where Emacs build, and 
it would not work on iOS without to begin with.

Hat tip to Aaron Griffith for sharing his knowledge.


-- 
Sincerely,

Roland Kaufmann







--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0001-Let-us-know-unknown-number-being-complained-about.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-Let-us-know-unknown-number-being-complained-about.patch"

>From 82a5aed44299db11cee3f97731a906e280cfb114 Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Sat, 13 Jun 2020 01:36:52 +0200
Subject: [PATCH 1/6] Let us know unknown number being complained about

This will let us discover new sections emitted by the compiler so we can
add support for them.
---
 src/unexmacosx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 59cbe3c..844fc87 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -628,7 +628,7 @@ print_load_command_name (int lc)
       break;
 #endif
     default:
-      printf ("unknown          ");
+      printf ("unknown (0x%x)   ", lc);
     }
 }
 
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0002-Make-function-generally-available-for-sections.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0002-Make-function-generally-available-for-sections.patch"

>From e27fe51106a00f6c10e3ac2ab51cb4d12e028491 Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Sat, 13 Jun 2020 02:07:57 +0200
Subject: [PATCH 2/6] Make function generally available for sections

---
 src/unexmacosx.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 844fc87..d274ab7 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -1121,7 +1121,6 @@ copy_dyld_info (struct load_command *lc, long delta)
 }
 #endif
 
-#ifdef LC_FUNCTION_STARTS
 /* Copy a LC_FUNCTION_STARTS/LC_DATA_IN_CODE/LC_DYLIB_CODE_SIGN_DRS
    load command from the input file to the output file, adjusting the
    data offset field.  */
@@ -1142,7 +1141,6 @@ copy_linkedit_data (struct load_command *lc, long delta)
 
   curr_header_offset += lc->cmdsize;
 }
-#endif
 
 /* Copy other kinds of load commands from the input file to the output
    file, ones that do not require adjustments of file offsets.  */
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0003-Allow-padding-of-sections-to-other-than-page-size.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0003-Allow-padding-of-sections-to-other-than-page-size.patch"

>From 5b9c1a0ebab3825dce85bc81139c36787923eec0 Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Thu, 27 Dec 2018 15:57:42 +0100
Subject: [PATCH 3/6] Allow padding of sections to other than page size

---
 src/unexmacosx.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index d274ab7..561a509 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -191,7 +191,8 @@ static unsigned long curr_header_offset = sizeof (struct mach_header);
 static unsigned long curr_file_offset = 0;
 
 static unsigned long pagesize;
-#define ROUNDUP_TO_PAGE_BOUNDARY(x)	(((x) + pagesize - 1) & ~(pagesize - 1))
+#define ROUNDUP_TO_BOUNDARY(x,size)	(((x) + size - 1) & ~(size - 1))
+#define ROUNDUP_TO_PAGE_BOUNDARY(x)	ROUNDUP_TO_BOUNDARY(x,pagesize)
 
 static int infd, outfd;
 
@@ -1125,13 +1126,16 @@ copy_dyld_info (struct load_command *lc, long delta)
    load command from the input file to the output file, adjusting the
    data offset field.  */
 static void
-copy_linkedit_data (struct load_command *lc, long delta)
+copy_linkedit_data (struct load_command *lc, long delta, long alignment)
 {
   struct linkedit_data_command *ldp = (struct linkedit_data_command *) lc;
 
   if (ldp->dataoff > 0)
     ldp->dataoff += delta;
 
+  /* add bytes necessary to be at given alignment */
+  ldp->dataoff = ROUNDUP_TO_BOUNDARY (ldp->dataoff, alignment);
+
   printf ("Writing ");
   print_load_command_name (lc->cmd);
   printf (" command\n");
@@ -1222,7 +1226,7 @@ dump_it (void)
 #ifdef LC_DYLIB_CODE_SIGN_DRS
       case LC_DYLIB_CODE_SIGN_DRS:
 #endif
-	copy_linkedit_data (lca[i], linkedit_delta);
+	copy_linkedit_data (lca[i], linkedit_delta, 1);
 	break;
 #endif
       default:
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0004-Output-code-signature-sections-align-on-16-bytes.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0004-Output-code-signature-sections-align-on-16-bytes.patch"

>From a4718afd4f5a9174e7f4f10b212bfebca6661cbe Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Thu, 27 Dec 2018 16:13:56 +0100
Subject: [PATCH 4/6] Output code signature sections; align on 16 bytes

---
 src/unexmacosx.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 561a509..653ecc0 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -628,6 +628,9 @@ print_load_command_name (int lc)
       printf ("LC_DYLIB_CODE_SIGN_DRS");
       break;
 #endif
+    case LC_CODE_SIGNATURE:
+      printf ("LC_CODE_SIGNATURE");
+      break;
     default:
       printf ("unknown (0x%x)   ", lc);
     }
@@ -1229,6 +1232,13 @@ dump_it (void)
 	copy_linkedit_data (lca[i], linkedit_delta, 1);
 	break;
 #endif
+      case LC_CODE_SIGNATURE:
+	/* as is quasi-documented in Technical Note TN2206, the code */
+	/* signature section is not aligned on page boundary, but    */
+	/* rather on a 16 bytes boundary (it is not large enough to  */
+	/* waste most of a page).                                    */
+	copy_linkedit_data (lca[i], linkedit_delta, 16);
+	break;
       default:
 	copy_other (lca[i]);
 	break;
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0005-Make-relocation-of-relative-pointers-a-no-op.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0005-Make-relocation-of-relative-pointers-a-no-op.patch"

>From a02638d9459d53f909593d4c6c9e17d4f1548c64 Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Thu, 27 Dec 2018 16:14:38 +0100
Subject: [PATCH 5/6] Make relocation of relative pointers a no-op

---
 src/unexmacosx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/unexmacosx.c b/src/unexmacosx.c
index 653ecc0..286749c 100644
--- a/src/unexmacosx.c
+++ b/src/unexmacosx.c
@@ -1024,6 +1024,11 @@ unrelocate (const char *name, off_t reloff, int nrel, vm_address_t base)
 		unreloc_count++;
 	      }
 	    break;
+	  case GENERIC_RELOC_LOCAL_SECTDIFF:
+	    /* nothing to do for relative pointer, as section order */
+	    /* is fixed as we dump the image; we won't need to move */
+	    /* them around later.                                   */
+	    break;
 	  default:
 	    unexec_error ("unrelocate: %s:%d cannot handle type = %d",
 			  name, i, reloc_info.r_type);
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46
Content-Type: text/x-patch; charset=UTF-8;
 name="0006-Allow-build-configuration-on-Apple-ARM-devices.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0006-Allow-build-configuration-on-Apple-ARM-devices.patch"

>From b1bd2b5cc076fcb1b4d2b2a790fb94bc860fb52b Mon Sep 17 00:00:00 2001
From: Roland Kaufmann <rlndkfmn+emacs@HIDDEN>
Date: Thu, 27 Dec 2018 15:51:49 +0100
Subject: [PATCH 6/6] Allow build configuration on Apple ARM devices

---
 configure.ac | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index b1b8c84..0006d75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -708,7 +708,7 @@ case "${canonical}" in
   *-apple-darwin* )
     case "${canonical}" in
       *-apple-darwin[0-9].*) unported=yes ;;
-      i[3456]86-* | x86_64-* )  ;;
+      i[3456]86-* | x86_64-* | arm-* )  ;;
       * )            unported=yes ;;
     esac
     opsys=darwin
-- 
2.25.2




--------------58C4D5B7A8BB366E981EAB46--




Acknowledgement sent to Roland Kaufmann <rlndkfmn+emacs@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#41994; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 22 Jun 2020 00:15:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.