/* Dump Emacs in Mach-O format for use on Mac OS X.
- Copyright (C) 2001, 2002, 2003, 2004, 2005,
- 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2001-2011 Free Software Foundation, Inc.
This file is part of GNU Emacs.
be changed accordingly.
*/
-#include <stdio.h>
+/* config.h #define:s malloc/realloc/free and then includes stdlib.h.
+ We want the undefined versions, but if config.h includes stdlib.h
+ with the #define:s in place, the prototypes will be wrong and we get
+ warnings. To prevent that, include stdlib.h before config.h. */
+
#include <stdlib.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <sys/types.h>
#include <config.h>
#undef malloc
#undef realloc
#undef free
+
+#include "unexec.h"
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <sys/types.h>
#include <unistd.h>
#include <mach/mach.h>
#include <mach-o/loader.h>
case LC_DYLD_INFO_ONLY:
printf ("LC_DYLD_INFO_ONLY");
break;
+#endif
+#ifdef LC_VERSION_MIN_MACOSX
+ case LC_VERSION_MIN_MACOSX:
+ printf ("LC_VERSION_MIN_MACOSX");
+ break;
+#endif
+#ifdef LC_FUNCTION_STARTS
+ case LC_FUNCTION_STARTS:
+ printf ("LC_FUNCTION_STARTS");
+ break;
#endif
default:
printf ("unknown ");
}
else if (strncmp (sectp->sectname, "__la_symbol_ptr", 16) == 0
|| strncmp (sectp->sectname, "__nl_symbol_ptr", 16) == 0
+ || strncmp (sectp->sectname, "__got", 16) == 0
|| strncmp (sectp->sectname, "__la_sym_ptr2", 16) == 0
|| strncmp (sectp->sectname, "__dyld", 16) == 0
|| strncmp (sectp->sectname, "__const", 16) == 0
}
#endif
+#ifdef LC_FUNCTION_STARTS
+/* Copy a LC_FUNCTION_STARTS 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)
+{
+ struct linkedit_data_command *ldp = (struct linkedit_data_command *) lc;
+
+ if (ldp->dataoff > 0)
+ ldp->dataoff += delta;
+
+ printf ("Writing ");
+ print_load_command_name (lc->cmd);
+ printf (" command\n");
+
+ if (!unexec_write (curr_header_offset, lc, lc->cmdsize))
+ unexec_error ("cannot write linkedit data command to header");
+
+ 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. */
static void
case LC_DYLD_INFO_ONLY:
copy_dyld_info (lca[i], linkedit_delta);
break;
+#endif
+#ifdef LC_FUNCTION_STARTS
+ case LC_FUNCTION_STARTS:
+ copy_linkedit_data (lca[i], linkedit_delta);
+ break;
#endif
default:
copy_other (lca[i]);
from it. The file names of the output and input files are outfile
and infile, respectively. The three other parameters are
ignored. */
-int
+void
unexec (const char *outfile, const char *infile)
{
if (in_dumped_exec)
dump_it ();
close (outfd);
- return 0;
}
else
malloc_zone_free (emacs_zone, (unexec_malloc_header_t *) ptr - 1);
}
-