Index: /trunk/source/lisp-kernel/mach-o-image.c
===================================================================
--- /trunk/source/lisp-kernel/mach-o-image.c	(revision 14608)
+++ /trunk/source/lisp-kernel/mach-o-image.c	(revision 14609)
@@ -83,9 +83,9 @@
     if (n < 0) {
       perror("reading from image");
-      exit(1);
+      _exit(1);
     }
     if (n == 0) {
       fprintf(stderr, "unexpected end of file reading image\n");
-      exit(1);
+      _exit(1);
     }
     total += n;
@@ -108,5 +108,5 @@
     if (n < 0) {
       perror("writing to image");
-      exit(1);
+      _exit(1);
     }
     total += n;
@@ -307,5 +307,5 @@
     f;
   int tag;
-  natural size_in_bytes;
+  natural size_in_bytes, code_words;
   macho_nlist symbol;
 
@@ -330,9 +330,14 @@
 #ifdef X8632
       f = ((LispObj)start)+fulltag_misc;
-      size_in_bytes = (header_element_count(header)<<node_shift)-tag_misc;
+      code_words = (unsigned short)deref(f,1);
+      if (code_words & 0x8000) {
+        code_words = header_element_count(header) - (code_words & 0x7fff);
+      }
+      size_in_bytes = (code_words<<node_shift)-tag_misc;
 #endif
 #ifdef X8664
       f = ((LispObj)start)+fulltag_function;
-      size_in_bytes = (header_element_count(header)<<node_shift)-tag_function;
+      code_words = (int)deref(f,1);
+      size_in_bytes = (code_words<<node_shift)-tag_function;
 #endif
 
@@ -484,5 +489,5 @@
 
   seg = add_macho_segment(p, 
-                          "READONLY",
+                          "__TEXT",
                           (natural)(readonly_area->low-4096),
                           4096+align_to_power_of_2(readonly_area->active-readonly_area->low,12),
@@ -492,5 +497,5 @@
                           VM_PROT_READ|VM_PROT_EXECUTE,
                           1, 
-                          "purespace");
+                          "text");
   init_macho_section(seg,
                      0,
@@ -827,4 +832,5 @@
     managed_static_area = new_area(ms_start,ms_end,AREA_MANAGED_STATIC);
     managed_static_area->active = ms_end;
+    add_area_holding_area_lock(managed_static_area);
     lisp_global(REF_BASE) = (LispObj) ms_start;
     
