From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Roland Kaufmann Newsgroups: gmane.emacs.bugs Subject: bug#41994: Emacs on Apple ARM devices Date: Mon, 22 Jun 2020 00:13:15 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------58C4D5B7A8BB366E981EAB46" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="113451"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 To: 41994@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 22 02:03:13 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jn9vc-000TUG-Qz for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 22 Jun 2020 02:03:12 +0200 Original-Received: from localhost ([::1]:45704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jn9vb-00066D-TQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 21 Jun 2020 20:03:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jn9vT-000661-9Z for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 20:03:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49551) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jn9vT-0004CD-18 for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 20:03:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jn9vS-0007Vg-UL for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 20:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Roland Kaufmann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 22 Jun 2020 00:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41994 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.159278413228785 (code B ref -1); Mon, 22 Jun 2020 00:03:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Jun 2020 00:02:12 +0000 Original-Received: from localhost ([127.0.0.1]:32861 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jn9ub-0007U6-D1 for submit@debbugs.gnu.org; Sun, 21 Jun 2020 20:02:12 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:34038) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jn8DM-0004qf-OP for submit@debbugs.gnu.org; Sun, 21 Jun 2020 18:13:28 -0400 Original-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 ) id 1jn8DM-0005KV-I2 for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 18:13:24 -0400 Original-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 ) id 1jn8DH-0006aF-NT for bug-gnu-emacs@gnu.org; Sun, 21 Jun 2020 18:13:24 -0400 Original-Received: by mail-lj1-x234.google.com with SMTP id s1so17168033ljo.0 for ; 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) Original-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 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 21 Jun 2020 15:13:15 -0700 (PDT) Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::234; envelope-from=rlndkfmn+emacs@gmail.com; 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-Mailman-Approved-At: Sun, 21 Jun 2020 20:02:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:182267 Archived-At: 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 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 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 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 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 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 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--