+ createIndirectDylibs();
+ createOpaqueFileSections();
+
+ while (fileIndex < _inputFiles.size()) {
+ ld::File *file = _inputFiles[fileIndex];
+ file->forEachAtom(handler);
+ fileIndex++;
+ }
+
+ switch ( _options.outputKind() ) {
+ case Options::kStaticExecutable:
+ case Options::kDynamicExecutable:
+ // add implicit __dso_handle label
+ handler.doAtom(DSOHandleAtom::_s_atomExecutable);
+ handler.doAtom(DSOHandleAtom::_s_atomAll);
+ if ( _options.pageZeroSize() != 0 )
+ handler.doAtom(*new PageZeroAtom(_options.pageZeroSize()));
+ if ( _options.hasCustomStack() && !_options.needsEntryPointLoadCommand() )
+ handler.doAtom(*new CustomStackAtom(_options.customStackSize()));
+ break;
+ case Options::kDynamicLibrary:
+ // add implicit __dso_handle label
+ handler.doAtom(DSOHandleAtom::_s_atomDylib);
+ handler.doAtom(DSOHandleAtom::_s_atomAll);
+ break;
+ case Options::kDynamicBundle:
+ // add implicit __dso_handle label
+ handler.doAtom(DSOHandleAtom::_s_atomBundle);
+ handler.doAtom(DSOHandleAtom::_s_atomAll);
+ break;
+ case Options::kDyld:
+ // add implicit __dso_handle label
+ handler.doAtom(DSOHandleAtom::_s_atomDyld);
+ handler.doAtom(DSOHandleAtom::_s_atomAll);
+ break;
+ case Options::kPreload:
+ // add implicit __mh_preload_header label
+ handler.doAtom(DSOHandleAtom::_s_atomPreload);
+ // add implicit __dso_handle label, but put it in __text section because
+ // with -preload the mach_header is no in the address space.
+ handler.doAtom(DSOHandleAtom::_s_atomPreloadDSO);
+ break;
+ case Options::kObjectFile:
+ handler.doAtom(DSOHandleAtom::_s_atomObjectFile);
+ break;
+ case Options::kKextBundle:
+ // add implicit __dso_handle label
+ handler.doAtom(DSOHandleAtom::_s_atomAll);
+ break;
+ }
+}
+
+
+bool InputFiles::searchLibraries(const char* name, bool searchDylibs, bool searchArchives, bool dataSymbolOnly, ld::File::AtomHandler& handler) const
+{
+ // Check each input library.
+ std::vector<LibraryInfo>::const_iterator libIterator = _searchLibraries.begin();
+
+
+ while (libIterator != _searchLibraries.end()) {
+ LibraryInfo lib = *libIterator;
+ if (lib.isDylib()) {
+ if (searchDylibs) {
+ ld::dylib::File *dylibFile = lib.dylib();
+ //fprintf(stderr, "searchLibraries(%s), looking in linked %s\n", name, dylibFile->path() );
+ if ( dylibFile->justInTimeforEachAtom(name, handler) ) {
+ // we found a definition in this dylib
+ // done, unless it is a weak definition in which case we keep searching
+ _options.snapshot().recordDylibSymbol(dylibFile, name);
+ if ( !dylibFile->hasWeakExternals() || !dylibFile->hasWeakDefinition(name)) {
+ return true;
+ }
+ // else continue search for a non-weak definition
+ }
+ }
+ } else {
+ if (searchArchives) {
+ ld::archive::File *archiveFile = lib.archive();
+ if ( dataSymbolOnly ) {
+ if ( archiveFile->justInTimeDataOnlyforEachAtom(name, handler) ) {
+ if ( _options.traceArchives() )
+ logArchive(archiveFile);
+ _options.snapshot().recordArchive(archiveFile->path());
+ // found data definition in static library, done
+ return true;
+ }
+ }
+ else {
+ if ( archiveFile->justInTimeforEachAtom(name, handler) ) {
+ if ( _options.traceArchives() )
+ logArchive(archiveFile);
+ _options.snapshot().recordArchive(archiveFile->path());
+ // found definition in static library, done
+ return true;
+ }
+ }
+ }
+ }
+ libIterator++;
+ }
+