1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-*
3 * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
25 #ifndef __INPUT_FILES_H__
26 #define __INPUT_FILES_H__
29 #include <sys/types.h>
32 #include <sys/sysctl.h>
37 #include <mach/mach_time.h>
38 #include <mach/vm_statistics.h>
39 #include <mach/mach_init.h>
40 #include <mach/mach_host.h>
42 #include <mach-o/dyld.h>
52 class InputFiles
: public ld::dylib::File::DylibHandler
55 InputFiles(Options
& opts
, const char** archName
);
57 // implementation from ld::dylib::File::DylibHandler
58 virtual ld::dylib::File
* findDylib(const char* installPath
, const char* fromPath
);
60 // iterates all atoms in initial files
61 bool forEachInitialAtom(ld::File::AtomHandler
&) const;
62 // searches libraries for name
63 bool searchLibraries(const char* name
, bool searchDylibs
, bool searchArchives
,
64 bool dataSymbolOnly
, ld::File::AtomHandler
&) const;
65 // see if any linked dylibs export a weak def of symbol
66 bool searchWeakDefInDylib(const char* name
) const;
67 // copy dylibs to link with in command line order
68 void dylibs(ld::Internal
& state
);
70 bool inferredArch() const { return _inferredArch
; }
72 uint32_t nextInputOrdinal() const { return _nextInputOrdinal
++; }
74 // for -print_statistics
75 uint64_t _totalObjectSize
;
76 uint64_t _totalArchiveSize
;
77 uint32_t _totalObjectLoaded
;
78 uint32_t _totalArchivesLoaded
;
79 uint32_t _totalDylibsLoaded
;
83 void inferArchitecture(Options
& opts
, const char** archName
);
84 const char* fileArch(const uint8_t* p
, unsigned len
);
85 ld::File
* makeFile(const Options::FileInfo
& info
, bool indirectDylib
);
86 ld::File
* addDylib(ld::dylib::File
* f
, const Options::FileInfo
& info
, uint64_t mappedLen
);
87 ld::File
* addObject(ld::relocatable::File
* f
, const Options::FileInfo
& info
, uint64_t mappedLen
);
88 ld::File
* addArchive(ld::File
* f
, const Options::FileInfo
& info
, uint64_t mappedLen
);
89 void logTraceInfo (const char* format
, ...) const;
90 void logDylib(ld::File
*, bool indirect
);
91 void logArchive(ld::File
*) const;
92 void createIndirectDylibs();
93 void checkDylibClientRestrictions(ld::dylib::File
*);
94 void createOpaqueFileSections();
98 bool operator()(const char* left
, const char* right
) const { return (strcmp(left
, right
) == 0); }
100 typedef __gnu_cxx::hash_map
<const char*, ld::dylib::File
*, __gnu_cxx::hash
<const char*>, CStringEquals
> InstallNameToDylib
;
102 const Options
& _options
;
103 std::vector
<ld::File
*> _inputFiles
;
104 mutable std::set
<class ld::File
*> _archiveFilesLogged
;
105 InstallNameToDylib _installPathToDylibs
;
106 std::set
<ld::dylib::File
*> _allDylibs
;
107 ld::dylib::File
* _bundleLoader
;
108 mutable uint32_t _nextInputOrdinal
;
109 bool _allDirectDylibsLoaded
;
116 #endif // __INPUT_FILES_H__