2 diff -ubr libstuff/Makefile libstuff/Makefile
3 --- libstuff/Makefile Fri Sep 6 18:27:55 2002
4 +++ libstuff/Makefile Mon Aug 25 21:54:30 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__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 -ubr 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 -ubr 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 -ubr 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 -ubr 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 -ubr 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 -ubr 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 -ubr 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: fake-mach.c
348 diff -ubr libstuff/get_arch_from_host.c libstuff/get_arch_from_host.c
349 --- libstuff/get_arch_from_host.c Tue Jan 14 23:35:27 2003
350 +++ libstuff/get_arch_from_host.c Mon Aug 25 13:17:40 2003
352 if(specific_arch_flag != NULL)
353 specific_arch_flag->name = "ppc7450";
355 + case CPU_SUBTYPE_POWERPC_970:
356 + if(family_arch_flag != NULL){
357 + family_arch_flag->name = "ppc";
358 + family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
360 + if(specific_arch_flag != NULL)
361 + specific_arch_flag->name = "ppc970";
364 if(family_arch_flag != NULL){
365 family_arch_flag->name = "ppc";
366 Only in libstuff: gpul_notes
367 diff -ubr libstuff/notes libstuff/notes
368 --- libstuff/notes Tue Jan 14 23:35:27 2003
369 +++ libstuff/notes Mon Aug 25 12:12:33 2003
372 - Deal with LC_PREPAGE and unknown load commands that don't need to be swapped.
374 +Changes for the 5.12 release (the cctools-469 release):
375 +- Fixed a problem with the added checks of the of the dylib_module struct in
376 + ofile.c made in cctools-466 for Radar bug #3208399 where it did not work if
377 + the file was not in host byte sex. The fix was to copy the struct and byte
378 + swap it if needed before doing the checks on the copy of the struct in
379 + check_dylib_module() in ofile.c . Radar bug #3228664.
381 +Changes for the 5.12 release (the cctools-467 release):
382 +- Added support for the PPC_RELOC_LO14_SECTDIFF relocation type used with
383 + double word load/store instructions. Radar bug #3218027.
384 + - Added tests for PPC_RELOC_LO14_SECTDIFF in both reloc_has_pair() and
385 + reloc_is_sectdiff() in reloc.c .
387 +Changes for the 5.12 release (the cctools-466 release):
388 +- Fixed the incorrect casts on the comparison of the nlist struct's n_strx field
389 + where the value being compared to was casted to a long. The correct fix was
390 + to cast n_strx to an unsigned long.
391 +- Added the missing checking of the dylib_module struct in ofile.c so that it
392 + would not return an ofile struct with a bad dylib_module. Also fixed a number
393 + of places the routine Mach_O_error() was called to print an error message but
394 + the code failed to return a failure status. Radar bug #3208399.
396 +Changes for the 5.12 release (the cctools-464 release):
397 +- Made changes to build cleanly with gcc3.3
398 + - Removed -Wno-precomp from the Makefile
399 + - Fixed warnings for "comparison between signed and unsigned" in writeout.c,
400 + symbol_list.c, ofile_get_word.c, round.c, ofile.c, and best_arch.c .
402 +Changes for the 5.12 release (the cctools-462 release):
403 +- Added support for MH_DYLIB_STUB libraries. Radar bug #3193744.
404 + - Did NOT change writeout() in writeout.c to handle the timestamp in
405 + MH_DYLIB_STUB filetypes like MH_DYLIB filetypes as the timestamp should
406 + not be changed or else this would mess up building prebound.
407 + - Changed the routines in ofile.c to handle MH_DYLIB_STUB filetypes like
408 + MH_DYLIB filetypes.
409 + - Changed check_object() in checkout.c to handle MH_DYLIB_STUB filetypes like
410 + MH_DYLIB filetypes.
412 +Changes for the 5.12 release (the cctools-457 release):
413 +- Changed ofile_map() added ofile_map_from_memory() which is everything from
414 + the original ofile_map() except mapping the file. This is needed so the
415 + NSCreateObjectFileImageFromMemory() api can be implemented. Radar bug
418 +Changes for the 5.12 release (the cctools-455 release):
419 +- Changed the code in dylib_roots.c to remove the check that the actual path of
420 + a binary equals the install name of the dynamic library. Radar bug #3147668.
422 +Changes for the 5.12 release (the cctools-450 release):
423 +- Changed get_segalign_from_flag() in arch.c to have 4K returned for i386 also.
424 + Radar bug #3120579.
426 +Changes for the 5.12 release (the cctools-449 release):
427 +- Added the arch flag i686 to be the same as pentpro in arch.c. Radar bug
430 +Changes for the 5.11 release (the cctools-444 release):
431 +- Added the file symbol_list.c which contains the code from strip.c for the
432 + symbol lists. Now also used by ld(1)'s -exported_symbols_list and
433 + -unexported_symbols_list options. Radar bug #3083844.
434 +- Picked up fix to LocForDylib() in SymLoc.c that was crashing when the
435 + DylibProjects directory was empty. Radar bug #3079374.
437 Changes for the 5.11 release (the cctools-440 release):
438 - Fixed the warnings about extra tokens at end of #endif directive in ofile.c
439 (Radar bug #3072042).
440 diff -ubr libstuff/ofile.c libstuff/ofile.c
441 --- libstuff/ofile.c Tue Jan 14 23:35:27 2003
442 +++ libstuff/ofile.c Mon Aug 25 23:49:59 2003
445 #include <mach/mach.h>
446 #include "stuff/openstep_mach.h"
452 #include <sys/file.h>
453 #include <mach-o/fat.h>
454 #include <mach-o/loader.h>
455 -#import <mach/m68k/thread_status.h>
456 -#import <mach/ppc/thread_status.h>
457 -#import <mach/m88k/thread_status.h>
458 -#import <mach/i860/thread_status.h>
459 -#import <mach/i386/thread_status.h>
460 -#import <mach/sparc/thread_status.h>
461 +#include <mach/m68k/thread_status.h>
462 +#include <mach/ppc/thread_status.h>
463 +#include <mach/m88k/thread_status.h>
464 +#include <mach/i860/thread_status.h>
465 +#include <mach/i386/thread_status.h>
466 +#include <mach/sparc/thread_status.h>
467 #include <mach-o/nlist.h>
468 #include <mach-o/reloc.h>
469 #include "stuff/bool.h"
471 unsigned long *member_name_size);
472 static enum check_type check_Mach_O(
473 struct ofile *ofile);
474 +static enum check_type check_dylib_module(
475 + struct ofile *ofile,
476 + struct symtab_command *st,
477 + struct dysymtab_command *dyst,
479 + unsigned long module_index);
484 else if(process_non_objects == TRUE ||
485 ofile.arch_type == OFILE_Mach_O){
486 if(ofile.arch_type == OFILE_Mach_O &&
487 - ofile.mh->filetype == MH_DYLIB){
488 + (ofile.mh->filetype == MH_DYLIB ||
489 + ofile.mh->filetype == MH_DYLIB_STUB)){
490 if(dylib_flat == TRUE){
491 processor(&ofile, arch_name, cookie);
494 else if(process_non_objects == TRUE ||
495 ofile.arch_type == OFILE_Mach_O){
496 if(ofile.arch_type == OFILE_Mach_O &&
497 - ofile.mh->filetype == MH_DYLIB){
498 + (ofile.mh->filetype == MH_DYLIB ||
499 + ofile.mh->filetype == MH_DYLIB_STUB)){
500 if(dylib_flat == TRUE){
501 processor(&ofile, NULL, cookie);
504 else if(process_non_objects == TRUE ||
505 ofile.arch_type == OFILE_Mach_O){
506 if(ofile.arch_type == OFILE_Mach_O &&
507 - ofile.mh->filetype == MH_DYLIB){
508 + (ofile.mh->filetype == MH_DYLIB ||
509 + ofile.mh->filetype == MH_DYLIB_STUB)){
510 if(dylib_flat == TRUE){
511 processor(&ofile, ofile.arch_flag.name, cookie);
516 if(ofile.mh->magic == SWAP_LONG(MH_MAGIC)){
517 - if(SWAP_LONG(ofile.mh->cputype) ==
518 + if((cpu_type_t)SWAP_LONG(ofile.mh->cputype) ==
519 arch_flags[i].cputype &&
520 - (SWAP_LONG(ofile.mh->cpusubtype) ==
521 + ((cpu_subtype_t)SWAP_LONG(ofile.mh->cpusubtype) ==
522 arch_flags[i].cpusubtype ||
526 if(arch_found == FALSE)
529 - if(ofile.mh->filetype == MH_DYLIB){
530 + if(ofile.mh->filetype == MH_DYLIB ||
531 + ofile.mh->filetype == MH_DYLIB_STUB){
532 if(dylib_flat == TRUE){
533 processor(&ofile, NULL, cookie);
535 @@ -658,19 +669,15 @@
538 struct stat stat_buf;
539 - unsigned long i, size, magic;
540 + unsigned long size, magic;
543 - enum byte_sex host_byte_sex;
544 - struct arch_flag host_arch_flag;
546 - const struct arch_flag *family_arch_flag;
548 magic = 0; /* to shut up the compiler warning message */
549 memset(ofile, '\0', sizeof(struct ofile));
551 /* Open the file and map it in */
552 - if((fd = open(file_name, O_RDONLY)) == -1){
553 + if((fd = open(file_name, O_RDWR)) == -1){
555 return(NSObjectFileImageAccess);
558 printf("Modification time = %ld\n", (long int)stat_buf.st_mtime);
561 + return(ofile_map_from_memory(addr, size, file_name, arch_flag,
562 + object_name, ofile, archives_with_fat_objects));
566 + * ofile_map_from_memory() is the guts of ofile_map() but with an interface
567 + * to pass the address and size of the file already mapped in.
571 +NSObjectFileImageReturnCode
575 +ofile_map_from_memory(
578 +const char *file_name,
579 +const struct arch_flag *arch_flag, /* can be NULL */
580 +const char *object_name, /* can be NULL */
581 +struct ofile *ofile,
582 +enum bool archives_with_fat_objects)
584 + unsigned long i, magic;
585 + enum byte_sex host_byte_sex;
586 + struct arch_flag host_arch_flag;
588 + const struct arch_flag *family_arch_flag;
590 /* fill in the start of the ofile structure */
591 ofile->file_name = savestr(file_name);
592 if(ofile->file_name == NULL)
593 @@ -1176,7 +1212,7 @@
597 - if(addr - ofile->file_addr > ofile->file_size){
598 + if(addr - ofile->file_addr > (ptrdiff_t)ofile->file_size){
599 error("fat file: %s offset to architecture %s extends past end "
600 "of file", ofile->file_name, ofile->arch_flag.name);
602 @@ -1327,7 +1363,7 @@
606 - if((addr + SARMAG) - ofile->file_addr > ofile->file_size){
607 + if((addr + SARMAG) - ofile->file_addr > (ptrdiff_t)ofile->file_size){
608 archive_error(ofile, "offset to first member extends past the end "
611 @@ -1832,7 +1868,7 @@
614 * ofile_first_module() set up the ofile structure (the dylib_module field)
615 - * for the first module of an MH_DYLIB file.
616 + * for the first module of an MH_DYLIB or MH_DYLIB_STUB file.
620 @@ -1856,7 +1892,8 @@
622 if(ofile->file_type == OFILE_FAT){
623 if(ofile->arch_type != OFILE_Mach_O &&
624 - ofile->mh->filetype != MH_DYLIB){
625 + (ofile->mh->filetype != MH_DYLIB &&
626 + ofile->mh->filetype != MH_DYLIB_STUB)){
627 error("ofile_first_module() called on fat file: %s with a "
628 "non-MH_DYLIB architecture or no architecture selected\n",
630 @@ -1864,7 +1901,8 @@
633 else if(ofile->arch_type != OFILE_Mach_O &&
634 - ofile->mh->filetype != MH_DYLIB){
635 + (ofile->mh->filetype != MH_DYLIB &&
636 + ofile->mh->filetype != MH_DYLIB_STUB)){
637 error("ofile_first_module() called and file type of %s is "
638 "non-MH_DYLIB\n", ofile->file_name);
640 @@ -1902,20 +1940,22 @@
641 m = *ofile->dylib_module;
643 swap_dylib_module(&m, 1, host_byte_sex);
644 + if(check_dylib_module(ofile, st, dyst, strings, 0) == CHECK_BAD)
646 ofile->dylib_module_name = strings + m.module_name;
651 * ofile_next_module() set up the ofile structure (the dylib_module field)
652 - * for the next module of an MH_DYLIB file.
653 + * for the next module of an MH_DYLIB or MH_DYLIB_STUB file.
661 + unsigned long i, module_index;
662 struct symtab_command *st;
663 struct dysymtab_command *dyst;
664 struct load_command *lc;
665 @@ -1926,7 +1966,8 @@
667 if(ofile->file_type == OFILE_FAT){
668 if(ofile->arch_type != OFILE_Mach_O &&
669 - ofile->mh->filetype != MH_DYLIB){
670 + (ofile->mh->filetype != MH_DYLIB &&
671 + ofile->mh->filetype != MH_DYLIB_STUB)){
672 error("ofile_next_module() called on fat file: %s with a "
673 "non-MH_DYLIB architecture or no architecture selected\n",
675 @@ -1934,7 +1975,8 @@
678 else if(ofile->arch_type != OFILE_Mach_O &&
679 - ofile->mh->filetype != MH_DYLIB){
680 + (ofile->mh->filetype != MH_DYLIB &&
681 + ofile->mh->filetype != MH_DYLIB_STUB)){
682 error("ofile_next_module() called and file type of %s is "
683 "non-MH_DYLIB\n", ofile->file_name);
685 @@ -1959,7 +2001,8 @@
689 - if((ofile->dylib_module + 1) - ofile->modtab >= ofile->nmodtab)
690 + module_index = (ofile->dylib_module + 1) - ofile->modtab;
691 + if(module_index >= ofile->nmodtab)
694 ofile->dylib_module++;
695 @@ -1969,13 +2012,17 @@
696 m = *ofile->dylib_module;
698 swap_dylib_module(&m, 1, host_byte_sex);
699 + if(check_dylib_module(ofile, st, dyst, strings, module_index) ==
702 ofile->dylib_module_name = strings + m.module_name;
707 * ofile_specific_module() set up the ofile structure (the dylib_module fields)
708 - * for the specified module, module_name, of an MH_DYLIB file.
709 + * for the specified module, module_name, of an MH_DYLIB or an MH_DYLIB_STUB
714 @@ -2000,7 +2047,8 @@
716 if(ofile->file_type == OFILE_FAT){
717 if(ofile->arch_type != OFILE_Mach_O &&
718 - ofile->mh->filetype != MH_DYLIB){
719 + (ofile->mh->filetype != MH_DYLIB &&
720 + ofile->mh->filetype != MH_DYLIB_STUB)){
721 error("ofile_specific_module() called on fat file: %s with a "
722 "non-MH_DYLIB architecture or no architecture selected\n",
724 @@ -2008,7 +2056,8 @@
727 else if(ofile->arch_type != OFILE_Mach_O &&
728 - ofile->mh->filetype != MH_DYLIB){
729 + (ofile->mh->filetype != MH_DYLIB &&
730 + ofile->mh->filetype != MH_DYLIB_STUB)){
731 error("ofile_specific_module() called and file type of %s is "
732 "non-MH_DYLIB\n", ofile->file_name);
734 @@ -2047,8 +2096,10 @@
737 swap_dylib_module(&m, 1, host_byte_sex);
738 - if(strcmp(module_name, strings + m.module_name) == 0){
739 ofile->dylib_module = p;
740 + if(check_dylib_module(ofile, st, dyst, strings, i) == CHECK_BAD)
742 + if(strcmp(module_name, strings + m.module_name) == 0){
743 ofile->dylib_module_name = strings + m.module_name;
746 @@ -2520,10 +2571,12 @@
749 if(ofile->file_type == OFILE_FAT){
750 - if(ofile->fat_archs[ofile->narch].cputype != ofile->mh->cputype)
751 + if(ofile->fat_archs[ofile->narch].cputype != ofile->mh->cputype){
752 Mach_O_error(ofile, "malformed fat file (fat header "
753 "architecture: %lu's cputype does not match "
754 "object file's mach header)", ofile->narch);
759 * Make a pass through the load commands checking them to the level
760 @@ -3595,55 +3648,73 @@
766 Mach_O_error(ofile, "truncated or malformed object (contains "
767 "LC_DYSYMTAB load command without a LC_SYMTAB load command)");
773 if(dyst->nlocalsym != 0 &&
774 - dyst->ilocalsym > st->nsyms)
775 + dyst->ilocalsym > st->nsyms){
776 Mach_O_error(ofile, "truncated or malformed object "
777 "(ilocalsym in LC_DYSYMTAB load command extends past "
778 "the end of the symbol table)");
781 if(dyst->nlocalsym != 0 &&
782 - dyst->ilocalsym + dyst->nlocalsym > st->nsyms)
783 + dyst->ilocalsym + dyst->nlocalsym > st->nsyms){
784 Mach_O_error(ofile, "truncated or malformed object "
785 "(ilocalsym plus nlocalsym in LC_DYSYMTAB load command "
786 "extends past the end of the symbol table)");
790 if(dyst->nextdefsym != 0 &&
791 - dyst->iextdefsym > st->nsyms)
792 + dyst->iextdefsym > st->nsyms){
793 Mach_O_error(ofile, "truncated or malformed object "
794 "(iextdefsym in LC_DYSYMTAB load command extends past "
795 "the end of the symbol table)");
798 if(dyst->nextdefsym != 0 &&
799 - dyst->iextdefsym + dyst->nextdefsym > st->nsyms)
800 + dyst->iextdefsym + dyst->nextdefsym > st->nsyms){
801 Mach_O_error(ofile, "truncated or malformed object "
802 "(iextdefsym plus nextdefsym in LC_DYSYMTAB load "
803 "command extends past the end of the symbol table)");
807 if(dyst->nundefsym != 0 &&
808 - dyst->iundefsym > st->nsyms)
809 + dyst->iundefsym > st->nsyms){
810 Mach_O_error(ofile, "truncated or malformed object "
811 "(iundefsym in LC_DYSYMTAB load command extends past "
812 "the end of the symbol table)");
815 if(dyst->nundefsym != 0 &&
816 - dyst->iundefsym + dyst->nundefsym > st->nsyms)
817 + dyst->iundefsym + dyst->nundefsym > st->nsyms){
818 Mach_O_error(ofile, "truncated or malformed object "
819 "(iundefsym plus nundefsym in LC_DYSYMTAB load command "
820 "extends past the end of the symbol table)");
824 - if(rc->init_module > dyst->nmodtab)
825 + if(rc->init_module > dyst->nmodtab){
826 Mach_O_error(ofile, "malformed object (init_module in "
827 "LC_ROUTINES load command extends past the end of "
828 "the module table)");
833 - if(hints->nhints != dyst->nundefsym)
834 + if(hints->nhints != dyst->nundefsym){
835 Mach_O_error(ofile, "malformed object (nhints in "
836 "LC_TWOLEVEL_HINTS load command not the same as "
837 "nundefsym in LC_DYSYMTAB load command)");
843 @@ -3655,6 +3726,109 @@
846 /* looks good return ok */
847 + return(CHECK_GOOD);
852 + * check_dylib_module() checks the object file's dylib_module as referenced
853 + * by the dylib_module field in the ofile for correctness.
858 +struct ofile *ofile,
859 +struct symtab_command *st,
860 +struct dysymtab_command *dyst,
862 +unsigned long module_index)
865 + return(CHECK_GOOD);
866 +#else /* !defined OTOOL */
868 + enum byte_sex host_byte_sex;
870 + struct dylib_module m;
872 + m = *ofile->dylib_module;
873 + host_byte_sex = get_host_byte_sex();
874 + swapped = (enum bool)(host_byte_sex != ofile->object_byte_sex);
876 + swap_dylib_module(&m, 1, host_byte_sex);
878 + if(m.module_name > st->strsize){
879 + Mach_O_error(ofile, "truncated or malformed object (module_name "
880 + "of module table entry %lu past the end of the string table)",
884 + for(i = m.module_name; i < st->strsize && strings[i] != '\0'; i++)
886 + if(i >= st->strsize){
887 + Mach_O_error(ofile, "truncated or malformed object (module_name "
888 + "of module table entry %lu extends past the end of the string "
889 + "table)", module_index);
893 + if(m.nextdefsym != 0){
894 + if(m.iextdefsym > st->nsyms){
895 + Mach_O_error(ofile, "truncated or malformed object (iextdefsym "
896 + "field of module table entry %lu past the end of the "
897 + "symbol table", module_index);
900 + if(m.iextdefsym + m.nextdefsym > st->nsyms){
901 + Mach_O_error(ofile, "truncated or malformed object (iextdefsym "
902 + "field of module table entry %lu plus nextdefsym field "
903 + "extends past the end of the symbol table", module_index);
907 + if(m.nlocalsym != 0){
908 + if(m.ilocalsym > st->nsyms){
909 + Mach_O_error(ofile, "truncated or malformed object (ilocalsym "
910 + "field of module table entry %lu past the end of the "
911 + "symbol table", module_index);
914 + if(m.ilocalsym + m.nlocalsym > st->nsyms){
915 + Mach_O_error(ofile, "truncated or malformed object (ilocalsym "
916 + "field of module table entry %lu plus nlocalsym field "
917 + "extends past the end of the symbol table", module_index);
921 + if(m.nrefsym != 0){
922 + if(m.irefsym > dyst->nextrefsyms){
923 + Mach_O_error(ofile, "truncated or malformed object (irefsym "
924 + "field of module table entry %lu past the end of the "
925 + "reference table", module_index);
928 + if(m.irefsym + m.nrefsym > dyst->nextrefsyms){
929 + Mach_O_error(ofile, "truncated or malformed object (irefsym "
930 + "field of module table entry %lu plus nrefsym field "
931 + "extends past the end of the reference table",module_index);
935 + if(m.nextrel != 0){
936 + if(m.iextrel > dyst->extreloff){
937 + Mach_O_error(ofile, "truncated or malformed object (iextrel "
938 + "field of module table entry %lu past the end of the "
939 + "external relocation enrties", module_index);
942 + if(m.iextrel + m.nextrel > dyst->extreloff){
943 + Mach_O_error(ofile, "truncated or malformed object (iextrel "
944 + "field of module table entry %lu plus nextrel field "
945 + "extends past the end of the external relocation enrties",
953 diff -ubr libstuff/ofile_get_word.c libstuff/ofile_get_word.c
954 --- libstuff/ofile_get_word.c Fri Sep 6 18:28:00 2002
955 +++ libstuff/ofile_get_word.c Mon Aug 25 13:17:40 2003
958 void *get_word_data /* struct mach_object_file *ofile */ )
961 + unsigned long i, j;
962 struct load_command *lc;
963 struct segment_command *sg;
965 diff -ubr libstuff/print.c libstuff/print.c
966 --- libstuff/print.c Tue Apr 30 00:37:20 2002
967 +++ libstuff/print.c Mon Aug 25 13:17:40 2003
970 * @APPLE_LICENSE_HEADER_END@
973 -#import "stuff/print.h"
975 +#include "stuff/print.h"
978 * All printing of all messages for ofile functions goes through this function.
979 diff -ubr libstuff/reloc.c libstuff/reloc.c
980 --- libstuff/reloc.c Tue Jan 14 23:35:27 2003
981 +++ libstuff/reloc.c Mon Aug 25 13:17:40 2003
983 r_type == PPC_RELOC_SECTDIFF ||
984 r_type == PPC_RELOC_HI16_SECTDIFF ||
985 r_type == PPC_RELOC_LO16_SECTDIFF ||
986 + r_type == PPC_RELOC_LO14_SECTDIFF ||
987 r_type == PPC_RELOC_HA16_SECTDIFF ||
988 r_type == PPC_RELOC_JBSR)
991 if(r_type == PPC_RELOC_SECTDIFF ||
992 r_type == PPC_RELOC_HI16_SECTDIFF ||
993 r_type == PPC_RELOC_LO16_SECTDIFF ||
994 + r_type == PPC_RELOC_LO14_SECTDIFF ||
995 r_type == PPC_RELOC_HA16_SECTDIFF)
998 diff -ubr libstuff/round.c libstuff/round.c
999 --- libstuff/round.c Tue Apr 30 00:37:20 2002
1000 +++ libstuff/round.c Mon Aug 25 13:17:40 2003
1002 * round() rounds v to a multiple of r.
1013 diff -ubr libstuff/swap_headers.c libstuff/swap_headers.c
1014 --- libstuff/swap_headers.c Tue Jan 14 23:35:27 2003
1015 +++ libstuff/swap_headers.c Mon Aug 25 13:17:40 2003
1017 * @APPLE_LICENSE_HEADER_END@
1019 #include <mach-o/loader.h>
1020 -#import <mach/m68k/thread_status.h>
1021 -#import <mach/ppc/thread_status.h>
1022 -#import <mach/m88k/thread_status.h>
1023 -#import <mach/i860/thread_status.h>
1024 -#import <mach/i386/thread_status.h>
1025 -#import <mach/hppa/thread_status.h>
1026 -#import <mach/sparc/thread_status.h>
1027 +#include <mach/m68k/thread_status.h>
1028 +#include <mach/ppc/thread_status.h>
1029 +#include <mach/m88k/thread_status.h>
1030 +#include <mach/i860/thread_status.h>
1031 +#include <mach/i386/thread_status.h>
1032 +#include <mach/hppa/thread_status.h>
1033 +#include <mach/sparc/thread_status.h>
1034 #include "stuff/bool.h"
1035 #include "stuff/bytesex.h"
1036 #include "stuff/errors.h"
1037 Only in libstuff: symbol_list.c
1038 diff -ubr libstuff/writeout.c libstuff/writeout.c
1039 --- libstuff/writeout.c Fri Sep 6 18:28:00 2002
1040 +++ libstuff/writeout.c Mon Aug 25 13:17:40 2003
1042 write_size = (file + file_size) - p;
1044 write_size = WRITE_SIZE;
1045 - if(write(fd, p, write_size) != write_size){
1046 + if(write(fd, p, write_size) != (int)write_size){
1047 system_error("can't write output file: %s", output);
1054 - if(write(fd, file, file_size) != file_size){
1055 + if(write(fd, file, file_size) != (int)file_size){
1056 system_error("can't write output file: %s", output);
1060 strings_size = object->output_strings_size;
1062 for(j = 0; j < nsymbols; j++){
1063 - if(symbols[j].n_un.n_strx > strings_size)
1064 + if((unsigned long)symbols[j].n_un.n_strx > strings_size)
1066 if(toc_symbol(symbols + j, commons_in_toc,
1067 object->sections) == TRUE){
1070 enum bool library_warnings)
1074 enum bool multiple_defs;
1075 struct member *member;
1077 @@ -1008,7 +1008,7 @@
1078 * only once (marked by changing the sign of their ran_off).
1080 multiple_defs = FALSE;
1081 - for(i = 0; i < (long)arch->toc_nranlibs - 1; i++){
1082 + for(i = 0; i < arch->toc_nranlibs - 1; i++){
1083 if(strcmp(arch->toc_ranlibs[i].ran_un.ran_name,
1084 arch->toc_ranlibs[i+1].ran_un.ran_name) == 0){
1085 if(multiple_defs == FALSE){