2 diff -rub ld/Makefile ld/Makefile
3 --- ld/Makefile Fri Sep 6 18:27:43 2002
4 +++ ld/Makefile Sat Sep 6 20:17:46 2003
6 -DKERNEL -DKERNEL_PRIVATE -DAPPLE -DNeXT -DLIBSA_PRIVATE
9 -MIG = $(NEXT_ROOT)/usr/bin/mig
12 ifeq "macos" "$(RC_OS)"
13 - X_CFLAGS := $(shell if [ "$(RC_RELEASE)" != "Beaker" ] && \
14 + X_CFLAGS := $(shell if [ `uname` != "Linux" ] && [ "$(RC_RELEASE)" != "Beaker" ] && \
15 [ "$(RC_RELEASE)" != "Bunsen" ] && \
16 [ "$(RC_RELEASE)" != "Gonzo" ] && \
17 [ "$(RC_RELEASE)" != "Kodiak" ]; then \
21 ifneq "mwccppc" "$(notdir $(CC))"
22 - GCC_FLAGS = -Wall -Wno-precomp $(X_CFLAGS)
23 + ifeq "Linux" "$(shell uname)"
24 + GCC_FLAGS = -Wall $(X_CFLAGS) -D__LITTLE_ENDIAN__ -U__BIG_ENDIAN__ -D__ppc__ -I/usr/include -I../../../macosx-include
26 + GCC_FLAGS = -Wall $(X_CFLAGS)
30 -USE_DEPENDENCY_FILE := $(shell if [ "$(notdir $(CC))" != "mwccppc" ]; then \
31 +# Hack: Add ../misc to the path because it contains seg_hack and ver_string
32 +ifneq ($(findstring ../misc,$(PATH)),../misc)
33 + PATH:=../misc:../../misc:$(PATH)
36 +USE_DEPENDENCY_FILE := $(shell if [ `uname` != "Linux" ] && [ "$(notdir $(CC))" != "mwccppc" ]; then \
37 echo YES ; else echo NO ; \
41 fvmlibs.c layout.c specs.c pass2.c generic_reloc.c rld.c sets.c \
42 4byte_literals.c 8byte_literals.c literal_pointers.c dylibs.c \
43 indirect_sections.c mod_sections.c i860_reloc.c ppc_reloc.c \
44 - m88k_reloc.c hppa_reloc.c sparc_reloc.c coalesced_sections.c
45 + m88k_reloc.c hppa_reloc.c sparc_reloc.c coalesced_sections.c fake-mach.c
46 OBJS = $(CFILES:.c=.o)
47 INSTALL_FILES = $(CFILES) $(HFILES) Makefile notes \
48 make.defs make_defs.h librld.ofileList
50 OFILE_DIR=. SRCROOT=.. RC_CFLAGS="$(RC_CFLAGS)" \
51 LIBSTUFF="-L../../libstuff -lstuff" \
52 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
53 - MAKEINCDIR=`pwd` COPTS="-DDEBUG" CC="$(CC)"; \
54 + MAKEINCDIR="`pwd`" COPTS="-DDEBUG" CC="$(CC)"; \
56 cd $(OBJROOT)/ld_dir; $(MAKE) -f $(SRCROOT)/Makefile ld.NEW \
57 VPATH=$(SRCROOT) OFILE_DIR=$(OBJROOT)/ld_dir \
58 SYMROOT=$(SYMROOT)/ld_dir SRCROOT=$(SRCROOT) \
59 - MAKEINCDIR=`pwd` COPTS="-DDEBUG" \
60 + MAKEINCDIR="`pwd`" COPTS="-DDEBUG" \
61 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
62 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
63 RC_CFLAGS="$(RC_CFLAGS)" CC="$(CC)"; \
67 cd ld_g_dir; $(MAKE) -f ../Makefile ld_g.NEW VPATH=.. OFILE_DIR=. \
68 - SRCROOT=.. MAKEINCDIR=`pwd` COPTS="-DDEBUG" OFLAG="" \
69 + SRCROOT=.. MAKEINCDIR="`pwd`" COPTS="-DDEBUG" OFLAG="" \
70 LIBSTUFF="-L../../libstuff -lstuff"
73 cd ld_p_dir; $(MAKE) -f ../Makefile ld.NEW VPATH=.. OFILE_DIR=. \
74 - SRCROOT=.. MAKEINCDIR=`pwd` COPTS="-pg -DDEBUG" \
75 + SRCROOT=.. MAKEINCDIR="`pwd`" COPTS="-pg -DDEBUG" \
76 LIBSTUFF="-L../../libstuff -lstuff_p"
78 shlib_ofiles: $(OBJROOT)/shlib_obj $(SYMROOT)/ld_dir
79 @if [ $(SRCROOT) = . ]; \
81 (cd shlib_obj; $(MAKE) -f ../Makefile librld.o VPATH=.. \
82 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
83 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
84 COPTS="-static -DRLD -DSHLIB -I/LocalDeveloper/Headers/libsys" \
85 LIBSTUFF="-L../../libstuff -lstuff_s" \
86 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" CC="$(CC)" \
88 COPTS="-static -DRLD -DSHLIB -I/LocalDeveloper/Headers/libsys" \
89 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff_s" \
90 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
91 - MAKEINCDIR=`pwd` RC_ARCHS="$(RC_ARCHS)"); \
92 + MAKEINCDIR="`pwd`" RC_ARCHS="$(RC_ARCHS)"); \
93 rm -f $(OBJROOT)/shlib_obj/librld.ofileList; \
94 cp librld.ofileList $(OBJROOT)/shlib_obj; \
97 @if [ $(SRCROOT) = . ]; \
99 (cd ptmp_obj; $(MAKE) -f ../Makefile librld_pg.a VPATH=.. \
100 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
101 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
102 LIBSTUFF="-L../../libstuff -lstuff_p" \
103 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" CC="$(CC)" \
104 RC_CFLAGS="$(RC_CFLAGS)" COPTS="-dynamic -DRLD -pg"); \
106 RC_CFLAGS="$(RC_CFLAGS)" CC="$(CC)" \
107 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff_p" \
108 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
109 - MAKEINCDIR=`pwd` COPTS="-dynamic -DRLD -pg"); \
110 + MAKEINCDIR="`pwd`" COPTS="-dynamic -DRLD -pg"); \
111 rm -f $(OBJROOT)/profile_obj/librld.o; \
112 rm -f $(OBJROOT)/profile_obj/librld.ofileList; \
113 cp $(OBJROOT)/ptmp_obj/librld.o $(OBJROOT)/profile_obj/librld.o; \
115 @if [ $(SRCROOT) = . ]; \
117 (cd otmp_obj; $(MAKE) -f ../Makefile librld_static.a VPATH=.. \
118 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
119 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
120 LIBSTUFF="-L../../libstuff -lstuff" CC="$(CC)" \
121 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
122 RC_CFLAGS="$(RC_CFLAGS)" COPTS="-static -DRLD"); \
124 RC_CFLAGS="$(RC_CFLAGS)" CC="$(CC)" \
125 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
126 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
127 - MAKEINCDIR=`pwd` COPTS="-static -DRLD"); \
128 + MAKEINCDIR="`pwd`" COPTS="-static -DRLD"); \
129 rm -f $(OBJROOT)/optimized_obj/librld.o; \
130 rm -f $(OBJROOT)/optimized_obj/librld.ofileList; \
131 cp $(OBJROOT)/otmp_obj/librld.o $(OBJROOT)/optimized_obj/librld.o;\
133 @if [ $(SRCROOT) = . ]; \
135 (cd dtmp_obj; $(MAKE) -f ../Makefile librld.a VPATH=.. \
136 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
137 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
138 LIBSTUFF="-L../../libstuff -lstuff" CC="$(CC)" \
139 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
140 RC_CFLAGS="$(RC_CFLAGS)" COPTS="-dynamic -DRLD"); \
142 RC_CFLAGS="$(RC_CFLAGS)" CC="$(CC)" \
143 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
144 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
145 - MAKEINCDIR=`pwd` COPTS="-dynamic -DRLD"); \
146 + MAKEINCDIR="`pwd`" COPTS="-dynamic -DRLD"); \
147 rm -f $(OBJROOT)/dynamic_obj/librld.o; \
148 rm -f $(OBJROOT)/dynamic_obj/librld.ofileList; \
149 cp $(OBJROOT)/dtmp_obj/librld.o $(OBJROOT)/dynamic_obj/librld.o;\
151 @if [ $(SRCROOT) = . ]; \
153 cd sarld_dir; $(MAKE) -f ../Makefile libsarld.a VPATH=.. \
154 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
155 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
156 COPTS="-static -DRLD -DSA_RLD" CC="$(CC)" \
157 LIBSTUFF="-L../../libstuff -lstuff" \
158 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
159 @@ -255,14 +264,14 @@
160 COPTS="-static -DRLD -DSA_RLD" RC_CFLAGS="$(RC_CFLAGS)" \
161 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
162 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
163 - MAKEINCDIR=`pwd` RC_ARCHS="$(RC_ARCHS)"; \
164 + MAKEINCDIR="`pwd`" RC_ARCHS="$(RC_ARCHS)"; \
167 kld_build: $(OBJROOT)/dynamic_kld $(OBJROOT)/static_kld $(SYMROOT)/ld_dir
168 @if [ $(SRCROOT) = . ]; \
170 cd dynamic_kld; $(MAKE) -f ../Makefile libkld.dylib VPATH=.. \
171 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
172 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
173 COPTS="-DRLD -DKLD" CC="$(CC)" \
174 LIBSTUFF="-L../../libstuff -lstuff" \
175 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
176 @@ -274,12 +283,12 @@
177 COPTS="-DRLD -DKLD" RC_CFLAGS="$(RC_CFLAGS)" \
178 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
179 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" \
180 - MAKEINCDIR=`pwd` RC_ARCHS="$(RC_ARCHS)"; \
181 + MAKEINCDIR="`pwd`" RC_ARCHS="$(RC_ARCHS)"; \
183 @if [ $(SRCROOT) = . ]; \
185 cd static_kld; $(MAKE) -f ../Makefile libkld.a VPATH=.. \
186 - MAKEINCDIR=`pwd` OFILE_DIR=. SRCROOT=.. \
187 + MAKEINCDIR="`pwd`" OFILE_DIR=. SRCROOT=.. \
188 COPTS="-static -DRLD -DKLD $(KERN)" CC="$(CC)" \
189 LIBSTUFF="-L../../libstuff -lstuff" PRIVATE_IFLAG="" \
190 LIBMACHO="-L../../libmacho/otmp_obj -lmacho_static" \
192 LIBSTUFF="-L$(SYMROOT)/../libstuff -lstuff" \
193 LIBMACHO="-L$(SYMROOT)/../libmacho -lmacho_static" \
194 VERS_STRING_FLAGS="$(VERS_STRING_FLAGS)" PRIVATE_IFLAG="" \
195 - MAKEINCDIR=`pwd` RC_ARCHS="$(RC_ARCHS)"; \
196 + MAKEINCDIR="`pwd`" RC_ARCHS="$(RC_ARCHS)"; \
199 ld.NEW: $(OBJS) ld_vers.o makeUser.o
201 makeUser.c ld.c: make.h
203 make.h makeUser.c: make.defs
204 - $(MIG) $(MIG_FLAGS) $(SRCROOT)/make.defs
206 + #~ $(MIG) $(MIG_FLAGS) $(SRCROOT)/make.defs
207 + #~ rm -f makeServer.c
208 + cp $(SRCROOT)/makeUser.c .
211 ifeq "mwccppc" "$(notdir $(CC))"
212 diff -rub ld/coalesced_sections.c ld/coalesced_sections.c
213 --- ld/coalesced_sections.c Tue Jan 14 23:35:24 2003
214 +++ ld/coalesced_sections.c Mon Aug 25 22:11:47 2003
215 @@ -579,15 +579,15 @@
217 * The number of relocation entries in the output file is based
218 * on one of three different cases:
219 - * The output file is a dynamic shared library file
220 + * The output file is a multi module dynamic shared library
221 * The output file has a dynamic linker load command
222 * The output does not have a dynamic linker load command
224 - if(filetype == MH_DYLIB){
225 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
227 - * For dynamic shared library files the modules are kept
228 - * separate so external relocation entries on input will be
229 - * external relocation entries on output. For local
230 + * For a multi module dynamic shared library the modules are
231 + * kept separate so external relocation entries on input
232 + * will be external relocation entries on output. For local
233 * relocation entries only non-position-independent local
234 * relocation entries are kept. Modules of dylibs are not
235 * linked together and can only be slid keeping all sections
236 Only in ld/: dtmp_obj
237 diff -rub ld/dylibs.c ld/dylibs.c
238 --- ld/dylibs.c Fri Sep 6 18:27:43 2002
239 +++ ld/dylibs.c Mon Aug 25 22:11:47 2003
246 +enum bool force_weak)
249 struct mach_header *mh;
251 * file. Only record the library itself.
253 if((lc->cmd != LC_LOAD_DYLIB &&
254 - lc->cmd != LC_LOAD_WEAK_DYLIB) || mh->filetype != MH_DYLIB){
255 + lc->cmd != LC_LOAD_WEAK_DYLIB) ||
256 + (mh->filetype != MH_DYLIB &&
257 + mh->filetype != MH_DYLIB_STUB) ){
258 dl = (struct dylib_command *)lc;
259 mdl = lookup_merged_dylib(dl);
260 if(filetype == MH_DYLIB && dylib_install_name != NULL &&
262 "same install_name (%s) as the output",
264 p = add_dynamic_lib(DYLIB, dl, cur_obj);
265 + p->force_weak_dylib = force_weak;
266 mdl->dynamic_library = p;
269 diff -rub ld/dylibs.h ld/dylibs.h
270 --- ld/dylibs.h Fri Sep 6 18:27:43 2002
271 +++ ld/dylibs.h Mon Aug 25 12:12:28 2003
273 __private_extern__ void create_dylib_id_command(
275 __private_extern__ void merge_dylibs(
277 + enum bool force_weak);
278 __private_extern__ void add_dylib_segment(
279 struct segment_command *sg,
281 Only in ld/: dynamic_kld
282 Only in ld/: dynamic_obj
283 Only in ld/: dynamic_profile_obj
284 Only in ld/: fake-mach.c
285 diff -rub ld/generic_reloc.c ld/generic_reloc.c
286 --- ld/generic_reloc.c Tue Jan 14 23:35:24 2003
287 +++ ld/generic_reloc.c Mon Aug 25 22:11:47 2003
288 @@ -351,13 +351,13 @@
290 * If the symbol is undefined (or common) or a global coalesced
291 * symbol where we need to force an external relocation entry
292 - * and we are not prebinding no relocation is done.
293 - * Or if the output file is MH_DYLIB no relocation is done
294 + * and we are not prebinding no relocation is done. Or if the
295 + * output file is a multi module MH_DYLIB no relocation is done
296 * unless the symbol is a private extern or we are prebinding.
298 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
299 (force_extern_reloc == TRUE && prebinding == FALSE) ||
300 - (filetype == MH_DYLIB &&
301 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
302 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
303 prebinding == FALSE) ) )
305 @@ -728,18 +728,19 @@
306 * For external relocation entries that the symbol is
307 * defined (not undefined or common) but not when we are
308 * forcing an external relocation entry for a global
309 - * coalesced symbol and if the output file is not MH_DYLIB
310 - * or the symbol is a private extern it is changed to a
311 - * local relocation entry using the section that symbol is
312 - * defined in. If still undefined or forcing an external
313 - * relocation entry for a global coalesced symbol then the
314 - * index of the symbol in the output file is set into
316 + * coalesced symbol and if the output file is not a multi
317 + * module MH_DYLIB or the symbol is a private extern, it is
318 + * changed to a local relocation entry using the section
319 + * that symbol is defined in. If still undefined or forcing
320 + * an external relocation entry for a global coalesced
321 + * symbol, then the index of the symbol in the output file
322 + * is set into r_symbolnum.
324 else if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
325 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
326 force_extern_reloc == FALSE &&
327 - (filetype != MH_DYLIB ||
328 + ((filetype != MH_DYLIB ||
329 + multi_module_dylib == FALSE) ||
330 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
333 diff -rub ld/hppa_reloc.c ld/hppa_reloc.c
334 --- ld/hppa_reloc.c Tue Jan 14 23:35:24 2003
335 +++ ld/hppa_reloc.c Mon Aug 25 22:11:47 2003
336 @@ -384,13 +384,13 @@
338 * If the symbol is undefined (or common) or a global coalesced
339 * symbol where we need to force an external relocation entry
340 - * and we are not prebinding no relocation is done.
341 - * Or if the output file is MH_DYLIB no relocation is done
342 + * and we are not prebinding no relocation is done. Or if the
343 + * output file is a multi module MH_DYLIB no relocation is done
344 * unless the symbol is a private extern or we are prebinding.
346 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
347 (force_extern_reloc == TRUE && prebinding == FALSE) ||
348 - (filetype == MH_DYLIB &&
349 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
350 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
351 prebinding == FALSE) ) )
354 section_map, r_address) +
356 if(save_reloc == 0 &&
357 - (filetype != MH_DYLIB || (r_extern == 1 &&
358 + ((filetype != MH_DYLIB ||
359 + multi_module_dylib == FALSE) ||
361 (merged_symbol->nlist.n_type & N_PEXT) ==
363 (output_for_dyld == FALSE || r_extern == 0 ||
364 @@ -1001,7 +1003,8 @@
367 if(save_reloc == 0 &&
368 - (filetype != MH_DYLIB || (r_extern == 1 &&
369 + ((filetype != MH_DYLIB || multi_module_dylib == FALSE) ||
371 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)) &&
372 (output_for_dyld == FALSE || r_extern == 0 ||
373 (merged_symbol->nlist.n_type & N_TYPE) != N_UNDF) &&
374 @@ -1054,18 +1057,19 @@
375 * For external relocation entries that the symbol is
376 * defined (not undefined or common) but not when we are
377 * forcing an external relocation entry for a global
378 - * coalesced symbol and if the output file is not MH_DYLIB
379 - * or the symbol is a private extern it is changed to a
380 - * local relocation entry using the section that symbol is
381 - * defined in. If still undefined or forcing an external
382 - * relocation entry for a global coalesced symbol then the
383 - * index of the symbol in the output file is set into
385 + * coalesced symbol and if the output file is not a multi
386 + * module MH_DYLIB or the symbol is a private extern, it is
387 + * changed to a local relocation entry using the section
388 + * that symbol is defined in. If still undefined or forcing
389 + * an external relocation entry for a global coalesced
390 + * symbol, then the index of the symbol in the output file
391 + * is set into r_symbolnum.
393 else if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
394 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
395 force_extern_reloc == FALSE &&
396 - (filetype != MH_DYLIB ||
397 + ((filetype != MH_DYLIB ||
398 + multi_module_dylib == FALSE) ||
399 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
402 diff -rub ld/i860_reloc.c ld/i860_reloc.c
403 --- ld/i860_reloc.c Tue Jan 14 23:35:24 2003
404 +++ ld/i860_reloc.c Mon Aug 25 22:11:47 2003
405 @@ -370,13 +370,13 @@
407 * If the symbol is undefined (or common) or a global coalesced
408 * symbol where we need to force an external relocation entry
409 - * and we are not prebinding no relocation is done.
410 - * Or if the output file is MH_DYLIB no relocation is done
411 + * and we are not prebinding no relocation is done. Or if the
412 + * output file is a multi module MH_DYLIB no relocation is done
413 * unless the symbol is a private extern or we are prebinding.
415 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
416 (force_extern_reloc == TRUE && prebinding == FALSE) ||
417 - (filetype == MH_DYLIB &&
418 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
419 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
420 prebinding == FALSE) ) )
422 @@ -762,19 +762,21 @@
423 * For external relocation entries that the symbol is
424 * defined (not undefined or common) but not when we are
425 * forcing an external relocation entry for a global
426 - * coalesced symbol and if the output file is not MH_DYLIB
427 - * or the symbol is a private extern it is changed to a
428 - * local relocation entry using the section that symbol is
429 - * defined in. If still undefined or forcing an external
430 - * relocation entry for a global coalesced symbol then the
431 - * index of the symbol in the output file is set into
433 + * coalesced symbol and if the output file is not a multi
434 + * module MH_DYLIB or the symbol is a private extern, it is
435 + * changed to a local relocation entry using the section
436 + * that symbol is defined in. If still undefined or forcing
437 + * an external relocation entry for a global coalesced
438 + * symbol, then the index of the symbol in the output file
439 + * is set into r_symbolnum.
441 if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
442 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
443 force_extern_reloc == FALSE &&
444 - (filetype != MH_DYLIB ||
445 + ((filetype != MH_DYLIB ||
446 + multi_module_dylib == FALSE) ||
447 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
448 + reloc->r_extern = 0;
451 * If this symbol was in the base file then no futher
452 diff -rub ld/indirect_sections.c ld/indirect_sections.c
453 --- ld/indirect_sections.c Tue Jan 14 23:35:24 2003
454 +++ ld/indirect_sections.c Mon Aug 25 22:11:47 2003
455 @@ -370,11 +370,13 @@
456 (merged_symbol->definition_object->section_maps[
457 merged_symbol->nlist.n_sect - 1].
458 s->flags & SECTION_TYPE) == S_COALESCED){
459 - if(output_for_dyld && has_dynamic_linker_command &&
460 + if((output_for_dyld && has_dynamic_linker_command &&
461 (((merged_symbol->nlist.n_desc & N_WEAK_DEF) !=
463 ((merged_symbol->nlist.n_type & N_PEXT) == N_PEXT &&
464 - keep_private_externs == FALSE) ) )
465 + keep_private_externs == FALSE) ) ) ||
466 + (filetype == MH_DYLIB && multi_module_dylib == FALSE &&
467 + (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT) )
468 fine_relocs[i].indirect_defined = TRUE;
470 fine_relocs[i].indirect_defined = FALSE;
472 if((merged_symbol->nlist.n_type & N_TYPE) == N_ABS)
473 section_map->absolute_indirect_defineds = TRUE;
475 - if(filetype == MH_DYLIB ||
476 + if((filetype == MH_DYLIB && multi_module_dylib == TRUE) ||
477 section_type == S_NON_LAZY_SYMBOL_POINTERS ||
478 fine_relocs[i].indirect_defined == FALSE){
479 fine_relocs[i].output_offset = lookup_indirect_item(
480 @@ -685,15 +687,16 @@
481 merged_symbol = (struct merged_symbol *)
482 merged_symbol->nlist.n_value;
484 - * For dynamic shared library format files the merged sections
485 - * that could have had external relocation entries must be
486 - * resolved to private extern symbols. This is because for
487 - * MH_DYLIB files all modules share the merged sections and the
488 - * entire section gets relocated when the library is mapped in.
489 - * So the above restriction assures the merged section will get
490 - * relocated properly and can be shared amoung library modules.
491 + * For multi module dynamic shared library format files the
492 + * merged sections that could have had external relocation
493 + * entries must be resolved to private extern symbols. This is
494 + * because for multi module MH_DYLIB files all modules share the
495 + * merged sections and the entire section gets relocated when
496 + * the library is mapped in. So the above restriction assures
497 + * the merged section will get relocated properly and can be
498 + * shared amoung library modules.
500 - if(filetype == MH_DYLIB){
501 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
503 * If the symbol is undefined or not a private extern it is
504 * an error for in this section for a MH_DYLIB file.
505 @@ -704,19 +707,20 @@
506 merged_symbol->defined_in_dylib == TRUE)){
507 if(merged_symbol->error_flagged_for_dylib == 0){
508 error_with_cur_obj("illegal undefined reference "
509 - "for MH_DYLIB output file to symbol: %s from "
510 - "section (%.16s,%.16s) relocation entry: %lu",
511 - merged_symbol->nlist.n_un.n_name,
512 - s->segname, s->sectname, i);
513 + "for multi module MH_DYLIB output file to "
514 + "symbol: %s from section (%.16s,%.16s) "
515 + "relocation entry: %lu",
516 + merged_symbol->nlist.n_un.n_name, s->segname,
518 merged_symbol->error_flagged_for_dylib = 1;
521 else if((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT){
522 if(merged_symbol->error_flagged_for_dylib == 0){
523 error_with_cur_obj("illegal external reference for "
524 - "MH_DYLIB output file to symbol: %s (not a "
525 - "private extern symbol) from section (%.16s,"
526 - "%.16s) relocation entry: %lu",
527 + "multi module MH_DYLIB output file to symbol: "
528 + "%s (not a private extern symbol) from section "
529 + "(%.16s,%.16s) relocation entry: %lu",
530 merged_symbol->nlist.n_un.n_name,
531 s->segname, s->sectname, i);
532 merged_symbol->error_flagged_for_dylib = 1;
533 @@ -760,18 +764,19 @@
535 * The number of relocation entries in the output file is based
536 * on one of three different cases:
537 - * The output file is a dynamic shared library file
538 + * The output file is a multi module dynamic shared library
539 * The output file has a dynamic linker load command
540 * The output does not have a dynamic linker load command
542 - if(filetype == MH_DYLIB){
543 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
545 - * For dynamic shared library files there are no external
546 - * relocation entries that will be left as external as
547 - * checked above. Only non-position-independent local
548 - * relocation entries are kept. Modules of dylibs are not
549 - * linked together and can only be slid keeping all sections
550 - * relative to each other the same.
551 + * For multi module dynamic shared library files there are
552 + * no external relocation entries that will be left as
553 + * external as checked above. Only non-position-independent
554 + * local relocation entries are kept. Modules of multi
555 + * module dylibs are not linked together and can only be
556 + * slid keeping all sections relative to each other the
560 ms->nlocrel += 1 + pair;
562 #if defined(DEBUG) && defined(PROBE_COUNT)
565 - hashval = ((long)merged_symbol) % INDIRECT_SECTION_HASHSIZE;
566 + hashval = ((unsigned long)merged_symbol) % INDIRECT_SECTION_HASHSIZE;
567 for(bp = data->hashtable[hashval]; bp; bp = bp->next){
568 #if defined(DEBUG) && defined(PROBE_COUNT)
570 @@ -1296,7 +1301,7 @@
571 if(nindirectsyms == 0)
573 if(strip_level == STRIP_ALL)
574 - fatal("can't use -s with input files containg indirect symbols "
575 + fatal("can't use -s with input files containing indirect symbols "
576 "(output file must contain at least global symbols, for "
577 "maximum stripping use -x)");
578 indirect_symbols = (unsigned long *)(output_addr +
579 diff -rub ld/layout.c ld/layout.c
580 --- ld/layout.c Tue Jan 14 23:35:24 2003
581 +++ ld/layout.c Mon Aug 25 23:22:05 2003
583 #include "stuff/openstep_mach.h"
584 #include <mach-o/fat.h>
585 #include <mach-o/loader.h>
586 -#import <mach/m68k/thread_status.h>
587 -#import <mach/ppc/thread_status.h>
588 -#import <mach/m88k/thread_status.h>
589 -#import <mach/i860/thread_status.h>
590 -#import <mach/i386/thread_status.h>
591 -#import <mach/hppa/thread_status.h>
592 -#import <mach/sparc/thread_status.h>
593 +#include <mach/m68k/thread_status.h>
594 +#include <mach/ppc/thread_status.h>
595 +#include <mach/m88k/thread_status.h>
596 +#include <mach/i860/thread_status.h>
597 +#include <mach/i386/thread_status.h>
598 +#include <mach/hppa/thread_status.h>
599 +#include <mach/sparc/thread_status.h>
600 #include <mach-o/nlist.h>
601 #include <mach-o/reloc.h>
603 +#include <mach/kern_return.h>
605 #if defined(RLD) && !defined(SA_RLD) && !(defined(KLD) && defined(__STATIC__))
606 +typedef void NXStream;
607 #include <mach-o/rld.h>
608 -#include <streams/streams.h>
609 +//~ #include <streams/streams.h>
610 #endif /* defined(RLD) && !defined(SA_RLD) &&
611 !(defined(KLD) && defined(__STATIC__)) */
612 #include "stuff/arch.h"
614 #include "mach-o/sarld.h"
615 #include "indirect_sections.h"
617 +#if ( defined(__MWERKS__) && !defined(__private_extern__) )
618 +#define __private_extern__ __declspec(private_extern)
619 +#elif ( defined(__linux__) && !defined(__private_extern__) )
620 +#define __private_extern__ extern
623 +/** gcc on Linux defines powerpc, if we are compiling on a powerpc. */
627 __private_extern__ long RLD_DEBUG_OUTPUT_FILENAME_flag;
630 if(filetype == MH_EXECUTE ||
631 filetype == MH_BUNDLE ||
632 filetype == MH_DYLIB ||
633 - filetype == MH_DYLINKER)
634 + filetype == MH_DYLINKER){
635 setup_link_editor_symbols();
636 + if(undefined_flag == UNDEFINED_DEFINE_A_WAY)
637 + define_undefined_symbols_a_way();
639 if(filetype == MH_PRELOAD)
640 define_link_editor_preload_symbols(TRUE);
641 #endif /* !defined(RLD) */
643 if(strip_level != STRIP_ALL)
644 linkedit_segment.sg.filesize +=
646 + - nstripped_merged_symbols
648 - nmerged_symbols_referenced_only_from_dylibs) *
649 sizeof(struct nlist) +
651 if(strip_level != STRIP_ALL){
652 output_symtab_info.symtab_command.nsyms =
654 + - nstripped_merged_symbols
656 - nmerged_symbols_referenced_only_from_dylibs;
657 output_symtab_info.symtab_command.strsize =
658 @@ -1301,20 +1319,21 @@
662 - * For rld() the output format is MH_OBJECT and only the contents of the
663 - * segment (the entire vmsize not just the filesize) without headers is
664 - * allocated and the address the segment is linked to is the address of
666 + * For rld() the output format is MH_OBJECT and the contents of the
667 + * first segment (the entire vmsize not just the filesize), if it exists,
668 + * plus headers are allocated and the address the segment is linked to
669 + * is the address of this memory.
672 - if(first_msg != NULL){
676 unsigned long allocate_size;
678 headers_size = round(headers_size, max_align);
679 - output_size = headers_size + first_msg->sg.vmsize;
680 + output_size = headers_size;
681 + if(first_msg != NULL)
682 + output_size += first_msg->sg.vmsize;
683 allocate_size = output_size;
684 if(strip_level != STRIP_ALL)
685 allocate_size += output_symtab_info.symtab_command.nsyms *
686 @@ -1346,6 +1365,8 @@
687 #endif /* RLD_VM_ALLOC_DEBUG */
688 sets[cur_set].output_addr = output_addr;
689 sets[cur_set].output_size = output_size;
691 + if(first_msg != NULL){
692 if(address_func != NULL){
693 if(RLD_DEBUG_OUTPUT_FILENAME_flag)
694 first_msg->sg.vmaddr =
695 @@ -2194,12 +2215,18 @@
696 (unsigned int)(ms->s.addr +
697 fine_relocs[k].output_offset),
699 - (k == object_file->section_maps[j].
701 - object_file->section_maps[j].s->size -
702 - fine_relocs[k].input_offset :
703 - fine_relocs[k + 1].input_offset -
704 - fine_relocs[k].input_offset));
705 + (k == (unsigned int)
706 + ((object_file->section_maps[j].
710 + (object_file->section_maps[j].s->size) -
711 + (unsigned int)(fine_relocs[k].
713 + (unsigned int)(fine_relocs[k + 1].
715 + (unsigned int)(fine_relocs[k].
717 print_obj_name(object_file);
720 diff -rub ld/ld.c ld/ld.c
721 --- ld/ld.c Tue Jan 14 23:35:24 2003
722 +++ ld/ld.c Mon Aug 25 22:11:47 2003
724 #include <mach/mach.h>
725 #include <mach/mach_error.h>
726 #include "stuff/seg_addr_table.h"
728 +#include "stuff/symbol_list.h"
731 #include <mach/mach_init.h>
732 #if defined(__OPENSTEP__) || defined(__GONZO_BUNSEN_BEAKER__)
734 __private_extern__ char *outputfile = NULL;
735 /* type of output file */
736 __private_extern__ unsigned long filetype = MH_EXECUTE;
737 +/* multi or single module dylib output */
738 +__private_extern__ enum bool multi_module_dylib = TRUE;
740 static enum bool filetype_specified = FALSE;
741 +static enum bool moduletype_specified = FALSE;
742 /* if the -A flag is specified use to set the object file type */
743 static enum bool Aflag_specified = FALSE;
744 #endif /* !defined(RLD) */
746 /* Strip the base file symbols (the -A argument's symbols) */
747 __private_extern__ enum bool strip_base_symbols = FALSE;
751 + * Data structures to perform selective exporting of global symbols.
752 + * save_symbols is the names of the symbols from -exported_symbols_list
753 + * remove_symbols is the names of the symbols from -unexported_symbols_list
755 +__private_extern__ struct symbol_list *save_symbols = NULL;
756 +__private_extern__ unsigned long nsave_symbols = 0;
757 +__private_extern__ struct symbol_list *remove_symbols = NULL;
758 +__private_extern__ unsigned long nremove_symbols = 0;
762 /* The list of symbols to be traced */
763 __private_extern__ char **trace_syms = NULL;
764 __private_extern__ unsigned long ntrace_syms = 0;
766 static enum bool read_only_reloc_flag_specified = FALSE;
767 static enum bool sect_diff_reloc_flag_specified = FALSE;
768 static enum bool weak_reference_mismatches_specified = FALSE;
769 +static enum bool prebind_all_twolevel_modules_specified = FALSE;
772 /* True if -m is specified to allow multiply symbols, as a warning */
777 - unsigned long i, j, symbols_created, objects_specified, sections_created;
779 + unsigned long j, symbols_created, objects_specified, sections_created;
780 unsigned long table_size;
782 char *p, *symbol_name, *indr_symbol_name, *endp, *file_name;
783 @@ -438,11 +459,16 @@
784 enum weak_reference_mismatches_handling new_weak_reference_mismatches;
785 enum bool is_framework;
787 + struct symbol_list *sp;
788 + char *exported_symbols_list, *unexported_symbols_list;
789 + enum bool missing_syms;
795 + exported_symbols_list = NULL;
796 + unexported_symbols_list = NULL;
799 #ifndef BINARY_COMPARE
805 + fatal("-l: argument missing");
806 /* path searched abbrevated file name, processed in the
807 next pass of parsing arguments */
810 prebind_allow_overlap = TRUE;
812 else if(strcmp(p, "prebind_all_twolevel_modules") == 0){
813 + if(prebind_all_twolevel_modules_specified == TRUE &&
814 + prebind_all_twolevel_modules == FALSE)
815 + fatal("both -prebind_all_twolevel_modules and "
816 + "-noprebind_all_twolevel_modules can't be "
818 prebind_all_twolevel_modules = TRUE;
819 + prebind_all_twolevel_modules_specified = TRUE;
821 else if(strcmp(p, "private_bundle") == 0){
822 private_bundle = TRUE;
824 else if(strcmp(p, "nomultidefs") == 0){
827 + else if(strcmp(p, "noprebind_all_twolevel_modules") == 0){
828 + if(prebind_all_twolevel_modules_specified == TRUE &&
829 + prebind_all_twolevel_modules == TRUE)
830 + fatal("both -prebind_all_twolevel_modules and "
831 + "-noprebind_all_twolevel_modules can't be "
833 + prebind_all_twolevel_modules = FALSE;
834 + prebind_all_twolevel_modules_specified = TRUE;
840 static_specified = TRUE;
841 twolevel_namespace = FALSE;
843 + else if(strcmp(p, "search_paths_first") == 0){
844 + search_paths_first = TRUE;
847 * Flags for specifing information about sections.
849 @@ -1225,6 +1271,15 @@
850 sub_librarys[nsub_librarys++] = argv[i+1];
853 + /* -single_module for MH_DYLIB output */
854 + else if(strcmp(p, "single_module") == 0){
855 + if(moduletype_specified == TRUE &&
856 + multi_module_dylib == TRUE)
857 + fatal("can't specify both -single_module and "
859 + moduletype_specified = TRUE;
860 + multi_module_dylib = FALSE;
865 @@ -1409,6 +1464,16 @@
866 new_multiply_defined_unused_flag;
869 + /* -multi_module for MH_DYLIB output */
870 + else if(strcmp(p, "multi_module") == 0){
871 + if(moduletype_specified == TRUE &&
872 + multi_module_dylib == FALSE)
873 + fatal("can't specify both -single_module and "
875 + moduletype_specified = TRUE;
876 + multi_module_dylib = TRUE;
879 /* treat multiply defined symbols as a warning not a
882 @@ -1426,6 +1491,10 @@
883 new_undefined_flag = UNDEFINED_WARNING;
884 else if(strcmp(argv[i], "suppress") == 0)
885 new_undefined_flag = UNDEFINED_SUPPRESS;
886 + else if(strcmp(argv[i], "dynamic_lookup") == 0)
887 + new_undefined_flag = UNDEFINED_DYNAMIC_LOOKUP;
888 + else if(strcmp(argv[i], "define_a_way") == 0)
889 + new_undefined_flag = UNDEFINED_DEFINE_A_WAY;
891 fatal("-undefined: unknown argument: %s", argv[i]);
892 new_undefined_flag = UNDEFINED_ERROR;
893 @@ -1450,6 +1519,17 @@
897 + else if(strcmp(p, "unexported_symbols_list") == 0){
899 + fatal("%s: argument missing", argv[i]);
900 + if(remove_symbols != NULL)
901 + fatal("%s: multiply specified", argv[i]);
902 + setup_symbol_list(argv[i+1], &remove_symbols,
904 + unexported_symbols_list = argv[i+1];
910 /* cause the specified symbol name to be undefined */
911 @@ -1467,6 +1547,17 @@
912 filetype = MH_EXECUTE;
915 + else if(strcmp(p, "exported_symbols_list") == 0){
917 + fatal("%s: argument missing", argv[i]);
918 + if(save_symbols != NULL)
919 + fatal("%s: multiply specified", argv[i]);
920 + setup_symbol_list(argv[i+1], &save_symbols,
922 + exported_symbols_list = argv[i+1];
926 /* specify the entry point, the symbol who's value to be
927 used as the program counter in the unix thread */
929 @@ -1526,6 +1617,26 @@
930 new_weak_reference_mismatches;
933 + else if(strcmp(p, "weak_library") == 0){
935 + fatal("-weak_library: argument missing");
936 + /* object file argv[i] processed in the next pass of
937 + parsing arguments */
940 + else if(strncmp(p, "weak-l", sizeof("weak-l") - 1) == 0){
941 + if(p[sizeof("weak-l") - 1] == '\0')
942 + fatal("-weak-l: argument missing");
943 + /* path searched abbrevated file name, processed in the
944 + next pass of parsing arguments */
946 + else if(strcmp(p, "weak_framework") == 0){
948 + fatal("-weak_framework: argument missing");
949 + /* path searched abbrevated framework name, processed
950 + in the next pass of parsing arguments */
956 @@ -1664,7 +1775,7 @@
957 rc_trace_dylibs = TRUE;
958 if(getenv("RC_TRACE_PREBINDING_DISABLED") != NULL)
959 rc_trace_prebinding_disabled = TRUE;
960 - if(getenv("XBS_TRACE_BUNDLE_LOADER") != NULL &&
961 + if(getenv("LD_TRACE_BUNDLE_LOADER") != NULL &&
962 bundle_loader != NULL)
963 print("[Logging for XBS] Referenced bundle loader: %s\n",
965 @@ -1702,7 +1813,8 @@
967 if(getenv("LD_PREBIND_ALLOW_OVERLAP") != NULL)
968 prebind_allow_overlap = TRUE;
969 - if(getenv("LD_PREBIND_ALL_TWOLEVEL_MODULES") != NULL)
970 + if(prebind_all_twolevel_modules_specified == FALSE &&
971 + getenv("LD_PREBIND_ALL_TWOLEVEL_MODULES") != NULL)
972 prebind_all_twolevel_modules = TRUE;
975 @@ -1765,6 +1877,31 @@
976 if(save_reloc && strip_base_symbols == TRUE)
977 fatal("can't use -b with -r (resulting file would not be "
979 + if(keep_private_externs == TRUE){
980 + if(save_symbols != NULL)
981 + fatal("can't use both -keep_private_externs and "
982 + "-exported_symbols_list");
983 + if(remove_symbols != NULL)
984 + fatal("can't use both -keep_private_externs and "
985 + "-unexported_symbols_list");
987 + if(save_symbols != NULL && remove_symbols != NULL){
988 + for(j = 0; j < nremove_symbols ; j++){
989 + sp = bsearch(remove_symbols[j].name,
990 + save_symbols, nsave_symbols,
991 + sizeof(struct symbol_list),
992 + (int (*)(const void *, const void *))
993 + symbol_list_bsearch);
995 + error("symbol name: %s is listed in both "
996 + "-exported_symbols_list and -unexported_symbols_list "
997 + "(can't be both exported and unexported)",
998 + remove_symbols[j].name);
1004 if(filetype_specified == TRUE && filetype == MH_OBJECT){
1006 fatal("incompatible to specifiy -object when -dynamic is used "
1007 @@ -2032,6 +2169,9 @@
1008 if(nallowable_clients != 0)
1009 fatal("-allowable_client flags can only be used when -dylib "
1010 "is also specified");
1011 + if(moduletype_specified == TRUE)
1012 + fatal("-single_module or -multi_module flags can only be used "
1013 + "when -dylib is also specified");
1015 if(filetype == MH_BUNDLE){
1016 if(dynamic == FALSE)
1017 @@ -2094,9 +2234,26 @@
1018 warning("flag: -init %s ignored (-dylib was not specified",
1021 - if(twolevel_namespace == TRUE && undefined_flag != UNDEFINED_ERROR){
1022 - fatal("-undefined error must be used when -twolevel_namespace is "
1024 + if(twolevel_namespace == TRUE &&
1025 + undefined_flag != UNDEFINED_ERROR &&
1026 + undefined_flag != UNDEFINED_DYNAMIC_LOOKUP &&
1027 + undefined_flag != UNDEFINED_DEFINE_A_WAY){
1028 + if(macosx_deployment_target >=MACOSX_DEPLOYMENT_TARGET_10_3)
1029 + fatal("-undefined error, -undefined dynamic_lookup or "
1030 + "-undefined define_a_way must be used when "
1031 + "-twolevel_namespace is in effect");
1033 + fatal("-undefined error or -undefined define_a_way must be "
1034 + "used when -twolevel_namespace is in effect");
1036 + if(undefined_flag == UNDEFINED_DYNAMIC_LOOKUP){
1037 + if(dynamic == FALSE)
1038 + fatal("incompatible flag -undefined dynamic_lookup used (must "
1039 + "specify \"-dynamic\" to be used)");
1040 + if(macosx_deployment_target < MACOSX_DEPLOYMENT_TARGET_10_3)
1041 + fatal("flag: -undefined dynamic_lookup can't be used with "
1042 + "MACOSX_DEPLOYMENT_TARGET environment variable set to: "
1043 + "%s", macosx_deployment_target_name);
1045 if(twolevel_namespace == TRUE && nundef_syms != 0){
1046 fatal("can't use -U flags when -twolevel_namespace is in effect");
1047 @@ -2181,10 +2338,9 @@
1050 if(seglinkedit_specified == FALSE){
1051 - if((filetype == MH_EXECUTE || filetype == MH_BUNDLE ||
1052 + if(filetype == MH_EXECUTE || filetype == MH_BUNDLE ||
1053 filetype == MH_FVMLIB ||
1054 - filetype == MH_DYLIB || filetype == MH_DYLINKER) &&
1055 - strip_level != STRIP_ALL)
1056 + filetype == MH_DYLIB || filetype == MH_DYLINKER)
1059 seglinkedit = FALSE;
1060 @@ -2215,12 +2371,12 @@
1061 * output force the bundle_loader to be loaded first.
1063 if(bundle_loader != NULL && twolevel_namespace == FALSE){
1064 - pass1(bundle_loader, FALSE, FALSE, FALSE, TRUE);
1065 + pass1(bundle_loader, FALSE, FALSE, FALSE, TRUE, FALSE);
1067 for(i = 1 ; i < argc ; i++){
1068 if(*argv[i] != '-'){
1069 /* just a normal object file name */
1070 - pass1(argv[i], FALSE, FALSE, FALSE, FALSE);
1071 + pass1(argv[i], FALSE, FALSE, FALSE, FALSE, FALSE);
1072 objects_specified++;
1075 @@ -2234,20 +2390,20 @@
1076 * loaded first above.
1078 if(twolevel_namespace == TRUE)
1079 - pass1(argv[i+1], FALSE, FALSE, FALSE, TRUE);
1080 + pass1(argv[i+1], FALSE, FALSE, FALSE, TRUE, FALSE);
1086 /* path searched abbrevated file name */
1087 - pass1(argv[i], TRUE, FALSE, FALSE, FALSE);
1088 + pass1(argv[i], TRUE, FALSE, FALSE, FALSE, FALSE);
1089 objects_specified++;
1092 if(base_obj != NULL)
1093 fatal("only one -A argument can be specified");
1094 - pass1(argv[++i], FALSE, TRUE, FALSE, FALSE);
1095 + pass1(argv[++i], FALSE, TRUE, FALSE, FALSE, FALSE);
1096 objects_specified++;
1099 @@ -2255,7 +2411,7 @@
1100 if(dynamic == FALSE)
1101 fatal("incompatible flag -framework used (must "
1102 "specify \"-dynamic\" to be used)");
1103 - pass1(argv[++i], FALSE, FALSE, TRUE, FALSE);
1104 + pass1(argv[++i], FALSE, FALSE, TRUE, FALSE, FALSE);
1105 objects_specified++;
1107 if(strcmp(p, "filelist") == 0){
1108 @@ -2296,7 +2452,8 @@
1109 file_name = mkstr(dirname, "/",
1112 - pass1(file_name, FALSE, FALSE, FALSE, FALSE);
1113 + pass1(file_name, FALSE, FALSE, FALSE, FALSE,
1115 objects_specified++;
1116 file_name = addr + j + 1;
1118 @@ -2314,7 +2471,8 @@
1121 if(strcmp(p, "undefined") == 0 ||
1122 - strcmp(p, "umbrella") == 0){
1123 + strcmp(p, "umbrella") == 0 ||
1124 + strcmp(p, "unexported_symbols_list") == 0){
1128 @@ -2421,6 +2579,23 @@
1130 if(strcmp(p, "weak_reference_mismatches") == 0)
1132 + else if(strcmp(p, "weak_library") == 0){
1133 + pass1(argv[++i], FALSE, FALSE, FALSE, FALSE, TRUE);
1134 + objects_specified++;
1136 + else if(strncmp(p, "weak-l", sizeof("weak-l") - 1) == 0){
1137 + /* path searched abbrevated file name */
1138 + pass1(argv[i] + sizeof("weak"), TRUE, FALSE, FALSE,
1140 + objects_specified++;
1142 + else if(strcmp(p, "weak_framework") == 0){
1143 + if(dynamic == FALSE)
1144 + fatal("incompatible flag -weak_framework used (must"
1145 + " specify \"-dynamic\" to be used)");
1146 + pass1(argv[++i], FALSE, FALSE, TRUE, FALSE, TRUE);
1147 + objects_specified++;
1152 @@ -2511,6 +2686,38 @@
1156 + * Check to that the exported or unexported symbols listed were seen.
1158 + if(save_symbols != NULL){
1159 + missing_syms = FALSE;
1160 + for(j = 0; j < nsave_symbols ; j++){
1161 + if(save_symbols[j].seen == FALSE){
1162 + if(missing_syms == FALSE){
1163 + error("symbols names listed in "
1164 + "-exported_symbols_list: %s not in linked "
1165 + "objects", exported_symbols_list);
1166 + missing_syms = TRUE;
1168 + printf("%s\n", save_symbols[j].name);
1172 + if(remove_symbols != NULL){
1173 + missing_syms = FALSE;
1174 + for(j = 0; j < nremove_symbols ; j++){
1175 + if(remove_symbols[j].seen == FALSE){
1176 + if(missing_syms == FALSE){
1177 + error("symbols names listed in "
1178 + "-unexported_symbols_list: %s not in linked "
1179 + "objects", unexported_symbols_list);
1180 + missing_syms = TRUE;
1182 + printf("%s\n", remove_symbols[j].name);
1188 * If there were any errors from layout() then don't continue.
1191 @@ -2718,7 +2925,9 @@
1196 + if(output_addr != NULL)
1197 + unlink(outputfile);
1202 diff -rub ld/ld.h ld/ld.h
1203 --- ld/ld.h Tue Jan 14 23:35:24 2003
1204 +++ ld/ld.h Mon Aug 25 12:12:29 2003
1209 + STRIP_DYNAMIC_EXECUTABLE,
1214 enum undefined_check_level {
1217 - UNDEFINED_SUPPRESS
1218 + UNDEFINED_SUPPRESS,
1219 + UNDEFINED_DYNAMIC_LOOKUP,
1220 + UNDEFINED_DEFINE_A_WAY
1223 /* The error level check for (twolevel namespace) multiply defined symbols */
1225 __private_extern__ char *outputfile;
1226 /* type of output file */
1227 __private_extern__ unsigned long filetype;
1228 +/* multi or single module dylib output */
1229 +__private_extern__ enum bool multi_module_dylib;
1232 * The architecture of the output file as specified by -arch and the cputype
1233 @@ -161,6 +166,18 @@
1234 __private_extern__ enum strip_levels strip_level;
1235 /* Strip the base file symbols (the -A argument's symbols) */
1236 __private_extern__ enum bool strip_base_symbols;
1240 + * Data structures to perform selective exporting of global symbols.
1241 + * save_symbols is the names of the symbols from -exported_symbols_list
1242 + * remove_symbols is the names of the symbols from -unexported_symbols_list
1244 +__private_extern__ struct symbol_list *save_symbols;
1245 +__private_extern__ unsigned long nsave_symbols;
1246 +__private_extern__ struct symbol_list *remove_symbols;
1247 +__private_extern__ unsigned long nremove_symbols;
1250 /* The list of symbols to be traced */
1251 __private_extern__ char **trace_syms;
1253 diff -rub ld/literal_pointers.c ld/literal_pointers.c
1254 --- ld/literal_pointers.c Tue Jan 14 23:35:25 2003
1255 +++ ld/literal_pointers.c Mon Aug 25 22:11:47 2003
1258 fine_relocs = allocate(nliterals * sizeof(struct fine_reloc));
1259 memset(fine_relocs, '\0', nliterals * sizeof(struct fine_reloc));
1260 - for(i = 0; i < nliterals; i++){
1261 - fine_relocs[i].output_offset = -1;
1262 + for(j = 0; j < nliterals; j++){
1263 + fine_relocs[j].output_offset = -1;
1265 section_map->fine_relocs = fine_relocs;
1266 section_map->nfine_relocs = nliterals;
1267 @@ -374,15 +374,16 @@
1271 - * For dynamic shared library format files the merged sections that
1272 - * could have had external relocation entries must be resolved to
1273 - * private extern symbols. This is because for MH_DYLIB files all
1274 - * modules share the merged sections and the entire section gets
1275 - * relocated when the library is mapped in. So the above
1276 - * restriction assures the merged section will get relocated
1277 - * properly and can be shared amoung library modules.
1278 + * For multi module dynamic shared library format files the
1279 + * merged sections that could have had external relocation
1280 + * entries must be resolved to private extern symbols. This is
1281 + * because for multi module MH_DYLIB files all modules share the
1282 + * merged sections and the entire section gets relocated when
1283 + * the library is mapped in. So the above restriction assures
1284 + * the merged section will get relocated properly and can be
1285 + * shared amoung library modules.
1287 - if(filetype == MH_DYLIB){
1288 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
1290 * If the symbol is undefined or not a private extern it is an
1291 * error for in this section for a MH_DYLIB file.
1292 @@ -390,21 +391,22 @@
1293 if(merged_symbol->nlist.n_type == (N_EXT | N_UNDF)){
1294 if(merged_symbol->error_flagged_for_dylib == 0){
1295 error_with_cur_obj("illegal undefined reference for "
1296 - "MH_DYLIB output file to symbol: %s from a literal "
1297 - "pointer section (section (%.16s,%.16s) relocation "
1298 - "entry: %lu)", merged_symbol->nlist.n_un.n_name,
1299 - s->segname, s->sectname, i);
1300 + "multi module MH_DYLIB output file to symbol: %s "
1301 + "from a literal pointer section (section (%.16s,"
1302 + "%.16s) relocation entry: %lu)",
1303 + merged_symbol->nlist.n_un.n_name, s->segname,
1305 merged_symbol->error_flagged_for_dylib = 1;
1308 else if((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT){
1309 if(merged_symbol->error_flagged_for_dylib == 0){
1310 error_with_cur_obj("illegal external reference for "
1311 - "MH_DYLIB output file to symbol: %s (not a private "
1312 - "extern symbol) from a literal pointer section "
1313 - "(section (%.16s,%.16s) relocation entry: %lu)",
1314 - merged_symbol->nlist.n_un.n_name, s->segname,
1316 + "multi module MH_DYLIB output file to symbol: %s "
1317 + "(not a private extern symbol) from a literal "
1318 + "pointer section (section (%.16s,%.16s) relocation "
1319 + "entry: %lu)", merged_symbol->nlist.n_un.n_name,
1320 + s->segname, s->sectname, i);
1321 merged_symbol->error_flagged_for_dylib = 1;
1325 * for this literal does not have an output_offset of -1 it is an error
1326 * because we have seen it before.
1328 - if(fine_relocs[r_address/4].output_offset != -1){
1329 + if((int)(fine_relocs[r_address/4].output_offset) != -1){
1330 error_with_cur_obj("more than one relocation entry for literal "
1331 "pointer at address 0x%x (r_address 0x%x) in section "
1332 "(%.16s,%.16s)", (unsigned int)(s->addr + r_address),
1333 @@ -606,16 +608,16 @@
1335 * The number of relocation entries in the output file is based
1336 * on one of three different cases:
1337 - * The output file is a dynamic shared library file
1338 + * The output file is a multi module dynamic shared library
1339 * The output file has a dynamic linker load command
1340 * The output does not have a dynamic linker load command
1342 - if(filetype == MH_DYLIB){
1343 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
1345 - * For dynamic shared library files there are no external
1346 - * relocation entries that will be left as external as
1347 - * checked above. Only non-sectdiff local relocation
1348 - * entries are kept. Modules of dylibs are not linked
1349 + * For a multi module dynamic shared library there are no
1350 + * external relocation entries that will be left as external as
1351 + * checked above. Only non-sectdiff local relocation entries
1352 + * are kept. Modules of multi module dylibs are not linked
1353 * together and can only be slid keeping all sections
1354 * relative to each other the same.
1356 diff -rub ld/m88k_reloc.c ld/m88k_reloc.c
1357 --- ld/m88k_reloc.c Tue Jan 14 23:35:25 2003
1358 +++ ld/m88k_reloc.c Mon Aug 25 22:11:47 2003
1359 @@ -373,13 +373,13 @@
1361 * If the symbol is undefined (or common) or a global coalesced
1362 * symbol where we need to force an external relocation entry
1363 - * and we are not prebinding no relocation is done.
1364 - * Or if the output file is MH_DYLIB no relocation is done
1365 + * and we are not prebinding no relocation is done. Or if the
1366 + * output file is a multi module MH_DYLIB no relocation is done
1367 * unless the symbol is a private extern or we are prebinding.
1369 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
1370 (force_extern_reloc == TRUE && prebinding == FALSE) ||
1371 - (filetype == MH_DYLIB &&
1372 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
1373 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
1374 prebinding == FALSE) ) )
1376 @@ -910,18 +910,19 @@
1377 * For external relocation entries that the symbol is
1378 * defined (not undefined or common) but not when we are
1379 * forcing an external relocation entry for a global
1380 - * coalesced symbol and if the output file is not MH_DYLIB
1381 - * or the symbol is a private extern it is changed to a
1382 - * local relocation entry using the section that symbol is
1383 - * defined in. If still undefined or forcing an external
1384 - * relocation entry for a global coalesced symbol then the
1385 - * index of the symbol in the output file is set into
1387 + * coalesced symbol and if the output file is not a multi
1388 + * module MH_DYLIB or the symbol is a private extern, it is
1389 + * changed to a local relocation entry using the section
1390 + * that symbol is defined in. If still undefined or forcing
1391 + * an external relocation entry for a global coalesced
1392 + * symbol, then the index of the symbol in the output file
1393 + * is set into r_symbolnum.
1395 else if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
1396 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
1397 force_extern_reloc == FALSE &&
1398 - (filetype != MH_DYLIB ||
1399 + ((filetype != MH_DYLIB ||
1400 + multi_module_dylib == FALSE) ||
1401 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
1402 reloc->r_extern = 0;
1405 Only in ld/: makeUser.c
1406 diff -rub ld/mod_sections.c ld/mod_sections.c
1407 --- ld/mod_sections.c Tue Jan 14 23:35:25 2003
1408 +++ ld/mod_sections.c Mon Aug 25 22:11:47 2003
1411 static struct merged_section *dylib_ms_init = NULL;
1412 static struct merged_section *dylib_ms_term = NULL;
1413 -static unsigned long ninit = 0;
1414 -static unsigned long nterm = 0;
1415 +__private_extern__ unsigned long ninit = 0;
1416 +__private_extern__ unsigned long nterm = 0;
1417 #endif /* !defined(RLD) */
1420 diff -rub ld/mod_sections.h ld/mod_sections.h
1421 --- ld/mod_sections.h Tue Apr 30 00:37:20 2002
1422 +++ ld/mod_sections.h Mon Aug 25 12:12:29 2003
1425 * Global types, variables and routines declared in the file modinit_sections.c.
1427 +__private_extern__ unsigned long ninit;
1428 +__private_extern__ unsigned long nterm;
1430 __private_extern__ void mod_section_merge(
1432 diff -rub ld/notes ld/notes
1433 --- ld/notes Tue Jan 14 23:35:25 2003
1434 +++ ld/notes Mon Aug 25 12:12:29 2003
1436 - For m68k builds -finline-functions crashes the compiler (used in the Makefile
1437 on the ld_build target).
1439 +Changes for the 5.12 release (the cctools-477 release):
1440 +- Picked up changes to kld interfaces. Changes in rld.c and layout.c .
1441 + Radar bug #3270588.
1443 +Changes for the 5.12 release (the cctools-473 release):
1444 +- Fixed a bug with the use of a modulus operator on a signed value which caused
1445 + a crash. The fix was to cast to unsigned long not long. The problem was in
1446 + lookup_indirect_item() in indirect_sections.c when it used the modulus
1447 + operator to come up with a hash value. Radar bug #3255992.
1449 +Changes for the 5.12 release (the cctools-472 release):
1450 +- Moved the #ifndef RLD in output_local_symbols() in symbols.c down so that
1451 + the call to swap_nlist() is not ifdef'ed out. This allows cross building of
1452 + a kernel's symbol file with kld. Radar bug #3251273.
1454 +Changes for the 5.12 release (the cctools-471 release):
1455 +- Backed out the change to call to _exit() in ld_exit() in ld.c in Radar bug
1456 + #3237013 as it does not flush the stdio buffers. Then changed the handler()
1457 + routine in ld.c used for signals to not call ld_exit() and instead unlink(2)
1458 + the output file if one was created and call _exit(1). Radar bug #3245341.
1459 +- Fixed a problem in the kld libraries where the code that was not ignoring the
1460 + alignment of non-regular non-zerofill sections from the base file. A missing
1461 + #ifdef KLD and test of the base file was needed on one more place in
1462 + merge_sections() in sections.c . Radar bug #3245534.
1464 +Changes for the 5.12 release (the cctools-470 release):
1465 +- Changed the call to exit() in ld_exit() in ld.c to _exit as it was causing a
1466 + hang in dyld when used with signal handlers. Radar bug #3237013.
1467 +- Added the flag -search_paths_first to cause -lx flags to search each path
1468 + for .dylib then .a before searching next path. Radar bug #3176974.
1469 + - Added the enum bool variable search_paths_first to pass1.c and pass1.h and
1470 + code to parse out the option and set variable in main() in ld.c .
1471 + - The new static routines search_paths_for_lname() and search_path_for_lname()
1472 + were added to pass1.c .
1473 + - In pass1() in pass1.c a test of the new search_paths_first variable is done
1474 + and if TRUE then search_paths_for_lname() is called.
1476 +Changes for the 5.12 release (the cctools-468 release):
1477 +- Added support to force a dynamic library to be marked weak in the output.
1478 + This can be done using these three flags:
1479 + -weak_framework Foo
1481 + -weak_library library_filename
1482 + Radar bug #3069758.
1483 + - Added parsing out "-weak_framework", "-weak-lx"and "-weak_library" to
1484 + ld.c and calling pass1() with the force_weak parameter as TRUE.
1485 + - Added the new boolean parameter force_weak to pass1() in pass1.c and
1486 + pass1.h . Changed the existing calls to pass1() in ld.c to pass the new
1487 + boolean parameter force_weak as FALSE.
1488 + - Added the new boolean parameter force_weak to pass1_fat(), pass1_archive()
1489 + and pass1_object() in pass1.c . Propagated the passing of this new
1490 + parameter down through the calls. And passed it as FALSE in call to
1491 + pass1_fat() and pass1_object() from open_dylib().
1492 + - Added the new boolean parameter force_weak to merge() in pass1.c . And
1493 + passed this as the parameter force_weak parameter or FALSE in the existing
1495 + - Added the new boolean parameter force_weak to merge_dylibs() in dylibs.c and
1496 + dylibs.h . After the call to add_dynamic_lib() the parameter force_weak is
1497 + set into the field force_weak_dylib in the dynamic_library struct.
1498 + - Added the boolean field force_weak_dylib to the dynamic_library structure
1500 + - Changed merge_dylib_module_symbols() in symbols.c to test the
1501 + force_weak_dylib field of the dynamic_library structure and if TRUE set the
1502 + N_WEAK_REF bit on the merged symbol to mark the symbol as a weak reference.
1504 +Changes for the 5.12 release (the cctools-468 release):
1505 +- Added support for the new use of the previously unused value 3 for r_length
1506 + to mean that the conditional branch was predicted using the Y-bit and the
1507 + sign of the displacement and opcode. Radar bug #3223045.
1508 + - Changed ppc_reloc() in ppc_reloc.c to correctly flip the Y-bit for
1509 + PPC_RELOC_BR14 r_types with an r_length value of 3 for branch conditions
1510 + that are not branch always and the sign of the displacement is different
1512 +- Fixed a problem when linking against stub libraries that the dependencies of
1513 + the stub libraries were getting recored in the output file. This caused them
1514 + to have LC_LOAD_DYLIB load commands which inturn messed up the recorded
1515 + library ordinals. The fix is in merge_dylibs() in dylibs.c to add a check
1516 + that the object's file type was not MH_DYLIB_STUB. Radar bug #3220772.
1518 +Changes for the 5.12 release (the cctools-467 release):
1519 +- Added support for the PPC_RELOC_LO14_SECTDIFF relocation type used with
1520 + double word load/store instructions. Radar bug #3218027.
1521 + - Changed ppc_reloc() in ppc_reloc.c treat a PPC_RELOC_LO14_SECTDIFF as it
1522 + other PowerPC section difference relocation entries and expect it to have
1523 + a pair. And added cases for PPC_RELOC_LO14_SECTDIFF to relocate it as it
1524 + would for PPC_RELOC_LO14.
1526 +Changes for the 5.12 release (the cctools-466 release):
1527 +- Added the new treatment of "-undefined define_a_way" to define all undefined
1528 + symbols as private extern symbols. This is a temporary work around to not
1529 + having dead-code stripping that also strips the undefined references from
1530 + dead code. Radar bug 3216770.
1531 + - Added the undefined_check_level enum UNDEFINED_DEFINE_A_WAY to ld.h .
1532 + - Added parsing out "-undefined define_a_way" in main() in ld.c and modified
1533 + checks to allow its use with -twolevel_namespace.
1534 + - Added the define_a_way bit field in the merged_symbol struct in symbols.h .
1535 + - Added the define_undefined_symbols_a_way() routine to symbols.c and
1536 + symbols.h . This routines sets up the undefined symbols to be defined and
1537 + sets the define_a_way bit field in the merged_symbol.
1538 + - Added code at the end of define_link_editor_dylib_symbols() in symbols.c to
1539 + loop through the symbol table and set the address of the symbols with the
1540 + define_a_way bit field set.
1541 + - In layout() in layout.c after it sets up the link editor defined symbols
1542 + a check of the undefined_flag for UNDEFINED_DEFINE_A_WAY is made and if so
1543 + a call to define_undefined_symbols_a_way() is made.
1544 +- Fixed the incorrect casts on the comparison of the nlist struct's n_strx field
1545 + where the value being compared to was casted to a long. The correct fix was
1546 + to cast n_strx to an unsigned long.
1547 +- Added the "-undefined dynamic_lookup" option for use in two-level namespace
1548 + images to all undefined symbols to be looked up dynamically with flat
1549 + namespace semantics. Radar bug #3210803.
1550 + - Added the undefined_check_level enum UNDEFINED_DYNAMIC_LOOKUP to ld.h .
1551 + - Added parsing out "-undefined dynamic_lookup" in main() in ld.c and modified
1552 + checks to allow its use with -twolevel_namespace. Also added checks when
1553 + "-undefined dynamic_lookup" is not allowed for -static and when
1554 + MACOSX_DEPLOYMENT_TARGET is less than 10.3 .
1555 + - Changed process_undefineds() in symbols.c to changed its check of
1556 + undefined_flag != UNDEFINED_SUPPRESS
1558 + (undefined_flag == UNDEFINED_ERROR ||
1559 + undefined_flag == UNDEFINED_WARNING)
1560 + and added an else cause to that if to check if undefined_flag is
1561 + UNDEFINED_DYNAMIC_LOOKUP and then set the library ordinal to
1562 + DYNAMIC_LOOKUP_ORDINAL if -r is not used and two-level namespace is in
1564 + - Changed check_symbol() in symbols.c to not treat a symbol with the library
1565 + ordinal DYNAMIC_LOOKUP_ORDINAL as an error.
1566 + - Changed merge_dylib_module_symbols() in symbols.c in the second loop that
1567 + loops through the symbols referenced by the dylib module when it is doing
1568 + symbol tracing to check the library_ordinal for DYNAMIC_LOOKUP_ORDINAL.
1569 + And if it is DYNAMIC_LOOKUP_ORDINAL not use it as a library ordinal and
1570 + let it just get printed as an unbounded reference.
1571 + - Changed merge_dylib_module_symbols() in symbols.c in the second loop where
1572 + it resolves the undefined references and changed the logic where it selects
1573 + how to resolve the symbol. It now sets a new boolean, resolve_flat, based
1574 + on the old logic plus looking at library_ordinal for DYNAMIC_LOOKUP_ORDINAL.
1575 + - Changed search_dynamic_libs() in pass1.c when it is has an undefined symbol
1576 + from a two-level namespace image to check the library ordinal for
1577 + DYNAMIC_LOOKUP_ORDINAL and if so treat it an internal error. Since the
1578 + above change to merge_dylib_module_symbols() should never let this happen.
1579 + - Also added this same check as above and internal error message to
1580 + process_undefineds() in symbols.c in two places. Also added a missing
1581 + check in the loop looking for previous undefined two-level namespace symbols
1582 + that did not check the twolevel_reference field before using the
1583 + library_ordinal. And added a check for DYNAMIC_LOOKUP_ORDINAL in the
1584 + loop the prints the references in the -Y loop.
1586 +Changes for the 5.12 release (the cctools-464 release):
1587 +- Changed the they way N_BINCL stabs with non-zero n_value fields are handled so
1588 + the n_value is not changed. Radar bug #3201935.
1589 + - Added field input_N_BINCL_n_value to the struct localsym_block in symbols.h
1590 + - In merged_symbols() in symbols.c when a new N_BINCL is found the n_value
1591 + of the N_BINCL nlist is saved in the input_N_BINCL_n_value field. And if
1592 + not zero the variable sum is set to that value. Later when a new symbol in
1593 + the group in encountered if input_N_BINCL_n_value is not zero then the
1594 + string for that symbol is not sum'ed.
1596 +Changes for the 5.12 release (the cctools-464 release):
1597 +- Made changes to build cleanly with gcc3.3
1598 + - Removed -Wno-precomp from the Makefile
1599 + - Fixed warnings for "comparison between signed and unsigned" in ld.c,
1600 + layout.c, pass2.c, literal_pointers.c, pass1.c, rld.c and sets.c .
1602 +Changes for the 5.12 release (the cctools-463 release):
1603 +- Added support for linking against MH_DYLIB_STUB libraries. Radar bug #3193744.
1604 + - Added a check for the MH_DYLIB_STUB filetype along with MH_DYLIB in
1605 + merge_symbols() in symbols.c .
1606 + - Added the testing of the filetype not being MH_DYLIB_STUB along with
1607 + testing of the section type not being S_ZEROFILL before checking the size
1608 + and offset of the section contents in check_cur_obj() in pass1.c .
1609 + - Added the testing for MH_DYLIB_STUB along with MH_DYLIB in a few places
1610 + in check_cur_obj() in pass1.c for various error checks.
1611 + - Changed the setting of cur_obj->dylib in check_cur_obj() in pass1.c to
1612 + include the MH_DYLIB_STUB filetype.
1614 +Changes for the 5.12 release (the cctools-462 release):
1615 +- Fixed a bug in the displacement overflow checking of a PPC_RELOC_BR14
1616 + relocation entry. The mask that was used was 0xfffe0000 which should
1617 + have been 0xffff8000 in the PPC_RELOC_BR14 cases in ppc_reloc.c .
1618 + Radar bug #3190434.
1620 +Changes for the 5.12 release (the cctools-457 release):
1621 +- For the -single_module dylib case the symbol stubs for coalesced private
1622 + extern symbols were not being removed when they could be. The change is in
1623 + indirect_section_merge() in indirect_sections.c after the test if the
1624 + merged symbol is a coalesced symbol the if statement on line 373. An
1625 + additional case was added to the if expression such that if the output file
1626 + is a dylib and not multi-module and the symbol is private extern then the
1627 + expression is TRUE and indirect_defined is set to TRUE. Radar bug #3163714.
1629 +Changes for the 5.12 release (the cctools-456 release):
1630 +- Changed XBS_TRACE_BUNDLE_LOADER to LD_TRACE_BUNDLE_LOADER in ld.c. Radar bug
1633 +Changes for the 5.12 release (the cctools-454 release):
1634 +- Fixed a bug when using the -m flag and having a multiple definition of a
1635 + private extern symbol. The problem was in merge_symbols the counts of
1636 + private exterals are first incremented. Then after multiply_defined() is
1637 + called a check was needed to see if allow_multiply_defined_symbols is TRUE
1638 + (the -m flag specified) and the counts for private exterals needed to be
1639 + decremented. Radar bug #3143764.
1640 +- Fixed a bug when creating an indirect symbol when the referenced symbol is
1641 + a private extern symbol that causes an internal overlap error. Radar bug
1643 + - Added code in reduce_indr_symbols() in symbols.c so the N_PEXT bit is
1644 + checked and then the counts of private exterals (nmerged_private_symbols)
1645 + and the object's count (nprivatesym) are incremented.
1646 + - Changed assign_output_symbol_indexes() in symbols.c to check the N_PEXT
1647 + bit of the indirect symbol if the symbol is N_INDR to correctly determine
1648 + if the symbol is a private extern symbol in the two places it checks this
1651 +Changes for the 5.12 release (the cctools-450 release):
1652 +- Added some double quotes in the Makefile around uses of `pwd` to be "`pwd`" so
1653 + if this were in a directory with a space it would work. Radar bug #3114622.
1654 +- Changed is_output_local_symbol() in symbols.c to strip symbols in sections
1655 + with the S_ATTR_STRIP_STATIC_SYMS attribute. To do this n_ssect and the
1656 + object struct that the symbol came from is passed to is_output_local_symbol().
1657 + Radar bug #3114458.
1658 +- Changed the -x flag to strip private externs that will be local symbols in the
1659 + output file. Radar bug #3114182.
1660 + - Changed is_output_local_symbol() in symbols.c for the STRIP_NONGLOBALS case
1661 + (the -x flag) to return FALSE causing all local symbols to be stripped.
1662 + This strips private externs that were local symbols in the input object
1664 + - Changed assign_output_symbol_indexes() in symbols.c to rebuild the merged
1665 + string table if we are stripping non-globals and we are not keeping private
1666 + externs and we have some private externs in the merged symbol table, and the
1667 + output is not a multi-module dylib. Then if this is the case the number of
1668 + private externs in each object is added to nstripped_merged_symbols so those
1669 + symbols are not counted.
1670 + - Changed output_merged_symbols() in symbols.c to check the strip_level for
1671 + STRIP_NONGLOBALS, and the output is not a multi-module dylib and not put ou
1672 + private externs in this case.
1674 +Changes for the 5.12 release (the cctools-447 release):
1675 +- Fixed a problem with -x not stripping STABS with the P_EXT bit on them. The
1677 + 00000000 - 00 0000 3c gcc2_compiled.
1678 + was not stripped because of a bug in is_output_local_symbol() in symbols.c in
1679 + the STRIP_NONGLOBALS because it did not first check for N_STAB bits in n_type.
1680 + Radar bug #3104019.
1681 +- Added the -noprebind_all_twolevel_modules flag that overrides the setting
1682 + of the environment variable LD_PREBIND_ALL_TWOLEVEL_MODULES. The changes are
1683 + in ld.c . Radar bug #3055372.
1684 +- Fixed a bug that was causing dynamic libraries that had nothing referenced in
1685 + them that also were used indirectly that did have symbols indirectly
1686 + referenced in them to be LC_LOAD_WEAK_DYLIB. The problem was that references
1687 + from dylibs that were were causing the some_symbols_referenced field to be
1688 + set for the dylib. The fix was to merge_dylib_module_symbols() symbols.c
1689 + where it sets some_symbols_referenced. Radar bug #3094497.
1690 +- Removed the const off of link_edit_common_object in symbols.[ch] to get rid
1691 + of warnings and since it is now written on.
1693 +Changes for the 5.11 release (the cctools-446 release):
1694 +- Changed it so that when -s is used on a dynamic dynamic executable it rebuilds
1695 + the string table in assign_output_symbol_indexes() in symbols.c so that the
1696 + symbol names for the discarded symbols don't end up in the string table.
1697 + Radar bug #3089997.
1698 +- Fixed a bug when using an export list and not listing a common symbol would
1699 + cause an internal overlap error. Radar bug #3088916.
1700 + - Changed define_common_symbols() in symbols.c right after
1701 + exports_list_processing() is called to check the N_PEXT bit and increment
1702 + the counts of private exterals. Both the object's count (nprivatesym) and
1703 + the global count (nmerged_private_symbols).
1704 + - Changed assign_output_symbol_indexes() in symbols.c to add the
1705 + link_edit_common_object object to the list of objects before counting
1706 + and assigning indexes to private extern symbols. Then at the end of the
1707 + loop copying back the updated object and taking it back off the list.
1709 +Changes for the 5.11 release (the cctools-445 release):
1710 +- Changed the semantics of -s on dynamic executables to do the same stripping
1711 + as strip(1) with no arguments. That is only save undefined symbols and
1712 + global symbols marked referenced dynamically. Radar bug #2545288.
1713 + - Added the STRIP_DYNAMIC_EXECUTABLE enum value to strip_levels in ld.h .
1714 + - Added the variable nstripped_merged_symbols to symbols.c and symbols.h to
1715 + set to the number of merged symbol being stripped out. This is non-zero
1716 + when the strip_level is STRIP_DYNAMIC_EXECUTABLE.
1717 + - Changed assign_output_symbol_indexes() in symbols.c so that if strip_level
1718 + is STRIP_ALL and has_dynamic_linker_command is set to change strip_level
1719 + to STRIP_DYNAMIC_EXECUTABLE;
1720 + - Changed assign_output_symbol_indexes() to assign indexes to only undefined
1721 + symbols and global symbols marked referenced dynamically and add up the
1722 + number of merged symbol being stripped out into nstripped_merged_symbols.
1723 + - Added the case label for STRIP_DYNAMIC_EXECUTABLE in
1724 + is_output_local_symbol() in symbols.c to also return FALSE.
1725 + - Changed output_merged_symbols() in symbols.c to check the strip_level for
1726 + STRIP_DYNAMIC_EXECUTABLE and the REFERENCED_DYNAMICALLY of the symbol
1727 + and not put out those symbols in that case.
1728 + - Changed layout_segments() in layout.c when setting the
1729 + linkedit_segment.sg.filesize and output_symtab_info.symtab_command.nsyms
1730 + to subtract nstripped_merged_symbols.
1731 + - Fixed a typo in an error message in output_indirect_symbols() in
1732 + indirect_sections.c (changed "containg" to "containing").
1734 +Changes for the 5.11 release (the cctools-444 release):
1735 +- Added the -exported_symbols_list and -unexported_symbols_list flags. Radar
1737 + - Changes in ld.c and ld.h for adding the save_symbols and remove_symbols
1738 + variables and parsing and checking the flags. As well as checking to see
1739 + that the symbols were seen after pass1.
1740 + - Changed merge_symbol() in symbols.c to check if the symbol is on the
1741 + save_symbols or remove_symbols list and set the N_PEXT bit as needed.
1742 +- Fixed a problem with ppc JSR's and doing an ld -r where the JBSR has an
1743 + external relocation entry and the symbol is not defined in the output.
1744 + The code in ppc_reloc.c was:
1747 + other_half = value;
1750 + value += other_half;
1751 + other_half = value;
1753 + And in the case of an external relocation entry where the symbol was
1754 + undefined 'offset' was not set. For JBSR external relocation entries the
1755 + offset part of "symbol+offset" is stored in the PAIR relocation entry in
1756 + 'other_half'. This is because the displacement of the bl instruction is for
1757 + the branch island. So the correct code works out to be the same as the
1758 + non-extern case and was changed to just this:
1759 + value += other_half;
1760 + other_half = value;
1761 + Radar bug #3054747.
1763 +Changes for the 5.11 release (the cctools-443 release):
1764 +- Added the -single_module and -multi_module flags. Radar bug #3080780.
1765 + - Changes in ld.c and ld.h for adding the boolean multi_module_dylib and
1766 + parsing and checking the flags.
1767 + - Changed one place in coalesced_sections.c in coalesced_section_merge()
1768 + where the number of relocation is determined. The MH_DYLIB case was changed
1769 + to include multi_module_dylib == TRUE.
1770 + - Changed two places in the relocation routines in generic_reloc.c,
1771 + i860_reloc.c, m88k_reloc.c, sparc_reloc.c, hppa_reloc.c and ppc_reloc.c.
1772 + For external relocation entries where the symbol is defined, if the output
1773 + file is a multi_module dylib no relocation is done unless the symbol is a
1774 + private extern or we are prebinding. In this case the relocation entry is
1775 + left as extern. For single_module dylibs the relocation is done and the
1776 + relocation entry turned into a local relocation entry.
1777 + - Changed two places in the relocation routines in hppa_reloc.c and
1778 + ppc_reloc.c for JBSR relocations. The JBSR relocation code does not do
1779 + relocation if multi_module dylib. but will do it for a single_module dylib.
1780 + - Changed indirect_sections.c in indirect_section_merge() in three places:
1781 + - The fine relocation entry for defined external symbols are kept in dylibs
1782 + if it is a multi_module dylib (not kept for single_module dylibs).
1783 + - The check external relocation entries resolving to private extern being is
1784 + flagged as an error is only done for multi_module dylibs.
1785 + - The code that counts up the relocation entries, was changed in the dylib
1786 + case to include multi_module_dylib == TRUE.
1787 + - Changed literal_pointers.c in two places:
1788 + - In literal_pointer_merge() the check external relocation entries resolving
1789 + to private extern being is flagged as an error is only done for
1790 + multi_module dylibs.
1791 + - In the static count_reloc() routine where the number of relocation is
1792 + determined, the MH_DYLIB case was changed to include
1793 + multi_module_dylib == TRUE.
1794 + - Changed objects.c in three places:
1795 + - In object_index() zero is returned when multi_module_dylib == FALSE.
1796 + - In fine_reloc_output_address() if the reloc is in a symbol stub section
1797 + and the symbol is defined and it is not in a multi_module dylib then
1798 + the merge symbol value from the fine_reloc is used.
1799 + - In fine_reloc_output_sectnum() if the reloc is in a symbol stub section
1800 + and the symbol is defined and it is not in a multi_module dylib then
1801 + the merge symbol section number from the fine_reloc is used.
1802 + - Changed sections.c in three places:
1803 + - In layout_relocs_for_dyld() the check that merged sections don't have
1804 + any external relocation entries in dylibs had multi_module_dylib == TRUE
1806 + - In count_relocs() the dylib case for the code counting the number of
1807 + relocation entries had multi_module_dylib == TRUE added to it.
1808 + - In reloc_output_for_dyld() a matching change for the above change to
1809 + count_relocs() was made for the dylib case addin multi_module_dylib ==TRUE
1811 + - Changed many places in symbols.c:
1812 + - In the routine merge_symbols()
1813 + - The number of defined externals is now only counted in the multi
1814 + module dylib case (need to be able allocate the reference maps).
1815 + - For a merged symbol that is a weak definition that is discarded, the
1816 + symbol counts for the reference map are adjusted and the reference
1817 + flags are updated only in the multi_module dylib case.
1818 + - The reference map flags are only set in the multi_module dylib case.
1819 + - In the routine command_line_symbol() and command_line_indr_symbol() the
1820 + reference map flags are set only in the multi_module dylib case.
1821 + - In the routine merge_dylib_module_symbols() and
1822 + merge_bundle_loader_symbols() for a merged symbol that is a weak
1823 + definition that is discarded, the symbol counts for the reference map are
1824 + adjusted and the reference flags are updated only in the multi_module
1826 + - In define_common_symbols() a check for multi_module dylib is made and
1827 + it is an error if there is a common symbol to define. Also the traceing
1828 + of commons is not done in dylib if multi_module_dylib == TRUE.
1829 + - In setup_link_editor_symbols() the code is not changed for the one place
1830 + that MH_DYLIB is used. As the reference table will be ignored and
1831 + output_dysymtab_info.dysymtab_command.nextrefsyms will be reset
1832 + layout_dylib_tables() for single module dylibs.
1833 + - In output_merged_symbols() the N_INDR symbols are set to the defining
1834 + symbol if it is a multi_module dylib and defined in the same object or
1835 + in a single module dylib.
1836 + - In layout_dylib_tables() the existing code for the reference table and
1837 + module table where placed in if statements with multi_module_dylib == TRUE
1838 + and new code was added for the single module case. For the reference
1839 + table its size is reset based on the defined and undefined merged symbols.
1840 + The module table size is one and a variable, dylib_single_module_name, was
1841 + added to save the pointer to the module name in the merged symbol table.
1842 + - In output_dylib_tables() the existing code for the reference table and
1843 + module table where placed in if statements with multi_module_dylib == TRUE
1844 + and new code was added for the single module case. For the reference
1845 + table its is built from the merged symbol table's defined and undefined
1846 + symbols. The one module table entry is built from the a variable,
1847 + dylib_single_module_name, which is a pointer to the module name in the
1848 + merged symbol table and the values in output_dysymtab_info.
1849 + -Changed mod_sections.c and mod_sections.h so that ninit and nterm were
1850 + __private_extern__ so that output_dylib_tables() in symbols.c could use
1851 + them for the single module dylib module table entry.
1853 Changes for the 5.11 release (the cctools-440 release):
1854 - Fixed the warnings about extra tokens at end of #endif directive in
1855 4byte_literals.c, 8byte_literals.c, coalesced_sections.c, cstring_literals.c,
1856 diff -rub ld/objects.c ld/objects.c
1857 --- ld/objects.c Tue Jan 14 23:35:25 2003
1858 +++ ld/objects.c Mon Aug 25 22:11:47 2003
1861 * object_index() returns the index into the module table for a object file
1862 * structure. It is only used in the creation of the table of contents entries
1863 - * in a MH_DYLIB file.
1864 + * in a multi module MH_DYLIB file.
1869 struct object_list *object_list, **p;
1870 struct object_file *cmp_obj;
1872 + if(multi_module_dylib == FALSE)
1875 for(p = &objects; *p; p = &(object_list->next)){
1878 else if((map->s->flags & SECTION_TYPE) == S_SYMBOL_STUBS &&
1879 fine_reloc->indirect_defined == TRUE){
1880 if(filetype != MH_DYLIB ||
1881 + (filetype == MH_DYLIB && multi_module_dylib == FALSE) ||
1882 (cur_obj == fine_reloc->merged_symbol->definition_object &&
1883 input_offset - fine_reloc->input_offset == 0)){
1884 if(cur_obj == fine_reloc->merged_symbol->definition_object)
1887 else if((map->s->flags & SECTION_TYPE) == S_SYMBOL_STUBS &&
1888 fine_reloc->indirect_defined == TRUE &&
1889 - filetype != MH_DYLIB){
1890 + (filetype != MH_DYLIB || multi_module_dylib == FALSE)){
1891 merged_symbol = (struct merged_symbol *)fine_reloc->output_offset;
1892 if((merged_symbol->nlist.n_type & N_TYPE) == N_INDR)
1893 merged_symbol = (struct merged_symbol *)
1894 Only in ld/: optimized_obj
1895 Only in ld/: otmp_obj
1896 diff -rub ld/pass1.c ld/pass1.c
1897 --- ld/pass1.c Tue Jan 14 23:35:25 2003
1898 +++ ld/pass1.c Mon Aug 25 22:11:47 2003
1903 +/* TRUE if -search_paths_first was specified */
1904 +__private_extern__ enum bool search_paths_first = FALSE;
1906 /* the user specified directories to search for -lx names, and the number
1908 __private_extern__ char **search_dirs = NULL;
1909 @@ -156,6 +159,15 @@
1913 +static void search_paths_for_lname(
1914 + const char *lname_argument,
1917 +static void search_path_for_lname(
1919 + const char *lname_argument,
1922 #endif /* !defined(RLD) */
1924 static void pass1_fat(
1926 unsigned long file_size,
1927 enum bool base_name,
1928 enum bool dylib_only,
1929 - enum bool bundle_loader);
1930 + enum bool bundle_loader,
1931 + enum bool force_weak);
1933 static void pass1_archive(
1936 unsigned long file_size,
1937 enum bool base_name,
1938 enum bool from_fat_file,
1939 - enum bool bundle_loader);
1940 + enum bool bundle_loader,
1941 + enum bool force_weak);
1943 static enum bool check_archive_arch(
1946 enum bool base_name,
1947 enum bool from_fat_file,
1948 enum bool dylib_only,
1949 - enum bool bundle_loader);
1950 + enum bool bundle_loader,
1951 + enum bool force_weak);
1954 static void load_init_dylib_module(
1957 enum bool base_name,
1958 enum bool framework_name,
1959 -enum bool bundle_loader)
1960 +enum bool bundle_loader,
1961 +enum bool force_weak)
1965 @@ -335,13 +351,22 @@
1968 if(dynamic == TRUE){
1969 + if(search_paths_first == TRUE){
1970 + search_paths_for_lname(&name[2], &file_name, &fd);
1973 p = mkstr("lib", &name[2], ".dylib", NULL);
1974 search_for_file(p, &file_name, &fd);
1977 p = mkstr("lib", &name[2], ".a", NULL);
1978 search_for_file(p, &file_name, &fd);
1983 + p = mkstr("lib", &name[2], ".a", NULL);
1984 + search_for_file(p, &file_name, &fd);
1987 fatal("can't locate file for: %s", name);
1989 @@ -444,15 +469,15 @@
1990 new_archive_or_fat(file_name, file_addr, file_size);
1992 pass1_fat(file_name, file_addr, file_size, base_name, FALSE,
1994 + bundle_loader, force_weak);
1996 else if(file_size >= SARMAG && strncmp(file_addr, ARMAG, SARMAG) == 0){
1997 pass1_archive(file_name, file_addr, file_size, base_name, FALSE,
1999 + bundle_loader, force_weak);
2002 pass1_object(file_name, file_addr, file_size, base_name, FALSE,
2003 - FALSE, bundle_loader);
2004 + FALSE, bundle_loader, force_weak);
2006 #ifdef VM_SYNC_DEACTIVATE
2007 vm_msync(mach_task_self(), (vm_address_t)file_addr,
2008 @@ -524,6 +549,65 @@
2014 + * search_paths_for_lname() takes the argument to a -lx option and and trys to
2015 + * open a file with the name libx.dylib or libx.a. This routine is only used
2016 + * when the -search_paths_first option is specified and -dynamic is in effect.
2017 + * And looks for a file name ending in .dylib then .a in each directory before
2018 + * looking in the next directory. The list of the -L search directories and in
2019 + * the standard directories are searched in that order. If this is sucessful
2020 + * it returns a pointer to the file name indirectly through file_name and the
2021 + * open file descriptor indirectly through fd.
2025 +search_paths_for_lname(
2026 +const char *lname_argument,
2033 + for(i = 0; i < nsearch_dirs ; i++){
2034 + search_path_for_lname(search_dirs[i], lname_argument, file_name,fd);
2038 + for(i = 0; standard_dirs[i] != NULL ; i++){
2039 + search_path_for_lname(standard_dirs[i],lname_argument,file_name,fd);
2046 + * search_path_for_lname() takes the argument to a -lx option and and trys to
2047 + * open a file with the name libx.dylib then libx.a in the specified directory
2048 + * name. This routine is only used when the -search_paths_first option is
2049 + * specified and -dynamic is in effect. If this is sucessful it returns a
2050 + * pointer to the file name indirectly through file_name and the open file
2051 + * descriptor indirectly through fd.
2055 +search_path_for_lname(
2057 +const char *lname_argument,
2061 + *file_name = mkstr(dir, "/", "lib", lname_argument, ".dylib", NULL);
2062 + if((*fd = open(*file_name, O_RDONLY)) != -1)
2066 + *file_name = mkstr(dir, "/", "lib", lname_argument, ".a", NULL);
2067 + if((*fd = open(*file_name, O_RDONLY)) != -1)
2071 #endif /* !defined(RLD) */
2075 unsigned long file_size,
2076 enum bool base_name,
2077 enum bool dylib_only,
2078 -enum bool bundle_loader)
2079 +enum bool bundle_loader,
2080 +enum bool force_weak)
2082 struct fat_header *fat_header;
2083 #ifdef __LITTLE_ENDIAN__
2084 @@ -671,11 +756,11 @@
2085 goto pass1_fat_return;
2087 pass1_archive(file_name, arch_addr, arch_size,
2088 - base_name, TRUE, bundle_loader);
2089 + base_name, TRUE, bundle_loader, force_weak);
2092 pass1_object(file_name, arch_addr, arch_size, base_name, TRUE,
2093 - dylib_only, bundle_loader);
2094 + dylib_only, bundle_loader, force_weak);
2096 goto pass1_fat_return;
2098 @@ -697,11 +782,11 @@
2099 goto pass1_fat_return;
2101 pass1_archive(file_name, arch_addr, arch_size, base_name, TRUE,
2103 + bundle_loader, force_weak);
2106 pass1_object(file_name, arch_addr, arch_size, base_name, TRUE,
2107 - dylib_only, bundle_loader);
2108 + dylib_only, bundle_loader, force_weak);
2110 goto pass1_fat_return;
2112 @@ -729,11 +814,11 @@
2113 goto pass1_fat_return;
2115 pass1_archive(file_name, arch_addr, arch_size,
2116 - base_name, TRUE, bundle_loader);
2117 + base_name, TRUE, bundle_loader, force_weak);
2120 pass1_object(file_name, arch_addr, arch_size, base_name, TRUE,
2121 - dylib_only, bundle_loader);
2122 + dylib_only, bundle_loader, force_weak);
2124 goto pass1_fat_return;
2127 unsigned long file_size,
2128 enum bool base_name,
2129 enum bool from_fat_file,
2130 -enum bool bundle_loader)
2131 +enum bool bundle_loader,
2132 +enum bool force_weak)
2134 unsigned long i, j, offset;
2136 @@ -1153,7 +1239,7 @@
2137 print_obj_name(cur_obj);
2138 print("loaded because of -all_load flag\n");
2140 - merge(FALSE, FALSE);
2141 + merge(FALSE, FALSE, force_weak);
2142 length = round(ar_size + ar_name_size, sizeof(short));
2143 offset = (offset - ar_name_size) + length;
2145 @@ -1271,7 +1357,7 @@
2146 if(toc_byte_sex != host_byte_sex)
2147 swap_ranlib(ranlibs, nranlibs, host_byte_sex);
2148 for(i = 0; i < nranlibs; i++){
2149 - if(ranlibs[i].ran_un.ran_strx >= (long)string_size){
2150 + if(ranlibs[i].ran_un.ran_strx >= string_size){
2151 error("malformed table of contents in: %s (ranlib struct %lu "
2152 "has bad string index, can't load from it)", file_name,i);
2154 @@ -1383,7 +1469,7 @@
2155 print("loaded because of -ObjC flag to get symbol: %s\n",
2156 bsearch_strings + ranlibs[i].ran_un.ran_strx);
2158 - merge(FALSE, FALSE);
2159 + merge(FALSE, FALSE, force_weak);
2161 free(loaded_offsets);
2163 @@ -1515,7 +1601,7 @@
2164 undefined->merged_symbol->nlist.n_un.n_name);
2167 - merge(FALSE, FALSE);
2168 + merge(FALSE, FALSE, force_weak);
2170 /* make sure this symbol got defined */
2172 @@ -1613,7 +1699,7 @@
2173 merged_symbol->nlist.n_un.n_name);
2176 - merge(FALSE, FALSE);
2177 + merge(FALSE, FALSE, force_weak);
2179 /* make sure this symbol got defined */
2181 @@ -1829,7 +1915,8 @@
2182 enum bool base_name,
2183 enum bool from_fat_file,
2184 enum bool dylib_only,
2185 -enum bool bundle_loader)
2186 +enum bool bundle_loader,
2187 +enum bool force_weak)
2191 @@ -1855,7 +1942,7 @@
2193 #endif /* !defined(RLD) */
2195 - merge(dylib_only, bundle_loader);
2196 + merge(dylib_only, bundle_loader, force_weak);
2200 @@ -2349,6 +2436,18 @@
2201 undefined->merged_symbol->nlist.n_desc);
2202 if(library_ordinal == SELF_LIBRARY_ORDINAL)
2203 p = undefined->merged_symbol->referencing_library;
2205 + * Note that if library_ordinal was DYNAMIC_LOOKUP_ORDINAL then
2206 + * merge_dylib_module_symbols() in symbols.c would not have
2207 + * set the twolevel_reference field to TRUE in the merged_symbol
2208 + * and if we get here it with this it is an internal error.
2210 + else if(library_ordinal == DYNAMIC_LOOKUP_ORDINAL)
2211 + fatal("internal error: search_dynamic_libs() with a "
2212 + "merged_symbol (%s) on the undefined list with "
2213 + "twolevel_reference == TRUE and library_ordinal == "
2214 + "DYNAMIC_LOOKUP_ORDINAL", undefined->merged_symbol->
2215 + nlist.n_un.n_name);
2217 p = undefined->merged_symbol->referencing_library->
2218 dependent_images[library_ordinal - 1];
2219 @@ -2615,7 +2714,7 @@
2220 undefined->merged_symbol->nlist.n_un.n_name);
2223 - merge(FALSE, FALSE);
2224 + merge(FALSE, FALSE, FALSE);
2226 /* make sure this symbol got defined */
2228 @@ -2688,7 +2787,7 @@
2229 undefined->merged_symbol->nlist.n_un.n_name);
2232 - merge(FALSE, FALSE);
2233 + merge(FALSE, FALSE, FALSE);
2235 /* make sure this symbol got defined */
2237 @@ -3464,11 +3563,12 @@
2238 if(fat_header->magic == SWAP_LONG(FAT_MAGIC))
2239 #endif /* __LITTLE_ENDIAN__ */
2241 - pass1_fat(file_name, file_addr, file_size, FALSE, TRUE, FALSE);
2242 + pass1_fat(file_name, file_addr, file_size, FALSE, TRUE, FALSE,
2246 pass1_object(file_name, file_addr, file_size, FALSE, FALSE, TRUE,
2252 @@ -3800,7 +3900,8 @@
2255 enum bool dylib_only,
2256 -enum bool bundle_loader)
2257 +enum bool bundle_loader,
2258 +enum bool force_weak)
2260 unsigned long previous_errors;
2262 @@ -3857,7 +3958,7 @@
2263 /* if this object has any dynamic shared library stuff merge it */
2264 if(cur_obj->dylib_stuff){
2267 + merge_dylibs(force_weak);
2271 @@ -3898,9 +3999,9 @@
2272 * the dysymtab field, the section_maps and nsection_maps fields (this routine
2273 * allocates the section_map structures and fills them in too), the fvmlib_
2274 * stuff field is set if any SG_FVMLIB segments or LC_LOADFVMLIB commands are
2275 - * seen and the dylib_stuff field is set if the file is a MH_DYLIB type and
2276 - * has a LC_ID_DYLIB command or a LC_LOAD_DYLIB or LC_LOAD_WEAK_DLIB command is
2278 + * seen and the dylib_stuff field is set if the file is a MH_DYLIB or
2279 + * MH_DYLIB_STUB type and has a LC_ID_DYLIB command or a LC_LOAD_DYLIB or
2280 + * LC_LOAD_WEAK_DLIB command is seen.
2284 @@ -4161,17 +4262,20 @@
2287 if((mh->flags & MH_DYLDLINK) != 0 &&
2288 - (mh->filetype != MH_DYLIB && mh->filetype != MH_DYLINKER) &&
2289 + (mh->filetype != MH_DYLIB &&
2290 + mh->filetype != MH_DYLIB_STUB &&
2291 + mh->filetype != MH_DYLINKER) &&
2292 bundle_loader == FALSE){
2293 error_with_cur_obj("is input for the dynamic link editor, is not "
2294 "relocatable by the static link editor again");
2298 - * If this is a MH_DYLIB file then a single LC_ID_DYLIB command must be
2299 - * seen to identify the library.
2300 + * If this is a MH_DYLIB or MH_DYLIB_STUB file then a single LC_ID_DYLIB
2301 + * command must be seen to identify the library.
2303 - cur_obj->dylib = (enum bool)(mh->filetype == MH_DYLIB);
2304 + cur_obj->dylib = (enum bool)(mh->filetype == MH_DYLIB ||
2305 + mh->filetype == MH_DYLIB_STUB);
2307 dylib_id_name = NULL;
2308 if(cur_obj->dylib == TRUE && dynamic == FALSE){
2309 @@ -4348,7 +4452,8 @@
2312 /* check the size and offset of the contents if it has any*/
2313 - if(section_type != S_ZEROFILL){
2314 + if(mh->filetype != MH_DYLIB_STUB &&
2315 + section_type != S_ZEROFILL){
2316 check_size_offset_sect(s->size, s->offset, sizeof(char),
2317 "size", "offset", i, j, s->segname, s->sectname);
2319 @@ -4569,14 +4674,16 @@
2320 filetype == MH_FVMLIB ? "MH_FVMLIB" : "MH_DYLINKER");
2323 - if(mh->filetype != MH_DYLIB){
2324 + if(mh->filetype != MH_DYLIB && mh->filetype != MH_DYLIB_STUB){
2325 error_with_cur_obj("LC_ID_DYLIB load command in non-"
2326 - "MH_DYLIB filetype");
2327 + "%s filetype", mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2332 error_with_cur_obj("malformed object (more than one "
2333 - "LC_ID_DYLIB load command in MH_DYLIB file)");
2334 + "LC_ID_DYLIB load command in %s file)", mh->filetype ==
2335 + MH_DYLIB ? "MH_DYLIB" : "MH_DYLIB_STUB");
2338 dl = (struct dylib_command *)lc;
2339 @@ -4655,14 +4762,17 @@
2340 filetype == MH_FVMLIB ? "MH_FVMLIB" : "MH_DYLINKER");
2343 - if(mh->filetype != MH_DYLIB){
2344 + if(mh->filetype != MH_DYLIB && mh->filetype != MH_DYLIB_STUB){
2345 error_with_cur_obj("LC_SUB_FRAMEWORK load command in non-"
2346 - "MH_DYLIB filetype");
2347 + "%s filetype", mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2352 error_with_cur_obj("malformed object (more than one "
2353 - "LC_SUB_FRAMEWORK load command in MH_DYLIB file)");
2354 + "LC_SUB_FRAMEWORK load command in %s file)",
2355 + mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2359 sub = (struct sub_framework_command *)lc;
2360 @@ -4699,9 +4809,10 @@
2361 filetype == MH_FVMLIB ? "MH_FVMLIB" : "MH_DYLINKER");
2364 - if(mh->filetype != MH_DYLIB){
2365 + if(mh->filetype != MH_DYLIB && mh->filetype != MH_DYLIB_STUB){
2366 error_with_cur_obj("LC_SUB_UMBRELLA load command in non-"
2367 - "MH_DYLIB filetype");
2368 + "%s filetype", mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2372 usub = (struct sub_umbrella_command *)lc;
2373 @@ -4738,9 +4849,10 @@
2374 filetype == MH_FVMLIB ? "MH_FVMLIB" : "MH_DYLINKER");
2377 - if(mh->filetype != MH_DYLIB){
2378 + if(mh->filetype != MH_DYLIB && mh->filetype != MH_DYLIB_STUB){
2379 error_with_cur_obj("LC_SUB_LIBRARY load command in non-"
2380 - "MH_DYLIB filetype");
2381 + "%s filetype", mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2385 lsub = (struct sub_library_command *)lc;
2386 @@ -4777,9 +4889,10 @@
2387 filetype == MH_FVMLIB ? "MH_FVMLIB" : "MH_DYLINKER");
2390 - if(mh->filetype != MH_DYLIB){
2391 + if(mh->filetype != MH_DYLIB && mh->filetype != MH_DYLIB_STUB){
2392 error_with_cur_obj("LC_SUB_CLIENT load command in non-"
2393 - "MH_DYLIB filetype");
2394 + "%s filetype", mh->filetype == MH_DYLIB ? "MH_DYLIB" :
2398 csub = (struct sub_client_command *)lc;
2399 @@ -5092,12 +5205,14 @@
2403 - * If this is a MH_DYLIB file then a single LC_ID_DYLIB command must be
2404 - * seen to identify the library.
2405 + * If this is a MH_DYLIB or MH_DYLIB_STUB file then a single
2406 + * LC_ID_DYLIB command must be seen to identify the library.
2408 - if(mh->filetype == MH_DYLIB && dlid == NULL){
2409 + if((mh->filetype == MH_DYLIB || mh->filetype == MH_DYLIB_STUB) &&
2411 error_with_cur_obj("malformed object (no LC_ID_DYLIB load command "
2412 - "in MH_DYLIB file)");
2413 + "in %s file)", mh->filetype == MH_DYLIB ?
2414 + "MH_DYLIB" : "MH_DYLIB_STUB");
2418 diff -rub ld/pass1.h ld/pass1.h
2419 --- ld/pass1.h Tue Jan 14 23:35:25 2003
2420 +++ ld/pass1.h Mon Aug 25 12:12:29 2003
2425 +/* TRUE if -search_paths_first was specified */
2426 +__private_extern__ enum bool search_paths_first;
2428 /* the user specified directories to search for -lx filenames, and the number
2430 __private_extern__ char **search_dirs;
2432 enum bool indirect_twolevel_ref_flagged;
2433 enum bool some_non_weak_refs;
2434 enum bool some_symbols_referenced;
2435 + enum bool force_weak_dylib;
2436 struct object_file *definition_obj;
2437 char *dylib_file; /* argument to -dylib_file "install_name:file_name" */
2438 struct dylib_table_of_contents *tocs;
2439 @@ -125,10 +129,12 @@
2441 enum bool base_name,
2442 enum bool framework_name,
2443 - enum bool bundle_loader);
2444 + enum bool bundle_loader,
2445 + enum bool force_weak);
2446 __private_extern__ void merge(
2447 enum bool dylib_only,
2448 - enum bool bundle_loader);
2449 + enum bool bundle_loader,
2450 + enum bool force_weak);
2451 __private_extern__ void check_fat(
2453 unsigned long file_size,
2454 diff -rub ld/pass2.c ld/pass2.c
2455 --- ld/pass2.c Tue Jan 14 23:35:25 2003
2456 +++ ld/pass2.c Mon Aug 25 22:11:47 2003
2459 * Write the entire object file.
2461 - if(write(fd, output_addr, output_size) != output_size)
2462 + if(write(fd, output_addr, output_size) != (int)output_size)
2463 system_fatal("can't write output file");
2465 if((r = vm_deallocate(mach_task_self(), (vm_address_t)output_addr,
2467 write_offset, write_size);
2469 lseek(fd, write_offset, L_SET);
2470 - if(write(fd, output_addr + write_offset, write_size) != write_size)
2471 + if(write(fd, output_addr + write_offset, write_size) !=
2473 system_fatal("can't write to output file");
2474 if((r = vm_deallocate(mach_task_self(), (vm_address_t)(output_addr +
2475 write_offset), write_size)) != KERN_SUCCESS)
2477 write_offset, write_size);
2479 lseek(fd, write_offset, L_SET);
2480 - if(write(fd, output_addr + write_offset, write_size) != write_size)
2481 + if(write(fd, output_addr + write_offset, write_size) !=
2483 system_fatal("can't write to output file");
2484 if((r = vm_deallocate(mach_task_self(), (vm_address_t)(output_addr +
2485 write_offset), write_size)) != KERN_SUCCESS)
2486 diff -rub ld/ppc_reloc.c ld/ppc_reloc.c
2487 --- ld/ppc_reloc.c Tue Jan 14 23:35:25 2003
2488 +++ ld/ppc_reloc.c Mon Aug 25 22:11:47 2003
2490 else if(r_type == PPC_RELOC_SECTDIFF ||
2491 r_type == PPC_RELOC_HI16_SECTDIFF ||
2492 r_type == PPC_RELOC_LO16_SECTDIFF ||
2493 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2494 r_type == PPC_RELOC_HA16_SECTDIFF){
2495 if(r_scattered != 1){
2496 error_with_cur_obj("relocation entry (%lu) in section "
2497 @@ -390,13 +391,13 @@
2499 * If the symbol is undefined (or common) or a global coalesced
2500 * symbol where we need to force an external relocation entry
2501 - * and we are not prebinding no relocation is done.
2502 - * Or if the output file is MH_DYLIB no relocation is done
2503 + * and we are not prebinding no relocation is done. Or if the
2504 + * output file is a multi module MH_DYLIB no relocation is done
2505 * unless the symbol is a private extern or we are prebinding.
2507 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
2508 (force_extern_reloc == TRUE && prebinding == FALSE) ||
2509 - (filetype == MH_DYLIB &&
2510 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
2511 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
2512 prebinding == FALSE) ) )
2515 if(r_type == PPC_RELOC_SECTDIFF ||
2516 r_type == PPC_RELOC_HI16_SECTDIFF ||
2517 r_type == PPC_RELOC_LO16_SECTDIFF ||
2518 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2519 r_type == PPC_RELOC_HA16_SECTDIFF){
2521 &(cur_obj->section_maps[pair_r_symbolnum - 1]);
2523 if(r_type == PPC_RELOC_SECTDIFF ||
2524 r_type == PPC_RELOC_HI16_SECTDIFF ||
2525 r_type == PPC_RELOC_LO16_SECTDIFF ||
2526 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2527 r_type == PPC_RELOC_HA16_SECTDIFF){
2528 value = - local_map->s->addr
2529 + (local_map->output_section->s.addr +
2533 case PPC_RELOC_LO14:
2534 + case PPC_RELOC_LO14_SECTDIFF:
2535 value = (other_half << 16) |
2536 (instruction & 0xfffc);
2539 if(r_type == PPC_RELOC_SECTDIFF ||
2540 r_type == PPC_RELOC_HI16_SECTDIFF ||
2541 r_type == PPC_RELOC_LO16_SECTDIFF ||
2542 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2543 r_type == PPC_RELOC_HA16_SECTDIFF){
2545 * For PPC_RELOC_SECTDIFF's the item to be
2547 ((value >> 16) & 0xffff);
2549 case PPC_RELOC_LO14:
2550 + case PPC_RELOC_LO14_SECTDIFF:
2551 if((value & 0x3) != 0)
2552 error_with_cur_obj("relocation error "
2553 "for relocation entry %lu in section "
2555 "multiple of 4 bytes)", i,
2556 section_map->s->segname,
2557 section_map->s->sectname);
2558 - if((value & 0xfffe0000) != 0xfffe0000 &&
2559 - (value & 0xfffe0000) != 0x00000000)
2560 + if((value & 0xffff8000) != 0xffff8000 &&
2561 + (value & 0xffff8000) != 0x00000000)
2562 error_with_cur_obj("relocation overflow "
2563 "for relocation entry %lu in section "
2564 "(%.16s,%.16s) (displacement too large)"
2565 @@ -817,6 +823,19 @@
2566 section_map->s->sectname);
2567 instruction = (instruction & 0xffff0003) |
2570 + * If this is a predicted branch conditional
2571 + * (r_length is 3) where the branch condition
2572 + * is not branch always and the sign of the
2573 + * displacement is different after relocation
2574 + * then flip the Y-bit to preserve the sense of
2575 + * the branch prediction.
2577 + if(r_length == 3 &&
2578 + (instruction & 0xfc000000) == 0x40000000 &&
2579 + (instruction & 0x03e00000) != 0x02800000 &&
2580 + (instruction & 0x00008000) != br14_disp_sign)
2581 + instruction ^= (1 << 21);
2583 case PPC_RELOC_BR24:
2584 if((value & 0x3) != 0)
2586 + fine_reloc_output_offset(
2587 section_map, r_address);
2588 if(save_reloc == 0 &&
2589 - (filetype != MH_DYLIB || (r_extern == 1 &&
2590 + ((filetype != MH_DYLIB ||
2591 + multi_module_dylib == FALSE) ||
2593 (merged_symbol->nlist.n_type & N_PEXT) ==
2595 (output_for_dyld == FALSE || r_extern == 0 ||
2597 other_half = immediate & 0xffff;
2599 case PPC_RELOC_LO14:
2600 + case PPC_RELOC_LO14_SECTDIFF:
2601 immediate = (other_half << 16) |
2602 (instruction & 0xfffc);
2604 @@ -991,14 +1013,28 @@
2605 "entry %lu in section (%.16s,%.16s) (displacement "
2606 "not a multiple of 4 bytes)", i,
2607 section_map->s->segname, section_map->s->sectname);
2608 - if((immediate & 0xfffe0000) != 0xfffe0000 &&
2609 - (immediate & 0xfffe0000) != 0x00000000)
2610 + if((immediate & 0xffff8000) != 0xffff8000 &&
2611 + (immediate & 0xffff8000) != 0x00000000)
2612 error_with_cur_obj("relocation overflow for relocation "
2613 "entry %lu in section (%.16s,%.16s) (displacement "
2614 "too large)", i, section_map->s->segname,
2615 section_map->s->sectname);
2616 instruction = (instruction & 0xffff0003) |
2617 (immediate & 0xfffc);
2619 + * If this is a predicted branch conditional
2620 + * (r_length is 3) where the branch condition
2621 + * is not branch always and the sign of the
2622 + * displacement is different after relocation
2623 + * then flip the Y-bit to preserve the sense of
2624 + * the branch prediction.
2626 + if(r_length == 3 &&
2627 + (instruction & 0xfc000000) == 0x40000000 &&
2628 + (instruction & 0x03e00000) != 0x02800000 &&
2629 + (instruction & 0x00008000) != br14_disp_sign)
2630 + instruction ^= (1 << 21);
2633 case PPC_RELOC_BR24:
2634 immediate = instruction & 0x03fffffc;
2635 @@ -1020,14 +1056,8 @@
2636 (immediate & 0x03fffffc);
2638 case PPC_RELOC_JBSR:
2641 - other_half = value;
2644 value += other_half;
2647 if(section_map->nfine_relocs == 0)
2648 value += - (section_map->output_section->s.addr +
2649 section_map->offset + r_address);
2650 @@ -1036,7 +1066,8 @@
2651 fine_reloc_output_offset(section_map,
2653 if(save_reloc == 0 &&
2654 - (filetype != MH_DYLIB || (r_extern == 1 &&
2655 + ((filetype != MH_DYLIB || multi_module_dylib == FALSE) ||
2657 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)) &&
2658 (output_for_dyld == FALSE || r_extern == 0 ||
2659 (merged_symbol->nlist.n_type & N_TYPE) != N_UNDF) &&
2660 @@ -1087,18 +1118,19 @@
2661 * For external relocation entries that the symbol is
2662 * defined (not undefined or common) but not when we are
2663 * forcing an external relocation entry for a global
2664 - * coalesced symbol and if the output file is not MH_DYLIB
2665 - * or the symbol is a private extern it is changed to a
2666 - * local relocation entry using the section that symbol is
2667 - * defined in. If still undefined or forcing an external
2668 - * relocation entry for a global coalesced symbol then the
2669 - * index of the symbol in the output file is set into
2671 + * coalesced symbol and if the output file is not a multi
2672 + * module MH_DYLIB or the symbol is a private extern, it is
2673 + * changed to a local relocation entry using the section
2674 + * that symbol is defined in. If still undefined or forcing
2675 + * an external relocation entry for a global coalesced
2676 + * symbol, then the index of the symbol in the output file
2677 + * is set into r_symbolnum.
2679 else if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
2680 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
2681 force_extern_reloc == FALSE &&
2682 - (filetype != MH_DYLIB ||
2683 + ((filetype != MH_DYLIB ||
2684 + multi_module_dylib == FALSE) ||
2685 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
2686 reloc->r_extern = 0;
2688 @@ -1251,6 +1283,7 @@
2689 if(r_type == PPC_RELOC_SECTDIFF ||
2690 r_type == PPC_RELOC_HI16_SECTDIFF ||
2691 r_type == PPC_RELOC_LO16_SECTDIFF ||
2692 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2693 r_type == PPC_RELOC_HA16_SECTDIFF){
2695 * For PPC_RELOC_SECTDIFF relocation entries (which
2696 @@ -1269,6 +1302,7 @@
2697 pair_local_map->output_section->s.addr);
2698 if(r_type == PPC_RELOC_HI16_SECTDIFF ||
2699 r_type == PPC_RELOC_LO16_SECTDIFF ||
2700 + r_type == PPC_RELOC_LO14_SECTDIFF ||
2701 r_type == PPC_RELOC_HA16_SECTDIFF)
2702 spair_reloc->r_address = other_half;
2704 Only in ld/: profile_obj
2705 Only in ld/: ptmp_obj
2706 diff -rub ld/rld.c ld/rld.c
2707 --- ld/rld.c Tue Jan 14 23:35:25 2003
2708 +++ ld/rld.c Mon Aug 25 22:11:47 2003
2710 #include "stuff/openstep_mach.h"
2711 #include <mach-o/fat.h>
2712 #include <mach-o/nlist.h>
2715 #include <mach-o/kld.h>
2716 -#else /* !defined(KLD) */
2718 +//~ #else /* !defined(KLD) */
2719 +typedef void NXStream;
2720 #include <mach-o/rld.h>
2721 -#include <streams/streams.h>
2722 +//~ #include <streams/streams.h>
2723 #include <objc/zone.h>
2725 #include <mach-o/rld_state.h>
2727 unsigned long (*address_func)(unsigned long size, unsigned long headers_size) =
2731 +enum strip_levels kld_requested_strip_level = STRIP_ALL;
2733 #if !defined(SA_RLD) && !(defined(KLD) && defined(__STATIC__))
2735 * The function pointer passed to moninitrld() to do profiling of rld loaded
2736 @@ -198,12 +203,12 @@
2738 #endif /* !defined(SA_RLD) && !defined(KLD) */
2740 -#if defined(KLD) && !defined(__STATIC__)
2742 static long internal_kld_load_basefile(
2743 const char *base_filename,
2746 -#endif /* defined(KLD) && !defined(__STATIC__) */
2747 +#endif /* defined(KLD) */
2749 #if !defined(SA_RLD) && !defined(KLD)
2752 if(output_filename != NULL)
2753 strip_level = STRIP_NONE;
2755 - strip_level = STRIP_ALL;
2756 + strip_level = kld_requested_strip_level;
2758 /* This must be cleared for each call to rld() */
2761 #if !defined(SA_RLD) && !(defined(KLD) && defined(__STATIC__))
2762 if(file_name == NULL){
2763 for(i = 0; object_filenames[i] != NULL; i++)
2764 - pass1((char *)object_filenames[i], FALSE, FALSE, FALSE, FALSE);
2765 + pass1((char *)object_filenames[i], FALSE, FALSE, FALSE, FALSE,
2769 #endif /* !defined(SA_RLD) && !(defined(KLD) && defined(__STATIC__)) */
2771 cur_obj->user_obj_addr = TRUE;
2772 cur_obj->obj_addr = (char *)obj_addr;
2773 cur_obj->obj_size = obj_size;
2774 - merge(FALSE, FALSE);
2775 + merge(FALSE, FALSE, FALSE);
2780 * Write the entire output file.
2782 if(write(fd, output_addr, output_size + symbol_size) !=
2783 - output_size + symbol_size){
2784 + (int)(output_size + symbol_size)){
2785 system_error("can't write output file: %s",output_filename);
2787 internal_kld_unload(TRUE);
2788 @@ -635,8 +641,14 @@
2789 * Deallocate the pages of memory for the symbol table if there are
2792 + if (strip_level == STRIP_ALL)
2793 deallocate_size = round(output_size + symbol_size, host_pagesize) -
2794 round(output_size, host_pagesize);
2796 + deallocate_size = 0;
2797 + sets[cur_set].output_size += symbol_size;
2800 if(deallocate_size > 0){
2801 if((r = vm_deallocate(mach_task_self(),
2802 (vm_address_t)(output_addr +
2803 @@ -777,18 +789,20 @@
2807 -#if !defined(SA_RLD) && !(defined(KLD) && defined(__STATIC__))
2808 +#if !defined(SA_RLD)
2810 * rld_load_basefile() loads a base file from an object file rather than just
2811 * picking up the link edit segment from this program.
2814 +#if !defined(__STATIC__)
2817 const char *base_filename)
2819 return(internal_kld_load_basefile(base_filename, NULL, 0));
2821 +#endif /* !defined(__STATIC__) */
2824 kld_load_basefile_from_memory(
2830 +#if !(defined(KLD) && defined(__STATIC__))
2831 + unsigned long size;
2834 struct stat stat_buf;
2835 @@ -834,13 +849,14 @@
2836 struct fat_header struct_fat_header;
2837 #endif /* __LITTLE_ENDIAN__ */
2838 struct fat_arch *fat_archs, *best_fat_arch;
2839 -#if !(defined(KLD) && defined(__STATIC__))
2840 struct arch_flag host_arch_flag;
2841 -#endif /* !(defined(KLD) && defined(__STATIC__)) */
2842 enum bool from_fat_file;
2845 from_fat_file = FALSE;
2847 +#endif /* !(defined(KLD) && defined(__STATIC__)) */
2850 error_stream = stream;
2851 #endif /* !defined(KLD) */
2853 base_name = allocate(strlen(base_filename) + 1);
2854 strcpy(base_name, base_filename);
2856 +#if !(defined(KLD) && defined(__STATIC__))
2859 * If there is to be an output file then save the symbols. Only the
2860 * symbols from the current set will be placed in the output file. The
2862 #endif /* __LITTLE_ENDIAN__ */
2864 if(sizeof(struct fat_header) + fat_header->nfat_arch *
2865 - sizeof(struct fat_arch) > size){
2866 + sizeof(struct fat_arch) > (unsigned long)size){
2867 error("fat file: %s truncated or malformed (fat_arch "
2868 "structs would extend past the end of the file)",
2870 @@ -1042,7 +1060,9 @@
2876 +#endif /* !(defined(KLD) && defined(__STATIC__)) */
2878 cur_obj = new_object_file();
2879 cur_obj->file_name = base_name;
2880 cur_obj->obj_addr = base_addr;
2881 @@ -1054,7 +1074,7 @@
2883 * Now that the file is mapped in merge it as the base file.
2885 - merge(FALSE, FALSE);
2886 + merge(FALSE, FALSE, FALSE);
2890 @@ -1071,6 +1091,7 @@
2893 clean_archives_and_fats();
2894 +#if !(defined(KLD) && defined(__STATIC__))
2895 if(from_fat_file == TRUE){
2896 if((r = vm_deallocate(mach_task_self(), (vm_address_t)addr,
2897 (vm_size_t)size)) != KERN_SUCCESS)
2898 @@ -1088,8 +1109,11 @@
2900 rld_maintain_states = FALSE;
2902 +#endif /* !(defined(KLD) && defined(__STATIC__)) */
2906 +#if !(defined(KLD) && defined(__STATIC__))
2907 rld_load_basefile_error_return:
2908 if((r = vm_deallocate(mach_task_self(), (vm_address_t)addr,
2909 (vm_size_t)size)) != KERN_SUCCESS)
2910 @@ -1106,6 +1130,7 @@
2912 #endif /* __LITTLE_ENDIAN__ */
2914 +#endif /* !(defined(KLD) && defined(__STATIC__)) */
2918 @@ -1638,7 +1663,7 @@
2919 * Write the entire output file.
2921 if(write(fd, output_addr, output_size + symbol_size) !=
2922 - output_size + symbol_size){
2923 + (int)(output_size + symbol_size)){
2924 system_error("can't write output file: %s",output_filename);
2925 (void)unlink(output_filename);
2927 @@ -1768,6 +1793,23 @@
2929 address_func = func;
2933 + * kld_set_link_options() .
2937 +kld_set_link_options(
2938 +#else /* !defined(KLD) */
2939 +rld_set_link_options(
2941 +unsigned long link_options)
2943 + if(KLD_STRIP_NONE & link_options)
2944 + kld_requested_strip_level = STRIP_NONE;
2946 + kld_requested_strip_level = STRIP_ALL;
2948 #endif /* !defined(SA_RLD) */
2951 @@ -1793,6 +1835,7 @@
2953 if(error_stream != NULL)
2954 NXVPrintf(error_stream, format, ap);
2955 +NXVPrintf(error_stream, format, ap);
2957 #endif /* !defined(SA_RLD) && !defined(KLD) */
2959 Only in ld/: sarld_dir
2960 diff -rub ld/sections.c ld/sections.c
2961 --- ld/sections.c Tue Jan 14 23:35:25 2003
2962 +++ ld/sections.c Mon Aug 25 22:11:47 2003
2963 @@ -324,6 +324,13 @@
2964 error_with_cur_obj("literal section (%.16s,%.16s) "
2965 "not allowed in I860 cputype objects",
2966 ms->s.segname, ms->s.sectname);
2969 + * For KLD the section's alignment from the base file is NOT
2972 + if(cur_obj != base_obj)
2974 if(s->align > ms->s.align)
2975 ms->s.align = s->align;
2977 @@ -2724,16 +2731,16 @@
2979 * It is an error if one of these types of merged sections
2980 * has an external relocation entry and the output is a
2981 - * dynamic library. As no library module will "own" it and
2982 - * it will never get used by the dynamic linker and the
2984 + * multi module dynamic library. As in a multi module dylib
2985 + * no library module will "own" it and it will never get
2986 + * used by the dynamic linker and the item relocated.
2988 if(ms->nextrel != 0){
2989 - if(filetype == MH_DYLIB)
2990 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE)
2991 fatal("internal error: layout_relocs_for_dyld() "
2992 "called with external relocation entries for "
2993 - "merged section (%.16s,%.16s) for MH_DYLIB "
2994 - "output", ms->s.segname, ms->s.sectname);
2995 + "merged section (%.16s,%.16s) for multi module "
2996 + "MH_DYLIB output", ms->s.segname, ms->s.sectname);
2997 /* TODO: can this ever get here? even if not MH_DYLIB? */
2998 ms->iextrel = nextrel;
2999 nextrel += ms->nextrel;
3000 @@ -3036,18 +3043,19 @@
3002 * The number of relocation entries in the output file is based on
3003 * one of three different cases:
3004 - * The output file is a dynamic shared library file
3005 + * The output file is a multi module dynamic shared library
3006 * The output file has a dynamic linker load command
3007 * The output does not have a dynamic linker load command
3009 - if(filetype == MH_DYLIB){
3010 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3012 - * For dynamic shared library files all external relocations are
3013 - * kept as external relocation entries except for references to
3014 - * private externs (which are kept as locals) and all non-
3015 - * position-independent local relocation entries are kept.
3016 - * Modules of dylibs are not linked together and can only be
3017 - * slid keeping all sections relative to each other the same.
3018 + * For multi module dynamic shared library files all external
3019 + * relocations are kept as external relocation entries except
3020 + * for references to private externs (which are kept as locals)
3021 + * and all non-position-independent local relocation entries
3022 + * are kept. Modules of multi module dylibs are not linked
3023 + * together and can only be slid keeping all sections relative
3024 + * to each other the same.
3026 if(r_extern && (merged_symbol->nlist.n_type & N_PEXT) == 0){
3027 (*nextrel) += 1 + pair;
3028 @@ -3953,19 +3961,19 @@
3030 * The relocation entries in the output file is based on one of
3031 * three different cases:
3032 - * The output file is a dynamic shared library file
3033 + * The output file is a multi module dynamic shared library
3034 * The output file has a dynamic linker load command
3035 * The output does not have a dynamic linker load command
3037 - if(filetype == MH_DYLIB){
3038 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3040 - * For dynamic shared library files all external relocations are
3041 - * kept as external relocation entries except for references to
3042 - * private externs (which are have been turned into locals and
3043 - * kept as locals) and all non-position-independent local
3044 - * relocation entrie are kept. Modules of dylibs are not linked
3045 - * together and can only be slid keeping all sections relative
3046 - * to each other the same.
3047 + * For multi module dynamic shared library files all external
3048 + * relocations are kept as external relocation entries except
3049 + * for references to private externs (which are have been turned
3050 + * into locals and kept as locals) and all non-position-
3051 + * independent local relocation entrie are kept. Modules of
3052 + * multi module dylibs are not linked together and can only be
3053 + * slid keeping all sections relative to each other the same.
3056 reloc->r_address += addr_adjust;
3057 diff -rub ld/sets.c ld/sets.c
3058 --- ld/sets.c Tue Jan 14 23:35:25 2003
3059 +++ ld/sets.c Mon Aug 25 22:11:47 2003
3061 clean_archives_and_fats(void)
3067 char *file_addr, *file_name;
3069 Only in ld/: shlib_obj
3070 diff -rub ld/sparc_reloc.c ld/sparc_reloc.c
3071 --- ld/sparc_reloc.c Tue Jan 14 23:35:25 2003
3072 +++ ld/sparc_reloc.c Mon Aug 25 22:11:47 2003
3073 @@ -385,13 +385,13 @@
3075 * If the symbol is undefined (or common) or a global coalesced
3076 * symbol where we need to force an external relocation entry
3077 - * and we are not prebinding no relocation is done.
3078 - * Or if the output file is MH_DYLIB no relocation is done
3079 + * and we are not prebinding no relocation is done. Or if the
3080 + * output file is a multi module MH_DYLIB no relocation is done
3081 * unless the symbol is a private extern or we are prebinding.
3083 if(((merged_symbol->nlist.n_type & N_TYPE) == N_UNDF) ||
3084 (force_extern_reloc == TRUE && prebinding == FALSE) ||
3085 - (filetype == MH_DYLIB &&
3086 + ((filetype == MH_DYLIB && multi_module_dylib == TRUE) &&
3087 (((merged_symbol->nlist.n_type & N_PEXT) != N_PEXT) &&
3088 prebinding == FALSE) ) )
3090 @@ -915,18 +915,19 @@
3091 * For external relocation entries that the symbol is
3092 * defined (not undefined or common) but not when we are
3093 * forcing an external relocation entry for a global
3094 - * coalesced symbol and if the output file is not MH_DYLIB
3095 - * or the symbol is a private extern it is changed to a
3096 - * local relocation entry using the section that symbol is
3097 - * defined in. If still undefined or forcing an external
3098 - * relocation entry for a global coalesced symbol then the
3099 - * index of the symbol in the output file is set into
3101 + * coalesced symbol and if the output file is not a multi
3102 + * module MH_DYLIB or the symbol is a private extern, it is
3103 + * changed to a local relocation entry using the section
3104 + * that symbol is defined in. If still undefined or forcing
3105 + * an external relocation entry for a global coalesced
3106 + * symbol, then the index of the symbol in the output file
3107 + * is set into r_symbolnum.
3109 else if((merged_symbol->nlist.n_type & N_TYPE) != N_UNDF &&
3110 (merged_symbol->nlist.n_type & N_TYPE) != N_PBUD &&
3111 force_extern_reloc == FALSE &&
3112 - (filetype != MH_DYLIB ||
3113 + ((filetype != MH_DYLIB ||
3114 + multi_module_dylib == FALSE) ||
3115 (merged_symbol->nlist.n_type & N_PEXT) == N_PEXT)){
3116 reloc->r_extern = 0;
3118 Only in ld/: static_kld
3119 diff -rub ld/symbols.c ld/symbols.c
3120 --- ld/symbols.c Tue Jan 14 23:35:25 2003
3121 +++ ld/symbols.c Mon Aug 25 22:11:47 2003
3123 #include "stuff/bool.h"
3124 #include "stuff/bytesex.h"
3125 #include "stuff/macosx_deployment_target.h"
3127 +#include "stuff/symbol_list.h"
3134 #include "hash_string.h"
3136 +#include "mod_sections.h"
3139 __private_extern__ char *base_name;
3141 __private_extern__ unsigned long nmerged_symbols_referenced_only_from_dylibs =0;
3144 + * nstripped_merged_symbols is set to the number of merged symbol being stripped
3145 + * out when the strip_level is STRIP_DYNAMIC_EXECUTABLE.
3147 +__private_extern__ unsigned long nstripped_merged_symbols = 0;
3150 * This is set by lookup_symbol() and used by enter_symbol(). When a symbol
3151 * is not found in the symbol_list by lookup_symbol() it returns a pointer
3152 * to a hash_table entry in a merged_symbol_list. The merged_symbol_list that
3153 @@ -205,6 +215,10 @@
3154 static struct object_file *link_edit_symbols_object = NULL;
3155 static void setup_link_edit_symbols_object(
3158 +static void exports_list_processing(
3159 + char *symbol_name,
3160 + struct nlist *symbol);
3161 #endif /* !defined(RLD) */
3165 #endif /* !defined(RLD) */
3168 -#if defined(RLD) && !defined(__DYNAMIC__)
3171 struct object_file link_edit_common_object = {
3172 "\"link editor\"", /* file_name */
3176 /* check the n_strx field of this symbol */
3177 if(symbol->n_un.n_strx < 0 ||
3178 - symbol->n_un.n_strx >= (long)(cur_obj->symtab->strsize)){
3179 + (unsigned long)symbol->n_un.n_strx >= cur_obj->symtab->strsize){
3180 error_with_cur_obj("bad string table index (%ld) for symbol %lu",
3181 symbol->n_un.n_strx, index);
3184 ((struct mach_header *)(cur_obj->obj_addr))->filetype !=
3186 (library_ordinal != SELF_LIBRARY_ORDINAL &&
3187 + (library_ordinal != DYNAMIC_LOOKUP_ORDINAL ||
3188 + cur_obj->nload_dylibs != DYNAMIC_LOOKUP_ORDINAL) &&
3189 library_ordinal-1 >= cur_obj->nload_dylibs) ){
3190 error_with_cur_obj("undefined symbol %lu (%s) has bad "
3191 "library oridinal %lu", index,
3193 cur_obj->symtab->symoff);
3194 object_strings = (char *)(cur_obj->obj_addr + cur_obj->symtab->stroff);
3195 if(cur_obj->swapped &&
3196 - ((struct mach_header *)cur_obj->obj_addr)->filetype != MH_DYLIB)
3197 + (((struct mach_header *)cur_obj->obj_addr)->filetype != MH_DYLIB ||
3198 + ((struct mach_header *)cur_obj->obj_addr)->filetype !=
3200 swap_nlist(object_symbols, cur_obj->symtab->nsyms, host_byte_sex);
3203 @@ -867,6 +882,18 @@
3204 object_undefineds++;
3205 /* TODO coalesce symbols may need to be accounted for depending on how they are
3209 + * If we have an -export_symbols_list or -unexport_symbol_list
3210 + * option set the private extern bit on symbols that are not to
3211 + * be exported for global symbols that are not undefined.
3213 + if((object_symbols[i].n_type & N_EXT) == N_EXT &&
3214 + object_symbols[i].n_type != (N_EXT | N_UNDF))
3215 + exports_list_processing(object_strings +
3216 + object_symbols[i].n_un.n_strx,
3217 + object_symbols + i);
3218 +#endif /* !defined(RLD) */
3220 * If this is a private external increment the count of
3221 * private exterals for this object and the total in the
3222 @@ -887,12 +914,12 @@
3226 - * If the output file type is a dynamic shared library then count the
3227 - * number of defined externals. And using this count, the count of
3228 - * undefined symbols and the count of private externs the reference map,
3229 - * to build the reference table, is allocated.
3230 + * If the output file type is a multi module dynamic shared library then
3231 + * count the number of defined externals. And using this count, the
3232 + * count of undefined symbols and the count of private externs then
3233 + * reference map, to build the reference table, is allocated.
3235 - if(filetype == MH_DYLIB){
3236 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3237 /* TODO coalesce symbols that are discarded need to be accounted for as
3238 undefined references */
3239 for(i = 0; i < cur_obj->symtab->nsyms; i++){
3240 @@ -1205,11 +1232,12 @@
3244 - * If the output file is a MH_DYLIB type reset the
3245 - * reference map for the merged external symbol that
3246 - * is being discarded.
3247 + * If the output file is a multi module MH_DYLIB type
3248 + * reset the reference map for the merged external
3249 + * symbol that is being discarded.
3251 if(filetype == MH_DYLIB &&
3252 + multi_module_dylib == TRUE &&
3253 merged_symbol->defined_in_dylib == FALSE){
3255 * Discared coalesced symbols are referenced as
3256 @@ -1292,9 +1320,24 @@
3257 printf("symbol: %s is coalesced\n", merged_symbol->nlist.n_un.n_name);
3262 multiply_defined(merged_symbol, &(object_symbols[i]),
3264 + if(allow_multiply_defined_symbols == TRUE){
3266 + * If this is a private external then decrement
3267 + * the previous incremented the count of private
3268 + * exterals for this object and the total in the
3269 + * output file since we are going to ignore this
3270 + * this multiply defined symbol.
3272 + if((object_symbols[i].n_type & N_EXT) &&
3273 + (object_symbols[i].n_type & N_PEXT)){
3274 + cur_obj->nprivatesym--;
3275 + nmerged_private_symbols--;
3281 * If this symbol was undefined or a common in this object
3282 @@ -1313,10 +1356,10 @@
3286 - * If the output file is a MH_DYLIB type set the reference map
3287 - * for this external symbol.
3288 + * If the output file is a multi module MH_DYLIB type set the
3289 + * reference map for this external symbol.
3291 - if(filetype == MH_DYLIB){
3292 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3293 cur_obj->reference_maps[nrefsym].merged_symbol =
3296 @@ -1353,6 +1396,7 @@
3298 else if(strip_level != STRIP_DUP_INCLS &&
3299 is_output_local_symbol(object_symbols[i].n_type,
3300 + object_symbols[i].n_sect, cur_obj,
3301 object_symbols[i].n_un.n_strx == 0 ? "" :
3302 object_strings + object_symbols[i].n_un.n_strx)){
3303 cur_obj->nlocalsym++;
3304 @@ -1427,6 +1471,10 @@
3305 localsym_block->index = i;
3306 localsym_block->state = PARSE_SYMBOLS;
3307 localsym_block->count = 1;
3308 + localsym_block->input_N_BINCL_n_value =
3309 + object_symbols[i].n_value;
3310 + if(localsym_block->input_N_BINCL_n_value != 0)
3311 + sum = localsym_block->input_N_BINCL_n_value;
3313 /* insert the first block in the list */
3314 localsym_block->next = *next_localsym_block;
3315 @@ -1506,7 +1554,8 @@
3316 if((object_symbols[j].n_type & N_STAB) != 0){
3317 cur_localsym_block->count++;
3319 - if(object_symbols[j].n_un.n_strx != 0){
3320 + if(localsym_block->input_N_BINCL_n_value == 0 &&
3321 + object_symbols[j].n_un.n_strx != 0){
3322 stab_string = object_strings +
3323 object_symbols[j].n_un.n_strx;
3324 for( ; *stab_string != '\0'; stab_string++){
3325 @@ -1687,6 +1736,55 @@
3329 + * exports_list_processing() takes a symbol_name and a defined symbol from an
3330 + * object file and sets the private extern bit is it is not to be exported. And
3331 + * also marks the symbol in the list as seen.
3335 +exports_list_processing(
3337 +struct nlist *symbol)
3339 + struct symbol_list *sp;
3341 + if(save_symbols != NULL){
3342 + sp = bsearch(symbol_name, save_symbols, nsave_symbols,
3343 + sizeof(struct symbol_list),
3344 + (int (*)(const void *, const void *))
3345 + symbol_list_bsearch);
3350 + if(symbol->n_desc & REFERENCED_DYNAMICALLY){
3351 + warning("symbol: %s referenced dynamically and must be "
3352 + "exported", symbol_name);
3355 + symbol->n_type |= N_PEXT;
3359 + if(remove_symbols != NULL){
3360 + sp = bsearch(symbol_name, remove_symbols, nremove_symbols,
3361 + sizeof(struct symbol_list),
3362 + (int (*)(const void *, const void *))
3363 + symbol_list_bsearch);
3366 + if(symbol->n_desc & REFERENCED_DYNAMICALLY){
3367 + warning("symbol: %s referenced dynamically and must be "
3368 + "exported", symbol_name);
3371 + symbol->n_type |= N_PEXT;
3378 * command_line_symbol() looks up a symbol name that comes from a command line
3379 * argument (like -u symbol_name) and returns a pointer to the merged symbol
3380 * table entry for it. If the symbol doesn't exist it enters an undefined
3381 @@ -1725,7 +1823,7 @@
3383 merged_symbol = enter_symbol(hash_pointer, &(undefined_symbol),
3384 symbol_name, command_line_object);
3385 - if(filetype == MH_DYLIB){
3386 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3387 command_line_object->reference_maps =
3388 reallocate(command_line_object->reference_maps,
3389 (command_line_object->nrefsym + 1) *
3390 @@ -1910,7 +2008,7 @@
3392 merged_symbol->nlist.n_value = (unsigned long)merged_indr_symbol;
3394 - if(filetype == MH_DYLIB){
3395 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE){
3396 command_line_object->nextdefsym = 1;
3397 command_line_object->reference_maps =
3398 reallocate(command_line_object->reference_maps,
3399 @@ -1951,7 +2049,7 @@
3400 struct nlist *symbols, *fake_trace_symbol;
3401 struct dylib_reference *refs;
3402 unsigned long flags;
3403 - enum bool was_traced;
3404 + enum bool was_traced, resolve_flat;
3405 struct merged_symbol **hash_pointer, *merged_symbol;
3406 struct object_file *obj;
3407 struct dylib_table_of_contents *toc;
3408 @@ -2031,11 +2129,12 @@
3412 - * If the output file is a MH_DYLIB type reset the
3413 - * reference map for the merged external symbol that
3414 + * If the output file is a multi module MH_DYLIB type reset
3415 + * the reference map for the merged external symbol that
3416 * is being discarded.
3418 if(filetype == MH_DYLIB &&
3419 + multi_module_dylib == TRUE &&
3420 merged_symbol->defined_in_dylib == FALSE){
3422 * Discared coalesced symbols are referenced as
3423 @@ -2208,6 +2307,13 @@
3424 merged_symbol->defined_in_dylib = TRUE;
3425 merged_symbol->definition_library = dynamic_library;
3427 + * If this shared library is being forced to be weak linked then
3428 + * set N_WEAK_REF to make this symbol a weak reference.
3430 + if(dynamic_library->force_weak_dylib &&
3431 + merged_symbol->referenced_in_non_dylib == TRUE)
3432 + merged_symbol->nlist.n_desc |= N_WEAK_REF;
3434 * If the merged symbol we are resolving is not a weak reference
3435 * and it is referenced from a non-dylib then set
3436 * some_non_weak_refs to TRUE.
3437 @@ -2215,6 +2321,7 @@
3438 if((merged_symbol->nlist.n_desc & N_WEAK_REF) == 0 &&
3439 merged_symbol->referenced_in_non_dylib == TRUE)
3440 dynamic_library->some_non_weak_refs = TRUE;
3441 + if(merged_symbol->referenced_in_non_dylib == TRUE)
3442 dynamic_library->some_symbols_referenced = TRUE;
3443 if((symbols[j].n_type & N_TYPE) == N_INDR){
3444 merged_symbol->nlist.n_type = N_INDR | N_EXT;
3445 @@ -2295,7 +2402,8 @@
3446 print_obj_name(cur_obj);
3447 library_ordinal = GET_LIBRARY_ORDINAL(symbols[
3448 refs[j].isym].n_desc);
3449 - if(library_ordinal != 0){
3450 + if(library_ordinal != 0 &&
3451 + library_ordinal != DYNAMIC_LOOKUP_ORDINAL){
3452 dep = dynamic_library->dependent_images[
3453 library_ordinal - 1];
3454 if(dep->umbrella_name != NULL)
3455 @@ -2316,13 +2424,32 @@
3459 - * If -force_flat_namespace is TRUE or this dylib is not a
3460 - * two-level namespace dylib then use flat semantics to resolve
3461 - * the undefined symbols from this dylib module.
3462 + * Determine how this reference will be resolved. If
3463 + * -force_flat_namespace is TRUE it will be resolved flat.
3464 + * If this dylib is not a two-level namespace dylib it will
3465 + * also be resolved flat. It it is a two-level dylib then
3466 + * if the library_ordinal is DYNAMIC_LOOKUP_ORDINAL it will be
3467 + * resolved flat. If it is a two-level namespace dylib and
3468 + * the library_ordinal is not DYNAMIC_LOOKUP_ORDINAL it will
3469 + * be resolved with two-level namespace semantics.
3471 - if(force_flat_namespace == TRUE ||
3472 - (((struct mach_header *)(cur_obj->obj_addr))->flags &
3473 - MH_TWOLEVEL) != MH_TWOLEVEL){
3474 + if(force_flat_namespace == TRUE)
3475 + resolve_flat = TRUE;
3477 + if((((struct mach_header *)(cur_obj->obj_addr))->
3478 + flags & MH_TWOLEVEL) == MH_TWOLEVEL){
3479 + library_ordinal = GET_LIBRARY_ORDINAL(
3480 + symbols[refs[j].isym].n_desc);
3481 + if(library_ordinal == DYNAMIC_LOOKUP_ORDINAL)
3482 + resolve_flat = TRUE;
3484 + resolve_flat = FALSE;
3487 + resolve_flat = TRUE;
3490 + if(resolve_flat == TRUE){
3491 /* lookup the symbol and see if it has already been seen */
3492 hash_pointer = lookup_symbol(symbol_name);
3493 if(*hash_pointer == NULL){
3494 @@ -2505,11 +2632,12 @@
3498 - * If the output file is a MH_DYLIB type reset the
3499 - * reference map for the merged external symbol that
3500 + * If the output file is a multi module MH_DYLIB type reset
3501 + * the reference map for the merged external symbol that
3502 * is being discarded.
3504 if(filetype == MH_DYLIB &&
3505 + multi_module_dylib == TRUE &&
3506 merged_symbol->defined_in_dylib == FALSE){
3508 * Discared coalesced symbols are referenced as
3509 @@ -2686,13 +2814,17 @@
3512 * is_output_local_symbol() returns TRUE or FALSE depending if the local symbol
3513 - * type and name passed to it will be in the output file's symbol table based
3514 - * on the level of symbol stripping.
3515 + * type, section, object and name passed to it will be in the output file's
3516 + * symbol table based on the level of symbol stripping. The obj passed must be
3517 + * be the object this symbol came from so that the the section can be checked
3518 + * for the S_ATTR_STRIP_STATIC_SYMS attribute flag.
3522 is_output_local_symbol(
3523 unsigned char n_type,
3524 +unsigned char n_sect,
3525 +struct object_file *obj,
3528 switch(strip_level){
3529 @@ -2700,14 +2832,15 @@
3530 case STRIP_DUP_INCLS:
3534 + case STRIP_DYNAMIC_EXECUTABLE:
3535 case STRIP_NONGLOBALS:
3536 - if(n_type & N_PEXT)
3540 if(n_type & N_STAB ||
3541 - (*symbol_name == 'L' && (n_type & N_STAB) == 0))
3542 + (*symbol_name == 'L' && (n_type & N_STAB) == 0) ||
3543 + ((n_type & N_TYPE) == N_SECT &&
3544 + (obj->section_maps[n_sect - 1].s->flags &
3545 + S_ATTR_STRIP_STATIC_SYMS) == S_ATTR_STRIP_STATIC_SYMS))
3549 @@ -3340,13 +3473,12 @@
3550 error("common symbols not allowed with MH_FVMLIB "
3553 - * If the output format is MH_DYLIB then commons are not
3554 - * allowed because each symbol can only be defined in at
3555 - * most one module.
3556 + * If the output format is multi module MH_DYLIB then * commons are not allowed because each symbol can only be
3557 + * defined in at most one module.
3559 - if(filetype == MH_DYLIB)
3560 + if(filetype == MH_DYLIB && multi_module_dylib == TRUE)
3561 error("common symbols not allowed with MH_DYLIB "
3563 + "output format with the -multi_module option");
3564 commons_exist = TRUE;
3566 if(sect_spec != NULL && sect_spec->order_filename != NULL){
3567 @@ -3461,7 +3593,8 @@
3568 * formats so trace each one. An error message for this
3569 * has been printed above.
3571 - if(filetype == MH_FVMLIB || filetype == MH_DYLIB)
3572 + if(filetype == MH_FVMLIB ||
3573 + (filetype == MH_DYLIB && multi_module_dylib == TRUE))
3574 trace_merged_symbol(merged_symbol);
3575 /* determine the alignment of this symbol */
3576 common_size = merged_symbol->nlist.n_value;
3577 @@ -3497,6 +3630,22 @@
3578 &link_edit_common_object;
3579 /* Create the space for this symbol */
3580 link_edit_common_section.size += common_size;
3582 + * If we have an -export_symbols_list or
3583 + * -unexport_symbol_list option set the private extern bit
3584 + * on the symbol if it is not to be exported.
3586 + exports_list_processing(merged_symbol->nlist.n_un.n_name,
3587 + &(merged_symbol->nlist));
3589 + * If this common symbol got made into a private extern with
3590 + * the processing of the exports list increment the count of
3591 + * private exterals.
3593 + if((merged_symbol->nlist.n_type & N_PEXT) == N_PEXT){
3594 + link_edit_common_object.nprivatesym++;
3595 + nmerged_private_symbols++;
3599 * Do the trace of this symbol if specified now that it has
3600 @@ -3557,6 +3706,58 @@
3605 + * define_undefined_symbols_a_way() is called to setup defining all remaining
3606 + * undefined symbols as private externs. Their final value gets set by
3607 + * define_link_editor_dylib_symbols().
3611 +define_undefined_symbols_a_way(
3615 + struct merged_symbol_list **p, *merged_symbol_list;
3616 + struct merged_symbol *merged_symbol;
3618 + for(p = &merged_symbol_lists; *p; p = &(merged_symbol_list->next)){
3619 + merged_symbol_list = *p;
3620 + for(i = 0; i < merged_symbol_list->used; i++){
3621 + merged_symbol = &(merged_symbol_list->merged_symbols[i]);
3622 + if(merged_symbol->nlist.n_type == (N_EXT | N_UNDF) &&
3623 + merged_symbol->nlist.n_value == 0){
3624 + if(dynamic == TRUE &&
3625 + filetype != MH_EXECUTE &&
3626 + merged_segments != NULL){
3627 + define_link_editor_symbol(
3628 + merged_symbol->nlist.n_un.n_name,
3629 + N_SECT | N_PEXT | N_EXT, /* n_type */
3635 + define_link_editor_symbol(
3636 + merged_symbol->nlist.n_un.n_name,
3637 + N_ABS | N_PEXT | N_EXT, /* n_type */
3638 + NO_SECT, /* n_sect */
3643 + * This symbol got made into a private extern so increment
3644 + * the count of private exterals.
3646 + if((merged_symbol->nlist.n_type & N_PEXT) == N_PEXT){
3647 + link_edit_symbols_object->nprivatesym++;
3648 + nmerged_private_symbols++;
3650 + merged_symbol->define_a_way = 1;
3658 setup_link_edit_symbols_object(
3659 @@ -3741,6 +3942,8 @@
3662 struct merged_symbol *merged_symbol;
3663 + struct merged_symbol_list **p, *merged_symbol_list;
3666 if(filetype == MH_BUNDLE)
3667 symbol_name = _MH_BUNDLE_SYM;
3668 @@ -3762,6 +3965,24 @@
3670 merged_symbol->nlist.n_value = header_address -
3671 link_edit_symbols_object->section_maps[0].output_section->s.addr;
3673 + /* set the correct values of the undefined symbols defined a way */
3674 + if(undefined_flag == UNDEFINED_DEFINE_A_WAY){
3675 + for(p = &merged_symbol_lists; *p; p = &(merged_symbol_list->next)){
3676 + merged_symbol_list = *p;
3677 + for(i = 0; i < merged_symbol_list->used; i++){
3678 + merged_symbol = &(merged_symbol_list->merged_symbols[i]);
3679 + if(merged_symbol->define_a_way == 1){
3680 + if(merged_symbol->nlist.n_sect == NO_SECT)
3681 + merged_symbol->nlist.n_value = header_address;
3683 + merged_symbol->nlist.n_value = header_address -
3684 + link_edit_symbols_object->section_maps[0].
3685 + output_section->s.addr;
3691 #endif /* !defined(RLD) */
3693 @@ -3942,6 +4163,16 @@
3694 merged_symbol->nlist.n_value = value;
3695 merged_symbol->definition_object = link_edit_symbols_object;
3699 + * If we have an -export_symbols_list or
3700 + * -unexport_symbol_list option set the private extern bit
3701 + * on the symbol if it is not to be exported.
3703 + exports_list_processing(merged_symbol->nlist.n_un.n_name,
3704 + &(merged_symbol->nlist));
3708 * Do the trace of this symbol if specified now that it has
3710 @@ -4057,6 +4288,16 @@
3711 for(j = 0; j < indr_depth; j++){
3712 indr_symbols[j]->nlist.n_value =
3713 (unsigned long)indr_symbol;
3715 + * If this indirect symbol is pointing to a
3716 + * private extern then increment the count of
3717 + * private exterals.
3719 + if((indr_symbol->nlist.n_type & N_PEXT) == N_PEXT){
3720 + indr_symbols[j]->definition_object->
3722 + nmerged_private_symbols++;
3727 @@ -4142,6 +4383,7 @@
3728 object_symbols[i].n_sect == nsect &&
3729 (strip_level == STRIP_NONE ||
3730 is_output_local_symbol(object_symbols[i].n_type,
3731 + object_symbols[i].n_sect, cur_obj,
3732 object_symbols[i].n_un.n_strx == 0 ? "" :
3734 object_symbols[i].n_un.n_strx))){
3735 @@ -4383,6 +4625,7 @@
3736 if((object_symbols[i].n_type & N_EXT) == 0 &&
3737 (strip_level == STRIP_NONE || strip_level == STRIP_DUP_INCLS ||
3738 is_output_local_symbol(object_symbols[i].n_type,
3739 + object_symbols[i].n_sect, cur_obj,
3740 object_symbols[i].n_un.n_strx == 0 ? "" :
3741 object_strings + object_symbols[i].n_un.n_strx))){
3743 @@ -4433,11 +4676,11 @@
3744 cur_obj->symtab->strsize);
3745 output_symtab_info.output_local_strsize += cur_obj->symtab->strsize;
3748 if(host_byte_sex != target_byte_sex){
3749 nlist = (struct nlist *)(output_addr + flush_symbol_offset);
3750 swap_nlist(nlist, output_nsyms, target_byte_sex);
3753 output_flush(flush_symbol_offset, output_nsyms * sizeof(struct nlist));
3754 output_flush(flush_string_offset, output_symtab_info.
3755 output_local_strsize -
3756 @@ -4503,6 +4746,7 @@
3757 if((object_symbols[i].n_type & N_EXT) == 0 &&
3758 (strip_level == STRIP_NONE ||
3759 is_output_local_symbol(object_symbols[i].n_type,
3760 + object_symbols[i].n_sect, obj,
3761 object_symbols[i].n_un.n_strx == 0 ? "" :
3762 object_strings + object_symbols[i].n_un.n_strx))){
3764 @@ -4609,6 +4853,7 @@
3765 if(indr_symbol->nlist.n_type != (N_EXT | N_UNDF) &&
3766 indr_symbol->nlist.n_type != (N_EXT | N_PBUD) &&
3767 (filetype != MH_DYLIB ||
3768 + (filetype == MH_DYLIB && multi_module_dylib == FALSE) ||
3769 merged_symbol->definition_object ==
3770 indr_symbol->definition_object)){
3771 merged_symbol->nlist.n_type = indr_symbol->nlist.n_type;
3772 @@ -4640,7 +4885,10 @@
3773 * the output file is the private externs if they are not to be kept
3774 * (that is they are to be made static and not kept as global symbols).
3776 - if(nmerged_private_symbols != 0 && keep_private_externs == FALSE){
3777 + if(nmerged_private_symbols != 0 &&
3778 + keep_private_externs == FALSE &&
3779 + (strip_level != STRIP_NONGLOBALS ||
3780 + (filetype == MH_DYLIB && multi_module_dylib == TRUE)) ){
3781 for(p = &merged_symbol_lists; *p; p = &(merged_symbol_list->next)){
3782 merged_symbol_list = *p;
3783 for(i = 0; i < merged_symbol_list->used; i++){
3784 @@ -4654,6 +4902,11 @@
3785 if(merged_symbol->definition_object->set_num != cur_set)
3788 + if(strip_level == STRIP_DYNAMIC_EXECUTABLE &&
3789 + (merged_symbol->nlist.n_desc & REFERENCED_DYNAMICALLY) !=
3790 + REFERENCED_DYNAMICALLY)
3793 if(merged_symbol->nlist.n_type & N_PEXT){
3795 * Place this symbol with the local symbols for the
3796 @@ -5020,7 +5273,8 @@
3797 if(allowed_undef == FALSE)
3799 if(save_reloc == FALSE &&
3800 - undefined_flag != UNDEFINED_SUPPRESS){
3801 + (undefined_flag == UNDEFINED_ERROR ||
3802 + undefined_flag == UNDEFINED_WARNING)){
3803 if(allowed_undef == FALSE || prebound_undef == TRUE){
3804 if(printed_undef == FALSE){
3805 if(undefined_flag == UNDEFINED_WARNING)
3806 @@ -5047,6 +5301,12 @@
3807 print("%s\n", merged_symbol->nlist.n_un.n_name);
3810 + else if(save_reloc == FALSE &&
3811 + undefined_flag == UNDEFINED_DYNAMIC_LOOKUP &&
3812 + twolevel_namespace == TRUE){
3813 + SET_LIBRARY_ORDINAL(merged_symbol->nlist.n_desc,
3814 + DYNAMIC_LOOKUP_ORDINAL);
3819 @@ -5177,6 +5437,8 @@
3826 * There can be two-level references left on the undefined list. These
3827 * are "fake" merged symbols as they are not entered in the symbol
3828 @@ -5198,6 +5460,18 @@
3829 undefined->merged_symbol->nlist.n_desc);
3830 if(library_ordinal == SELF_LIBRARY_ORDINAL)
3831 lib = undefined->merged_symbol->referencing_library;
3833 + * Note that if library_ordinal was DYNAMIC_LOOKUP_ORDINAL then
3834 + * merge_dylib_module_symbols() in symbols.c would not have
3835 + * set the twolevel_reference field to TRUE in the merged_symbol
3836 + * and if we get here it with this it is an internal error.
3838 + else if(library_ordinal == DYNAMIC_LOOKUP_ORDINAL)
3839 + fatal("internal error: process_undefineds() 1 with a "
3840 + "merged_symbol (%s) on the undefined list with "
3841 + "twolevel_reference == TRUE and library_ordinal == "
3842 + "DYNAMIC_LOOKUP_ORDINAL", undefined->merged_symbol->
3843 + nlist.n_un.n_name);
3845 lib = undefined->merged_symbol->referencing_library->
3846 dependent_images[library_ordinal - 1];
3847 @@ -5205,10 +5479,25 @@
3848 for(prevs = undefined_list.next;
3850 prevs = prevs->next){
3851 + if(prevs->merged_symbol->twolevel_reference == FALSE)
3853 library_ordinal = GET_LIBRARY_ORDINAL(
3854 prevs->merged_symbol->nlist.n_desc);
3855 if(library_ordinal == SELF_LIBRARY_ORDINAL)
3856 prev_lib = prevs->merged_symbol->referencing_library;
3858 + * Note that if library_ordinal was DYNAMIC_LOOKUP_ORDINAL
3859 + * then merge_dylib_module_symbols() in symbols.c would not
3860 + * have set the twolevel_reference field to TRUE in the
3861 + * merged_symbol and if we get here it with this it is an
3864 + else if(library_ordinal == DYNAMIC_LOOKUP_ORDINAL)
3865 + fatal("internal error: process_undefineds() 2 with a "
3866 + "merged_symbol (%s) on the undefined list with "
3867 + "twolevel_reference == TRUE and library_ordinal "
3868 + "== DYNAMIC_LOOKUP_ORDINAL",
3869 + prevs->merged_symbol->nlist.n_un.n_name);
3871 prev_lib = prevs->merged_symbol->referencing_library->
3872 dependent_images[library_ordinal - 1];
3873 @@ -5277,9 +5566,10 @@
3875 merged_symbol->nlist.n_un.n_name);
3877 - if(merged_symbol->twolevel_reference == TRUE){
3878 library_ordinal = GET_LIBRARY_ORDINAL(
3879 merged_symbol->nlist.n_desc);
3880 + if(merged_symbol->twolevel_reference == TRUE &&
3881 + library_ordinal != DYNAMIC_LOOKUP_ORDINAL){
3882 if(library_ordinal == SELF_LIBRARY_ORDINAL)
3883 lib = merged_symbol->referencing_library;
3885 @@ -5419,13 +5709,54 @@
3886 assign_output_symbol_indexes(
3889 - unsigned long index, i, nextdefsym, nundefsym;
3890 + unsigned long index, i, nextdefsym, nundefsym, n_pext;
3891 struct merged_symbol_list **p, *merged_symbol_list;
3892 - struct merged_symbol *merged_symbol;
3893 + struct merged_symbol *merged_symbol, *indr_symbol;
3894 struct object_list *object_list, **q;
3895 + struct object_file *last_object;
3896 + enum bool rebuild_merged_string_table;
3898 - if(strip_level == STRIP_ALL)
3899 + rebuild_merged_string_table = FALSE;
3900 + if(strip_level == STRIP_ALL){
3901 + if(has_dynamic_linker_command){
3902 + strip_level = STRIP_DYNAMIC_EXECUTABLE;
3904 + * In order to not put out strings for merged symbols that will
3905 + * be discared we need to rebuild the merged string table for
3906 + * only the symbols not stripped.
3908 + merged_string_blocks = NULL;
3909 + merged_string_size = 0;
3910 + rebuild_merged_string_table = TRUE;
3913 + seglinkedit = FALSE;
3918 + * If we are stripping non-globals and we are not keeping private
3919 + * externs and we have some private externs in the merged symbol table,
3920 + * and the output is not a multi-module dylib, then in order to not put
3921 + * out strings for them we also need to rebuild the merged string table
3922 + * without these symbols.
3924 + else if(strip_level == STRIP_NONGLOBALS &&
3925 + keep_private_externs == FALSE &&
3926 + nmerged_private_symbols != 0 &&
3927 + (filetype != MH_DYLIB || multi_module_dylib == FALSE)){
3928 + merged_string_blocks = NULL;
3929 + merged_string_size = 0;
3930 + rebuild_merged_string_table = TRUE;
3934 + * Add a copy of the object file for the common symbols that the link
3935 + * editor allocated into the object file list. Since it is possible
3936 + * that some of the common symbols are not on the export list they could
3937 + * have been made into private externs.
3939 + last_object = add_last_object_file(&link_edit_common_object);
3942 * Private exterals are always kept when any symbols are kept. The
3943 @@ -5467,7 +5798,12 @@
3944 if(keep_private_externs == FALSE){
3945 cur_obj->iprivatesym = index;
3946 cur_obj->cprivatesym = index;
3947 + if(strip_level != STRIP_DYNAMIC_EXECUTABLE &&
3948 + (strip_level != STRIP_NONGLOBALS ||
3949 + (filetype == MH_DYLIB && multi_module_dylib == TRUE)))
3950 index += cur_obj->nprivatesym;
3952 + nstripped_merged_symbols += cur_obj->nprivatesym;
3956 @@ -5476,12 +5812,21 @@
3958 if((keep_private_externs == TRUE && index != nlocal_symbols) ||
3959 (keep_private_externs == FALSE && index != nlocal_symbols +
3960 - nmerged_private_symbols))
3961 + nmerged_private_symbols - nstripped_merged_symbols))
3962 fatal("internal error: assign_output_symbol_indexes() "
3963 "inconsistent local symbol counts");
3964 output_dysymtab_info.dysymtab_command.nlocalsym = index;
3967 + * Copy the values that got set in the above loop back into the
3968 + * object file for the the common symbols. Then remove the copy of
3969 + * the object file from the object file list.
3971 + link_edit_common_object = *last_object;
3972 + remove_last_object_file(last_object);
3976 * Count the number of undefined symbols and defined external symbols.
3977 * Private exterals are counted as defined externals if
3978 * keep_private_externs is TRUE.
3979 @@ -5504,11 +5849,36 @@
3980 if(merged_symbol->nlist.n_type == (N_EXT | N_UNDF) ||
3981 merged_symbol->nlist.n_type == (N_EXT | N_PBUD) ||
3982 (merged_symbol->nlist.n_type == (N_EXT | N_INDR) &&
3983 - merged_symbol->defined_in_dylib == TRUE))
3984 + merged_symbol->defined_in_dylib == TRUE)){
3986 - else if(keep_private_externs == TRUE ||
3987 - (merged_symbol->nlist.n_type & N_PEXT) == 0)
3988 + if(rebuild_merged_string_table == TRUE)
3989 + merged_symbol->nlist.n_un.n_name =
3990 + enter_string(merged_symbol->nlist.n_un.n_name);
3993 + if(merged_symbol->nlist.n_type == (N_EXT | N_INDR)){
3994 + indr_symbol = (struct merged_symbol *)
3995 + (merged_symbol->nlist.n_value);
3996 + n_pext = indr_symbol->nlist.n_type & N_PEXT;
3999 + n_pext = merged_symbol->nlist.n_type & N_PEXT;
4001 + if(keep_private_externs == TRUE || n_pext == 0){
4002 + if(strip_level != STRIP_DYNAMIC_EXECUTABLE ||
4003 + (merged_symbol->nlist.n_desc &
4004 + REFERENCED_DYNAMICALLY) == REFERENCED_DYNAMICALLY){
4006 + if(rebuild_merged_string_table == TRUE)
4007 + merged_symbol->nlist.n_un.n_name =
4008 + enter_string(merged_symbol->
4009 + nlist.n_un.n_name);
4012 + nstripped_merged_symbols++;
4019 @@ -5543,11 +5913,25 @@
4020 (merged_symbol->nlist.n_type == (N_EXT | N_INDR) &&
4021 merged_symbol->defined_in_dylib == TRUE))
4022 undefsyms_order[nundefsym++] = merged_symbol;
4023 - else if(keep_private_externs == TRUE ||
4024 - (merged_symbol->nlist.n_type & N_PEXT) == 0)
4026 + if(merged_symbol->nlist.n_type == (N_EXT | N_INDR)){
4027 + indr_symbol = (struct merged_symbol *)
4028 + (merged_symbol->nlist.n_value);
4029 + n_pext = indr_symbol->nlist.n_type & N_PEXT;
4032 + n_pext = merged_symbol->nlist.n_type & N_PEXT;
4034 + if(keep_private_externs == TRUE || n_pext == 0){
4035 + if(strip_level != STRIP_DYNAMIC_EXECUTABLE ||
4036 + (merged_symbol->nlist.n_desc &
4037 + REFERENCED_DYNAMICALLY) == REFERENCED_DYNAMICALLY){
4038 extdefsyms_order[nextdefsym++] = merged_symbol;
4046 * Sort the defined symbols by module for MH_DYLIB formats and by
4047 @@ -5688,6 +6072,12 @@
4051 + * This is a pointer to the module name saved in the merged string table for
4052 + * the one module table entry for a single module dylib.
4054 +char *dylib_single_module_name;
4057 * layout_dylib_tables() sizes and readys the tables for a dynamic library file.
4058 * The merged symbol indexes have already been assigned before this is called.
4059 * There are three tables:
4060 @@ -5705,10 +6095,12 @@
4061 struct object_list *object_list, **q;
4064 + if(multi_module_dylib == TRUE){
4066 - * The reference table was sized as the symbols were merged. All that
4067 - * is left to do for the reference table is to adjust the flags for
4068 - * undefined references that ended up referencing private externs.
4069 + * For multi module dylibs the reference table was sized as the
4070 + * symbols were merged. All that is left to do for the reference
4071 + * table is to adjust the flags for undefined references that ended
4072 + * up referencing private externs.
4074 for(q = &objects; *q; q = &(object_list->next)){
4076 @@ -5721,7 +6113,8 @@
4077 if(cur_obj->dylinker)
4079 for(j = 0; j < cur_obj->nrefsym; j++){
4080 - merged_symbol = cur_obj->reference_maps[j].merged_symbol;
4082 + cur_obj->reference_maps[j].merged_symbol;
4083 if(merged_symbol->nlist.n_type & N_PEXT){
4084 flags = cur_obj->reference_maps[j].flags;
4085 if(flags == REFERENCE_FLAG_UNDEFINED_NON_LAZY)
4086 @@ -5735,27 +6128,43 @@
4088 * The merged symbol is not a private extern. So it
4089 * might be a non-weak symbol that is being used and
4090 - * some weak private externs refs were discarded. If
4091 - * so we need to make the refs non-weak.
4092 + * some weak private externs refs were discarded.
4093 + * If so we need to make the refs non-weak.
4095 flags = cur_obj->reference_maps[j].flags;
4096 - if(flags == REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY)
4098 + REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY)
4099 cur_obj->reference_maps[j].flags =
4100 REFERENCE_FLAG_UNDEFINED_NON_LAZY;
4101 - else if(flags == REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY)
4103 + REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY)
4104 cur_obj->reference_maps[j].flags =
4105 REFERENCE_FLAG_UNDEFINED_LAZY;
4114 - * The module table is sized from the number of modules loaded. The
4115 - * module_name of each module in the dynamic shared library is set from
4116 - * base name or archive member name of the object loaded. The string
4117 - * for the module_name is then saved with the merged strings so that it
4118 - * can be converted to a string table index on output.
4119 + * For single module dylibs the reference table size is reset here
4120 + * from the defined and undefined merged symbols. The contents of
4121 + * the reference table for single module dylibs will be filled in
4122 + * output_dylib_tables() from the merged symbol table.
4124 + output_dysymtab_info.dysymtab_command.nextrefsyms =
4125 + output_dysymtab_info.dysymtab_command.nextdefsym +
4126 + output_dysymtab_info.dysymtab_command.nundefsym;
4129 + if(multi_module_dylib == TRUE){
4131 + * For multi module dylibs the module table is sized from the number
4132 + * of modules loaded. The module_name of each module in the dynamic
4133 + * shared library is set from base name or archive member name of
4134 + * the object loaded. The string for the module_name is then saved
4135 + * with the merged strings so that it can be converted to a string
4136 + * table index on output.
4138 output_dysymtab_info.dysymtab_command.nmodtab = 0;
4139 for(q = &objects; *q; q = &(object_list->next)){
4140 @@ -5786,6 +6195,17 @@
4147 + * For single module dylibs there is one module table entry.
4148 + * The module_name is set to "single module". The string for the
4149 + * module_name is then saved with the merged strings so that it can
4150 + * be converted to a string table index on output.
4152 + output_dysymtab_info.dysymtab_command.nmodtab = 1;
4153 + dylib_single_module_name = enter_string("single module");
4157 * The table of contents is sized from the number of defined external
4158 @@ -5815,6 +6235,7 @@
4159 struct merged_symbol_list **p, *merged_symbol_list;
4160 struct merged_symbol *merged_symbol;
4161 struct dylib_table_of_contents *tocs, *toc;
4162 + struct merged_section *ms;
4165 * Output the reference table.
4166 @@ -5822,6 +6243,11 @@
4167 flush_offset = output_dysymtab_info.dysymtab_command.extrefsymoff;
4168 refs = (struct dylib_reference *)(output_addr + flush_offset);
4170 + if(multi_module_dylib == TRUE){
4172 + * For multi module dylibs there is a reference table for each
4173 + * object loaded built from the reference_maps.
4175 for(q = &objects; *q; q = &(object_list->next)){
4177 for(i = 0; i < object_list->used; i++){
4178 @@ -5840,6 +6266,35 @@
4185 + * For single module dylibs there is one reference table and it is
4186 + * built from the merged symbol table.
4188 + for(p = &merged_symbol_lists; *p; p = &(merged_symbol_list->next)){
4189 + merged_symbol_list = *p;
4190 + for(i = 0; i < merged_symbol_list->used; i++){
4191 + merged_symbol = &(merged_symbol_list->merged_symbols[i]);
4192 + if(merged_symbol->referenced_in_non_dylib == FALSE)
4194 + if(merged_symbol->nlist.n_type == (N_EXT | N_UNDF) ||
4195 + merged_symbol->nlist.n_type == (N_EXT | N_PBUD) ||
4196 + (merged_symbol->nlist.n_type == (N_EXT | N_INDR) &&
4197 + merged_symbol->defined_in_dylib == TRUE)){
4198 + ref->isym = merged_symbol_output_index(merged_symbol);
4199 + ref->flags = merged_symbol->nlist.n_desc &
4203 + else if((merged_symbol->nlist.n_type & N_PEXT) == 0){
4204 + ref->isym = merged_symbol_output_index(merged_symbol);
4205 + ref->flags = REFERENCE_FLAG_DEFINED;
4211 if(host_byte_sex != target_byte_sex){
4212 swap_dylib_reference(refs,
4213 output_dysymtab_info.dysymtab_command.nextrefsyms,
4214 @@ -5855,6 +6310,11 @@
4215 flush_offset = output_dysymtab_info.dysymtab_command.modtaboff;
4216 mods = (struct dylib_module *)(output_addr + flush_offset);
4218 + if(multi_module_dylib == TRUE){
4220 + * For multi module dylibs there is a module table for each
4221 + * object loaded built from the info saved in the object struct.
4223 for(q = &objects; *q; q = &(object_list->next)){
4225 for(i = 0; i < object_list->used; i++){
4226 @@ -5873,7 +6333,7 @@
4227 mod->nlocalsym = cur_obj->nlocalsym + cur_obj->nprivatesym;
4228 mod->iextrel = cur_obj->iextrel;
4229 mod->nextrel = cur_obj->nextrel;
4230 - mod->iinit_iterm = (cur_obj->iterm << 16) | cur_obj->iinit ;
4231 + mod->iinit_iterm = (cur_obj->iterm << 16) | cur_obj->iinit;
4232 mod->ninit_nterm = (cur_obj->nterm << 16) | cur_obj->ninit;
4233 if(cur_obj->objc_module_info != NULL){
4234 mod->objc_module_info_addr =
4235 @@ -5887,6 +6347,39 @@
4236 mod->objc_module_info_size = 0;
4244 + * For single module dylibs there is one module table entry.
4246 + mod->module_name = STRING_SIZE_OFFSET +
4247 + merged_symbol_string_index(dylib_single_module_name);
4249 + output_dysymtab_info.dysymtab_command.iextdefsym;
4251 + output_dysymtab_info.dysymtab_command.nextdefsym;
4254 + output_dysymtab_info.dysymtab_command.nextrefsyms;
4256 + output_dysymtab_info.dysymtab_command.ilocalsym;
4258 + output_dysymtab_info.dysymtab_command.nlocalsym;
4261 + output_dysymtab_info.dysymtab_command.nextrel;
4262 + mod->iinit_iterm = 0;
4263 + mod->ninit_nterm = (nterm << 16) | ninit;
4264 + ms = lookup_merged_section(SEG_OBJC, SECT_OBJC_MODULES);
4266 + mod->objc_module_info_addr = ms->s.addr;
4267 + mod->objc_module_info_size = ms->s.size;
4270 + mod->objc_module_info_addr = 0;
4271 + mod->objc_module_info_size = 0;
4274 if(host_byte_sex != target_byte_sex){
4275 diff -rub ld/symbols.h ld/symbols.h
4276 --- ld/symbols.h Tue Jan 14 23:35:25 2003
4277 +++ ld/symbols.h Mon Aug 25 12:12:29 2003
4279 /* only in the undefined list as a two- */
4280 /* level namespace reference from a dylib.*/
4281 weak_reference_mismatch:1, /* seen both a weak and non-weak reference */
4283 + define_a_way:1, /* set if this symbol was defined as a */
4284 + /* result of -undefined define_a_way */
4285 output_index:23; /* the symbol table index this symbol will */
4286 /* have in the output file. */
4287 int undef_order; /* if the symbol was undefined the order it */
4288 @@ -184,6 +185,12 @@
4289 __private_extern__ unsigned long nmerged_symbols_referenced_only_from_dylibs;
4292 + * nstripped_merged_symbols is set to the number of merged symbol being stripped
4293 + * out when the strip_level is STRIP_DYNAMIC_EXECUTABLE.
4295 +__private_extern__ unsigned long nstripped_merged_symbols;
4298 * The head of the list of the blocks that store the strings for the merged
4299 * symbols and the total size of all the strings. The size of the strings for
4300 * the private externals is included in the the merge string size.
4302 * The object file that is created for the common symbols to be allocated in.
4305 -#if defined(RLD) && !defined(__DYNAMIC__)
4308 struct object_file link_edit_common_object;
4312 unsigned long index;
4313 unsigned long count;
4314 enum localsym_block_state state;
4315 + unsigned long input_N_BINCL_n_value;
4317 struct localsym_block *next;
4321 __private_extern__ void define_common_symbols(
4323 +__private_extern__ void define_undefined_symbols_a_way(
4325 __private_extern__ void define_link_editor_execute_symbols(
4326 unsigned long header_address);
4327 __private_extern__ void setup_link_editor_symbols(
4329 #endif /* defined(RLD) && !defined(SA_RLD) */
4330 __private_extern__ enum bool is_output_local_symbol(
4331 unsigned char n_type,
4332 + unsigned char n_sect,
4333 + struct object_file *obj,
4335 __private_extern__ unsigned long merged_symbol_output_index(
4336 struct merged_symbol *merged_symbol);