2 diff -rub libstuff/Makefile libstuff/Makefile
3 --- libstuff/Makefile Fri Sep 6 18:27:55 2002
4 +++ libstuff/Makefile Sat Sep 6 20:12:21 2003
8 ifeq "macos" "$(RC_OS)"
9 - X_CFLAGS := $(shell if [ "$(RC_RELEASE)" != "Beaker" ] && \
10 + X_CFLAGS := $(shell if [ `uname` != "Linux" ] && [ "$(RC_RELEASE)" != "Beaker" ] && \
11 [ "$(RC_RELEASE)" != "Bunsen" ] && \
12 [ "$(RC_RELEASE)" != "Gonzo" ] && \
13 [ "$(RC_RELEASE)" != "Kodiak" ]; then \
18 -USE_DEPENDENCY_FILE := $(shell if [ "$(notdir $(CC))" != "mwccppc" ]; then \
19 +USE_DEPENDENCY_FILE := $(shell if [ `uname` != "Linux" ] && [ "$(notdir $(CC))" != "mwccppc" ]; then \
20 echo YES ; else echo NO ; \
23 ifeq "mwccppc" "$(notdir $(CC))"
24 CFLAGS = $(OFLAG) -g -gccinc -I$(SRCROOT)/../include
26 - CFLAGS = $(OFLAG) -g -I$(SRCROOT)/../include -Wall -Wno-precomp $(X_CFLAGS)
27 + ifeq "Linux" "$(shell uname)"
28 + CFLAGS = $(OFLAG) -g -I$(SRCROOT)/../include -Wall $(X_CFLAGS) -D__LITTLE_ENDIAN__ -U__BIG_ENDIAN__ -D__ppc__ -I/usr/include -I../../../macosx-include
30 + CFLAGS = $(OFLAG) -g -I$(SRCROOT)/../include -Wall $(X_CFLAGS)
34 ifneq "" "$(wildcard /bin/mkdirs)"
36 set_arch_flag_name.c seg_addr_table.c dylib_table.c \
37 breakout.c writeout.c checkout.c fatal_arch.c ofile_get_word.c \
38 vm_flush_cache.c hash_string.c dylib_roots.c guess_short_name.c \
39 - SymLoc.c get_arch_from_host.c crc32.c macosx_deployment_target.c
40 + SymLoc.c get_arch_from_host.c crc32.c macosx_deployment_target.c \
41 + symbol_list.c fake-mach.c
42 OBJS = $(CFILES:.c=.o)
43 INSTALL_FILES = $(CFILES) Makefile notes
53 RC_CFLAGS="$(RC_CFLAGS)" \
55 OFILE_DIR=$(OBJROOT)/dynamic_obj \
62 RC_CFLAGS="$(RC_CFLAGS)" \
67 - COPTS="-dynamic -pg" \
70 RC_CFLAGS="$(RC_CFLAGS)" \
71 RC_ARCHS="$(RC_ARCHS)"; \
73 OFILE_DIR=$(OBJROOT)/profile_obj \
76 - COPTS="-dynamic -pg" \
79 RC_CFLAGS="$(RC_CFLAGS)" \
80 RC_ARCHS="$(RC_ARCHS)"; \
84 $(PRODUCT): $(OFILE_DIR) $(SYMROOT) $(OBJS)
85 - libtool -static -o $(SYMROOT)/$(PRODUCT) $(OBJS)
86 + ar r $(SYMROOT)/$(PRODUCT) $(OBJS)
87 + ranlib $(SYMROOT)/$(PRODUCT)
89 ifeq "NO" "$(USE_DEPENDENCY_FILE)"
91 diff -rub libstuff/SymLoc.c libstuff/SymLoc.c
92 --- libstuff/SymLoc.c Fri Sep 6 18:27:55 2002
93 +++ libstuff/SymLoc.c Mon Aug 25 13:17:40 2003
97 -#import <sys/types.h>
100 +#include <sys/types.h>
102 #define _POSIX_SOURCE
106 -#import "stuff/bool.h"
107 -#import "stuff/errors.h"
108 -#import "stuff/allocate.h"
109 -#import "stuff/SymLoc.h"
112 +#include "stuff/bool.h"
113 +#include "stuff/errors.h"
114 +#include "stuff/allocate.h"
115 +#include "stuff/SymLoc.h"
118 symLocForDylib(const char *installName, const char *releaseName,
120 system_error("symLocForDylib(): Can't opendir %s", buf);
125 // read DylibProjects entries
127 diff -rub libstuff/arch.c libstuff/arch.c
128 --- libstuff/arch.c Tue Jan 14 23:35:27 2003
129 +++ libstuff/arch.c Mon Aug 25 13:17:40 2003
131 { "ppc750", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_750 },
132 { "ppc7400",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7400 },
133 { "ppc7450",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7450 },
134 + { "ppc970", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_970 },
135 { "i486", CPU_TYPE_I386, CPU_SUBTYPE_486 },
136 { "i486SX", CPU_TYPE_I386, CPU_SUBTYPE_486SX },
137 { "pentium",CPU_TYPE_I386, CPU_SUBTYPE_PENT }, /* same as i586 */
138 { "i586", CPU_TYPE_I386, CPU_SUBTYPE_586 },
139 - { "pentpro", CPU_TYPE_I386, CPU_SUBTYPE_PENTPRO },
140 + { "pentpro", CPU_TYPE_I386, CPU_SUBTYPE_PENTPRO }, /* same as i686 */
141 + { "i686", CPU_TYPE_I386, CPU_SUBTYPE_PENTPRO },
142 { "pentIIm3",CPU_TYPE_I386, CPU_SUBTYPE_PENTII_M3 },
143 { "pentIIm5",CPU_TYPE_I386, CPU_SUBTYPE_PENTII_M5 },
144 { "m68030", CPU_TYPE_MC680x0, CPU_SUBTYPE_MC68030_ONLY },
146 const struct arch_flag *flag)
148 if(flag->cputype == CPU_TYPE_POWERPC ||
149 - flag->cputype == CPU_TYPE_VEO)
150 + flag->cputype == CPU_TYPE_VEO ||
151 + flag->cputype == CPU_TYPE_I386)
152 return(0x1000); /* 4K */
154 return(0x2000); /* 8K */
155 diff -rub libstuff/best_arch.c libstuff/best_arch.c
156 --- libstuff/best_arch.c Tue Jan 14 23:35:27 2003
157 +++ libstuff/best_arch.c Mon Aug 25 13:17:40 2003
159 struct fat_arch *fat_archs,
160 unsigned long nfat_archs)
162 - unsigned long i, lowest_family, lowest_model, lowest_index;
164 + long lowest_family, lowest_model, lowest_index;
167 * Look for the first exact match.
168 @@ -183,14 +184,21 @@
169 * An exact match as not found. So for all the PowerPC subtypes
170 * pick the subtype from the following order starting from a subtype
171 * that will work (contains altivec if needed):
172 - * 7450, 7400, 750, 604e, 604, 603ev, 603e, 603, ALL
173 + * 790, 7450, 7400, 750, 604e, 604, 603ev, 603e, 603, ALL
174 * Note the 601 is NOT in the list above. It is only picked via
175 * an exact match. For an unknown subtype pick only the ALL type if
179 + case CPU_SUBTYPE_POWERPC_970:
180 case CPU_SUBTYPE_POWERPC_7450:
181 case CPU_SUBTYPE_POWERPC_7400:
182 + for(i = 0; i < nfat_archs; i++){
183 + if(fat_archs[i].cputype != cputype)
185 + if(fat_archs[i].cpusubtype == CPU_SUBTYPE_POWERPC_970)
186 + return(fat_archs + i);
188 for(i = 0; i < nfat_archs; i++){
189 if(fat_archs[i].cputype != cputype)
191 diff -rub libstuff/bytesex.c libstuff/bytesex.c
192 --- libstuff/bytesex.c Fri Sep 6 18:27:56 2002
193 +++ libstuff/bytesex.c Mon Aug 25 13:17:40 2003
196 #include <mach-o/fat.h>
197 #include <mach-o/loader.h>
198 -#import <mach/m68k/thread_status.h>
199 -#import <mach/ppc/thread_status.h>
200 -#import <mach/m88k/thread_status.h>
201 -#import <mach/i860/thread_status.h>
202 -#import <mach/i386/thread_status.h>
203 -#import <mach/hppa/thread_status.h>
204 -#import <mach/sparc/thread_status.h>
205 +#include <mach/m68k/thread_status.h>
206 +#include <mach/ppc/thread_status.h>
207 +#include <mach/m88k/thread_status.h>
208 +#include <mach/i860/thread_status.h>
209 +#include <mach/i386/thread_status.h>
210 +#include <mach/hppa/thread_status.h>
211 +#include <mach/sparc/thread_status.h>
212 #include <mach-o/nlist.h>
213 #include <mach-o/reloc.h>
214 #include <mach-o/ranlib.h>
215 diff -rub libstuff/checkout.c libstuff/checkout.c
216 --- libstuff/checkout.c Fri Sep 6 18:27:57 2002
217 +++ libstuff/checkout.c Mon Aug 25 13:17:40 2003
220 lc = (struct load_command *)((char *)lc + lc->cmdsize);
222 - if(object->mh->filetype == MH_DYLIB && dl_id == NULL)
223 + if((object->mh->filetype == MH_DYLIB ||
224 + object->mh->filetype == MH_DYLIB_STUB) && dl_id == NULL)
225 fatal_arch(arch, member, "malformed file (no LC_ID_DYLIB load "
226 - "command in MH_DYLIB file): ");
227 + "command in %s file): ", object->mh->filetype == MH_DYLIB ?
228 + "MH_DYLIB" : "MH_DYLIB_STUB");
229 if(object->hints_cmd != NULL){
230 if(object->dyst == NULL && object->hints_cmd->nhints != 0)
231 fatal_arch(arch, member, "malformed file (LC_TWOLEVEL_HINTS "
233 * and a relocatable object file. Since it has a dynamic symbol
234 * table command it could have an indirect symbol table.
236 - if(object->mh->filetype == MH_DYLIB){
237 + if(object->mh->filetype == MH_DYLIB /* ||
238 + object->mh->filetype == MH_DYLIB_STUB */ ){
240 * This is a dynamic shared library.
241 * The order of the symbolic info is:
242 @@ -172,10 +175,10 @@
244 * two-level namespace hints
245 * external relocation entries
246 + * indirect symbol table
250 - * indirect symbol table
252 * strings for external symbols
253 * strings for local symbols
254 diff -rub libstuff/crc32.c libstuff/crc32.c
255 --- libstuff/crc32.c Fri Sep 6 18:27:57 2002
256 +++ libstuff/crc32.c Mon Aug 25 13:19:21 2003
259 #include <sys/types.h>
261 +#if ( defined(__MWERKS__) && !defined(__private_extern__) )
262 +#define __private_extern__ __declspec(private_extern)
263 +#elif ( defined(__linux__) && !defined(__private_extern__) )
264 +#define __private_extern__ extern
267 static const u_int32_t crctab[] = {
269 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
270 diff -rub libstuff/dylib_roots.c libstuff/dylib_roots.c
271 --- libstuff/dylib_roots.c Fri Sep 6 18:27:58 2002
272 +++ libstuff/dylib_roots.c Mon Aug 25 13:17:40 2003
274 enum bool check_result;
277 -static void check_for_install_name(
278 +static void check_for_dylib(
285 ofile_process(image_file_name, NULL, 0, TRUE,
286 - TRUE, TRUE, FALSE, check_for_install_name, &block);
287 + TRUE, TRUE, FALSE, check_for_dylib, &block);
288 if(block.check_result == TRUE)
289 return(image_file_name);
290 free(image_file_name);
291 @@ -148,14 +148,14 @@
294 * Now that we found a file with the same base_name in the root
295 - * check to see that it is a dynamic library with the correct
296 - * install name. Assume it is an if it is not then the
297 - * routine check_for_install_name() will reset the check_result
298 - * in the block passed to it back to FALSE.
299 + * check to see that it is a dynamic library. Assume it is an
300 + * if it is not then the routine check_for_dylib() will
301 + * reset the check_result in the block passed to
302 + * it back to FALSE.
304 block.check_result = TRUE;
305 ofile_process(ftsent->fts_path, NULL, 0, TRUE,
306 - TRUE, TRUE, FALSE, check_for_install_name,&block);
307 + TRUE, TRUE, FALSE, check_for_dylib,&block);
308 if(block.check_result == TRUE){
309 image_file_name = allocate(ftsent->fts_pathlen + 1);
310 strcpy(image_file_name, ftsent->fts_path);
315 -check_for_install_name(
322 struct check_block *block;
323 struct load_command *lc;
324 - struct dylib_command *dl;
328 - printf("In check_for_install_name() ofile->file_name = %s",
329 + printf("In check_for_dylib() ofile->file_name = %s",
331 if(arch_name != NULL)
332 printf(" arch_name = %s\n", arch_name);
334 lc = ofile->load_commands;
335 for(i = 0; i < ofile->mh->ncmds; i++){
336 if(lc->cmd == LC_ID_DYLIB){
337 - dl = (struct dylib_command *)lc;
338 - name = (char *)lc + dl->dylib.name.offset;
339 - if(strncmp(name, "@executable_path/",
340 - sizeof("@executable_path") - 1) == 0)
342 - if(strcmp(name, block->install_name) != 0)
343 - block->check_result = FALSE;
346 lc = (struct load_command *)((char *)lc + lc->cmdsize);
347 Only in libstuff/: dynamic_obj
348 Only in libstuff/: fake-mach.c
349 diff -rub libstuff/get_arch_from_host.c libstuff/get_arch_from_host.c
350 --- libstuff/get_arch_from_host.c Tue Jan 14 23:35:27 2003
351 +++ libstuff/get_arch_from_host.c Mon Aug 25 13:17:40 2003
353 if(specific_arch_flag != NULL)
354 specific_arch_flag->name = "ppc7450";
356 + case CPU_SUBTYPE_POWERPC_970:
357 + if(family_arch_flag != NULL){
358 + family_arch_flag->name = "ppc";
359 + family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
361 + if(specific_arch_flag != NULL)
362 + specific_arch_flag->name = "ppc970";
365 if(family_arch_flag != NULL){
366 family_arch_flag->name = "ppc";
367 Only in libstuff/: gpul_notes
368 Only in libstuff/: libstuff.a
369 Only in libstuff/: libstuff.dylib
370 Only in libstuff/: libstuff_p.a
371 diff -rub libstuff/notes libstuff/notes
372 --- libstuff/notes Tue Jan 14 23:35:27 2003
373 +++ libstuff/notes Mon Aug 25 12:12:33 2003
376 - Deal with LC_PREPAGE and unknown load commands that don't need to be swapped.
378 +Changes for the 5.12 release (the cctools-469 release):
379 +- Fixed a problem with the added checks of the of the dylib_module struct in
380 + ofile.c made in cctools-466 for Radar bug #3208399 where it did not work if
381 + the file was not in host byte sex. The fix was to copy the struct and byte
382 + swap it if needed before doing the checks on the copy of the struct in
383 + check_dylib_module() in ofile.c . Radar bug #3228664.
385 +Changes for the 5.12 release (the cctools-467 release):
386 +- Added support for the PPC_RELOC_LO14_SECTDIFF relocation type used with
387 + double word load/store instructions. Radar bug #3218027.
388 + - Added tests for PPC_RELOC_LO14_SECTDIFF in both reloc_has_pair() and
389 + reloc_is_sectdiff() in reloc.c .
391 +Changes for the 5.12 release (the cctools-466 release):
392 +- Fixed the incorrect casts on the comparison of the nlist struct's n_strx field
393 + where the value being compared to was casted to a long. The correct fix was
394 + to cast n_strx to an unsigned long.
395 +- Added the missing checking of the dylib_module struct in ofile.c so that it
396 + would not return an ofile struct with a bad dylib_module. Also fixed a number
397 + of places the routine Mach_O_error() was called to print an error message but
398 + the code failed to return a failure status. Radar bug #3208399.
400 +Changes for the 5.12 release (the cctools-464 release):
401 +- Made changes to build cleanly with gcc3.3
402 + - Removed -Wno-precomp from the Makefile
403 + - Fixed warnings for "comparison between signed and unsigned" in writeout.c,
404 + symbol_list.c, ofile_get_word.c, round.c, ofile.c, and best_arch.c .
406 +Changes for the 5.12 release (the cctools-462 release):
407 +- Added support for MH_DYLIB_STUB libraries. Radar bug #3193744.
408 + - Did NOT change writeout() in writeout.c to handle the timestamp in
409 + MH_DYLIB_STUB filetypes like MH_DYLIB filetypes as the timestamp should
410 + not be changed or else this would mess up building prebound.
411 + - Changed the routines in ofile.c to handle MH_DYLIB_STUB filetypes like
412 + MH_DYLIB filetypes.
413 + - Changed check_object() in checkout.c to handle MH_DYLIB_STUB filetypes like
414 + MH_DYLIB filetypes.
416 +Changes for the 5.12 release (the cctools-457 release):
417 +- Changed ofile_map() added ofile_map_from_memory() which is everything from
418 + the original ofile_map() except mapping the file. This is needed so the
419 + NSCreateObjectFileImageFromMemory() api can be implemented. Radar bug
422 +Changes for the 5.12 release (the cctools-455 release):
423 +- Changed the code in dylib_roots.c to remove the check that the actual path of
424 + a binary equals the install name of the dynamic library. Radar bug #3147668.
426 +Changes for the 5.12 release (the cctools-450 release):
427 +- Changed get_segalign_from_flag() in arch.c to have 4K returned for i386 also.
428 + Radar bug #3120579.
430 +Changes for the 5.12 release (the cctools-449 release):
431 +- Added the arch flag i686 to be the same as pentpro in arch.c. Radar bug
434 +Changes for the 5.11 release (the cctools-444 release):
435 +- Added the file symbol_list.c which contains the code from strip.c for the
436 + symbol lists. Now also used by ld(1)'s -exported_symbols_list and
437 + -unexported_symbols_list options. Radar bug #3083844.
438 +- Picked up fix to LocForDylib() in SymLoc.c that was crashing when the
439 + DylibProjects directory was empty. Radar bug #3079374.
441 Changes for the 5.11 release (the cctools-440 release):
442 - Fixed the warnings about extra tokens at end of #endif directive in ofile.c
443 (Radar bug #3072042).
444 diff -rub libstuff/ofile.c libstuff/ofile.c
445 --- libstuff/ofile.c Tue Jan 14 23:35:27 2003
446 +++ libstuff/ofile.c Tue Sep 2 20:15:34 2003
449 * @APPLE_LICENSE_HEADER_END@
451 +#include "machine/endian.h"
456 #include <mach/mach.h>
457 #include "stuff/openstep_mach.h"
463 #include <sys/file.h>
464 #include <mach-o/fat.h>
465 #include <mach-o/loader.h>
466 -#import <mach/m68k/thread_status.h>
467 -#import <mach/ppc/thread_status.h>
468 -#import <mach/m88k/thread_status.h>
469 -#import <mach/i860/thread_status.h>
470 -#import <mach/i386/thread_status.h>
471 -#import <mach/sparc/thread_status.h>
472 +#include <mach/m68k/thread_status.h>
473 +#include <mach/ppc/thread_status.h>
474 +#include <mach/m88k/thread_status.h>
475 +#include <mach/i860/thread_status.h>
476 +#include <mach/i386/thread_status.h>
477 +#include <mach/sparc/thread_status.h>
478 #include <mach-o/nlist.h>
479 #include <mach-o/reloc.h>
480 #include "stuff/bool.h"
482 unsigned long *member_name_size);
483 static enum check_type check_Mach_O(
484 struct ofile *ofile);
485 +static enum check_type check_dylib_module(
486 + struct ofile *ofile,
487 + struct symtab_command *st,
488 + struct dysymtab_command *dyst,
490 + unsigned long module_index);
495 else if(process_non_objects == TRUE ||
496 ofile.arch_type == OFILE_Mach_O){
497 if(ofile.arch_type == OFILE_Mach_O &&
498 - ofile.mh->filetype == MH_DYLIB){
499 + (ofile.mh->filetype == MH_DYLIB ||
500 + ofile.mh->filetype == MH_DYLIB_STUB)){
501 if(dylib_flat == TRUE){
502 processor(&ofile, arch_name, cookie);
505 else if(process_non_objects == TRUE ||
506 ofile.arch_type == OFILE_Mach_O){
507 if(ofile.arch_type == OFILE_Mach_O &&
508 - ofile.mh->filetype == MH_DYLIB){
509 + (ofile.mh->filetype == MH_DYLIB ||
510 + ofile.mh->filetype == MH_DYLIB_STUB)){
511 if(dylib_flat == TRUE){
512 processor(&ofile, NULL, cookie);
515 else if(process_non_objects == TRUE ||
516 ofile.arch_type == OFILE_Mach_O){
517 if(ofile.arch_type == OFILE_Mach_O &&
518 - ofile.mh->filetype == MH_DYLIB){
519 + (ofile.mh->filetype == MH_DYLIB ||
520 + ofile.mh->filetype == MH_DYLIB_STUB)){
521 if(dylib_flat == TRUE){
522 processor(&ofile, ofile.arch_flag.name, cookie);
527 if(ofile.mh->magic == SWAP_LONG(MH_MAGIC)){
528 - if(SWAP_LONG(ofile.mh->cputype) ==
529 + if((cpu_type_t)SWAP_LONG(ofile.mh->cputype) ==
530 arch_flags[i].cputype &&
531 - (SWAP_LONG(ofile.mh->cpusubtype) ==
532 + ((cpu_subtype_t)SWAP_LONG(ofile.mh->cpusubtype) ==
533 arch_flags[i].cpusubtype ||
537 if(arch_found == FALSE)
540 - if(ofile.mh->filetype == MH_DYLIB){
541 + if(ofile.mh->filetype == MH_DYLIB ||
542 + ofile.mh->filetype == MH_DYLIB_STUB){
543 if(dylib_flat == TRUE){
544 processor(&ofile, NULL, cookie);
546 @@ -658,19 +670,15 @@
549 struct stat stat_buf;
550 - unsigned long i, size, magic;
551 + unsigned long size, magic;
554 - enum byte_sex host_byte_sex;
555 - struct arch_flag host_arch_flag;
557 - const struct arch_flag *family_arch_flag;
559 magic = 0; /* to shut up the compiler warning message */
560 memset(ofile, '\0', sizeof(struct ofile));
562 /* Open the file and map it in */
563 - if((fd = open(file_name, O_RDONLY)) == -1){
564 + if((fd = open(file_name, O_RDWR)) == -1){
566 return(NSObjectFileImageAccess);
569 printf("Modification time = %ld\n", (long int)stat_buf.st_mtime);
572 + return(ofile_map_from_memory(addr, size, file_name, arch_flag,
573 + object_name, ofile, archives_with_fat_objects));
577 + * ofile_map_from_memory() is the guts of ofile_map() but with an interface
578 + * to pass the address and size of the file already mapped in.
582 +NSObjectFileImageReturnCode
586 +ofile_map_from_memory(
589 +const char *file_name,
590 +const struct arch_flag *arch_flag, /* can be NULL */
591 +const char *object_name, /* can be NULL */
592 +struct ofile *ofile,
593 +enum bool archives_with_fat_objects)
595 + unsigned long i, magic;
596 + enum byte_sex host_byte_sex;
597 + struct arch_flag host_arch_flag;
599 + const struct arch_flag *family_arch_flag;
601 /* fill in the start of the ofile structure */
602 ofile->file_name = savestr(file_name);
603 if(ofile->file_name == NULL)
608 - /* see if this file is Mach-O file */
610 else if(size >= sizeof(struct mach_header) &&
611 (magic == MH_MAGIC || magic == SWAP_LONG(MH_MAGIC))){
612 ofile->file_type = OFILE_Mach_O;
613 @@ -1176,7 +1213,7 @@
617 - if(addr - ofile->file_addr > ofile->file_size){
618 + if(addr - ofile->file_addr > (ptrdiff_t)ofile->file_size){
619 error("fat file: %s offset to architecture %s extends past end "
620 "of file", ofile->file_name, ofile->arch_flag.name);
622 @@ -1327,7 +1364,7 @@
626 - if((addr + SARMAG) - ofile->file_addr > ofile->file_size){
627 + if((addr + SARMAG) - ofile->file_addr > (ptrdiff_t)ofile->file_size){
628 archive_error(ofile, "offset to first member extends past the end "
631 @@ -1832,7 +1869,7 @@
634 * ofile_first_module() set up the ofile structure (the dylib_module field)
635 - * for the first module of an MH_DYLIB file.
636 + * for the first module of an MH_DYLIB or MH_DYLIB_STUB file.
640 @@ -1856,7 +1893,8 @@
642 if(ofile->file_type == OFILE_FAT){
643 if(ofile->arch_type != OFILE_Mach_O &&
644 - ofile->mh->filetype != MH_DYLIB){
645 + (ofile->mh->filetype != MH_DYLIB &&
646 + ofile->mh->filetype != MH_DYLIB_STUB)){
647 error("ofile_first_module() called on fat file: %s with a "
648 "non-MH_DYLIB architecture or no architecture selected\n",
650 @@ -1864,7 +1902,8 @@
653 else if(ofile->arch_type != OFILE_Mach_O &&
654 - ofile->mh->filetype != MH_DYLIB){
655 + (ofile->mh->filetype != MH_DYLIB &&
656 + ofile->mh->filetype != MH_DYLIB_STUB)){
657 error("ofile_first_module() called and file type of %s is "
658 "non-MH_DYLIB\n", ofile->file_name);
660 @@ -1902,20 +1941,22 @@
661 m = *ofile->dylib_module;
663 swap_dylib_module(&m, 1, host_byte_sex);
664 + if(check_dylib_module(ofile, st, dyst, strings, 0) == CHECK_BAD)
666 ofile->dylib_module_name = strings + m.module_name;
671 * ofile_next_module() set up the ofile structure (the dylib_module field)
672 - * for the next module of an MH_DYLIB file.
673 + * for the next module of an MH_DYLIB or MH_DYLIB_STUB file.
681 + unsigned long i, module_index;
682 struct symtab_command *st;
683 struct dysymtab_command *dyst;
684 struct load_command *lc;
685 @@ -1926,7 +1967,8 @@
687 if(ofile->file_type == OFILE_FAT){
688 if(ofile->arch_type != OFILE_Mach_O &&
689 - ofile->mh->filetype != MH_DYLIB){
690 + (ofile->mh->filetype != MH_DYLIB &&
691 + ofile->mh->filetype != MH_DYLIB_STUB)){
692 error("ofile_next_module() called on fat file: %s with a "
693 "non-MH_DYLIB architecture or no architecture selected\n",
695 @@ -1934,7 +1976,8 @@
698 else if(ofile->arch_type != OFILE_Mach_O &&
699 - ofile->mh->filetype != MH_DYLIB){
700 + (ofile->mh->filetype != MH_DYLIB &&
701 + ofile->mh->filetype != MH_DYLIB_STUB)){
702 error("ofile_next_module() called and file type of %s is "
703 "non-MH_DYLIB\n", ofile->file_name);
705 @@ -1959,7 +2002,8 @@
709 - if((ofile->dylib_module + 1) - ofile->modtab >= ofile->nmodtab)
710 + module_index = (ofile->dylib_module + 1) - ofile->modtab;
711 + if(module_index >= ofile->nmodtab)
714 ofile->dylib_module++;
715 @@ -1969,13 +2013,17 @@
716 m = *ofile->dylib_module;
718 swap_dylib_module(&m, 1, host_byte_sex);
719 + if(check_dylib_module(ofile, st, dyst, strings, module_index) ==
722 ofile->dylib_module_name = strings + m.module_name;
727 * ofile_specific_module() set up the ofile structure (the dylib_module fields)
728 - * for the specified module, module_name, of an MH_DYLIB file.
729 + * for the specified module, module_name, of an MH_DYLIB or an MH_DYLIB_STUB
734 @@ -2000,7 +2048,8 @@
736 if(ofile->file_type == OFILE_FAT){
737 if(ofile->arch_type != OFILE_Mach_O &&
738 - ofile->mh->filetype != MH_DYLIB){
739 + (ofile->mh->filetype != MH_DYLIB &&
740 + ofile->mh->filetype != MH_DYLIB_STUB)){
741 error("ofile_specific_module() called on fat file: %s with a "
742 "non-MH_DYLIB architecture or no architecture selected\n",
744 @@ -2008,7 +2057,8 @@
747 else if(ofile->arch_type != OFILE_Mach_O &&
748 - ofile->mh->filetype != MH_DYLIB){
749 + (ofile->mh->filetype != MH_DYLIB &&
750 + ofile->mh->filetype != MH_DYLIB_STUB)){
751 error("ofile_specific_module() called and file type of %s is "
752 "non-MH_DYLIB\n", ofile->file_name);
754 @@ -2047,8 +2097,10 @@
757 swap_dylib_module(&m, 1, host_byte_sex);
758 - if(strcmp(module_name, strings + m.module_name) == 0){
759 ofile->dylib_module = p;
760 + if(check_dylib_module(ofile, st, dyst, strings, i) == CHECK_BAD)
762 + if(strcmp(module_name, strings + m.module_name) == 0){
763 ofile->dylib_module_name = strings + m.module_name;
766 @@ -2520,10 +2572,12 @@
769 if(ofile->file_type == OFILE_FAT){
770 - if(ofile->fat_archs[ofile->narch].cputype != ofile->mh->cputype)
771 + if(ofile->fat_archs[ofile->narch].cputype != ofile->mh->cputype){
772 Mach_O_error(ofile, "malformed fat file (fat header "
773 "architecture: %lu's cputype does not match "
774 "object file's mach header)", ofile->narch);
779 * Make a pass through the load commands checking them to the level
780 @@ -3595,55 +3649,73 @@
786 Mach_O_error(ofile, "truncated or malformed object (contains "
787 "LC_DYSYMTAB load command without a LC_SYMTAB load command)");
793 if(dyst->nlocalsym != 0 &&
794 - dyst->ilocalsym > st->nsyms)
795 + dyst->ilocalsym > st->nsyms){
796 Mach_O_error(ofile, "truncated or malformed object "
797 "(ilocalsym in LC_DYSYMTAB load command extends past "
798 "the end of the symbol table)");
801 if(dyst->nlocalsym != 0 &&
802 - dyst->ilocalsym + dyst->nlocalsym > st->nsyms)
803 + dyst->ilocalsym + dyst->nlocalsym > st->nsyms){
804 Mach_O_error(ofile, "truncated or malformed object "
805 "(ilocalsym plus nlocalsym in LC_DYSYMTAB load command "
806 "extends past the end of the symbol table)");
810 if(dyst->nextdefsym != 0 &&
811 - dyst->iextdefsym > st->nsyms)
812 + dyst->iextdefsym > st->nsyms){
813 Mach_O_error(ofile, "truncated or malformed object "
814 "(iextdefsym in LC_DYSYMTAB load command extends past "
815 "the end of the symbol table)");
818 if(dyst->nextdefsym != 0 &&
819 - dyst->iextdefsym + dyst->nextdefsym > st->nsyms)
820 + dyst->iextdefsym + dyst->nextdefsym > st->nsyms){
821 Mach_O_error(ofile, "truncated or malformed object "
822 "(iextdefsym plus nextdefsym in LC_DYSYMTAB load "
823 "command extends past the end of the symbol table)");
827 if(dyst->nundefsym != 0 &&
828 - dyst->iundefsym > st->nsyms)
829 + dyst->iundefsym > st->nsyms){
830 Mach_O_error(ofile, "truncated or malformed object "
831 "(iundefsym in LC_DYSYMTAB load command extends past "
832 "the end of the symbol table)");
835 if(dyst->nundefsym != 0 &&
836 - dyst->iundefsym + dyst->nundefsym > st->nsyms)
837 + dyst->iundefsym + dyst->nundefsym > st->nsyms){
838 Mach_O_error(ofile, "truncated or malformed object "
839 "(iundefsym plus nundefsym in LC_DYSYMTAB load command "
840 "extends past the end of the symbol table)");
844 - if(rc->init_module > dyst->nmodtab)
845 + if(rc->init_module > dyst->nmodtab){
846 Mach_O_error(ofile, "malformed object (init_module in "
847 "LC_ROUTINES load command extends past the end of "
848 "the module table)");
853 - if(hints->nhints != dyst->nundefsym)
854 + if(hints->nhints != dyst->nundefsym){
855 Mach_O_error(ofile, "malformed object (nhints in "
856 "LC_TWOLEVEL_HINTS load command not the same as "
857 "nundefsym in LC_DYSYMTAB load command)");
863 @@ -3655,6 +3727,109 @@
866 /* looks good return ok */
867 + return(CHECK_GOOD);
872 + * check_dylib_module() checks the object file's dylib_module as referenced
873 + * by the dylib_module field in the ofile for correctness.
878 +struct ofile *ofile,
879 +struct symtab_command *st,
880 +struct dysymtab_command *dyst,
882 +unsigned long module_index)
885 + return(CHECK_GOOD);
886 +#else /* !defined OTOOL */
888 + enum byte_sex host_byte_sex;
890 + struct dylib_module m;
892 + m = *ofile->dylib_module;
893 + host_byte_sex = get_host_byte_sex();
894 + swapped = (enum bool)(host_byte_sex != ofile->object_byte_sex);
896 + swap_dylib_module(&m, 1, host_byte_sex);
898 + if(m.module_name > st->strsize){
899 + Mach_O_error(ofile, "truncated or malformed object (module_name "
900 + "of module table entry %lu past the end of the string table)",
904 + for(i = m.module_name; i < st->strsize && strings[i] != '\0'; i++)
906 + if(i >= st->strsize){
907 + Mach_O_error(ofile, "truncated or malformed object (module_name "
908 + "of module table entry %lu extends past the end of the string "
909 + "table)", module_index);
913 + if(m.nextdefsym != 0){
914 + if(m.iextdefsym > st->nsyms){
915 + Mach_O_error(ofile, "truncated or malformed object (iextdefsym "
916 + "field of module table entry %lu past the end of the "
917 + "symbol table", module_index);
920 + if(m.iextdefsym + m.nextdefsym > st->nsyms){
921 + Mach_O_error(ofile, "truncated or malformed object (iextdefsym "
922 + "field of module table entry %lu plus nextdefsym field "
923 + "extends past the end of the symbol table", module_index);
927 + if(m.nlocalsym != 0){
928 + if(m.ilocalsym > st->nsyms){
929 + Mach_O_error(ofile, "truncated or malformed object (ilocalsym "
930 + "field of module table entry %lu past the end of the "
931 + "symbol table", module_index);
934 + if(m.ilocalsym + m.nlocalsym > st->nsyms){
935 + Mach_O_error(ofile, "truncated or malformed object (ilocalsym "
936 + "field of module table entry %lu plus nlocalsym field "
937 + "extends past the end of the symbol table", module_index);
941 + if(m.nrefsym != 0){
942 + if(m.irefsym > dyst->nextrefsyms){
943 + Mach_O_error(ofile, "truncated or malformed object (irefsym "
944 + "field of module table entry %lu past the end of the "
945 + "reference table", module_index);
948 + if(m.irefsym + m.nrefsym > dyst->nextrefsyms){
949 + Mach_O_error(ofile, "truncated or malformed object (irefsym "
950 + "field of module table entry %lu plus nrefsym field "
951 + "extends past the end of the reference table",module_index);
955 + if(m.nextrel != 0){
956 + if(m.iextrel > dyst->extreloff){
957 + Mach_O_error(ofile, "truncated or malformed object (iextrel "
958 + "field of module table entry %lu past the end of the "
959 + "external relocation enrties", module_index);
962 + if(m.iextrel + m.nextrel > dyst->extreloff){
963 + Mach_O_error(ofile, "truncated or malformed object (iextrel "
964 + "field of module table entry %lu plus nextrel field "
965 + "extends past the end of the external relocation enrties",
973 diff -rub libstuff/ofile_get_word.c libstuff/ofile_get_word.c
974 --- libstuff/ofile_get_word.c Fri Sep 6 18:28:00 2002
975 +++ libstuff/ofile_get_word.c Mon Aug 25 13:17:40 2003
978 void *get_word_data /* struct mach_object_file *ofile */ )
981 + unsigned long i, j;
982 struct load_command *lc;
983 struct segment_command *sg;
985 diff -rub libstuff/print.c libstuff/print.c
986 --- libstuff/print.c Tue Apr 30 00:37:20 2002
987 +++ libstuff/print.c Mon Aug 25 13:17:40 2003
990 * @APPLE_LICENSE_HEADER_END@
993 -#import "stuff/print.h"
995 +#include "stuff/print.h"
998 * All printing of all messages for ofile functions goes through this function.
999 Only in libstuff/: profile_obj
1000 diff -rub libstuff/reloc.c libstuff/reloc.c
1001 --- libstuff/reloc.c Tue Jan 14 23:35:27 2003
1002 +++ libstuff/reloc.c Mon Aug 25 13:17:40 2003
1004 r_type == PPC_RELOC_SECTDIFF ||
1005 r_type == PPC_RELOC_HI16_SECTDIFF ||
1006 r_type == PPC_RELOC_LO16_SECTDIFF ||
1007 + r_type == PPC_RELOC_LO14_SECTDIFF ||
1008 r_type == PPC_RELOC_HA16_SECTDIFF ||
1009 r_type == PPC_RELOC_JBSR)
1012 if(r_type == PPC_RELOC_SECTDIFF ||
1013 r_type == PPC_RELOC_HI16_SECTDIFF ||
1014 r_type == PPC_RELOC_LO16_SECTDIFF ||
1015 + r_type == PPC_RELOC_LO14_SECTDIFF ||
1016 r_type == PPC_RELOC_HA16_SECTDIFF)
1019 diff -rub libstuff/round.c libstuff/round.c
1020 --- libstuff/round.c Tue Apr 30 00:37:20 2002
1021 +++ libstuff/round.c Mon Aug 25 13:17:40 2003
1023 * round() rounds v to a multiple of r.
1034 Only in libstuff/: shlib_obj
1035 Only in libstuff/: static_obj
1036 diff -rub libstuff/swap_headers.c libstuff/swap_headers.c
1037 --- libstuff/swap_headers.c Tue Jan 14 23:35:27 2003
1038 +++ libstuff/swap_headers.c Mon Aug 25 13:17:40 2003
1040 * @APPLE_LICENSE_HEADER_END@
1042 #include <mach-o/loader.h>
1043 -#import <mach/m68k/thread_status.h>
1044 -#import <mach/ppc/thread_status.h>
1045 -#import <mach/m88k/thread_status.h>
1046 -#import <mach/i860/thread_status.h>
1047 -#import <mach/i386/thread_status.h>
1048 -#import <mach/hppa/thread_status.h>
1049 -#import <mach/sparc/thread_status.h>
1050 +#include <mach/m68k/thread_status.h>
1051 +#include <mach/ppc/thread_status.h>
1052 +#include <mach/m88k/thread_status.h>
1053 +#include <mach/i860/thread_status.h>
1054 +#include <mach/i386/thread_status.h>
1055 +#include <mach/hppa/thread_status.h>
1056 +#include <mach/sparc/thread_status.h>
1057 #include "stuff/bool.h"
1058 #include "stuff/bytesex.h"
1059 #include "stuff/errors.h"
1060 Only in libstuff/: symbol_list.c
1061 diff -rub libstuff/writeout.c libstuff/writeout.c
1062 --- libstuff/writeout.c Fri Sep 6 18:28:00 2002
1063 +++ libstuff/writeout.c Mon Aug 25 13:17:40 2003
1065 write_size = (file + file_size) - p;
1067 write_size = WRITE_SIZE;
1068 - if(write(fd, p, write_size) != write_size){
1069 + if(write(fd, p, write_size) != (int)write_size){
1070 system_error("can't write output file: %s", output);
1077 - if(write(fd, file, file_size) != file_size){
1078 + if(write(fd, file, file_size) != (int)file_size){
1079 system_error("can't write output file: %s", output);
1083 strings_size = object->output_strings_size;
1085 for(j = 0; j < nsymbols; j++){
1086 - if(symbols[j].n_un.n_strx > strings_size)
1087 + if((unsigned long)symbols[j].n_un.n_strx > strings_size)
1089 if(toc_symbol(symbols + j, commons_in_toc,
1090 object->sections) == TRUE){
1093 enum bool library_warnings)
1097 enum bool multiple_defs;
1098 struct member *member;
1100 @@ -1008,7 +1008,7 @@
1101 * only once (marked by changing the sign of their ran_off).
1103 multiple_defs = FALSE;
1104 - for(i = 0; i < (long)arch->toc_nranlibs - 1; i++){
1105 + for(i = 0; i < arch->toc_nranlibs - 1; i++){
1106 if(strcmp(arch->toc_ranlibs[i].ran_un.ran_name,
1107 arch->toc_ranlibs[i+1].ran_un.ran_name) == 0){
1108 if(multiple_defs == FALSE){