2003/09/07 04:31:44
[org.ibex.core.git] / upstream / darwin-linker / patches / libstuff.patch
1 Only in libstuff: CVS
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
5 @@ -1,7 +1,7 @@
6  RC_OS = macos
7  OFLAG = -O
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 \
14 @@ -10,14 +10,18 @@
15  endif
16  
17  
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 ; \
21              fi; )
22         
23  ifeq "mwccppc" "$(notdir $(CC))"
24    CFLAGS = $(OFLAG) -g -gccinc -I$(SRCROOT)/../include
25  else
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
29 +  else
30 +    CFLAGS = $(OFLAG) -g -I$(SRCROOT)/../include -Wall $(X_CFLAGS)
31 +  endif
32  endif
33  
34  ifneq "" "$(wildcard /bin/mkdirs)"
35 @@ -40,7 +44,8 @@
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
44  
45 @@ -90,7 +95,7 @@
46                 OFILE_DIR=.                                             \
47                 SRCROOT=..                                              \
48                 SYMROOT=..                                              \
49 -               COPTS="-dynamic"                                        \
50 +               COPTS=""                                        \
51                 OFLAG="$(OFLAG)"                                        \
52                 CFILES="$(CFILES)"                                      \
53                 RC_CFLAGS="$(RC_CFLAGS)"                                \
54 @@ -103,7 +108,7 @@
55                 OFILE_DIR=$(OBJROOT)/dynamic_obj                        \
56                 SRCROOT=$(SRCROOT)                                      \
57                 SYMROOT=$(SYMROOT)                                      \
58 -               COPTS="-dynamic"                                        \
59 +               COPTS=""                                        \
60                 OFLAG="$(OFLAG)"                                        \
61                 CFILES="$(CFILES)"                                      \
62                 RC_CFLAGS="$(RC_CFLAGS)"                                \
63 @@ -120,7 +125,7 @@
64                 OFILE_DIR=.                                             \
65                 SRCROOT=..                                              \
66                 SYMROOT=..                                              \
67 -               COPTS="-dynamic -pg"                                    \
68 +               COPTS="-pg"                                     \
69                 OFLAG="$(OFLAG)"                                        \
70                 RC_CFLAGS="$(RC_CFLAGS)"                                \
71                 RC_ARCHS="$(RC_ARCHS)";                                 \
72 @@ -132,7 +137,7 @@
73                 OFILE_DIR=$(OBJROOT)/profile_obj                        \
74                 SRCROOT=$(SRCROOT)                                      \
75                 SYMROOT=$(SYMROOT)                                      \
76 -               COPTS="-dynamic -pg"                                    \
77 +               COPTS="-pg"                                     \
78                 OFLAG="$(OFLAG)"                                        \
79                 RC_CFLAGS="$(RC_CFLAGS)"                                \
80                 RC_ARCHS="$(RC_ARCHS)";                                 \
81 @@ -167,7 +172,8 @@
82         fi
83  
84  $(PRODUCT):    $(OFILE_DIR) $(SYMROOT) $(OBJS)
85 -       libtool -static -o $(SYMROOT)/$(PRODUCT) $(OBJS)
86 +       ar r $(SYMROOT)/$(PRODUCT) $(OBJS)
87 +       ranlib $(SYMROOT)/$(PRODUCT)
88  
89  ifeq "NO" "$(USE_DEPENDENCY_FILE)"
90  .c.o:
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
94 @@ -1,15 +1,15 @@
95 -#import <libc.h>
96 -#import <ctype.h>
97 -#import <sys/types.h>
98 +#include <libc.h>
99 +#include <ctype.h>
100 +#include <sys/types.h>
101  #ifdef __OPENSTEP__
102  #define _POSIX_SOURCE
103  #endif
104 -#import <dirent.h>
105 -#import <pwd.h>
106 -#import "stuff/bool.h"
107 -#import "stuff/errors.h"
108 -#import "stuff/allocate.h"
109 -#import "stuff/SymLoc.h"
110 +#include <dirent.h>
111 +#include <pwd.h>
112 +#include "stuff/bool.h"
113 +#include "stuff/errors.h"
114 +#include "stuff/allocate.h"
115 +#include "stuff/SymLoc.h"
116  
117  const char *
118  symLocForDylib(const char *installName, const char *releaseName,
119 @@ -101,6 +101,7 @@
120          system_error("symLocForDylib(): Can't opendir %s", buf);
121          return NULL;
122      }
123 +    c = NULL;
124  
125      // read DylibProjects entries
126      *buf = '\0';
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
130 @@ -60,11 +60,13 @@
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 },
145 @@ -269,7 +271,8 @@
146  const struct arch_flag *flag)
147  {
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 */
153         else
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
158 @@ -44,7 +44,8 @@
159  struct fat_arch *fat_archs,
160  unsigned long nfat_archs)
161  {
162 -    unsigned long i, lowest_family, lowest_model, lowest_index;
163 +    unsigned long i;
164 +    long lowest_family, lowest_model, lowest_index;
165  
166         /*
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
176              * it exists.
177              */
178             switch(cpusubtype){
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)
184 +                       continue;
185 +                   if(fat_archs[i].cpusubtype == CPU_SUBTYPE_POWERPC_970)
186 +                       return(fat_archs + i);
187 +               }
188                 for(i = 0; i < nfat_archs; i++){
189                     if(fat_archs[i].cputype != cputype)
190                         continue;
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
194 @@ -25,13 +25,13 @@
195  #include <string.h>
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
218 @@ -132,9 +132,11 @@
219             }
220             lc = (struct load_command *)((char *)lc + lc->cmdsize);
221         }
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 "
232 @@ -161,7 +163,8 @@
233              * and a relocatable object file.  Since it has a dynamic symbol
234              * table command it could have an indirect symbol table.
235              */
236 -           if(object->mh->filetype == MH_DYLIB){
237 +           if(object->mh->filetype == MH_DYLIB /* ||
238 +              object->mh->filetype == MH_DYLIB_STUB */ ){
239                 /*
240                  * This is a dynamic shared library.
241                  * The order of the symbolic info is:
242 @@ -172,10 +175,10 @@
243                  *              undefined symbols
244                  *      two-level namespace hints
245                  *      external relocation entries
246 +                *      indirect symbol table
247                  *      table of contents
248                  *      module table
249                  *      reference table
250 -                *      indirect symbol table
251                  *      string 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
257 @@ -35,6 +35,12 @@
258   */
259  #include <sys/types.h>
260  
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
265 +#endif
266 +
267  static const u_int32_t crctab[] = {
268         0x0,
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
273 @@ -21,7 +21,7 @@
274      enum bool check_result;
275  };
276  
277 -static void check_for_install_name(
278 +static void check_for_dylib(
279      struct ofile *ofile,
280      char *arch_name,
281      void *cookie);
282 @@ -77,7 +77,7 @@
283                 }
284             }
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 @@
292  #endif
293                 /*
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.
303                  */
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);
311 @@ -189,7 +189,7 @@
312  
313  static
314  void
315 -check_for_install_name(
316 +check_for_dylib(
317  struct ofile *ofile,
318  char *arch_name,
319  void *cookie)
320 @@ -197,11 +197,9 @@
321      unsigned long i;
322      struct check_block *block;
323      struct load_command *lc;
324 -    struct dylib_command *dl;
325 -    char *name;
326  
327  #ifdef BIG_DEBUG
328 -       printf("In check_for_install_name() ofile->file_name = %s",
329 +       printf("In check_for_dylib() ofile->file_name = %s",
330                ofile->file_name);
331         if(arch_name != NULL)
332             printf(" arch_name = %s\n", arch_name);
333 @@ -218,13 +216,6 @@
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)
341 -                   return;
342 -               if(strcmp(name, block->install_name) != 0)
343 -                   block->check_result = FALSE;
344                 return;
345             }
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
351 @@ -181,6 +181,14 @@
352                 if(specific_arch_flag != NULL)
353                     specific_arch_flag->name = "ppc7450";
354                 return(1);
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;
359 +               }
360 +               if(specific_arch_flag != NULL)
361 +                   specific_arch_flag->name = "ppc970";
362 +               return(1);
363             default:
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
370 @@ -5,6 +5,69 @@
371  TODO:
372  - Deal with LC_PREPAGE and unknown load commands that don't need to be swapped.
373  
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.
380 +
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 .
386 +
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.
395 +
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 .
401 +
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.
411 +
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
416 +  #3131622.
417 +
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.
421 +
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.
425 +
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
428 +  #3111977.
429 +
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.
436 +
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
443 @@ -27,6 +27,7 @@
444  #include <libc.h>
445  #include <mach/mach.h>
446  #include "stuff/openstep_mach.h"
447 +#include <stddef.h>
448  #include <stdarg.h>
449  #include <limits.h>
450  #include <errno.h>
451 @@ -35,12 +36,12 @@
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"
470 @@ -91,6 +92,12 @@
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,
478 +    char *strings,
479 +    unsigned long module_index);
480  
481  #ifndef OFI
482  /*
483 @@ -229,7 +236,8 @@
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);
492                                     }
493 @@ -349,7 +357,8 @@
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);
502                                 }
503 @@ -445,7 +454,8 @@
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);
512                         }
513 @@ -557,9 +567,9 @@
514                     }
515  #ifdef OTOOL
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 ||
523                             family == TRUE)){
524                             arch_found = TRUE;
525 @@ -580,7 +590,8 @@
526                 if(arch_found == FALSE)
527                     return;
528             }
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);
534                 }
535 @@ -658,19 +669,15 @@
536  {
537      int fd;
538      struct stat stat_buf;
539 -    unsigned long i, size, magic;
540 +    unsigned long size, magic;
541      kern_return_t r;
542      char *addr;
543 -    enum byte_sex host_byte_sex;
544 -    struct arch_flag host_arch_flag;
545 -    enum bool family;
546 -    const struct arch_flag *family_arch_flag;
547  
548         magic = 0; /* to shut up the compiler warning message */
549         memset(ofile, '\0', sizeof(struct ofile));
550  
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){
554  #ifdef OFI
555             return(NSObjectFileImageAccess);
556  #else
557 @@ -700,6 +707,35 @@
558             printf("Modification time = %ld\n", (long int)stat_buf.st_mtime);
559  #endif /* OTOOL */
560  
561 +       return(ofile_map_from_memory(addr, size, file_name, arch_flag,
562 +                            object_name, ofile, archives_with_fat_objects));
563 +}
564 +
565 +/*
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.
568 + */
569 +__private_extern__
570 +#ifdef OFI
571 +NSObjectFileImageReturnCode
572 +#else
573 +enum bool
574 +#endif
575 +ofile_map_from_memory(
576 +char *addr,
577 +unsigned long size,
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)
583 +{
584 +    unsigned long i, magic;
585 +    enum byte_sex host_byte_sex;
586 +    struct arch_flag host_arch_flag;
587 +    enum bool family;
588 +    const struct arch_flag *family_arch_flag;
589 +
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 @@
594         }
595  
596  #ifdef OTOOL
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);
601             return(FALSE);
602 @@ -1327,7 +1363,7 @@
603             return(FALSE);
604         }
605  #ifdef OTOOL
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 "
609                           "of the file");
610             return(FALSE);
611 @@ -1832,7 +1868,7 @@
612  
613  /*
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.
617   */
618  __private_extern__
619  enum bool
620 @@ -1856,7 +1892,8 @@
621  
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",
629                       ofile->file_name);
630 @@ -1864,7 +1901,8 @@
631             }
632         }
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);
639             return(FALSE);
640 @@ -1902,20 +1940,22 @@
641         m = *ofile->dylib_module;
642         if(swapped)
643             swap_dylib_module(&m, 1, host_byte_sex);
644 +       if(check_dylib_module(ofile, st, dyst, strings, 0) == CHECK_BAD)
645 +           return(FALSE);
646         ofile->dylib_module_name = strings + m.module_name;
647         return(TRUE);
648  }
649  
650  /*
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.
654   */
655  __private_extern__
656  enum bool
657  ofile_next_module(
658  struct ofile *ofile)
659  {
660 -    unsigned long i;
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 @@
666  
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",
674                       ofile->file_name);
675 @@ -1934,7 +1975,8 @@
676             }
677         }
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);
684             return(FALSE);
685 @@ -1959,7 +2001,8 @@
686             return(FALSE);
687         }
688  
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)
692             return(FALSE);
693  
694         ofile->dylib_module++;
695 @@ -1969,13 +2012,17 @@
696         m = *ofile->dylib_module;
697         if(swapped)
698             swap_dylib_module(&m, 1, host_byte_sex);
699 +       if(check_dylib_module(ofile, st, dyst, strings, module_index) ==
700 +          CHECK_BAD)
701 +           return(FALSE);
702         ofile->dylib_module_name = strings + m.module_name;
703         return(TRUE);
704  }
705  
706  /*
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
710 + * file.
711   */
712  __private_extern__
713  enum bool
714 @@ -2000,7 +2047,8 @@
715  
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",
723                       ofile->file_name);
724 @@ -2008,7 +2056,8 @@
725             }
726         }
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);
733             return(FALSE);
734 @@ -2047,8 +2096,10 @@
735             m = *p;
736             if(swapped)
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)
741 +               return(FALSE);
742 +           if(strcmp(module_name, strings + m.module_name) == 0){
743                 ofile->dylib_module_name = strings + m.module_name;
744                 return(TRUE);
745             }
746 @@ -2520,10 +2571,12 @@
747             return(CHECK_BAD);
748         }
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);
755 +               return(CHECK_BAD);
756 +           }
757         }
758         /*
759          * Make a pass through the load commands checking them to the level
760 @@ -3595,55 +3648,73 @@
761             }
762         }
763         if(st == NULL){
764 -           if(dyst != NULL)
765 +           if(dyst != NULL){
766                 Mach_O_error(ofile, "truncated or malformed object (contains "
767                   "LC_DYSYMTAB load command without a LC_SYMTAB load command)");
768 +               return(CHECK_BAD);
769 +           }
770         }
771         else{
772             if(dyst != NULL){
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)");
779 +                   return(CHECK_BAD);
780 +               }
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)");
787 +                   return(CHECK_BAD);
788 +               }
789  
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)");
796 +                   return(CHECK_BAD);
797 +               }
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)");
804 +                   return(CHECK_BAD);
805 +               }
806  
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)");
813 +                   return(CHECK_BAD);
814 +               }
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)");
821 +                   return(CHECK_BAD);
822 +               }
823                 if(rc != NULL){
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)");
829 +                       return(CHECK_BAD);
830 +                   }
831                 }
832                 if(hints != NULL){
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)");
838 +                       return(CHECK_BAD);
839 +                   }
840                 }
841             }
842         }
843 @@ -3655,6 +3726,109 @@
844         }
845  
846         /* looks good return ok */
847 +       return(CHECK_GOOD);
848 +#endif /* OTOOL */
849 +}
850 +
851 +/*
852 + * check_dylib_module() checks the object file's dylib_module as referenced
853 + * by the dylib_module field in the ofile for correctness.
854 + */
855 +static
856 +enum check_type
857 +check_dylib_module(
858 +struct ofile *ofile,
859 +struct symtab_command *st,
860 +struct dysymtab_command *dyst,
861 +char *strings,
862 +unsigned long module_index)
863 +{
864 +#ifdef OTOOL
865 +       return(CHECK_GOOD);
866 +#else /* !defined OTOOL */
867 +    unsigned long i;
868 +    enum byte_sex host_byte_sex;
869 +    enum bool swapped;
870 +    struct dylib_module m;
871 +
872 +       m = *ofile->dylib_module;
873 +       host_byte_sex = get_host_byte_sex();
874 +       swapped = (enum bool)(host_byte_sex != ofile->object_byte_sex);
875 +       if(swapped)
876 +           swap_dylib_module(&m, 1, host_byte_sex);
877 +
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)",
881 +               module_index);
882 +           return(CHECK_BAD);
883 +       }
884 +       for(i = m.module_name; i < st->strsize && strings[i] != '\0'; i++)
885 +               ;
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);
890 +           return(CHECK_BAD);
891 +       }
892 +
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);
898 +               return(CHECK_BAD);
899 +           }
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);
904 +               return(CHECK_BAD);
905 +           }
906 +       }
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);
912 +               return(CHECK_BAD);
913 +           }
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);
918 +               return(CHECK_BAD);
919 +           }
920 +       }
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);
926 +               return(CHECK_BAD);
927 +           }
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);
932 +               return(CHECK_BAD);
933 +           }
934 +       }
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);
940 +               return(CHECK_BAD);
941 +           }
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",
946 +                   module_index);
947 +               return(CHECK_BAD);
948 +           }
949 +       }
950         return(CHECK_GOOD);
951  #endif /* OTOOL */
952  }
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
956 @@ -34,7 +34,7 @@
957  unsigned long *word,
958  void *get_word_data /* struct mach_object_file *ofile */ )
959  {
960 -    int i, j;
961 +    unsigned long i, j;
962      struct load_command *lc;
963      struct segment_command *sg;
964      struct section *s;
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
968 @@ -21,8 +21,8 @@
969   * 
970   * @APPLE_LICENSE_HEADER_END@
971   */
972 -#import <stdio.h>
973 -#import "stuff/print.h"
974 +#include <stdio.h>
975 +#include "stuff/print.h"
976  
977  /*
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
982 @@ -106,6 +106,7 @@
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)
989                 return(TRUE);
990 @@ -164,6 +165,7 @@
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)
996                 return(TRUE);
997             break;
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
1001 @@ -26,9 +26,9 @@
1002   * round() rounds v to a multiple of r.
1003   */
1004  __private_extern__
1005 -long
1006 +unsigned long
1007  round(
1008 -long v,
1009 +unsigned long v,
1010  unsigned long r)
1011  {
1012         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
1016 @@ -22,13 +22,13 @@
1017   * @APPLE_LICENSE_HEADER_END@
1018   */
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
1041 @@ -511,7 +511,7 @@
1042                     write_size = (file + file_size) - p;
1043                 else
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);
1048                     goto cleanup;
1049                 }
1050 @@ -560,7 +560,7 @@
1051         }
1052         else{
1053  no_throttle:
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);
1057                 goto cleanup;
1058             }
1059 @@ -807,7 +807,7 @@
1060                     strings_size = object->output_strings_size;
1061                 }
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)
1065                         continue;
1066                     if(toc_symbol(symbols + j, commons_in_toc,
1067                        object->sections) == TRUE){
1068 @@ -998,7 +998,7 @@
1069  char *output,
1070  enum bool library_warnings)
1071  {
1072 -    long i;
1073 +    unsigned long i;
1074      enum bool multiple_defs;
1075      struct member *member;
1076  
1077 @@ -1008,7 +1008,7 @@
1078          * only once (marked by changing the sign of their ran_off).
1079          */
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){