X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/266a86bd7fedf743225c2497956b73ecb2245196..e499d0eebc7d8c12b42b2aa5392ce747ca3619ea:/src/unexmacosx.c diff --git a/src/unexmacosx.c b/src/unexmacosx.c index 5c450e062c..0f5ad5498b 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -1,6 +1,5 @@ /* Dump Emacs in Mach-O format for use on Mac OS X. - Copyright (C) 2001, 2002, 2003, 2004, 2005, - 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2001-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -86,8 +85,20 @@ along with GNU Emacs. If not, see . */ be changed accordingly. */ -#include +/* 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 +#include +#undef malloc +#undef realloc +#undef free + +#include "unexec.h" + +#include #include #include #include @@ -98,10 +109,6 @@ along with GNU Emacs. If not, see . */ #if defined (__ppc__) #include #endif -#include -#undef malloc -#undef realloc -#undef free #ifdef HAVE_MALLOC_MALLOC_H #include #else @@ -266,7 +273,7 @@ unexec_copy (off_t dest, off_t src, ssize_t count) /* Debugging and informational messages routines. */ -static void +static _Noreturn void unexec_error (const char *format, ...) { va_list ap; @@ -387,7 +394,7 @@ build_region_list (void) } else { - r = (struct region_t *) malloc (sizeof (struct region_t)); + r = malloc (sizeof *r); if (!r) unexec_error ("cannot allocate region structure"); @@ -469,7 +476,7 @@ find_emacs_zone_regions (void) { num_unexec_regions = 0; - emacs_zone->introspect->enumerator (mach_task_self(), 0, + emacs_zone->introspect->enumerator (mach_task_self (), 0, MALLOC_PTR_REGION_RANGE_TYPE | MALLOC_ADMIN_REGION_RANGE_TYPE, (vm_address_t) emacs_zone, @@ -589,6 +596,16 @@ print_load_command_name (int lc) 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 "); @@ -652,7 +669,7 @@ read_load_commands (void) #endif nlc = mh.ncmds; - lca = (struct load_command **) malloc (nlc * sizeof (struct load_command *)); + lca = malloc (nlc * sizeof *lca); for (i = 0; i < nlc; i++) { @@ -661,7 +678,7 @@ read_load_commands (void) size first and then read the rest. */ if (!unexec_read (&lc, sizeof (struct load_command))) unexec_error ("cannot read load command"); - lca[i] = (struct load_command *) malloc (lc.cmdsize); + lca[i] = malloc (lc.cmdsize); memcpy (lca[i], &lc, sizeof (struct load_command)); if (!unexec_read (lca[i] + 1, lc.cmdsize - sizeof (struct load_command))) unexec_error ("cannot read content of load command"); @@ -790,9 +807,9 @@ copy_data_segment (struct load_command *lc) { sectp->flags = S_REGULAR; if (!unexec_write (sectp->offset, (void *) sectp->addr, sectp->size)) - unexec_error ("cannot write section %s", sectp->sectname); + unexec_error ("cannot write section %.16s", sectp->sectname); if (!unexec_write (header_offset, sectp, sizeof (struct section))) - unexec_error ("cannot write section %s's header", sectp->sectname); + unexec_error ("cannot write section %.16s's header", sectp->sectname); } else if (strncmp (sectp->sectname, SECT_BSS, 16) == 0) { @@ -810,33 +827,37 @@ copy_data_segment (struct load_command *lc) my_size = (unsigned long)my_endbss_static - sectp->addr; if (!(sectp->addr <= (unsigned long)my_endbss_static && my_size <= sectp->size)) - unexec_error ("my_endbss_static is not in section %s", + unexec_error ("my_endbss_static is not in section %.16s", sectp->sectname); if (!unexec_write (sectp->offset, (void *) sectp->addr, my_size)) - unexec_error ("cannot write section %s", sectp->sectname); + unexec_error ("cannot write section %.16s", sectp->sectname); if (!unexec_write_zero (sectp->offset + my_size, sectp->size - my_size)) - unexec_error ("cannot write section %s", sectp->sectname); + unexec_error ("cannot write section %.16s", sectp->sectname); if (!unexec_write (header_offset, sectp, sizeof (struct section))) - unexec_error ("cannot write section %s's header", sectp->sectname); + unexec_error ("cannot write section %.16s's header", sectp->sectname); } 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 || strncmp (sectp->sectname, "__cfstring", 16) == 0 || strncmp (sectp->sectname, "__gcc_except_tab", 16) == 0 || strncmp (sectp->sectname, "__program_vars", 16) == 0 + || strncmp (sectp->sectname, "__mod_init_func", 16) == 0 + || strncmp (sectp->sectname, "__mod_term_func", 16) == 0 || strncmp (sectp->sectname, "__objc_", 7) == 0) { if (!unexec_copy (sectp->offset, old_file_offset, sectp->size)) - unexec_error ("cannot copy section %s", sectp->sectname); + unexec_error ("cannot copy section %.16s", sectp->sectname); if (!unexec_write (header_offset, sectp, sizeof (struct section))) - unexec_error ("cannot write section %s's header", sectp->sectname); + unexec_error ("cannot write section %.16s's header", sectp->sectname); } else - unexec_error ("unrecognized section name in __DATA segment"); + unexec_error ("unrecognized section %.16s in __DATA segment", + sectp->sectname); printf (" section %-16.16s at %#8lx - %#8lx (sz: %#8lx)\n", sectp->sectname, (long) (sectp->offset), @@ -1125,6 +1146,28 @@ copy_dyld_info (struct load_command *lc, long delta) } #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 @@ -1196,6 +1239,11 @@ dump_it (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]); @@ -1218,8 +1266,7 @@ dump_it (void) and infile, respectively. The three other parameters are ignored. */ void -unexec (char *outfile, char *infile, void *start_data, void *start_bss, - void *entry_address) +unexec (const char *outfile, const char *infile) { if (in_dumped_exec) unexec_error ("Unexec from a dumped executable is not supported."); @@ -1331,7 +1378,7 @@ unexec_realloc (void *old_ptr, size_t new_size) size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size; size_t size = new_size > old_size ? old_size : new_size; - p = (size_t *) malloc (new_size); + p = malloc (new_size); if (size) memcpy (p, old_ptr, size); } @@ -1373,6 +1420,3 @@ unexec_free (void *ptr) else malloc_zone_free (emacs_zone, (unexec_malloc_header_t *) ptr - 1); } - -/* arch-tag: 1a784f7b-a184-4c4f-9544-da8619593d72 - (do not change this comment) */