Subject: bug#60220: 29.0.60; macOS 13.1 crash shortly after starting Emacs

From: Aaron Jensen <[email-masked]>
Date: Thu, 29 Dec 2022 22:54:50 -0500

On Thu, Dec 29, 2022 at 9:11 PM Aaron Jensen <[email-masked]> wrote:
>
> On Thu, Dec 29, 2022 at 8:16 PM Paul Eggert <[email-masked]> wrote:
> >
> > On 12/29/22 16:03, Aaron Jensen wrote:
> > > Would it make sense to use block_atimers while loading native lisp? If
> >
> > Might, but it might make more sense not to be dynamically loading code
> > during an idle timer. Surely this could cause problems even in
> > non-native lisp. Anyway, I suggest consulting a macOS expert before
> > doing much experimenting; there's not enough evidence now for me to give
> > advice.
>
>
> I reported a bug and opened a discussion on the developer forum. We
> will see where that goes.
>
> I also added printfs on either side of native-elisp-load. When I got a
> crash, it was in a magit eln again and from what I can tell, every
> "start loading" had a matching "loaded" logged. I don't know that that
> definitely rules out the load interrupted theory or not.
>
> Furthermore, I've been able to crash it in a debugger. I don't know
> what to do there though, so I'm not sure how useful that is at this
> point.
>
> Aaron

I was able to reproduce it in an after-init hook (so no timers involved)

-------------------------------------
Translated Report (Full Report Below)
-------------------------------------

