2003/09/07 04:31:44
[org.ibex.core.git] / upstream / darwin-linker / patches / misc.patch
1 Only in misc: CVS
2 diff -ubr misc/Makefile misc/Makefile
3 --- misc/Makefile       Tue Jan 14 23:35:29 2003
4 +++ misc/Makefile       Mon Aug 25 22:06:23 2003
5 @@ -2,11 +2,11 @@
6  OFLAG = -O
7  RC_OS = macos
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 -            echo -Wno-long-double -no-cpp-precomp; \
15 +            echo -Wno-long-double -no-cpp-precomp ; \
16              fi; )
17  endif
18  
19 @@ -14,11 +14,16 @@
20    CFLAGS = $(OFLAG) -g \
21          -I$(SRCROOT) -I$(SRCROOT)/../include -I$(OFILE_DIR)
22  else
23 -  CFLAGS = $(OFLAG) -g -Wall -Wno-precomp $(X_CFLAGS) \
24 +  ifeq "Linux" "$(shell uname)"
25 +    CFLAGS = $(OFLAG) -g -Wall $(X_CFLAGS) \
26 +      -I$(SRCROOT) -I$(SRCROOT)/../include -I$(OFILE_DIR) -D__ppc__ -I/usr/include -I../../macosx-include
27 +  else
28 +    CFLAGS = $(OFLAG) -g -Wall $(X_CFLAGS) \
29          -I$(SRCROOT) -I$(SRCROOT)/../include -I$(OFILE_DIR)
30 +  endif
31  endif
32  
33 -USE_DEPENDENCY_FILE := $(shell if [ "$(notdir $(CC))" != "mwccppc" ]; then \
34 +USE_DEPENDENCY_FILE := $(shell if [ `uname` != "Linux" ] && [ "$(notdir $(CC))" != "mwccppc" ]; then \
35              echo YES ; else echo NO ; \
36              fi; )
37  
38 @@ -44,10 +49,7 @@
39  LOCLIBDIR = /usr/local/lib
40  
41  CFILES1 = libtool.c
42 -CFILES2 = main.c lipo.c size.c strings.c nm.c checksyms.c inout.c \
43 -        indr.c strip.c atom.c segedit.c kern_tool.c cmpdylib.c \
44 -        dylib_pcsampler.c pagestuff.c redo_prebinding.c seg_addr_table.c \
45 -        check_dylib.c seg_hack.c check_hints.c install_name_tool.c
46 +CFILES2 = seg_hack.c strip.c
47  ifeq "nextstep" "$(RC_OS)"
48    CFILES3 = file.c ar.c
49  endif
50 @@ -56,11 +58,7 @@
51                 notes
52  
53  
54 -PROGS = lipo.NEW size.NEW strings.NEW nm.NEW \
55 -       libtool.NEW checksyms.NEW indr.NEW strip.NEW nmedit.NEW \
56 -       segedit.NEW kern_tool.NEW cmpdylib.NEW \
57 -       dylib_pcsampler.NEW pagestuff.NEW redo_prebinding.NEW \
58 -       seg_addr_table.NEW check_dylib.NEW seg_hack.NEW install_name_tool.NEW
59 +PROGS = seg_hack.NEW strip.NEW
60  
61  teflon_all macos_all: $(PROGS)
62  
63 @@ -71,7 +69,7 @@
64  lib_ofiles: $(OFILE_DIR) $(SYMROOT) libredo_prebinding.a
65  
66  vers.c:
67 -       vers_string -c $(VERS_STRING_FLAGS) cctools_misc > $(OFILE_DIR)/$@
68 +       ./vers_string -c $(VERS_STRING_FLAGS) cctools_misc > $(OFILE_DIR)/$@
69  
70  ifeq "NO" "$(USE_DEPENDENCY_FILE)"
71  .c.o:
72 @@ -222,6 +220,7 @@
73                 $(OFILE_DIR)/seg_hack.o $(OFILE_DIR)/vers.o $(LIBSTUFF)
74         $(CC) $(CFLAGS) $(RC_CFLAGS) -o $(SYMROOT)/seg_hack.NEW \
75                 $(OFILE_DIR)/seg_hack.private.o
76 +       cp $(SYMROOT)/seg_hack.NEW $(SYMROOT)/seg_hack
77  
78  install_name_tool.NEW: install_name_tool.o vers.o
79         $(CC) $(CFLAGS) $(RC_CFLAGS) -nostdlib -r \
80 @@ -331,7 +330,8 @@
81         $(SYMROOT)/redo_prebinding.NEW \
82         $(SYMROOT)/libredo_prebinding.a \
83         $(SYMROOT)/kern_tool.NEW \
84 -       $(SYMROOT)/cmpdylib.NEW
85 +       $(SYMROOT)/cmpdylib.NEW \
86 +       $(SYMROOT)/seg_hack
87  
88  shlib_clean:
89         -rm -f \
90 Only in misc: ar.c
91 Only in misc: atom.c
92 Only in misc: check_dylib.c
93 Only in misc: check_hints.c
94 Only in misc: checksyms.c
95 Only in misc: cmpdylib.c
96 Only in misc: dylib_pcsampler.c
97 Only in misc: file.c
98 Only in misc: indr.c
99 Only in misc: inout.c
100 Only in misc: install_name_tool.c
101 Only in misc: kern_tool.c
102 Only in misc: libtool.c
103 Only in misc: lipo.c
104 Only in misc: main.c
105 Only in misc: nm.c
106 diff -ubr misc/notes misc/notes
107 --- misc/notes  Tue Jan 14 23:35:29 2003
108 +++ misc/notes  Mon Aug 25 12:12:34 2003
109 @@ -7,6 +7,148 @@
110    could have been set otherwise and does not print the next line.
111  - Maybe add fat support for segedit(1)
112  
113 +Changes for the 5.12 release (the cctools-474 release):
114 +- Fixed a bug in redo_prebinding that was leaking memory if the
115 +  allow_missing_architectures parameter was used and the fat file did not
116 +  contain an architecture.  The fix was in load_library() in 4 places it
117 +  checks to see if the missing architecure is allowed to be missing and it now
118 +  unmap's the ofile before returning.  Radar bug #3144803.
119 +
120 +Changes for the 5.12 release (the cctools-472 release):
121 +- Fixed a bug in seg_addr_table(1) when run with -relayout the <<< Next split
122 +  address to assign >>> isn't getting set properly.  The fix in in main() to add
123 +  relayout == FALSE to the if() condition for the code that loops and updates
124 +  the NEXT_SPLIT_ADDRESS_TO_ASSIGN.  Radar bug #3245958.
125 +
126 +Changes for the 5.12 release (the cctools-470 release):
127 +- Added the -c option to strip(1) to strip the section contents of a dynamic
128 +  shared library and create a stub library.  Radar bug #3235093.
129 +- Changed install_name_tool(1) to not change MH_DYLIB_STUB filetypes.  
130 +  Radar bug #3235093.
131 +- Added the flag -search_paths_first to cause -lx flags to search each path
132 +  for .dylib then .a before searching next path to libtool(1).  Radar bug
133 +  #3176974.
134 +  - Added the enum bool variable search_paths_first to the cmd_flags struct and
135 +    code to parse out the option, set variable and add it to the ldflags[] in
136 +    main() .
137 +  - The new static routines search_paths_for_lname() and search_path_for_lname()
138 +    were added.
139 +  - In file_name_from_l_flag() a test of the new search_paths_first variable is
140 +    done and if TRUE then search_paths_for_lname() is called.
141 +
142 +Changes for the 5.12 release (the cctools-469 release):
143 +- Added support for the -weak-lx, -weak_library and -weak_framework flags to
144 +  libtool(1).  Radar bug #3069758.
145 +- Fixed a bug seg_addr_table(1) in next_flat_seg1addr() where the variable i
146 +  was previously changed to unsigned.  The second loop uses this varaiable as
147 +  signed and thus this change was causing the loop to never terminate.  Radar
148 +  bug 3225931.
149 +
150 +Changes for the 5.12 release (the cctools-466 release):
151 +- Fixed a bug in libtool(1) for the -static option that caused it to crash if
152 +  the objects contained no symbols to put in the table of contents.  Radar bug
153 +  #3217471.
154 +- Fixed the incorrect casts on the comparison of the nlist struct's n_strx field
155 +  where the value being compared to was casted to a long.  The correct fix was
156 +  to cast n_strx to an unsigned long.
157 +- Changed print_mach_symbols() in nm.c to print "(dynamically looked up)" for
158 +  the library ordinal DYNAMIC_LOOKUP_ORDINAL which are looked up dynamically
159 +  with flat namespace semantics in two-level namespace images.  Radar bug
160 +  #3210803.
161 +- Changed get_primary_lib() in redo_prebinding.c to check for the library
162 +  ordinal DYNAMIC_LOOKUP_ORDINAL and return NULL.  Radar bug #3210803.
163 +
164 +Changes for the 5.12 release (the cctools-464 release):
165 +- Made changes to build cleanly with gcc3.3
166 +  - Removed -Wno-precomp from the Makefile
167 +  - Fixed warnings for "comparison between signed and unsigned" in lipo.c,
168 +    size.c, strings.c, nm.c, libtool.c, checksyms.c, indr.c, strip.c, segedit.c,
169 +    kern_tool.c, cmpdylib.c, dylib_pcsampler.c, pagestuff.c, redo_prebinding.c,
170 +    seg_addr_table.c, check_dylib.c, seg_hack.c and install_name_tool.c.
171 +
172 +Changes for the 5.12 release (the cctools-463 release):
173 +- Added support for MH_DYLIB_STUB libraries.  Radar bug #3193744.
174 +  - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in add_member()
175 +    in libtool.c .
176 +  - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in
177 +    translate_object() in indr.c in the error check.
178 +  - Added a case for MH_DYLIB_STUB in type_buf() in file.c (note this is the
179 +    old file(1) command and is no longer used).
180 +  - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in check_dylib()
181 +    in cmpdylib.c in 2 places.
182 +  - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in checksyms() and
183 +    in check_dynamic_binary() in checksyms.c in 3 places in all.
184 +  - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in check_hints.c .
185 +
186 +Changes for the 5.12 release (the cctools-461 release):
187 +- Fixed a bug in install_name_tool(1) that caused it to crash when the new
188 +  load commands were smaller than the old load commands.  Radar bug #3161586.
189 +
190 +Changes for the 5.12 release (the cctools-456 release):
191 +- Fixed a bug in the redo_prebinding code when the allow_missing_architectures
192 +  parameter to the redo_prebinding() API is non-zero.  In the routine
193 +  load_library() an extra check is needed to not cause an error if we are
194 +  allowing missing architectures.  The case where this happens is when there
195 +  is a fat file that the architecture we don't care about depends on a library
196 +  in another fat file but the time stamps for the libraries don't match.
197 +  Radar bug #3144552.
198 +
199 +Changes for the 5.12 release (the cctools-455 release):
200 +- Fixed a bug in the redo_prebinding code in the routine link_library_module()
201 +  in redo_prebinding.c.  The problem was that when a reference to a private
202 +  extern was found only the module containing it was marked linked.  A call
203 +  to link_library_module() for that module was needed to pull in its
204 +  dependencies and get those modules marked as LINKED.  Radar bug #3126383.
205 +
206 +Changes for the 5.12 release (the cctools-454 release):
207 +- Fixed a bug where seg_addr_table doesn't catch when an address is assigned in
208 +  the "alternate" area.  seg_addr_table(1) was using the wrong constant to
209 +  check the validity of newly assigned addresses, the fix is to use the correct
210 +  constant.  Radar bug #3138181.
211 +
212 +Changes for the 5.12 release (the cctools-452 release):
213 +- Fixed the bug fix done for Radar bug #3124262 below in the redo_prebinding
214 +  code. The copied code from the above loop was wrong as it changed this:
215 +                   if(libs[i].module_states[j] == LINKED)
216 +  to this:
217 +                   if(libs[j].module_states[k] == LINKED ||
218 +                      (prebind_all_twolevel_modules == TRUE &&
219 +                       (libs[j].ofile->mh->flags & MH_TWOLEVEL) ==
220 +                                MH_TWOLEVEL))
221 +  which should have been this:
222 +                   if(libs[i].module_states[j] == LINKED ||
223 +                      (prebind_all_twolevel_modules == TRUE &&
224 +                       (libs[i].ofile->mh->flags & MH_TWOLEVEL) ==
225 +                                MH_TWOLEVEL))
226 +  which used the correct index variables.  Radar bug #3133589.
227 +
228 +Changes for the 5.12 release (the cctools-451 release):
229 +- Fixed a bug in the redo_prebinding code that did not set the all the bits
230 +  in the linked_modules bit vector for any new LC_PREBOUND_DYLIB load commands
231 +  when prebind_all_twolevel_modules was TRUE.  Radar bug #3124262.
232 +
233 +Changes for the 5.12 release (the cctools-448 release):
234 +- Added an entry stabnames[] array in nm.c for N_OPT that is emitted with
235 +  gcc2_compiled and in gcc source.  Radar bug #3104328.
236 +
237 +Changes for the 5.12 release (the cctools-447 release):
238 +- Fixed a bug in add_member() in libtool.c when get_arch_family_from_cputype()
239 +  returns NULL.
240 +
241 +Changes for the 5.11 release (the cctools-446 release):
242 +- Added passing -x from libtool to ld.  Radar bug #3088301.
243 +
244 +Changes for the 5.11 release (the cctools-444 release):
245 +- Added passing -exported_symbols_list & -unexported_symbols_list from libtool
246 +  to ld.  Radar bug #3083844.
247 +- Factored out some of the symbol list stuff out of strip.c into libstuff so
248 +  ld(1)'s -exported_symbols_list and -unexported_symbols_list options can use
249 +  it.  Radar bug #3083844.
250 +
251 +Changes for the 5.11 release (the cctools-443 release):
252 +- Added passing -single_module & -multi_module from libtool to ld.  Also added
253 +  passing -u flags.  Radar #3080780.
254 +
255  Changes for the 5.11 release (the cctools-440 release):
256  - Fixed the warnings about extra tokens at end of #endif directive in
257    check_hints.c, strip.c and make_defs.h (Radar bug #3072042).
258 Only in misc: pagestuff.c
259 Only in misc: redo_prebinding.c
260 Only in misc: seg_addr_table.c
261 diff -ubr misc/seg_hack.c misc/seg_hack.c
262 --- misc/seg_hack.c     Fri Sep  6 18:28:06 2002
263 +++ misc/seg_hack.c     Mon Aug 25 12:12:34 2003
264 @@ -58,7 +58,7 @@
265  char **argv,
266  char **envp)
267  {
268 -    unsigned long i;
269 +    int i;
270      char *input, *output;
271      struct arch *archs;
272      unsigned long narchs;
273 Only in misc: segedit.c
274 Only in misc: size.c
275 Only in misc: strings.c
276 diff -ubr misc/strip.c misc/strip.c
277 --- misc/strip.c        Tue Jan 14 23:35:30 2003
278 +++ misc/strip.c        Mon Aug 25 22:02:32 2003
279 @@ -38,11 +38,13 @@
280  #include <mach-o/reloc.h>
281  #include <mach-o/nlist.h>
282  #include <mach-o/stab.h>
283 -#include <stuff/breakout.h>
284 -#include <stuff/allocate.h>
285 -#include <stuff/errors.h>
286 -#include <stuff/round.h>
287 +#include "stuff/breakout.h"
288 +#include "stuff/allocate.h"
289 +#include "stuff/errors.h"
290 +#include "stuff/round.h"
291  #include "stuff/reloc.h"
292 +#include "stuff/reloc.h"
293 +#include "stuff/symbol_list.h"
294  
295  /* These are set from the command line arguments */
296  char *progname;                /* name of the program for error messages (argv[0]) */
297 @@ -62,6 +64,8 @@
298  static long Sflag;     /* -S strip only debugger symbols N_STAB */
299  static long xflag;     /* -x strip non-globals */
300  static long Xflag;     /* -X strip local symbols with 'L' names */
301 +static long cflag;     /* -c strip section contents from dynamic libraries
302 +                          files to create stub libraries */
303  static long strip_all = 1;
304  /*
305   * This is set on an object by object basis if the strip_all flag is still set
306 @@ -76,11 +80,6 @@
307   * save_symbols is the names of the symbols from the -s <file> argument.
308   * remove_symbols is the names of the symbols from the -R <file> argument.
309   */
310 -struct symbol_list {
311 -    char *name;                /* name of the global symbol */
312 -    struct nlist *sym; /* pointer to the nlist structure for this symbol */
313 -    enum bool seen;    /* set if the symbol is seen in the input file */
314 -};
315  static struct symbol_list *save_symbols = NULL;
316  static unsigned long nsave_symbols = 0;
317  static struct symbol_list *remove_symbols = NULL;
318 @@ -106,12 +105,12 @@
319   * and the new counts of local, defined external and undefined symbols.
320   */
321  static struct nlist *new_symbols = NULL;
322 -static long new_nsyms = 0;
323 +static unsigned long new_nsyms = 0;
324  static char *new_strings = NULL;
325 -static long new_strsize = 0;
326 -static long new_nlocalsym = 0;
327 -static long new_nextdefsym = 0;
328 -static long new_nundefsym = 0;
329 +static unsigned long new_strsize = 0;
330 +static unsigned long new_nlocalsym = 0;
331 +static unsigned long new_nextdefsym = 0;
332 +static unsigned long new_nundefsym = 0;
333  
334  /*
335   * These hold the new table of contents, reference table and module table for
336 @@ -169,9 +168,9 @@
337      struct member *member,
338      struct object *object,
339      struct nlist *symbols,
340 -    long nsyms,
341 +    unsigned long nsyms,
342      char *strings,
343 -    long strsize,
344 +    unsigned long strsize,
345      struct dylib_table_of_contents *tocs,
346      unsigned long ntoc,
347      struct dylib_module *mods,
348 @@ -202,9 +201,9 @@
349      struct member *member,
350      struct object *object,
351      struct nlist *symbols,
352 -    long nsyms,
353 +    unsigned long nsyms,
354      char *strings,
355 -    long strsize,
356 +    unsigned long strsize,
357      struct dylib_table_of_contents *tocs,
358      unsigned long ntoc,
359      struct dylib_module *mods,
360 @@ -213,19 +212,6 @@
361      unsigned long nextrefsyms);
362  #endif /* NMEDIT */
363  
364 -static void setup_symbol_list(
365 -    char *file,
366 -    struct symbol_list **list,
367 -    unsigned long *size);
368 -
369 -static int cmp_qsort_name(
370 -    const struct symbol_list *sym1,
371 -    const struct symbol_list *sym2);
372 -
373 -static int cmp_bsearch(
374 -    const char *name,
375 -    const struct symbol_list *sym);
376 -
377  #ifndef NMEDIT
378  static void setup_debug_filenames(
379      char *dfile);
380 @@ -260,7 +246,8 @@
381  char *argv[],
382  char *envp[])
383  {
384 -    unsigned long i, j, args_left, files_specified;
385 +    int i;
386 +    unsigned long j, args_left, files_specified;
387      struct arch_flag *arch_flags;
388      unsigned long narch_flags;
389      enum bool all_archs;
390 @@ -388,6 +375,12 @@
391                             strip_all = 0;
392  #endif /* !defined(NMEDIT) */
393                             break;
394 +#ifndef NMEDIT
395 +                       case 'c':
396 +                           cflag = 1;
397 +                           strip_all = 0;
398 +                           break;
399 +#endif /* NMEDIT */
400                         default:
401                             error("unrecognized option: %s", argv[i]);
402                             usage();
403 @@ -421,16 +414,16 @@
404         if(Rfile){
405             setup_symbol_list(Rfile, &remove_symbols, &nremove_symbols);
406             if(sfile){
407 -               for(i = 0; i < nremove_symbols ; i++){
408 -                   sp = bsearch(remove_symbols[i].name,
409 +               for(j = 0; j < nremove_symbols ; j++){
410 +                   sp = bsearch(remove_symbols[j].name,
411                                  save_symbols, nsave_symbols,
412                                  sizeof(struct symbol_list),
413                                  (int (*)(const void *, const void *))
414 -                                   cmp_bsearch);
415 +                                   symbol_list_bsearch);
416                     if(sp != NULL){
417                         error("symbol name: %s is listed in both -s %s and -R "
418                               "%s files (can't be both saved and removed)",
419 -                             remove_symbols[i].name, sfile, Rfile);
420 +                             remove_symbols[j].name, sfile, Rfile);
421                     }
422                 }
423                 if(errors)
424 @@ -635,7 +628,7 @@
425  
426             /*
427              * Now this arch[i] has been selected to be processed so process it
428 -            * according to it's type.
429 +            * according to its type.
430              */
431             if(archs[i].type == OFILE_ARCHIVE){
432                 for(j = 0; j < archs[i].nmembers; j++){
433 @@ -753,7 +746,7 @@
434      unsigned long nextrefsyms;
435      unsigned long *indirectsyms;
436      unsigned long nindirectsyms;
437 -    long i, j, k;
438 +    unsigned long i, j, k;
439      struct load_command *lc;
440      struct segment_command *sg;
441      struct section *s;
442 @@ -780,6 +773,15 @@
443         strings = object->object_addr + object->st->stroff;
444         strsize = object->st->strsize;
445  
446 +#ifndef NMEDIT
447 +       if(object->mh->filetype != MH_DYLIB && cflag)
448 +           fatal_arch(arch, member, "-c can't be used on non-dynamic "
449 +                      "library: ");
450 +#endif /* !(NMEDIT) */
451 +       if(object->mh->filetype == MH_DYLIB_STUB)
452 +           fatal_arch(arch, member, "dynamic stub library can't be changed "
453 +                      "once created: ");
454 +
455         if(object->mh->filetype == MH_DYLIB){
456             tocs = (struct dylib_table_of_contents *)
457                     (object->object_addr + object->dyst->tocoff);
458 @@ -795,6 +797,71 @@
459                 swap_dylib_module(mods, nmodtab, host_byte_sex);
460                 swap_dylib_reference(refs, nextrefsyms, host_byte_sex);
461             }
462 +#ifndef NMEDIT
463 +           /* 
464 +            * In the -c flag is specified then strip the section contents of
465 +            * this dynamic library and change it into a stub library.  When
466 +            * creating a stub library the timestamp is not changed.
467 +            */
468 +           if(cflag){
469 +               object->mh->filetype = MH_DYLIB_STUB;
470 +               arch->dont_update_LC_ID_DYLIB_timestamp = TRUE;
471 +
472 +               lc = object->load_commands;
473 +               for(i = 0; i < object->mh->ncmds; i++){
474 +                   if(lc->cmd == LC_SEGMENT){
475 +                       sg = (struct segment_command *)lc;
476 +                       if(strcmp(sg->segname, SEG_LINKEDIT) != 0){
477 +                           /*
478 +                            * Zero out the section offset, reloff, and size
479 +                            * fields as the section contents are being removed.
480 +                            */
481 +                           s = (struct section *)&sg[1];
482 +                           for(j = 0; j < sg->nsects; j++){
483 +                               /*
484 +                                * For section types with indirect tables we
485 +                                * do not zero out the section size in a stub
486 +                                * library.  As the section size is needed to
487 +                                * know now many indirect table entries the
488 +                                * section has.  This is a bit odd but programs
489 +                                * dealing with MH_DYLIB_STUB filetypes special
490 +                                * case this.
491 +                                */ 
492 +                               section_type = s[j].flags & SECTION_TYPE;
493 +                               if(section_type != S_SYMBOL_STUBS &&
494 +                                  section_type != S_LAZY_SYMBOL_POINTERS &&
495 +                                  section_type != S_NON_LAZY_SYMBOL_POINTERS){
496 +                                   s[j].size = 0;
497 +                               }
498 +                               s[j].addr    = 0;
499 +                               s[j].offset  = 0;
500 +                               s[j].reloff  = 0;
501 +                           }
502 +                           /* zero out file offset and size in the segment */
503 +                           sg->fileoff = 0;
504 +                           sg->filesize = 0;
505 +                       }
506 +                   }
507 +                   lc = (struct load_command *)((char *)lc + lc->cmdsize);
508 +               }
509 +               /*
510 +                * To get the right amount of the file copied out by writeout()
511 +                * for the case when we are stripping out the section contents
512 +                * we reduce the object size by the size of the section contents
513 +                * including the padding after the load commands.  Then this
514 +                * size minus the size of the input symbolic information is
515 +                * copied out.
516 +                */
517 +               object->object_size -= (object->seg_linkedit->fileoff -
518 +                       (sizeof(struct mach_header) + object->mh->sizeofcmds));
519 +               /*
520 +                * Set the file offset to the link edit information to be right
521 +                * after the load commands.
522 +                */
523 +               object->seg_linkedit->fileoff = 
524 +                       sizeof(struct mach_header) + object->mh->sizeofcmds;
525 +           }
526 +#endif /* !(NMEDIT) */
527         }
528         else{
529             tocs = NULL;
530 @@ -877,7 +944,12 @@
531             
532                 }
533  
534 -               if(object->mh->filetype == MH_DYLIB){
535 +               /*
536 +                * If the -c option is specified the object's filetype will
537 +                * have been changed from MH_DYLIB to MH_DYLIB_STUB above.
538 +                */
539 +               if(object->mh->filetype == MH_DYLIB ||
540 +                  object->mh->filetype == MH_DYLIB_STUB){
541                     object->output_tocs = new_tocs;
542                     object->output_ntoc = new_ntoc;
543  #ifdef NMEDIT
544 @@ -910,9 +982,20 @@
545                     object->dyst->ntoc * sizeof(struct dylib_table_of_contents)+
546                     object->dyst->nmodtab * sizeof(struct dylib_module) +
547                     object->dyst->nextrefsyms * sizeof(struct dylib_reference);
548 +#ifndef NMEDIT
549 +               /*
550 +                * When stripping out the section contents to create a
551 +                * dynamic library stub the relocation info also gets
552 +                * stripped.
553 +                */
554 +               if(!cflag) 
555 +#endif /* !(NMEDIT) */
556 +               {
557                 object->output_sym_info_size +=
558                     object->dyst->nlocrel * sizeof(struct relocation_info) +
559 -                   object->dyst->nextrel * sizeof(struct relocation_info) +
560 +                       object->dyst->nextrel * sizeof(struct relocation_info);
561 +               }
562 +               object->output_sym_info_size +=
563                     object->dyst->nindirectsyms * sizeof(unsigned long) +
564                     new_ntoc * sizeof(struct dylib_table_of_contents)+
565                     object->dyst->nmodtab * sizeof(struct dylib_module) +
566 @@ -961,10 +1044,24 @@
567                 if(object->dyst->nlocrel != 0){
568                     object->output_loc_relocs = (struct relocation_info *)
569                         (object->object_addr + object->dyst->locreloff);
570 +#ifndef NMEDIT
571 +                   /*
572 +                    * When stripping out the section contents to create a
573 +                    * dynamic library stub the relocation info also gets
574 +                    * stripped.
575 +                    */
576 +                   if(cflag){
577 +                       object->dyst->nlocrel = 0;
578 +                       object->dyst->locreloff = 0;
579 +                   }
580 +                   else
581 +#endif /* defined(NMEDIT) */
582 +                   {
583                     object->dyst->locreloff = offset;
584                     offset += object->dyst->nlocrel *
585                               sizeof(struct relocation_info);
586                 }
587 +               }
588                 else
589                     object->dyst->locreloff = 0;
590  
591 @@ -990,10 +1087,24 @@
592                 if(object->dyst->nextrel != 0){
593                     object->output_ext_relocs = (struct relocation_info *)
594                         (object->object_addr + object->dyst->extreloff);
595 +#ifndef NMEDIT
596 +                   /*
597 +                    * When stripping out the section contents to create a
598 +                    * dynamic library stub the relocation info also gets
599 +                    * stripped.
600 +                    */
601 +                   if(cflag){
602 +                       object->dyst->nextrel = 0;
603 +                       object->dyst->extreloff = 0;
604 +                   }
605 +                   else
606 +#endif /* defined(NMEDIT) */
607 +                   {
608                     object->dyst->extreloff = offset;
609                     offset += object->dyst->nextrel *
610                               sizeof(struct relocation_info);
611                 }
612 +               }
613                 else
614                     object->dyst->extreloff = 0;
615  
616 @@ -1014,6 +1125,24 @@
617                     object->dyst->tocoff = 0;
618  
619                 if(object->dyst->nmodtab != 0){
620 +#ifndef NMEDIT
621 +                   /*
622 +                    * When stripping out the section contents to create a
623 +                    * dynamic library stub zero out the fields in the module
624 +                    * table for the sections and relocation information.
625 +                    */
626 +                   if(cflag){
627 +                       /* Clear Objective-C address and size from modules. */
628 +                       for(k = 0; k < object->dyst->nmodtab; k++){
629 +                           mods[k].iinit_iterm = 0;
630 +                           mods[k].ninit_nterm = 0;
631 +                           mods[k].iextrel = 0;
632 +                           mods[k].nextrel = 0;
633 +                           mods[k].objc_module_info_addr = 0;
634 +                           mods[k].objc_module_info_size = 0;
635 +                       }
636 +                   }
637 +#endif /* !(NMEDIT) */
638                     object->dyst->modtaboff = offset;
639                     offset += object->dyst->nmodtab *
640                               sizeof(struct dylib_module);
641 @@ -1423,120 +1552,6 @@
642         }
643  }
644  
645 -/*
646 - * This is called to setup a symbol list from a file.  It reads the file with
647 - * the strings in it and places them in an array of symbol_list structures and
648 - * then sorts them by name.
649 - *
650 - * The file that contains the symbol names must have symbol names one per line,
651 - * leading and trailing white space is removed and lines starting with a '#'
652 - * and lines with only white space are ignored.
653 - */
654 -static
655 -void
656 -setup_symbol_list(
657 -char *file,
658 -struct symbol_list **list,
659 -unsigned long *size)
660 -{
661 -    int fd, i, j, len, strings_size;
662 -    struct stat stat_buf;
663 -    char *strings, *p, *line;
664 -
665 -       if((fd = open(file, O_RDONLY)) < 0){
666 -           system_error("can't open: %s", file);
667 -           return;
668 -       }
669 -       if(fstat(fd, &stat_buf) == -1){
670 -           system_error("can't stat: %s", file);
671 -           close(fd);
672 -           return;
673 -       }
674 -       strings_size = stat_buf.st_size;
675 -       strings = (char *)allocate(strings_size + 2);
676 -       strings[strings_size] = '\n';
677 -       strings[strings_size + 1] = '\0';
678 -       if(read(fd, strings, strings_size) != strings_size){
679 -           system_error("can't read: %s", file);
680 -           close(fd);
681 -           return;
682 -       }
683 -       /*
684 -        * Change the newlines to '\0' and count the number of lines with
685 -        * symbol names.  Lines starting with '#' are comments and lines
686 -        * contain all space characters do not contain symbol names.
687 -        */
688 -       p = strings;
689 -       line = p;
690 -       for(i = 0; i < strings_size + 1; i++){
691 -           if(*p == '\n' || *p == '\r'){
692 -               *p = '\0';
693 -               if(*line != '#'){
694 -                   while(*line != '\0' && isspace(*line))
695 -                       line++;
696 -                   if(*line != '\0')
697 -                       (*size)++;
698 -               }
699 -               p++;
700 -               line = p;
701 -           }
702 -           else{
703 -               p++;
704 -           }
705 -       }
706 -       *list = (struct symbol_list *)
707 -               allocate((*size) * sizeof(struct symbol_list));
708 -
709 -       /*
710 -        * Place the strings in the list trimming leading and trailing spaces
711 -        * from the lines with symbol names.
712 -        */
713 -       p = strings;
714 -       line = p;
715 -       for(i = 0; i < (*size); ){
716 -           p += strlen(p) + 1;
717 -           if(*line != '#' && *line != '\0'){
718 -               while(*line != '\0' && isspace(*line))
719 -                   line++;
720 -               if(*line != '\0'){
721 -                   (*list)[i].name = line;
722 -                   (*list)[i].seen = FALSE;
723 -                   i++;
724 -                   len = strlen(line);
725 -                   j = len - 1;
726 -                   while(j > 0 && isspace(line[j])){
727 -                       j--;
728 -                   }
729 -                   if(j > 0 && j + 1 < len && isspace(line[j+1]))
730 -                       line[j+1] = '\0';
731 -               }
732 -           }
733 -           line = p;
734 -       }
735 -
736 -       qsort(*list, *size, sizeof(struct symbol_list),
737 -             (int (*)(const void *, const void *))cmp_qsort_name);
738 -
739 -       /* remove duplicates on the list */
740 -       for(i = 0; i < (*size); i++){
741 -           if(i + 1 < (*size)){
742 -               if(strcmp((*list)[i].name, (*list)[i+1].name) == 0){
743 -                   for(j = 1; j < ((*size) - i - 1); j++){
744 -                       (*list)[i + j].name = (*list)[i + j + 1].name;
745 -                   }
746 -                   *size = *size - 1;
747 -               }
748 -           }
749 -       }
750 -
751 -#ifdef DEBUG
752 -       printf("symbol list:\n");
753 -       for(i = 0; i < (*size); i++){
754 -           printf("0x%x name = %s\n", &((*list)[i]),(*list)[i].name);
755 -       }
756 -#endif /* DEBUG */
757 -}
758 -
759  #ifndef NMEDIT
760  /*
761   * This is called if there is a -d option specified.  It reads the file with
762 @@ -1609,9 +1624,9 @@
763  struct member *member,
764  struct object *object,
765  struct nlist *symbols,
766 -long nsyms,
767 +unsigned long nsyms,
768  char *strings,
769 -long strsize,
770 +unsigned long strsize,
771  struct dylib_table_of_contents *tocs,
772  unsigned long ntoc,
773  struct dylib_module *mods,
774 @@ -1621,7 +1636,8 @@
775  unsigned long *indirectsyms,
776  unsigned long nindirectsyms)
777  {
778 -    long i, j, k, n, inew_syms, save_debug, missing_syms, missing_symbols;
779 +    unsigned long i, j, k, n, inew_syms, save_debug, missing_syms;
780 +    unsigned long missing_symbols;
781      char *p, *q, **pp, *basename;
782      struct symbol_list *sp;
783      unsigned long new_ext_strsize, len, *changes, inew_undefsyms;
784 @@ -1686,7 +1702,7 @@
785         for(i = 0; i < nsyms; i++){
786             if(symbols[i].n_un.n_strx != 0){
787                 if(symbols[i].n_un.n_strx < 0 ||
788 -                  symbols[i].n_un.n_strx > strsize){
789 +                  (unsigned long)symbols[i].n_un.n_strx > strsize){
790                     error_arch(arch, member, "bad string index for symbol "
791                                "table entry %ld in: ", i);
792                     return(FALSE);
793 @@ -1838,7 +1854,7 @@
794                                      save_symbols, nsave_symbols,
795                                      sizeof(struct symbol_list),
796                                      (int (*)(const void *, const void *))
797 -                                       cmp_bsearch);
798 +                                       symbol_list_bsearch);
799                         if(sp != NULL){
800                             if(sp->sym == NULL){
801                                 sp->sym = &(symbols[i]);
802 @@ -1885,7 +1901,7 @@
803                                  remove_symbols, nremove_symbols,
804                                  sizeof(struct symbol_list),
805                                  (int (*)(const void *, const void *))
806 -                                   cmp_bsearch);
807 +                                   symbol_list_bsearch);
808                     if(sp != NULL){
809                         if((symbols[i].n_type & N_TYPE) == N_UNDF ||
810                            (symbols[i].n_type & N_TYPE) == N_PBUD){
811 @@ -1960,7 +1976,7 @@
812                                  save_symbols, nsave_symbols,
813                                  sizeof(struct symbol_list),
814                                  (int (*)(const void *, const void *))
815 -                                   cmp_bsearch);
816 +                                   symbol_list_bsearch);
817                     if(sp != NULL){
818                         if(sp->sym != NULL &&
819                            (sp->sym->n_type & N_PEXT) != N_PEXT){
820 @@ -2467,30 +2483,6 @@
821  }
822  #endif /* !defined(NMEDIT) */
823  
824 -/*
825 - * Function for qsort for comparing symbol list names.
826 - */
827 -static
828 -int
829 -cmp_qsort_name(
830 -const struct symbol_list *sym1,
831 -const struct symbol_list *sym2)
832 -{
833 -       return(strcmp(sym1->name, sym2->name));
834 -}
835 -
836 -/*
837 - * Function for bsearch for finding a symbol.
838 - */
839 -static
840 -int
841 -cmp_bsearch(
842 -const char *name,
843 -const struct symbol_list *sym)
844 -{
845 -       return(strcmp(name, sym->name));
846 -}
847 -
848  #ifndef NMEDIT
849  /*
850   * Function for qsort for comparing object names.
851 @@ -2525,9 +2517,9 @@
852  struct member *member,
853  struct object *object,
854  struct nlist *symbols,
855 -long nsyms,
856 +unsigned long nsyms,
857  char *strings,
858 -long strsize,
859 +unsigned long strsize,
860  struct dylib_table_of_contents *tocs,
861  unsigned long ntoc,
862  struct dylib_module *mods,
863 @@ -2667,7 +2659,7 @@
864             len = 0;
865             if(symbols[i].n_un.n_strx != 0){
866                 if(symbols[i].n_un.n_strx < 0 ||
867 -                  symbols[i].n_un.n_strx > strsize){
868 +                  (unsigned long)symbols[i].n_un.n_strx > strsize){
869                     error_arch(arch, member, "bad string index for symbol "
870                                "table entry %lu in: ", i);
871                     return(FALSE);
872 @@ -2695,7 +2687,7 @@
873                                          remove_symbols, nremove_symbols,
874                                          sizeof(struct symbol_list),
875                                          (int (*)(const void *, const void *))
876 -                                           cmp_bsearch);
877 +                                           symbol_list_bsearch);
878                             if(sp != NULL){
879                                 if(sp->sym != NULL){
880                                     error_arch(arch, member, "more than one "
881 @@ -2719,7 +2711,7 @@
882                                          save_symbols, nsave_symbols,
883                                          sizeof(struct symbol_list),
884                                          (int (*)(const void *, const void *))
885 -                                           cmp_bsearch);
886 +                                           symbol_list_bsearch);
887                             if(sp != NULL){
888                                 if(sp->sym != NULL){
889                                     error_arch(arch, member, "more than one "
890 @@ -2738,7 +2730,7 @@
891                                  remove_symbols, nremove_symbols,
892                                  sizeof(struct symbol_list),
893                                  (int (*)(const void *, const void *))
894 -                                   cmp_bsearch);
895 +                                   symbol_list_bsearch);
896                     if(sp != NULL){
897                         if(sp->sym != NULL){
898                             error_arch(arch, member, "more than one symbol "
899 @@ -2777,7 +2769,7 @@
900                                  save_symbols, nsave_symbols,
901                                  sizeof(struct symbol_list),
902                                  (int (*)(const void *, const void *))
903 -                                   cmp_bsearch);
904 +                                   symbol_list_bsearch);
905                     if(sp != NULL){
906                         if(sp->sym != NULL){
907                             error_arch(arch, member, "more than one symbol "
908 @@ -2910,19 +2902,19 @@
909                 if((global_name[0] == '+' || global_name[0] == '-') &&
910                    global_name[1] == '['){
911                     j = 2;
912 -                   while(j + symbols[i].n_un.n_strx < strsize &&
913 +                   while(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
914                           global_name[j] != ']')
915                         j++;
916 -                   if(j + symbols[i].n_un.n_strx < strsize &&
917 +                   if(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
918                        global_name[j] == ']')
919                         j++;
920                 }
921                 else
922                     j = 0;
923 -               while(j + symbols[i].n_un.n_strx < strsize &&
924 +               while(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
925                       global_name[j] != ':')
926                     j++;
927 -               if(j + symbols[i].n_un.n_strx >= strsize){
928 +               if(j + (unsigned long)symbols[i].n_un.n_strx >= strsize){
929                     error_arch(arch, member, "bad N_STAB symbol name for entry "
930                         "%lu (does not contain ':' separating name from type) "
931                         "in: ", i);
932 @@ -2945,7 +2937,8 @@
933                         symbols[i].n_sect = (*global_symbol)->n_sect;
934                         symbols[i].n_value = (*global_symbol)->n_value;
935                         symbols[i].n_desc = (*global_symbol)->n_desc;
936 -                       if(j + 1 + symbols[i].n_un.n_strx >= strsize ||
937 +                       if(j + 1 + (unsigned long)symbols[i].n_un.n_strx >=
938 +                          strsize ||
939                            global_name[j+1] != 'G'){
940                             error_arch(arch, member, "bad N_GSYM symbol name "
941                                 "for entry %lu (does not have type 'G' after "
942 @@ -2955,7 +2948,8 @@
943                         global_name[j+1] = 'S';
944                     }
945                     else{ /* symbols[i].n_type == N_FUN */
946 -                       if(j + 1 + symbols[i].n_un.n_strx >= strsize ||
947 +                       if(j + 1 + (unsigned long)symbols[i].n_un.n_strx >=
948 +                          strsize ||
949                            global_name[j+1] == 'F'){
950                             global_name[j+1] = 'f';
951                         }
952 Only in misc: vers_string