2363a1e3e97c5dd624a615f8695b704b58387723
[org.ibex.core.git] / upstream / darwin-linker / patches / misc.patch
1 Only in misc/: CVS
2 diff -rub misc/Makefile misc/Makefile
3 --- misc/Makefile       Tue Jan 14 23:35:29 2003
4 +++ misc/Makefile       Sat Sep  6 20:17:36 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__LITTLE_ENDIAN__ -U__BIG_ENDIAN__ -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 -rub 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 Only in misc/: seg_hack
262 Only in misc/: seg_hack.NEW
263 diff -rub misc/seg_hack.c misc/seg_hack.c
264 --- misc/seg_hack.c     Fri Sep  6 18:28:06 2002
265 +++ misc/seg_hack.c     Mon Aug 25 12:12:34 2003
266 @@ -58,7 +58,7 @@
267  char **argv,
268  char **envp)
269  {
270 -    unsigned long i;
271 +    int i;
272      char *input, *output;
273      struct arch *archs;
274      unsigned long narchs;
275 Only in misc/: seg_hack.o
276 Only in misc/: seg_hack.private.o
277 Only in misc/: segedit.c
278 Only in misc/: size.c
279 Only in misc/: strings.c
280 Only in misc/: strip.NEW
281 diff -rub misc/strip.c misc/strip.c
282 --- misc/strip.c        Tue Jan 14 23:35:30 2003
283 +++ misc/strip.c        Mon Aug 25 22:02:32 2003
284 @@ -38,11 +38,13 @@
285  #include <mach-o/reloc.h>
286  #include <mach-o/nlist.h>
287  #include <mach-o/stab.h>
288 -#include <stuff/breakout.h>
289 -#include <stuff/allocate.h>
290 -#include <stuff/errors.h>
291 -#include <stuff/round.h>
292 +#include "stuff/breakout.h"
293 +#include "stuff/allocate.h"
294 +#include "stuff/errors.h"
295 +#include "stuff/round.h"
296  #include "stuff/reloc.h"
297 +#include "stuff/reloc.h"
298 +#include "stuff/symbol_list.h"
299  
300  /* These are set from the command line arguments */
301  char *progname;                /* name of the program for error messages (argv[0]) */
302 @@ -62,6 +64,8 @@
303  static long Sflag;     /* -S strip only debugger symbols N_STAB */
304  static long xflag;     /* -x strip non-globals */
305  static long Xflag;     /* -X strip local symbols with 'L' names */
306 +static long cflag;     /* -c strip section contents from dynamic libraries
307 +                          files to create stub libraries */
308  static long strip_all = 1;
309  /*
310   * This is set on an object by object basis if the strip_all flag is still set
311 @@ -76,11 +80,6 @@
312   * save_symbols is the names of the symbols from the -s <file> argument.
313   * remove_symbols is the names of the symbols from the -R <file> argument.
314   */
315 -struct symbol_list {
316 -    char *name;                /* name of the global symbol */
317 -    struct nlist *sym; /* pointer to the nlist structure for this symbol */
318 -    enum bool seen;    /* set if the symbol is seen in the input file */
319 -};
320  static struct symbol_list *save_symbols = NULL;
321  static unsigned long nsave_symbols = 0;
322  static struct symbol_list *remove_symbols = NULL;
323 @@ -106,12 +105,12 @@
324   * and the new counts of local, defined external and undefined symbols.
325   */
326  static struct nlist *new_symbols = NULL;
327 -static long new_nsyms = 0;
328 +static unsigned long new_nsyms = 0;
329  static char *new_strings = NULL;
330 -static long new_strsize = 0;
331 -static long new_nlocalsym = 0;
332 -static long new_nextdefsym = 0;
333 -static long new_nundefsym = 0;
334 +static unsigned long new_strsize = 0;
335 +static unsigned long new_nlocalsym = 0;
336 +static unsigned long new_nextdefsym = 0;
337 +static unsigned long new_nundefsym = 0;
338  
339  /*
340   * These hold the new table of contents, reference table and module table for
341 @@ -169,9 +168,9 @@
342      struct member *member,
343      struct object *object,
344      struct nlist *symbols,
345 -    long nsyms,
346 +    unsigned long nsyms,
347      char *strings,
348 -    long strsize,
349 +    unsigned long strsize,
350      struct dylib_table_of_contents *tocs,
351      unsigned long ntoc,
352      struct dylib_module *mods,
353 @@ -202,9 +201,9 @@
354      struct member *member,
355      struct object *object,
356      struct nlist *symbols,
357 -    long nsyms,
358 +    unsigned long nsyms,
359      char *strings,
360 -    long strsize,
361 +    unsigned long strsize,
362      struct dylib_table_of_contents *tocs,
363      unsigned long ntoc,
364      struct dylib_module *mods,
365 @@ -213,19 +212,6 @@
366      unsigned long nextrefsyms);
367  #endif /* NMEDIT */
368  
369 -static void setup_symbol_list(
370 -    char *file,
371 -    struct symbol_list **list,
372 -    unsigned long *size);
373 -
374 -static int cmp_qsort_name(
375 -    const struct symbol_list *sym1,
376 -    const struct symbol_list *sym2);
377 -
378 -static int cmp_bsearch(
379 -    const char *name,
380 -    const struct symbol_list *sym);
381 -
382  #ifndef NMEDIT
383  static void setup_debug_filenames(
384      char *dfile);
385 @@ -260,7 +246,8 @@
386  char *argv[],
387  char *envp[])
388  {
389 -    unsigned long i, j, args_left, files_specified;
390 +    int i;
391 +    unsigned long j, args_left, files_specified;
392      struct arch_flag *arch_flags;
393      unsigned long narch_flags;
394      enum bool all_archs;
395 @@ -388,6 +375,12 @@
396                             strip_all = 0;
397  #endif /* !defined(NMEDIT) */
398                             break;
399 +#ifndef NMEDIT
400 +                       case 'c':
401 +                           cflag = 1;
402 +                           strip_all = 0;
403 +                           break;
404 +#endif /* NMEDIT */
405                         default:
406                             error("unrecognized option: %s", argv[i]);
407                             usage();
408 @@ -421,16 +414,16 @@
409         if(Rfile){
410             setup_symbol_list(Rfile, &remove_symbols, &nremove_symbols);
411             if(sfile){
412 -               for(i = 0; i < nremove_symbols ; i++){
413 -                   sp = bsearch(remove_symbols[i].name,
414 +               for(j = 0; j < nremove_symbols ; j++){
415 +                   sp = bsearch(remove_symbols[j].name,
416                                  save_symbols, nsave_symbols,
417                                  sizeof(struct symbol_list),
418                                  (int (*)(const void *, const void *))
419 -                                   cmp_bsearch);
420 +                                   symbol_list_bsearch);
421                     if(sp != NULL){
422                         error("symbol name: %s is listed in both -s %s and -R "
423                               "%s files (can't be both saved and removed)",
424 -                             remove_symbols[i].name, sfile, Rfile);
425 +                             remove_symbols[j].name, sfile, Rfile);
426                     }
427                 }
428                 if(errors)
429 @@ -635,7 +628,7 @@
430  
431             /*
432              * Now this arch[i] has been selected to be processed so process it
433 -            * according to it's type.
434 +            * according to its type.
435              */
436             if(archs[i].type == OFILE_ARCHIVE){
437                 for(j = 0; j < archs[i].nmembers; j++){
438 @@ -753,7 +746,7 @@
439      unsigned long nextrefsyms;
440      unsigned long *indirectsyms;
441      unsigned long nindirectsyms;
442 -    long i, j, k;
443 +    unsigned long i, j, k;
444      struct load_command *lc;
445      struct segment_command *sg;
446      struct section *s;
447 @@ -780,6 +773,15 @@
448         strings = object->object_addr + object->st->stroff;
449         strsize = object->st->strsize;
450  
451 +#ifndef NMEDIT
452 +       if(object->mh->filetype != MH_DYLIB && cflag)
453 +           fatal_arch(arch, member, "-c can't be used on non-dynamic "
454 +                      "library: ");
455 +#endif /* !(NMEDIT) */
456 +       if(object->mh->filetype == MH_DYLIB_STUB)
457 +           fatal_arch(arch, member, "dynamic stub library can't be changed "
458 +                      "once created: ");
459 +
460         if(object->mh->filetype == MH_DYLIB){
461             tocs = (struct dylib_table_of_contents *)
462                     (object->object_addr + object->dyst->tocoff);
463 @@ -795,6 +797,71 @@
464                 swap_dylib_module(mods, nmodtab, host_byte_sex);
465                 swap_dylib_reference(refs, nextrefsyms, host_byte_sex);
466             }
467 +#ifndef NMEDIT
468 +           /* 
469 +            * In the -c flag is specified then strip the section contents of
470 +            * this dynamic library and change it into a stub library.  When
471 +            * creating a stub library the timestamp is not changed.
472 +            */
473 +           if(cflag){
474 +               object->mh->filetype = MH_DYLIB_STUB;
475 +               arch->dont_update_LC_ID_DYLIB_timestamp = TRUE;
476 +
477 +               lc = object->load_commands;
478 +               for(i = 0; i < object->mh->ncmds; i++){
479 +                   if(lc->cmd == LC_SEGMENT){
480 +                       sg = (struct segment_command *)lc;
481 +                       if(strcmp(sg->segname, SEG_LINKEDIT) != 0){
482 +                           /*
483 +                            * Zero out the section offset, reloff, and size
484 +                            * fields as the section contents are being removed.
485 +                            */
486 +                           s = (struct section *)&sg[1];
487 +                           for(j = 0; j < sg->nsects; j++){
488 +                               /*
489 +                                * For section types with indirect tables we
490 +                                * do not zero out the section size in a stub
491 +                                * library.  As the section size is needed to
492 +                                * know now many indirect table entries the
493 +                                * section has.  This is a bit odd but programs
494 +                                * dealing with MH_DYLIB_STUB filetypes special
495 +                                * case this.
496 +                                */ 
497 +                               section_type = s[j].flags & SECTION_TYPE;
498 +                               if(section_type != S_SYMBOL_STUBS &&
499 +                                  section_type != S_LAZY_SYMBOL_POINTERS &&
500 +                                  section_type != S_NON_LAZY_SYMBOL_POINTERS){
501 +                                   s[j].size = 0;
502 +                               }
503 +                               s[j].addr    = 0;
504 +                               s[j].offset  = 0;
505 +                               s[j].reloff  = 0;
506 +                           }
507 +                           /* zero out file offset and size in the segment */
508 +                           sg->fileoff = 0;
509 +                           sg->filesize = 0;
510 +                       }
511 +                   }
512 +                   lc = (struct load_command *)((char *)lc + lc->cmdsize);
513 +               }
514 +               /*
515 +                * To get the right amount of the file copied out by writeout()
516 +                * for the case when we are stripping out the section contents
517 +                * we reduce the object size by the size of the section contents
518 +                * including the padding after the load commands.  Then this
519 +                * size minus the size of the input symbolic information is
520 +                * copied out.
521 +                */
522 +               object->object_size -= (object->seg_linkedit->fileoff -
523 +                       (sizeof(struct mach_header) + object->mh->sizeofcmds));
524 +               /*
525 +                * Set the file offset to the link edit information to be right
526 +                * after the load commands.
527 +                */
528 +               object->seg_linkedit->fileoff = 
529 +                       sizeof(struct mach_header) + object->mh->sizeofcmds;
530 +           }
531 +#endif /* !(NMEDIT) */
532         }
533         else{
534             tocs = NULL;
535 @@ -877,7 +944,12 @@
536             
537                 }
538  
539 -               if(object->mh->filetype == MH_DYLIB){
540 +               /*
541 +                * If the -c option is specified the object's filetype will
542 +                * have been changed from MH_DYLIB to MH_DYLIB_STUB above.
543 +                */
544 +               if(object->mh->filetype == MH_DYLIB ||
545 +                  object->mh->filetype == MH_DYLIB_STUB){
546                     object->output_tocs = new_tocs;
547                     object->output_ntoc = new_ntoc;
548  #ifdef NMEDIT
549 @@ -910,9 +982,20 @@
550                     object->dyst->ntoc * sizeof(struct dylib_table_of_contents)+
551                     object->dyst->nmodtab * sizeof(struct dylib_module) +
552                     object->dyst->nextrefsyms * sizeof(struct dylib_reference);
553 +#ifndef NMEDIT
554 +               /*
555 +                * When stripping out the section contents to create a
556 +                * dynamic library stub the relocation info also gets
557 +                * stripped.
558 +                */
559 +               if(!cflag) 
560 +#endif /* !(NMEDIT) */
561 +               {
562                 object->output_sym_info_size +=
563                     object->dyst->nlocrel * sizeof(struct relocation_info) +
564 -                   object->dyst->nextrel * sizeof(struct relocation_info) +
565 +                       object->dyst->nextrel * sizeof(struct relocation_info);
566 +               }
567 +               object->output_sym_info_size +=
568                     object->dyst->nindirectsyms * sizeof(unsigned long) +
569                     new_ntoc * sizeof(struct dylib_table_of_contents)+
570                     object->dyst->nmodtab * sizeof(struct dylib_module) +
571 @@ -961,10 +1044,24 @@
572                 if(object->dyst->nlocrel != 0){
573                     object->output_loc_relocs = (struct relocation_info *)
574                         (object->object_addr + object->dyst->locreloff);
575 +#ifndef NMEDIT
576 +                   /*
577 +                    * When stripping out the section contents to create a
578 +                    * dynamic library stub the relocation info also gets
579 +                    * stripped.
580 +                    */
581 +                   if(cflag){
582 +                       object->dyst->nlocrel = 0;
583 +                       object->dyst->locreloff = 0;
584 +                   }
585 +                   else
586 +#endif /* defined(NMEDIT) */
587 +                   {
588                     object->dyst->locreloff = offset;
589                     offset += object->dyst->nlocrel *
590                               sizeof(struct relocation_info);
591                 }
592 +               }
593                 else
594                     object->dyst->locreloff = 0;
595  
596 @@ -990,10 +1087,24 @@
597                 if(object->dyst->nextrel != 0){
598                     object->output_ext_relocs = (struct relocation_info *)
599                         (object->object_addr + object->dyst->extreloff);
600 +#ifndef NMEDIT
601 +                   /*
602 +                    * When stripping out the section contents to create a
603 +                    * dynamic library stub the relocation info also gets
604 +                    * stripped.
605 +                    */
606 +                   if(cflag){
607 +                       object->dyst->nextrel = 0;
608 +                       object->dyst->extreloff = 0;
609 +                   }
610 +                   else
611 +#endif /* defined(NMEDIT) */
612 +                   {
613                     object->dyst->extreloff = offset;
614                     offset += object->dyst->nextrel *
615                               sizeof(struct relocation_info);
616                 }
617 +               }
618                 else
619                     object->dyst->extreloff = 0;
620  
621 @@ -1014,6 +1125,24 @@
622                     object->dyst->tocoff = 0;
623  
624                 if(object->dyst->nmodtab != 0){
625 +#ifndef NMEDIT
626 +                   /*
627 +                    * When stripping out the section contents to create a
628 +                    * dynamic library stub zero out the fields in the module
629 +                    * table for the sections and relocation information.
630 +                    */
631 +                   if(cflag){
632 +                       /* Clear Objective-C address and size from modules. */
633 +                       for(k = 0; k < object->dyst->nmodtab; k++){
634 +                           mods[k].iinit_iterm = 0;
635 +                           mods[k].ninit_nterm = 0;
636 +                           mods[k].iextrel = 0;
637 +                           mods[k].nextrel = 0;
638 +                           mods[k].objc_module_info_addr = 0;
639 +                           mods[k].objc_module_info_size = 0;
640 +                       }
641 +                   }
642 +#endif /* !(NMEDIT) */
643                     object->dyst->modtaboff = offset;
644                     offset += object->dyst->nmodtab *
645                               sizeof(struct dylib_module);
646 @@ -1423,120 +1552,6 @@
647         }
648  }
649  
650 -/*
651 - * This is called to setup a symbol list from a file.  It reads the file with
652 - * the strings in it and places them in an array of symbol_list structures and
653 - * then sorts them by name.
654 - *
655 - * The file that contains the symbol names must have symbol names one per line,
656 - * leading and trailing white space is removed and lines starting with a '#'
657 - * and lines with only white space are ignored.
658 - */
659 -static
660 -void
661 -setup_symbol_list(
662 -char *file,
663 -struct symbol_list **list,
664 -unsigned long *size)
665 -{
666 -    int fd, i, j, len, strings_size;
667 -    struct stat stat_buf;
668 -    char *strings, *p, *line;
669 -
670 -       if((fd = open(file, O_RDONLY)) < 0){
671 -           system_error("can't open: %s", file);
672 -           return;
673 -       }
674 -       if(fstat(fd, &stat_buf) == -1){
675 -           system_error("can't stat: %s", file);
676 -           close(fd);
677 -           return;
678 -       }
679 -       strings_size = stat_buf.st_size;
680 -       strings = (char *)allocate(strings_size + 2);
681 -       strings[strings_size] = '\n';
682 -       strings[strings_size + 1] = '\0';
683 -       if(read(fd, strings, strings_size) != strings_size){
684 -           system_error("can't read: %s", file);
685 -           close(fd);
686 -           return;
687 -       }
688 -       /*
689 -        * Change the newlines to '\0' and count the number of lines with
690 -        * symbol names.  Lines starting with '#' are comments and lines
691 -        * contain all space characters do not contain symbol names.
692 -        */
693 -       p = strings;
694 -       line = p;
695 -       for(i = 0; i < strings_size + 1; i++){
696 -           if(*p == '\n' || *p == '\r'){
697 -               *p = '\0';
698 -               if(*line != '#'){
699 -                   while(*line != '\0' && isspace(*line))
700 -                       line++;
701 -                   if(*line != '\0')
702 -                       (*size)++;
703 -               }
704 -               p++;
705 -               line = p;
706 -           }
707 -           else{
708 -               p++;
709 -           }
710 -       }
711 -       *list = (struct symbol_list *)
712 -               allocate((*size) * sizeof(struct symbol_list));
713 -
714 -       /*
715 -        * Place the strings in the list trimming leading and trailing spaces
716 -        * from the lines with symbol names.
717 -        */
718 -       p = strings;
719 -       line = p;
720 -       for(i = 0; i < (*size); ){
721 -           p += strlen(p) + 1;
722 -           if(*line != '#' && *line != '\0'){
723 -               while(*line != '\0' && isspace(*line))
724 -                   line++;
725 -               if(*line != '\0'){
726 -                   (*list)[i].name = line;
727 -                   (*list)[i].seen = FALSE;
728 -                   i++;
729 -                   len = strlen(line);
730 -                   j = len - 1;
731 -                   while(j > 0 && isspace(line[j])){
732 -                       j--;
733 -                   }
734 -                   if(j > 0 && j + 1 < len && isspace(line[j+1]))
735 -                       line[j+1] = '\0';
736 -               }
737 -           }
738 -           line = p;
739 -       }
740 -
741 -       qsort(*list, *size, sizeof(struct symbol_list),
742 -             (int (*)(const void *, const void *))cmp_qsort_name);
743 -
744 -       /* remove duplicates on the list */
745 -       for(i = 0; i < (*size); i++){
746 -           if(i + 1 < (*size)){
747 -               if(strcmp((*list)[i].name, (*list)[i+1].name) == 0){
748 -                   for(j = 1; j < ((*size) - i - 1); j++){
749 -                       (*list)[i + j].name = (*list)[i + j + 1].name;
750 -                   }
751 -                   *size = *size - 1;
752 -               }
753 -           }
754 -       }
755 -
756 -#ifdef DEBUG
757 -       printf("symbol list:\n");
758 -       for(i = 0; i < (*size); i++){
759 -           printf("0x%x name = %s\n", &((*list)[i]),(*list)[i].name);
760 -       }
761 -#endif /* DEBUG */
762 -}
763 -
764  #ifndef NMEDIT
765  /*
766   * This is called if there is a -d option specified.  It reads the file with
767 @@ -1609,9 +1624,9 @@
768  struct member *member,
769  struct object *object,
770  struct nlist *symbols,
771 -long nsyms,
772 +unsigned long nsyms,
773  char *strings,
774 -long strsize,
775 +unsigned long strsize,
776  struct dylib_table_of_contents *tocs,
777  unsigned long ntoc,
778  struct dylib_module *mods,
779 @@ -1621,7 +1636,8 @@
780  unsigned long *indirectsyms,
781  unsigned long nindirectsyms)
782  {
783 -    long i, j, k, n, inew_syms, save_debug, missing_syms, missing_symbols;
784 +    unsigned long i, j, k, n, inew_syms, save_debug, missing_syms;
785 +    unsigned long missing_symbols;
786      char *p, *q, **pp, *basename;
787      struct symbol_list *sp;
788      unsigned long new_ext_strsize, len, *changes, inew_undefsyms;
789 @@ -1686,7 +1702,7 @@
790         for(i = 0; i < nsyms; i++){
791             if(symbols[i].n_un.n_strx != 0){
792                 if(symbols[i].n_un.n_strx < 0 ||
793 -                  symbols[i].n_un.n_strx > strsize){
794 +                  (unsigned long)symbols[i].n_un.n_strx > strsize){
795                     error_arch(arch, member, "bad string index for symbol "
796                                "table entry %ld in: ", i);
797                     return(FALSE);
798 @@ -1838,7 +1854,7 @@
799                                      save_symbols, nsave_symbols,
800                                      sizeof(struct symbol_list),
801                                      (int (*)(const void *, const void *))
802 -                                       cmp_bsearch);
803 +                                       symbol_list_bsearch);
804                         if(sp != NULL){
805                             if(sp->sym == NULL){
806                                 sp->sym = &(symbols[i]);
807 @@ -1885,7 +1901,7 @@
808                                  remove_symbols, nremove_symbols,
809                                  sizeof(struct symbol_list),
810                                  (int (*)(const void *, const void *))
811 -                                   cmp_bsearch);
812 +                                   symbol_list_bsearch);
813                     if(sp != NULL){
814                         if((symbols[i].n_type & N_TYPE) == N_UNDF ||
815                            (symbols[i].n_type & N_TYPE) == N_PBUD){
816 @@ -1960,7 +1976,7 @@
817                                  save_symbols, nsave_symbols,
818                                  sizeof(struct symbol_list),
819                                  (int (*)(const void *, const void *))
820 -                                   cmp_bsearch);
821 +                                   symbol_list_bsearch);
822                     if(sp != NULL){
823                         if(sp->sym != NULL &&
824                            (sp->sym->n_type & N_PEXT) != N_PEXT){
825 @@ -2467,30 +2483,6 @@
826  }
827  #endif /* !defined(NMEDIT) */
828  
829 -/*
830 - * Function for qsort for comparing symbol list names.
831 - */
832 -static
833 -int
834 -cmp_qsort_name(
835 -const struct symbol_list *sym1,
836 -const struct symbol_list *sym2)
837 -{
838 -       return(strcmp(sym1->name, sym2->name));
839 -}
840 -
841 -/*
842 - * Function for bsearch for finding a symbol.
843 - */
844 -static
845 -int
846 -cmp_bsearch(
847 -const char *name,
848 -const struct symbol_list *sym)
849 -{
850 -       return(strcmp(name, sym->name));
851 -}
852 -
853  #ifndef NMEDIT
854  /*
855   * Function for qsort for comparing object names.
856 @@ -2525,9 +2517,9 @@
857  struct member *member,
858  struct object *object,
859  struct nlist *symbols,
860 -long nsyms,
861 +unsigned long nsyms,
862  char *strings,
863 -long strsize,
864 +unsigned long strsize,
865  struct dylib_table_of_contents *tocs,
866  unsigned long ntoc,
867  struct dylib_module *mods,
868 @@ -2667,7 +2659,7 @@
869             len = 0;
870             if(symbols[i].n_un.n_strx != 0){
871                 if(symbols[i].n_un.n_strx < 0 ||
872 -                  symbols[i].n_un.n_strx > strsize){
873 +                  (unsigned long)symbols[i].n_un.n_strx > strsize){
874                     error_arch(arch, member, "bad string index for symbol "
875                                "table entry %lu in: ", i);
876                     return(FALSE);
877 @@ -2695,7 +2687,7 @@
878                                          remove_symbols, nremove_symbols,
879                                          sizeof(struct symbol_list),
880                                          (int (*)(const void *, const void *))
881 -                                           cmp_bsearch);
882 +                                           symbol_list_bsearch);
883                             if(sp != NULL){
884                                 if(sp->sym != NULL){
885                                     error_arch(arch, member, "more than one "
886 @@ -2719,7 +2711,7 @@
887                                          save_symbols, nsave_symbols,
888                                          sizeof(struct symbol_list),
889                                          (int (*)(const void *, const void *))
890 -                                           cmp_bsearch);
891 +                                           symbol_list_bsearch);
892                             if(sp != NULL){
893                                 if(sp->sym != NULL){
894                                     error_arch(arch, member, "more than one "
895 @@ -2738,7 +2730,7 @@
896                                  remove_symbols, nremove_symbols,
897                                  sizeof(struct symbol_list),
898                                  (int (*)(const void *, const void *))
899 -                                   cmp_bsearch);
900 +                                   symbol_list_bsearch);
901                     if(sp != NULL){
902                         if(sp->sym != NULL){
903                             error_arch(arch, member, "more than one symbol "
904 @@ -2777,7 +2769,7 @@
905                                  save_symbols, nsave_symbols,
906                                  sizeof(struct symbol_list),
907                                  (int (*)(const void *, const void *))
908 -                                   cmp_bsearch);
909 +                                   symbol_list_bsearch);
910                     if(sp != NULL){
911                         if(sp->sym != NULL){
912                             error_arch(arch, member, "more than one symbol "
913 @@ -2910,19 +2902,19 @@
914                 if((global_name[0] == '+' || global_name[0] == '-') &&
915                    global_name[1] == '['){
916                     j = 2;
917 -                   while(j + symbols[i].n_un.n_strx < strsize &&
918 +                   while(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
919                           global_name[j] != ']')
920                         j++;
921 -                   if(j + symbols[i].n_un.n_strx < strsize &&
922 +                   if(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
923                        global_name[j] == ']')
924                         j++;
925                 }
926                 else
927                     j = 0;
928 -               while(j + symbols[i].n_un.n_strx < strsize &&
929 +               while(j + (unsigned long)symbols[i].n_un.n_strx < strsize &&
930                       global_name[j] != ':')
931                     j++;
932 -               if(j + symbols[i].n_un.n_strx >= strsize){
933 +               if(j + (unsigned long)symbols[i].n_un.n_strx >= strsize){
934                     error_arch(arch, member, "bad N_STAB symbol name for entry "
935                         "%lu (does not contain ':' separating name from type) "
936                         "in: ", i);
937 @@ -2945,7 +2937,8 @@
938                         symbols[i].n_sect = (*global_symbol)->n_sect;
939                         symbols[i].n_value = (*global_symbol)->n_value;
940                         symbols[i].n_desc = (*global_symbol)->n_desc;
941 -                       if(j + 1 + symbols[i].n_un.n_strx >= strsize ||
942 +                       if(j + 1 + (unsigned long)symbols[i].n_un.n_strx >=
943 +                          strsize ||
944                            global_name[j+1] != 'G'){
945                             error_arch(arch, member, "bad N_GSYM symbol name "
946                                 "for entry %lu (does not have type 'G' after "
947 @@ -2955,7 +2948,8 @@
948                         global_name[j+1] = 'S';
949                     }
950                     else{ /* symbols[i].n_type == N_FUN */
951 -                       if(j + 1 + symbols[i].n_un.n_strx >= strsize ||
952 +                       if(j + 1 + (unsigned long)symbols[i].n_un.n_strx >=
953 +                          strsize ||
954                            global_name[j+1] == 'F'){
955                             global_name[j+1] = 'f';
956                         }
957 Only in misc/: strip.o
958 Only in misc/: strip.private.o
959 Only in misc/: vers.c
960 Only in misc/: vers.o
961 Only in misc/: vers_string