Process:               Emacs [33253]
Path:                  /opt/homebrew/*/Emacs.app/Contents/MacOS/Emacs
Identifier:            org.gnu.Emacs
Version:               Version 29.0.60 (9.0)
Code Type:             ARM-64 (Native)
Parent Process:        zsh [69115]
Responsible:           iTerm2 [64164]
User ID:               501

Date/Time:             2022-12-29 22:51:06.9736 -0500
OS Version:            macOS 13.1 (22C65)
Report Version:        12
Anonymous UUID:        CD1F31D7-5E61-2935-643D-55F58CD29C12

Sleep/Wake UUID:       F85FABBE-D01F-449A-BF1E-0176C31B6028

Time Awake Since Boot: 210000 seconds
Time Since Wake:       128 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00000000000000f9
Exception Codes:       0x0000000000000001, 0x00000000000000f9

VM Region Info: 0xf9 is not in any region.  Bytes before following
region: 105553518919431
      REGION TYPE                    START - END         [ VSIZE]
PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->
      MALLOC_NANO (reserved)   600018000000-600020000000 [128.0M]
rw-/rwx SM=NUL  ...(unallocated)

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib               0x1a6d621b0 __pthread_kill + 8
1   libsystem_pthread.dylib               0x1a6d98cec pthread_kill + 288
2   libsystem_c.dylib                     0x1a6c9aa50 raise + 32
3   Emacs                                 0x100a31aec
terminate_due_to_signal + 204
4   Emacs                                 0x100a322f0 emacs_abort + 20
5   Emacs                                 0x100a00db0 ns_term_shutdown + 132
6   Emacs                                 0x1008ecb94 shut_down_emacs + 332
7   Emacs                                 0x100a31ab4
terminate_due_to_signal + 148
8   Emacs                                 0x10090f084 handle_fatal_signal + 16
9   Emacs                                 0x10090f100
deliver_thread_signal + 124
10  Emacs                                 0x10090d700
deliver_fatal_thread_signal + 12
11  Emacs                                 0x10090f160 handle_sigsegv + 96
12  libsystem_platform.dylib             0x1a6dc72a4 _sigtramp + 56
13  dyld                                 0x1a6a99380
lsl::BTree<lsl::Allocator::Buffer,
std::__1::less<lsl::Allocator::Buffer>,
false>::const_iterator::operator++() + 60
14  dyld                                 0x1a6a99d54
lsl::BTree<lsl::Allocator::Buffer,
std::__1::less<lsl::Allocator::Buffer>,
false>::erase(lsl::BTree<lsl::Allocator::Buffer,
std::__1::less<lsl::Allocator::Buffer>, false>::const_iterator) + 76
15  dyld                                 0x1a6a999fc
lsl::PersistentAllocator::reserveRange(lsl::BTree<lsl::Allocator::Buffer,
lsl::PersistentAllocator::RegionSizeCompare, false>::const_iterator&,
lsl::Allocator::Buffer) + 264
16  dyld                                 0x1a6a9a0b0
lsl::PersistentAllocator::allocate_buffer(unsigned long, unsigned
long, unsigned long, lsl::Allocator**) + 624
17  dyld                                 0x1a6a991e0
lsl::Allocator::aligned_alloc(unsigned long, unsigned long) + 180
18  dyld                                 0x1a6a99230
lsl::Allocator::strdup(char const*) + 48
19  dyld                                 0x1a6a968b8
dyld4::FileManager::fileRecordForPath(char const*) + 40
20  dyld                                 0x1a6ab4624
dyld4::Atlas::ProcessSnapshot::Serializer::readMappedFileInfo(std::__1::span<std::byte,
18446744073709551615ul>&, unsigned long long&, lsl::UUID&,
dyld4::FileRecord&) + 132
21  dyld                                 0x1a6ab3170
dyld4::Atlas::ProcessSnapshot::Serializer::deserialize(std::__1::span<std::byte,
18446744073709551615ul>) + 928
22  dyld                                 0x1a6ab2cec
dyld4::Atlas::ProcessSnapshot::ProcessSnapshot(lsl::Allocator&,
dyld4::FileManager&, bool, std::__1::span<std::byte,
18446744073709551615ul>) + 304
23  dyld                                 0x1a6a7ef64
lsl::UniquePtr<dyld4::Atlas::ProcessSnapshot>
lsl::Allocator::makeUnique<dyld4::Atlas::ProcessSnapshot,
lsl::EphemeralAllocator&, dyld4::FileManager&, bool,
std::__1::span<std::byte, 18446744073709551615ul>
const&>(lsl::EphemeralAllocator&, dyld4::FileManager&, bool&&,
std::__1::span<std::byte, 18446744073709551615ul> const&) + 80
24  dyld                                 0x1a6a7bafc
dyld4::RuntimeState::getCurrentProcessSnapshot() + 96
25  dyld                                 0x1a6a7b8cc
dyld4::RuntimeState::notifyDebuggerLoad(std::__1::span<dyld4::Loader
const*, 18446744073709551615ul> const&) + 72
26  dyld                                 0x1a6aaaf3c
dyld4::APIs::dlopen_from(char const*, int, void*)::$_0::operator()()
const + 748
27  dyld                                 0x1a6aa4968
dyld4::APIs::dlopen_from(char const*, int, void*) + 892
28  Emacs                                 0x1009b4db0 Fnative_elisp_load + 356
29  Emacs                                 0x10099088c Fload + 2104
30  Emacs                                 0x1009925f0 save_match_data_load + 92
31  Emacs                                 0x10096c928
load_with_autoload_queue + 120
32  Emacs                                 0x100978d84 Frequire + 560
33  Emacs                                 0x100968a30 eval_sub + 2236
34  Emacs                                 0x10096b158
internal_lisp_condition_case + 884
35  Emacs                                 0x10096889c eval_sub + 1832
36  Emacs                                 0x100968bac Fprogn + 48
37  Emacs                                 0x10096a3a8 Fwhile + 80
38  Emacs                                 0x10096889c eval_sub + 1832
39  Emacs                                 0x100968bac Fprogn + 48
40  Emacs                                 0x10096889c eval_sub + 1832
41  Emacs                                 0x10096889c eval_sub + 1832
42  Emacs                                 0x100968bac Fprogn + 48
43  Emacs                                 0x10096e10c funcall_lambda + 1316
44  Emacs                                 0x10096a724 Ffuncall + 316
45  Emacs                                 0x100968998 eval_sub + 2084
46  Emacs                                 0x100968bac Fprogn + 48
47  Emacs                                 0x10096a2b4 Flet + 840
48  Emacs                                 0x10096889c eval_sub + 1832
49  Emacs                                 0x100968bac Fprogn + 48
50  Emacs                                 0x10096e10c funcall_lambda + 1316
51  Emacs                                 0x10096a724 Ffuncall + 316
52  Emacs                                 0x100968998 eval_sub + 2084
53  Emacs                                 0x100968bac Fprogn + 48
54  Emacs                                 0x10096889c eval_sub + 1832
55  Emacs                                 0x10096b158
internal_lisp_condition_case + 884
56  Emacs                                 0x10096889c eval_sub + 1832
57  Emacs                                 0x100968bac Fprogn + 48
58  Emacs                                 0x10096e10c funcall_lambda + 1316
59  Emacs                                 0x10096a724 Ffuncall + 316
60  Emacs                                 0x10096d35c
run_hook_wrapped_funcall + 28
61  Emacs                                 0x10096d1f0 run_hook_with_args + 320
62  Emacs                                 0x100968998 eval_sub + 2084
63  Emacs                                 0x10096b158
internal_lisp_condition_case + 884
64  Emacs                                 0x10096889c eval_sub + 1832
65  Emacs                                 0x100968bac Fprogn + 48
66  Emacs                                 0x10096a2b4 Flet + 840
67  Emacs                                 0x10096889c eval_sub + 1832
68  Emacs                                 0x100968bac Fprogn + 48
69  Emacs                                 0x10096a3a8 Fwhile + 80
70  Emacs                                 0x10096889c eval_sub + 1832
71  Emacs                                 0x100968bac Fprogn + 48
72  Emacs                                 0x10096a2b4 Flet + 840
73  Emacs                                 0x10096889c eval_sub + 1832
74  Emacs                                 0x100968bac Fprogn + 48
75  Emacs                                 0x10096e10c funcall_lambda + 1316
76  Emacs                                 0x10096a724 Ffuncall + 316
77  Emacs                                 0x10096cf28 Fapply + 612
78  Emacs                                 0x1009ab940 exec_byte_code + 2988
79  Emacs                                 0x10096a724 Ffuncall + 316
80  startup-bbc6ea72-452f9f58.eln        0x104f8431c
F636f6d6d616e642d6c696e65_command_line_0 + 5452
81  Emacs                                 0x10096a724 Ffuncall + 316
82  startup-bbc6ea72-452f9f58.eln        0x104f80bb8
F6e6f726d616c2d746f702d6c6576656c_normal_top_level_0 + 3156
83  Emacs                                 0x100968918 eval_sub + 1956
84  Emacs                                 0x10096ca4c Feval + 88
85  Emacs                                 0x10096b32c
internal_condition_case + 96
86  Emacs                                 0x1009011c8 top_level_1 + 48
87  Emacs                                 0x10096ad50 internal_catch + 88
88  Emacs                                 0x100a31f08 command_loop.cold.1 + 64
89  Emacs                                 0x1008ef488 command_loop + 152
90  Emacs                                 0x1008ef344 recursive_edit_1 + 148
91  Emacs                                 0x1008ef5a8 Frecursive_edit + 264
92  Emacs                                 0x1008ee924 main + 7484
93  dyld                                 0x1a6a6fe50 start + 2544

Thread 1:
0   libsystem_pthread.dylib               0x1a6d93e18 start_wqthread + 0

Thread 2:
0   libsystem_pthread.dylib               0x1a6d93e18 start_wqthread + 0

Thread 3:: gmain
0   libsystem_kernel.dylib               0x1a6d64a00 __select + 8
1   libglib-2.0.0.dylib                   0x10189b090 g_poll + 424
2   libglib-2.0.0.dylib                   0x10188e234
g_main_context_iterate + 340
3   libglib-2.0.0.dylib                   0x10188e2fc
g_main_context_iteration + 60
4   libglib-2.0.0.dylib                   0x10188f694 glib_worker_main + 48
5   libglib-2.0.0.dylib                   0x1018b2918 g_thread_proxy + 68
6   libsystem_pthread.dylib               0x1a6d9906c _pthread_start + 148
7   libsystem_pthread.dylib               0x1a6d93e2c thread_start + 8

Thread 4:
0   libsystem_pthread.dylib               0x1a6d93e18 start_wqthread + 0

Thread 5:
0   libsystem_pthread.dylib               0x1a6d93e18 start_wqthread + 0

Thread 6:
0   libsystem_kernel.dylib               0x1a6d5ffa4 __pselect + 8
1   libsystem_kernel.dylib               0x1a6d5fe7c pselect$DARWIN_EXTSN + 64
2   Emacs                                 0x100a01e90 -[EmacsApp
fd_handler:] + 184
3   Foundation                           0x1a7d79470 __NSThread__start__ + 716
4   libsystem_pthread.dylib               0x1a6d9906c _pthread_start + 148
5   libsystem_pthread.dylib               0x1a6d93e2c thread_start + 8

Thread 7:: com.apple.NSEventThread
0   libsystem_kernel.dylib               0x1a6d59d70 mach_msg2_trap + 8
1   libsystem_kernel.dylib               0x1a6d6b8a4 mach_msg2_internal + 80
2   libsystem_kernel.dylib               0x1a6d625c4 mach_msg_overwrite + 540
3   libsystem_kernel.dylib               0x1a6d5a0ec mach_msg + 24
4   CoreFoundation                       0x1a6e78bc0
__CFRunLoopServiceMachPort + 160
5   CoreFoundation                       0x1a6e774ac __CFRunLoopRun + 1232
6   CoreFoundation                       0x1a6e76888 CFRunLoopRunSpecific + 612
7   AppKit                               0x1aa222410 _NSEventThread + 172
8   libsystem_pthread.dylib               0x1a6d9906c _pthread_start + 148
9   libsystem_pthread.dylib               0x1a6d93e2c thread_start + 8