Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dumped emacs is unusable #1

Open
cooljeanius opened this issue Jan 21, 2018 · 5 comments
Open

dumped emacs is unusable #1

cooljeanius opened this issue Jan 21, 2018 · 5 comments

Comments

@cooljeanius
Copy link
Owner

cooljeanius commented Jan 21, 2018

trying to bootstrap results in:

cd ../lisp; make -w autoloads EMACS="../src/bootstrap-emacs"
make[2]: Entering directory `/private/var/root/emacs/lisp'
EMACSLOADPATH='.' '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp -l autoload \
   --eval "(setq generate-autoload-cookie \";;;###cal-autoload\")" \
   --eval "(setq generated-autoload-file (expand-file-name (unmsys--file-name \"/var/root/emacs/lisp/calendar/cal-loaddefs.el\")))" \
   --eval "(setq make-backup-files nil)" \
   -f batch-update-autoloads /var/root/emacs/lisp/calendar
/bin/sh: ../src/bootstrap-emacs: Cannot allocate memory
make[2]: *** [/var/root/emacs/lisp/calendar/cal-loaddefs.el] Error 126
make[2]: Leaving directory `/private/var/root/emacs/lisp'
make[1]: *** [/var/root/emacs/src/../lisp/loaddefs.el] Error 2
make[1]: Leaving directory `/private/var/root/emacs/src'
make: *** [src] Error 2

When debugging in gdb, the debugger can't handle it either:

$ gdb src/bootstrap-emacs
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin"...Reading symbols for shared libraries ...

[snip]

.... done

(gdb) break main 
Breakpoint 1 at 0x2a8eed: file emacs.c, line 710.
(gdb) run
Starting program: /private/var/root/emacs/src/bootstrap-emacs 
arch: posix_spawnp: /private/var/root/emacs/src/bootstrap-emacs: Cannot allocate memory

Program exited with code 01.
(gdb)

The odd thing is, though, that machocheck/isemacsvalid says the executable is okay...

$ ./isemacsvalid src/bootstrap-emacs
Is emacs valid?
Per-arch emacs is outdated; need to regenerate it.
This program is running from path './isemacsvalid' with '1' additional argument(s).
Checking argument number '1' in argv.
Argument number '1' in argv is 'src/bootstrap-emacs'.
Checking 'src/bootstrap-emacs'...
Treating 'bootstrap-emacs' as the output result of an emacs dump.
Checking mach header...
Header flags are 0x1000085.
Done checking mach header.
Checking load commands...
Checking section ranges for segment number 0 named __PAGEZERO...
Checking section ranges for segment number 1 named __TEXT...
Done checking section __text in segment __TEXT.
Done checking section __text_startup in segment __TEXT.
Done checking section __text_cold in segment __TEXT.
Done checking section __symbol_stub in segment __TEXT.
Done checking section __stub_helper in segment __TEXT.
Done checking section __cstring in segment __TEXT.
Done checking section __const in segment __TEXT.
Checking section ranges for segment number 2 named __DATA...
Done checking section __dyld in segment __DATA.
Done checking section __nl_symbol_ptr in segment __DATA.
Done checking section __la_symbol_ptr in segment __DATA.
Done checking section __data in segment __DATA.
Done checking section __static_data in segment __DATA.
Done checking section __const in segment __DATA.
Done checking section __bss3 in segment __DATA.
Done checking section __bss5 in segment __DATA.
Done checking section __pu_bss2 in segment __DATA.
Done checking section __pu_bss5 in segment __DATA.
Done checking section __pu_bss3 in segment __DATA.
Done checking section __common in segment __DATA.
Done checking section __bss2 in segment __DATA.
Checking section ranges for segment number 3 named __DATA...
Checking section ranges for segment number 4 named __DATA...
Checking section ranges for segment number 5 named __DATA...
Checking section ranges for segment number 6 named __DATA...
Checking section ranges for segment number 7 named __DATA...
Checking section ranges for segment number 8 named __LINKEDIT...
Done checking load commands.
Checking indirect symbol table...
There are 56 commands to process here.
Done checking indirect symbol table.
Checking relocations...
Done checking relocations.
Checking symbol table...
External symbols start at 25652 (a.k.a. 0x6434).
Done checking symbol table.
Checking inits and terms...
Done checking inits and terms; checked 0 total.
machocheck_main() returned 0: success, should be valid.

...so, I'm not sure if the error is coming from the darwin arch executable, or darwin's libc, or the shell, or what. I've tried building my own gdb with --disable-arch-for-exec but that has its own issues...

(Note: I formerly had a bounty for this on BountySource, but then I deleted my BountySource account due to bad interactions with them on Twitter, so now if you are interested in a bounty, contact me separately to find a way to do it outside of their system)

@cooljeanius
Copy link
Owner Author

Fuller output including text printed while dumping:

Loading /Users/ericgallager/emacs/lisp/site-init.el (source)...
Dumping under names emacs and emacs-24.3.50
--- List of All Regions ---
   address     size prot maxp
         0   0x1000 none none
    0x1000 0x225000 r x  rwx 
  0x226000 0x1b2000 rw   rwx 
  0x3d8000  0x51000 rw   rwx 
  0x429000  0xc0000 r    rwx 
  0x4e9000   0x8000 r x  rwx 
  0x4f1000   0x1000 rw   rwx 
  0x4f2000   0x3000 r    rwx 
  0x4f5000  0x21000 r x  rwx 
  0x516000   0x1000 rw   rwx 
  0x517000   0x1000 rw   rwx 
  0x518000   0x7000 r    rwx 
  0x51f000 0x1a8000 r x  rwx 
0x6c7000 is above 0x59e000; we must now be into the shared libraries.
--- List of Regions to be Dumped ---
   address     size prot maxp
         0   0x1000 none none
    0x1000 0x225000 r x  rwx 
  0x226000 0x203000 rw   rwx 
  0x429000  0xc0000 r    rwx 
  0x4e9000   0x8000 r x  rwx 
  0x4f1000   0x1000 rw   rwx 
  0x4f2000   0x3000 r    rwx 
  0x4f5000  0x21000 r x  rwx 
  0x516000   0x2000 rw   rwx 
  0x518000   0x7000 r    rwx 
  0x51f000 0x1a8000 r x  rwx 
--- Header Information ---
Magic = 0xfeedface (32-bit)
CPUType = 7 (i.e. "i386")
CPUSubType = 3 (more specifically, "Intel 80x86")
FileType = 0x2 (demand-paged executable file)
NCmds = 51
SizeOfCmds = 4092
Flags = 0x01000085
Highest address of load commands in input file:  0x4e9000
Lowest offset of all sections in __TEXT segment:     0x2160
--- List of Load Commands in Input File ---
 # cmd           cmdnum           cmdsize segname              address        size
 0 LC_SEGMENT (0x00000001)             56 __PAGEZERO                 0      0x1000
 1 LC_SEGMENT (0x00000001)            532 __TEXT                0x1000    0x225000
                           __text               0x3160 0x20242e (flags: 0x80000400)
                           __text_startup     0x205590   0x19e2 (flags: 0x80000400)
                           __text_cold        0x206f72     0x8e (flags: 0x80000400)
                           __symbol_stub      0x207000   0x11fa (flags: 0x80000408)
                           __stub_helper      0x2081fc   0x1e02 (flags: 0x80000400)
                           __cstring          0x20a000  0x1a7b7 (flags:        0x2)
                           __const            0x2247c0   0x1838 (flags:          0)
 2 LC_SEGMENT (0x00000001)            940 __DATA              0x226000    0x203000
                           __dyld             0x226000      0x8 (flags:          0)
                           __nl_symbol_ptr    0x226008    0x910 (flags:        0x6)
                           __la_symbol_ptr    0x226918    0xbfc (flags:        0x7)
                           __data             0x227520 0x1ae760 (flags:          0)
                           __static_data      0x3d5c80     0x26 (flags:          0)
                           __const            0x3d5cc0   0x20f8 (flags:          0)
                           __bss3             0x3d7db8     0x30 (flags:        0x1)
                           __bss5             0x3d7e00  0x4b340 (flags:        0x1)
                           __pu_bss2          0x423140    0x830 (flags:        0x1)
                           __pu_bss5          0x423980   0x2194 (flags:        0x1)
                           __pu_bss3          0x425b18    0x408 (flags:        0x1)
                           __common           0x425f20     0x34 (flags:        0x1)
                           __bss2             0x425f54   0x25f0 (flags:        0x1)
 3 LC_SEGMENT (0x00000001)             56 __LINKEDIT          0x429000     0xc0000
 4 LC_DYLD_INFO_ONLY (0x80000022)      48
 5 LC_SYMTAB (0x00000002)              24
 6 LC_DYSYMTAB (0x0000000b)            80
 7 LC_LOAD_DYLINKER (0x0000000e)       28
 8 LC_UUID (0x0000001b)                24
 9 LC_VERSION_MIN_MACOSX (0x00000024)  16
10 LC_UNIXTHREAD (0x00000005)          80
11 LC_LOAD_DYLIB (0x0000000c)          48
12 LC_LOAD_DYLIB (0x0000000c)          52
13 LC_LOAD_DYLIB (0x0000000c)          52
14 LC_LOAD_DYLIB (0x0000000c)          48
15 LC_LOAD_DYLIB (0x0000000c)          48
16 LC_LOAD_DYLIB (0x0000000c)          52
17 LC_LOAD_DYLIB (0x0000000c)          52
18 LC_LOAD_DYLIB (0x0000000c)          48
19 LC_LOAD_DYLIB (0x0000000c)          56
20 LC_LOAD_DYLIB (0x0000000c)          48
21 LC_LOAD_DYLIB (0x0000000c)          56
22 LC_LOAD_DYLIB (0x0000000c)          56
23 LC_LOAD_DYLIB (0x0000000c)          56
24 LC_LOAD_DYLIB (0x0000000c)          56
25 LC_LOAD_DYLIB (0x0000000c)          56
26 LC_LOAD_DYLIB (0x0000000c)          56
27 LC_LOAD_DYLIB (0x0000000c)          56
28 LC_LOAD_DYLIB (0x0000000c)          60
29 LC_LOAD_DYLIB (0x0000000c)          56
30 LC_LOAD_DYLIB (0x0000000c)          52
31 LC_LOAD_DYLIB (0x0000000c)          52
32 LC_LOAD_DYLIB (0x0000000c)          60
33 LC_LOAD_DYLIB (0x0000000c)          56
34 LC_LOAD_DYLIB (0x0000000c)          52
35 LC_LOAD_DYLIB (0x0000000c)         104
36 LC_LOAD_DYLIB (0x0000000c)          52
37 LC_LOAD_DYLIB (0x0000000c)          52
38 LC_LOAD_DYLIB (0x0000000c)          60
39 LC_LOAD_DYLIB (0x0000000c)          60
40 LC_LOAD_DYLIB (0x0000000c)          60
41 LC_LOAD_DYLIB (0x0000000c)          48
42 LC_LOAD_DYLIB (0x0000000c)          60
43 LC_LOAD_DYLIB (0x0000000c)          52
44 LC_LOAD_DYLIB (0x0000000c)          68
45 LC_LOAD_DYLIB (0x0000000c)          72
46 LC_LOAD_DYLIB (0x0000000c)          48
47 LC_LOAD_DYLIB (0x0000000c)          60
48 LC_LOAD_DYLIB (0x0000000c)          56
49 LC_LOAD_DYLIB (0x0000000c)          56
50 LC_FUNCTION_STARTS (0x00000026)     16
 0xc6fc080 (sz:   0x3f1c/  0x3f20) (0 to go in this loop)
 0xc600000 (sz:  0x40831/ 0xfc080) (0 to go in this loop)
 0xcff8000 (sz:   0x5036/  0x7f98) (0 to go in this loop)
 0xc800000 (sz: 0x501bff/0x7f8000) (0 to go in this loop)
 0xc54a000 (sz:        0/  0x1000) (0 to go in this loop)
Region 1: removed 1000 zerod bytes from filesize
Page (  0x1000) aligning region @0xc600000 size from  0xfc080 to  0xfd000
Page (  0x1000) aligning region @0xc6fc000 size from   0x3fa0 to   0x4000
Region 4: removed 2f6401 zerod bytes from filesize
Page (  0x1000) aligning region @0xcff8000 size from   0x7f98 to   0x8000
Region 5: removed 2000 zerod bytes from filesize
--- Load Commands written to Output File ---
Writing segment __PAGEZERO       @         0 (       0/     0x1000 @           0)
Writing segment __TEXT           @         0 (0x225000/   0x225000 @      0x1000)
Writing segment __DATA           @  0x225000 (0x203000/   0x203000 @    0x226000)
        section __dyld           at 0x225000 - 0x225008 (sz:      0x8), with type 0x00 (regular)
        section __nl_symbol_ptr  at 0x225008 - 0x225918 (sz:    0x910), with type 0x06 (non-lazy symbol pointers)
        section __la_symbol_ptr  at 0x225918 - 0x226514 (sz:    0xbfc), with type 0x07 (lazy symbol pointers)
        section __data           at 0x226520 - 0x3d4c80 (sz: 0x1ae760), with type 0x00 (regular)
        section __static_data    at 0x3d4c80 - 0x3d4ca6 (sz:     0x26), with type 0x00 (regular)
        section __const          at 0x3d4cc0 - 0x3d6db8 (sz:   0x20f8), with type 0x00 (regular)
        section __bss3           at 0x3d6db8 - 0x3d6de8 (sz:     0x30), with type 0x01 (zerofill)
        section __bss5           at 0x3d6e00 - 0x422140 (sz:  0x4b340), with type 0x01 (zerofill)
        section __pu_bss2        at 0x422140 - 0x422970 (sz:    0x830), with type 0x01 (zerofill)
        section __pu_bss5        at 0x422980 - 0x424b14 (sz:   0x2194), with type 0x01 (zerofill)
        section __pu_bss3        at 0x424b18 - 0x424f20 (sz:    0x408), with type 0x01 (zerofill)
        section __common         at 0x424f20 - 0x424f54 (sz:     0x34), with type 0x01 (zerofill)
        section __bss2           at 0x424f54 - 0x427544 (sz:   0x25f0), with type 0x01 (zerofill)
Section sizes in this segment added up to 0x2024f2, which is less than its vmsize of 0x203000.
Writing segment __DATA           @  0x428000 (       0/     0x1000 @   0xc54a000)
Writing segment __DATA           @  0x428000 ( 0xfd000/    0xfd000 @   0xc600000)
Writing segment __DATA           @  0x525000 (  0x4000/     0x4000 @   0xc6fc000)
Writing segment __DATA           @  0x529000 (0x501bff/   0x7f8000 @   0xc800000)
Writing segment __DATA           @  0xa2b000 (  0x6000/     0x8000 @   0xcff8000)
Total filesize of new __DATA segments written: 6327295
Writing segment __LINKEDIT       @  0xa31000 ( 0xbfb94/    0xc0000 @    0x429000)
Writing LC_DYLD_INFO_ONLY (0x80000022) 		command ( 5)
Writing LC_SYMTAB                      		command ( 6)
Writing LC_DYSYMTAB                    		command ( 7)
Writing LC_LOAD_DYLINKER (0x0000000e)  		command ( 8)
Writing LC_UUID (0x0000001b)           		command ( 9)
Writing LC_VERSION_MIN_MACOSX (0x00000024) 	command (10)
Writing LC_UNIXTHREAD (0x00000005)     		command (11)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (12)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (13)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (14)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (15)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (16)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (17)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (18)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (19)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (20)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (21)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (22)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (23)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (24)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (25)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (26)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (27)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (28)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (29)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (30)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (31)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (32)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (33)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (34)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (35)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (36)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (37)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (38)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (39)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (40)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (41)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (42)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (43)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (44)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (45)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (46)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (47)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (48)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (49)
Writing LC_LOAD_DYLIB (0x0000000c)     		command (50)
Writing LC_FUNCTION_STARTS (0x00000026) 	command (51)
4144 unused bytes follow Mach-O header
returning to loadup.el; 46012 pure bytes used while dumping
emacs -> bootstrap-emacs
if test "x/opt/local/bin/machocheck" != "x"; then \
	  /opt/local/bin/machocheck -progress bootstrap-emacs; \
	fi
ok: bootstrap-emacs
if test "xdsymutil" != "x"; then \
	  dsymutil bootstrap-emacs; \
	fi
Compiling some files earlier to speed up further compilation.
cd ../lisp; make  compile-first EMACS="../src/bootstrap-emacs"
Compiling /Users/ericgallager/emacs/lisp/emacs-lisp/macroexp.el to /Users/ericgallager/emacs/lisp/emacs-lisp/macroexp.elc
EMACSLOADPATH='.' '../src/bootstrap-emacs' -batch --no-site-file --no-site-lisp --eval "(setq max-lisp-eval-depth 2200)" --eval '(setq load-prefer-newer t)'  \
		-f batch-byte-compile /Users/ericgallager/emacs/lisp/emacs-lisp/macroexp.el
make[2]: *** [/Users/ericgallager/emacs/lisp/emacs-lisp/macroexp.elc] Segmentation fault
make[1]: *** [bootstrap-emacs] Error 2
make: *** [src] Error 2

@cooljeanius
Copy link
Owner Author

Crash log from the shell doesn't tell much:
sh_2018-01-22-184255_Eric-Gallagers-MacBook-Pro.crash.txt

@cooljeanius cooljeanius changed the title dumped emacs is unusable dumped emacs is unusable [$15] Feb 20, 2018
@cooljeanius cooljeanius added the needs help needs help label Sep 28, 2020
@cooljeanius cooljeanius changed the title dumped emacs is unusable [$15] dumped emacs is unusable May 25, 2021
@cooljeanius
Copy link
Owner Author

issue #2 might need fixing first actually

@cooljeanius
Copy link
Owner Author

currently I'm waiting on macports/macports-ports#18956 to be merged so that I can check out the ld64 sources for some isemacsvalid updates... can someone please help?
(just phrasing that as a question so that I can add the "question" tag)

@cooljeanius
Copy link
Owner Author

currently I'm waiting on macports/macports-ports#18956 to be merged so that I can check out the ld64 sources for some isemacsvalid updates... can someone please help? (just phrasing that as a question so that I can add the "question" tag)

OK so that PR is now merged, so I've updated the machochecker sources for isemacsvalid, and it looks like the current issue isn't actually with the executable being invalid after all, but rather a legit code error that's probably due to malloc/free getting redefined somewhere:

Running ./temacs for bootstrapping
emacs.c, line 728: Hello.
unexmacosx.c, line 2280: zone created: 0x105537000.
In sort_args: pointers to attempt to free: options: 0x1068040c8, new: 0x106804098, and priority: 0x1068040e8.
temacs(53296,0x10e6cae00) malloc: *** error for object 0x1068040c8: pointer being freed was not allocated
temacs(53296,0x10e6cae00) malloc: *** set a breakpoint in malloc_error_break to debug
/bin/sh: line 1: 53296 Abort trap: 6           ./temacs --batch --load loadup bootstrap
make[1]: *** [bootstrap-emacs] Error 1
make: *** [src] Error 2

...but the pointer in question (options), was actually created by xnmalloc earlier in the function, so idk what it's talking about when it says it wasn't allocated:

emacs/src/emacs.c

Line 1876 in ab9e250

int *options = xnmalloc(argc, sizeof(*options));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant