CMUCL commit: src/lisp (mach-o.c)

Raymond Toy rtoy at common-lisp.net
Sat Jul 31 02:18:40 CEST 2010


    Date: Friday, July 30, 2010 @ 20:18:40
  Author: rtoy
    Path: /project/cmucl/cvsroot/src/lisp

Modified: mach-o.c

More cleanups.

o Disable all of those debugging prints.
o Add ability to enable those debugging prints if desired.  (May go a
  way some day.)
o Get rid of some compiler warnings.
o Get rid of the global eh variable; it's not required to be global. 


----------+
 mach-o.c |   42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)


Index: src/lisp/mach-o.c
diff -u src/lisp/mach-o.c:1.2 src/lisp/mach-o.c:1.3
--- src/lisp/mach-o.c:1.2	Fri Jul 30 20:03:23 2010
+++ src/lisp/mach-o.c	Fri Jul 30 20:18:40 2010
@@ -16,8 +16,8 @@
 
 typedef struct mach_header MachO_hdr;
 
-/* Elf data structures. */
-static MachO_hdr eh;
+/* Uncomment to enable debugging prints */
+/* #define DEBUG_MACH_O */
 
 /* Names of the Lisp image ELF sections. These names must be the same as
    the corresponding names found in the linker script.  */
@@ -86,7 +86,7 @@
 static int
 write_mach_o_header(int fd)
 {
-    extern MachO_hdr eh;
+    MachO_hdr eh;
 
     /* Ident array. */
     eh.magic = MH_MAGIC;
@@ -114,7 +114,7 @@
     /* Size is 1 segment command + 1 section command */
     lc.cmdsize = sizeof(lc) + sizeof(struct section);
     strncpy(lc.segname, name, sizeof(lc.segname));
-    lc.vmaddr = start;
+    lc.vmaddr = (uint32_t) start;
     lc.vmsize = length;
     /* Offset where the data is.  It's the header, the segment
      * command, and one section */
@@ -135,7 +135,7 @@
 
     strncpy(sc.sectname, object_name, sizeof(sc.sectname));
     strncpy(sc.segname, object_name, sizeof(sc.segname));
-    sc.addr = start;
+    sc.addr = (uint32_t) start;
     sc.size = length;
     /* Offset of the data.  We have one header, one segment and one
      * section */
@@ -246,8 +246,6 @@
         }
         
 	if (stat(command, &st) == 0) {
-            extern int main();
-            
 	    free(paths);
 	    printf("\t[%s: linking %s... \n", command, file);
 	    fflush(stdout);
@@ -302,9 +300,11 @@
 void
 map_core_sections(const char *exec_name)
 {
+    MachO_hdr eh;
     int exec_fd;
     int sections_remaining = 3;
-    int i, j;
+    int i;
+    int j;
     extern int image_dynamic_space_size;
     extern int image_static_space_size;
     extern int image_read_only_space_size;
@@ -326,22 +326,30 @@
          */
         
         eread(exec_fd, &lc, sizeof(lc), __func__);
+#ifdef DEBUG_MACH_O
         fprintf(stderr, "Load %d:  cmd = %d, cmdsize = %d\n", i, lc.cmd, lc.cmdsize);
-        
+#endif
+
         if (lc.cmd == LC_SEGMENT) {
             /* Read the rest of the command, which is a segment command. */
-            fprintf(stderr, "Reading next %d bytes for SEGMENT\n", sizeof(sc) - sizeof(lc));
+#ifdef DEBUG_MACH_O
+            fprintf(stderr, "Reading next %ld bytes for SEGMENT\n", sizeof(sc) - sizeof(lc));
+#endif
             eread(exec_fd, &sc.segname, sizeof(sc) - sizeof(lc), __func__);
+#ifdef DEBUG_MACH_O
             fprintf(stderr, "LC_SEGMENT: name = %s\n", sc.segname);
+#endif
 
             /* See if the segment name matches any of our section names */
             for (j = 0; j < 3; ++j) {
                 if (strncmp(sc.segname, section_names[j], sizeof(sc.segname)) == 0) {
                     /* Found a core segment.  Map it! */
+#ifdef DEBUG_MACH_O
                     fprintf(stderr, "Matched!\n");
-                    fprintf(stderr, " Fileoff = %ld\n", sc.fileoff);
-                    fprintf(stderr, " vmaddr  = 0x%lx\n", sc.vmaddr);
-                    fprintf(stderr, " vmsize  = 0x%lx\n", sc.vmsize);
+                    fprintf(stderr, " Fileoff = %u\n", sc.fileoff);
+                    fprintf(stderr, " vmaddr  = 0x%x\n", sc.vmaddr);
+                    fprintf(stderr, " vmsize  = 0x%x\n", sc.vmsize);
+#endif
                     
                     if ((os_vm_address_t) os_map(exec_fd, sc.fileoff,
                                                  (os_vm_address_t) sc.vmaddr,
@@ -371,12 +379,16 @@
                     break;
                 }
             }
-            fprintf(stderr, "Skipping %d remainder bytes left in command\n",
+#ifdef DEBUG_MACH_O
+            fprintf(stderr, "Skipping %ld remainder bytes left in command\n",
                     lc.cmdsize - sizeof(sc));
+#endif
             elseek(exec_fd, lc.cmdsize - sizeof(sc), SEEK_CUR, __func__);
         } else {
             /* Seek to the next command */
-            fprintf(stderr, "Seeking by %d bytes\n", lc.cmdsize - sizeof(lc));
+#ifdef DEBUG_MACH_O
+            fprintf(stderr, "Seeking by %ld bytes\n", lc.cmdsize - sizeof(lc));
+#endif
             elseek(exec_fd, lc.cmdsize - sizeof(lc), SEEK_CUR, __func__);
         }
     }



More information about the cmucl-commit mailing list