2 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
4 * Copyright (c) 2005-2011 Apple Inc. All rights reserved.
6 * @APPLE_LICENSE_HEADER_START@
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
30 #include <sys/param.h>
37 #include <unordered_map>
38 #include <unordered_set>
40 #include "Architectures.hpp"
41 #include "MachOFileAbstraction.hpp"
42 #include "MachOTrie.hpp"
43 #include "macho_dylib_file.h"
44 #include "../code-sign-blobs/superblob.h"
51 template <typename A
> class File
;
55 // An ExportAtom has no content. It exists so that the linker can track which imported
56 // symbols came from which dynamic libraries.
59 class ExportAtom
: public ld::Atom
62 ExportAtom(const File
<A
>& f
, const char* nm
, bool weakDef
,
63 bool tlv
, typename
A::P::uint_t address
)
64 : ld::Atom(f
._importProxySection
, ld::Atom::definitionProxy
,
65 (weakDef
? ld::Atom::combineByName
: ld::Atom::combineNever
),
66 ld::Atom::scopeLinkageUnit
,
67 (tlv
? ld::Atom::typeTLV
: ld::Atom::typeUnclassified
),
68 symbolTableNotIn
, false, false, false, ld::Atom::Alignment(0)),
69 _file(f
), _name(nm
), _address(address
) {}
70 // overrides of ld::Atom
71 virtual const ld::File
* file() const { return &_file
; }
72 virtual const char* name() const { return _name
; }
73 virtual uint64_t size() const { return 0; }
74 virtual uint64_t objectAddress() const { return _address
; }
75 virtual void copyRawContent(uint8_t buffer
[]) const { }
76 virtual void setScope(Scope
) { }
79 typedef typename
A::P P
;
80 typedef typename
A::P::uint_t pint_t
;
82 virtual ~ExportAtom() {}
92 // An ImportAtom has no content. It exists so that when linking a main executable flat-namespace
93 // the imports of all flat dylibs are checked
96 class ImportAtom
: public ld::Atom
99 ImportAtom(File
<A
>& f
, std::vector
<const char*>& imports
);
101 // overrides of ld::Atom
102 virtual ld::File
* file() const { return &_file
; }
103 virtual const char* name() const { return "import-atom"; }
104 virtual uint64_t size() const { return 0; }
105 virtual uint64_t objectAddress() const { return 0; }
106 virtual void copyRawContent(uint8_t buffer
[]) const { }
107 virtual void setScope(Scope
) { }
108 virtual ld::Fixup::iterator
fixupsBegin() const { return &_undefs
[0]; }
109 virtual ld::Fixup::iterator
fixupsEnd() const { return &_undefs
[_undefs
.size()]; }
112 typedef typename
A::P P
;
114 virtual ~ImportAtom() {}
118 mutable std::vector
<ld::Fixup
> _undefs
;
121 template <typename A
>
122 ImportAtom
<A
>::ImportAtom(File
<A
>& f
, std::vector
<const char*>& imports
)
123 : ld::Atom(f
._flatDummySection
, ld::Atom::definitionRegular
, ld::Atom::combineNever
, ld::Atom::scopeTranslationUnit
,
124 ld::Atom::typeUnclassified
, symbolTableNotIn
, false, false, false, ld::Atom::Alignment(0)), _file(f
)
126 for(std::vector
<const char*>::iterator it
=imports
.begin(); it
!= imports
.end(); ++it
) {
127 _undefs
.push_back(ld::Fixup(0, ld::Fixup::k1of1
, ld::Fixup::kindNone
, false, strdup(*it
)));
134 // The reader for a dylib extracts all exported symbols names from the memory-mapped
135 // dylib, builds a hash table, then unmaps the file. This is an important memory
136 // savings for large dylibs.
138 template <typename A
>
139 class File
: public ld::dylib::File
142 static bool validFile(const uint8_t* fileContent
, bool executableOrDylib
);
143 File(const uint8_t* fileContent
, uint64_t fileLength
, const char* path
,
144 time_t mTime
, ld::File::Ordinal ordinal
, bool linkingFlatNamespace
,
145 bool linkingMainExecutable
, bool hoistImplicitPublicDylibs
,
146 ld::MacVersionMin macMin
, ld::IOSVersionMin iPhoneMin
, bool allowSimToMacOSX
, bool addVers
,
147 bool logAllFiles
, const char* installPath
, bool indirectDylib
);
150 // overrides of ld::File
151 virtual bool forEachAtom(ld::File::AtomHandler
&) const;
152 virtual bool justInTimeforEachAtom(const char* name
, ld::File::AtomHandler
&) const;
153 virtual ld::File::ObjcConstraint
objCConstraint() const { return _objcContraint
; }
154 virtual uint8_t swiftVersion() const { return _swiftVersion
; }
156 // overrides of ld::dylib::File
157 virtual void processIndirectLibraries(ld::dylib::File::DylibHandler
*, bool);
158 virtual bool providedExportAtom() const { return _providedAtom
; }
159 virtual const char* parentUmbrella() const { return _parentUmbrella
; }
160 virtual const std::vector
<const char*>* allowableClients() const { return _allowableClients
.size() != 0 ? &_allowableClients
: NULL
; }
161 virtual bool hasWeakExternals() const { return _hasWeakExports
; }
162 virtual bool deadStrippable() const { return _deadStrippable
; }
163 virtual bool hasPublicInstallName() const{ return _hasPublicInstallName
; }
164 virtual bool hasWeakDefinition(const char* name
) const;
165 virtual bool allSymbolsAreWeakImported() const;
166 virtual const void* codeSignatureDR() const { return _codeSignatureDR
; }
167 virtual bool installPathVersionSpecific() const { return _installPathOverride
; }
168 virtual bool appExtensionSafe() const { return _appExtensionSafe
; };
169 virtual ld::MacVersionMin
macMinVersion() const { return _macMinVersionInDylib
; }
170 virtual ld::IOSVersionMin
iOSMinVersion() const { return _iOSMinVersionInDylib
; }
175 struct ReExportChain
{ ReExportChain
* prev
; File
<A
>* file
; };
177 void assertNoReExportCycles(ReExportChain
*);
180 typedef typename
A::P P
;
181 typedef typename
A::P::E E
;
182 typedef typename
A::P::uint_t pint_t
;
184 friend class ExportAtom
<A
>;
185 friend class ImportAtom
<A
>;
188 std::size_t operator()(const char* __s
) const {
189 unsigned long __h
= 0;
191 __h
= 5 * __h
+ *__s
;
195 struct AtomAndWeak
{ ld::Atom
* atom
; bool weakDef
; bool tlv
; pint_t address
; };
196 typedef std::unordered_map
<const char*, AtomAndWeak
, ld::CStringHash
, ld::CStringEquals
> NameToAtomMap
;
197 typedef std::unordered_set
<const char*, CStringHash
, ld::CStringEquals
> NameSet
;
199 struct Dependent
{ const char* path
; File
<A
>* dylib
; bool reExport
; };
201 bool containsOrReExports(const char* name
, bool* weakDef
, bool* tlv
, pint_t
* defAddress
) const;
202 bool isPublicLocation(const char* pth
);
203 bool wrongOS() { return _wrongOS
; }
204 void addSymbol(const char* name
, bool weak
, bool tlv
, pint_t address
);
205 void addDyldFastStub();
206 void buildExportHashTableFromExportInfo(const macho_dyld_info_command
<P
>* dyldInfo
,
207 const uint8_t* fileContent
);
208 void buildExportHashTableFromSymbolTable(const macho_dysymtab_command
<P
>* dynamicInfo
,
209 const macho_nlist
<P
>* symbolTable
, const char* strings
,
210 const uint8_t* fileContent
);
211 static uint32_t parseVersionNumber32(const char* versionString
);
212 static const char* objCInfoSegmentName();
213 static const char* objCInfoSectionName();
215 const ld::MacVersionMin _macVersionMin
;
216 const ld::IOSVersionMin _iOSVersionMin
;
217 const bool _allowSimToMacOSXLinking
;
218 const bool _addVersionLoadCommand
;
220 bool _implicitlyLinkPublicDylibs
;
221 ld::File::ObjcConstraint _objcContraint
;
222 uint8_t _swiftVersion
;
223 ld::Section _importProxySection
;
224 ld::Section _flatDummySection
;
225 std::vector
<Dependent
> _dependentDylibs
;
226 std::vector
<const char*> _allowableClients
;
227 mutable NameToAtomMap _atoms
;
228 NameSet _ignoreExports
;
229 const char* _parentUmbrella
;
230 ImportAtom
<A
>* _importAtom
;
231 const void* _codeSignatureDR
;
233 bool _hasWeakExports
;
234 bool _deadStrippable
;
235 bool _hasPublicInstallName
;
236 mutable bool _providedAtom
;
237 bool _explictReExportFound
;
239 bool _installPathOverride
;
240 bool _indirectDylibsProcessed
;
241 bool _appExtensionSafe
;
242 ld::MacVersionMin _macMinVersionInDylib
;
243 ld::IOSVersionMin _iOSMinVersionInDylib
;
245 static bool _s_logHashtable
;
248 template <typename A
>
249 bool File
<A
>::_s_logHashtable
= false;
251 template <> const char* File
<x86_64
>::objCInfoSegmentName() { return "__DATA"; }
252 template <> const char* File
<arm
>::objCInfoSegmentName() { return "__DATA"; }
253 template <typename A
> const char* File
<A
>::objCInfoSegmentName() { return "__OBJC"; }
255 template <> const char* File
<x86_64
>::objCInfoSectionName() { return "__objc_imageinfo"; }
256 template <> const char* File
<arm
>::objCInfoSectionName() { return "__objc_imageinfo"; }
257 template <typename A
> const char* File
<A
>::objCInfoSectionName() { return "__image_info"; }
259 template <typename A
>
260 File
<A
>::File(const uint8_t* fileContent
, uint64_t fileLength
, const char* pth
, time_t mTime
, ld::File::Ordinal ord
,
261 bool linkingFlatNamespace
, bool linkingMainExecutable
, bool hoistImplicitPublicDylibs
,
262 ld::MacVersionMin macMin
, ld::IOSVersionMin iOSMin
, bool allowSimToMacOSX
, bool addVers
,
263 bool logAllFiles
, const char* targetInstallPath
, bool indirectDylib
)
264 : ld::dylib::File(strdup(pth
), mTime
, ord
),
265 _macVersionMin(macMin
), _iOSVersionMin(iOSMin
), _allowSimToMacOSXLinking(allowSimToMacOSX
), _addVersionLoadCommand(addVers
),
266 _linkingFlat(linkingFlatNamespace
), _implicitlyLinkPublicDylibs(hoistImplicitPublicDylibs
),
267 _objcContraint(ld::File::objcConstraintNone
), _swiftVersion(0),
268 _importProxySection("__TEXT", "__import", ld::Section::typeImportProxies
, true),
269 _flatDummySection("__LINKEDIT", "__flat_dummy", ld::Section::typeLinkEdit
, true),
270 _parentUmbrella(NULL
), _importAtom(NULL
), _codeSignatureDR(NULL
),
271 _noRexports(false), _hasWeakExports(false),
272 _deadStrippable(false), _hasPublicInstallName(false),
273 _providedAtom(false), _explictReExportFound(false), _wrongOS(false), _installPathOverride(false),
274 _indirectDylibsProcessed(false), _appExtensionSafe(false),
275 _macMinVersionInDylib(ld::macVersionUnset
), _iOSMinVersionInDylib(ld::iOSVersionUnset
)
277 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
278 const uint32_t cmd_count
= header
->ncmds();
279 const macho_load_command
<P
>* const cmds
= (macho_load_command
<P
>*)((char*)header
+ sizeof(macho_header
<P
>));
280 const macho_load_command
<P
>* const cmdsEnd
= (macho_load_command
<P
>*)((char*)header
+ sizeof(macho_header
<P
>) + header
->sizeofcmds());
282 // write out path for -t option
286 // a "blank" stub has zero load commands
287 if ( (header
->filetype() == MH_DYLIB_STUB
) && (cmd_count
== 0) ) {
288 // no further processing needed
289 munmap((caddr_t
)fileContent
, fileLength
);
294 // optimize the case where we know there is no reason to look at indirect dylibs
295 _noRexports
= (header
->flags() & MH_NO_REEXPORTED_DYLIBS
)
296 || (header
->filetype() == MH_BUNDLE
)
297 || (header
->filetype() == MH_EXECUTE
); // bundles and exectuables can be used via -bundle_loader
298 _hasWeakExports
= (header
->flags() & MH_WEAK_DEFINES
);
299 _deadStrippable
= (header
->flags() & MH_DEAD_STRIPPABLE_DYLIB
);
300 _appExtensionSafe
= (header
->flags() & MH_APP_EXTENSION_SAFE
);
302 // pass 1: get pointers, and see if this dylib uses compressed LINKEDIT format
303 const macho_dysymtab_command
<P
>* dynamicInfo
= NULL
;
304 const macho_dyld_info_command
<P
>* dyldInfo
= NULL
;
305 const macho_linkedit_data_command
<P
>* codeSignature
= NULL
;
306 const macho_nlist
<P
>* symbolTable
= NULL
;
307 const char* strings
= NULL
;
308 bool compressedLinkEdit
= false;
309 uint32_t dependentLibCount
= 0;
310 const macho_load_command
<P
>* cmd
= cmds
;
311 for (uint32_t i
= 0; i
< cmd_count
; ++i
) {
312 macho_dylib_command
<P
>* dylibID
;
313 const macho_symtab_command
<P
>* symtab
;
314 switch (cmd
->cmd()) {
316 symtab
= (macho_symtab_command
<P
>*)cmd
;
317 symbolTable
= (const macho_nlist
<P
>*)((char*)header
+ symtab
->symoff());
318 strings
= (char*)header
+ symtab
->stroff();
319 if ( (symtab
->stroff() + symtab
->strsize()) > fileLength
)
320 throwf("mach-o string pool extends beyond end of file in %s", pth
);
323 dynamicInfo
= (macho_dysymtab_command
<P
>*)cmd
;
326 case LC_DYLD_INFO_ONLY
:
327 dyldInfo
= (macho_dyld_info_command
<P
>*)cmd
;
328 compressedLinkEdit
= true;
331 dylibID
= (macho_dylib_command
<P
>*)cmd
;
332 _dylibInstallPath
= strdup(dylibID
->name());
333 _dylibTimeStamp
= dylibID
->timestamp();
334 _dylibCurrentVersion
= dylibID
->current_version();
335 _dylibCompatibilityVersion
= dylibID
->compatibility_version();
336 _hasPublicInstallName
= isPublicLocation(_dylibInstallPath
);
339 case LC_LOAD_WEAK_DYLIB
:
342 case LC_REEXPORT_DYLIB
:
343 _explictReExportFound
= true;
346 case LC_SUB_FRAMEWORK
:
347 _parentUmbrella
= strdup(((macho_sub_framework_command
<P
>*)cmd
)->umbrella());
350 _allowableClients
.push_back(strdup(((macho_sub_client_command
<P
>*)cmd
)->client()));
352 case LC_VERSION_MIN_MACOSX
:
353 if ( (_iOSVersionMin
!= ld::iOSVersionUnset
) && !_allowSimToMacOSXLinking
) {
355 if ( _addVersionLoadCommand
&& !indirectDylib
)
356 throw "building for iOS Simulator, but linking against dylib built for MacOSX";
358 _macMinVersionInDylib
= (ld::MacVersionMin
)((macho_version_min_command
<P
>*)cmd
)->version();
360 case LC_VERSION_MIN_IPHONEOS
:
361 if ( _macVersionMin
!= ld::macVersionUnset
) {
363 if ( _addVersionLoadCommand
&& !indirectDylib
)
364 throw "building for MacOSX, but linking against dylib built for iOS Simulator";
366 _iOSMinVersionInDylib
= (ld::IOSVersionMin
)((macho_version_min_command
<P
>*)cmd
)->version();
368 case LC_CODE_SIGNATURE
:
369 codeSignature
= (macho_linkedit_data_command
<P
>* )cmd
;
371 case macho_segment_command
<P
>::CMD
:
372 // check for Objective-C info
373 if ( strcmp(((macho_segment_command
<P
>*)cmd
)->segname(), objCInfoSegmentName()) == 0 ) {
374 const macho_segment_command
<P
>* segment
= (macho_segment_command
<P
>*)cmd
;
375 const macho_section
<P
>* const sectionsStart
= (macho_section
<P
>*)((char*)segment
+ sizeof(macho_segment_command
<P
>));
376 const macho_section
<P
>* const sectionsEnd
= §ionsStart
[segment
->nsects()];
377 for (const macho_section
<P
>* sect
=sectionsStart
; sect
< sectionsEnd
; ++sect
) {
378 if ( strncmp(sect
->sectname(), objCInfoSectionName(), strlen(objCInfoSectionName())) == 0 ) {
379 // struct objc_image_info {
380 // uint32_t version; // initially 0
383 // #define OBJC_IMAGE_SUPPORTS_GC 2
384 // #define OBJC_IMAGE_GC_ONLY 4
385 // #define OBJC_IMAGE_IS_SIMULATED 32
387 const uint32_t* contents
= (uint32_t*)(&fileContent
[sect
->offset()]);
388 if ( (sect
->size() >= 8) && (contents
[0] == 0) ) {
389 uint32_t flags
= E::get32(contents
[1]);
390 if ( (flags
& 4) == 4 )
391 _objcContraint
= ld::File::objcConstraintGC
;
392 else if ( (flags
& 2) == 2 )
393 _objcContraint
= ld::File::objcConstraintRetainReleaseOrGC
;
394 else if ( (flags
& 32) == 32 )
395 _objcContraint
= ld::File::objcConstraintRetainReleaseForSimulator
;
397 _objcContraint
= ld::File::objcConstraintRetainRelease
;
398 _swiftVersion
= ((flags
>> 8) & 0xFF);
400 else if ( sect
->size() > 0 ) {
401 warning("can't parse %s/%s section in %s", objCInfoSegmentName(), objCInfoSectionName(), this->path());
407 cmd
= (const macho_load_command
<P
>*)(((char*)cmd
)+cmd
->cmdsize());
409 throwf("malformed dylb, load command #%d is outside size of load commands in %s", i
, pth
);
412 // figure out if we need to examine dependent dylibs
413 // with compressed LINKEDIT format, MH_NO_REEXPORTED_DYLIBS can be trusted
414 bool processDependentLibraries
= true;
415 if ( compressedLinkEdit
&& _noRexports
&& !linkingFlatNamespace
)
416 processDependentLibraries
= false;
418 if ( processDependentLibraries
) {
419 // pass 2 builds list of all dependent libraries
420 _dependentDylibs
.reserve(dependentLibCount
);
422 unsigned int reExportDylibCount
= 0;
423 for (uint32_t i
= 0; i
< cmd_count
; ++i
) {
424 switch (cmd
->cmd()) {
426 case LC_LOAD_WEAK_DYLIB
:
427 // with new linkedit format only care about LC_REEXPORT_DYLIB
428 if ( compressedLinkEdit
&& !linkingFlatNamespace
)
430 case LC_REEXPORT_DYLIB
:
431 ++reExportDylibCount
;
433 entry
.path
= strdup(((macho_dylib_command
<P
>*)cmd
)->name());
435 entry
.reExport
= (cmd
->cmd() == LC_REEXPORT_DYLIB
);
436 if ( (targetInstallPath
== NULL
) || (strcmp(targetInstallPath
, entry
.path
) != 0) )
437 _dependentDylibs
.push_back(entry
);
440 cmd
= (const macho_load_command
<P
>*)(((char*)cmd
)+cmd
->cmdsize());
442 // verify MH_NO_REEXPORTED_DYLIBS bit was correct
443 if ( compressedLinkEdit
&& !linkingFlatNamespace
) {
444 assert(reExportDylibCount
!= 0);
446 // pass 3 add re-export info
448 for (uint32_t i
= 0; i
< cmd_count
; ++i
) {
449 const char* frameworkLeafName
;
450 const char* dylibBaseName
;
451 switch (cmd
->cmd()) {
452 case LC_SUB_UMBRELLA
:
453 frameworkLeafName
= ((macho_sub_umbrella_command
<P
>*)cmd
)->sub_umbrella();
454 for (typename
std::vector
<Dependent
>::iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); ++it
) {
455 const char* dylibName
= it
->path
;
456 const char* lastSlash
= strrchr(dylibName
, '/');
457 if ( (lastSlash
!= NULL
) && (strcmp(&lastSlash
[1], frameworkLeafName
) == 0) )
462 dylibBaseName
= ((macho_sub_library_command
<P
>*)cmd
)->sub_library();
463 for (typename
std::vector
<Dependent
>::iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); ++it
) {
464 const char* dylibName
= it
->path
;
465 const char* lastSlash
= strrchr(dylibName
, '/');
466 const char* leafStart
= &lastSlash
[1];
467 if ( lastSlash
== NULL
)
468 leafStart
= dylibName
;
469 const char* firstDot
= strchr(leafStart
, '.');
470 int len
= strlen(leafStart
);
471 if ( firstDot
!= NULL
)
472 len
= firstDot
- leafStart
;
473 if ( strncmp(leafStart
, dylibBaseName
, len
) == 0 )
478 cmd
= (const macho_load_command
<P
>*)(((char*)cmd
)+cmd
->cmdsize());
482 // validate minimal load commands
483 if ( (_dylibInstallPath
== NULL
) && ((header
->filetype() == MH_DYLIB
) || (header
->filetype() == MH_DYLIB_STUB
)) )
484 throwf("dylib %s missing LC_ID_DYLIB load command", pth
);
485 if ( dyldInfo
== NULL
) {
486 if ( symbolTable
== NULL
)
487 throw "binary missing LC_SYMTAB load command";
488 if ( dynamicInfo
== NULL
)
489 throw "binary missing LC_DYSYMTAB load command";
492 // if linking flat and this is a flat dylib, create one atom that references all imported symbols
493 if ( linkingFlatNamespace
&& linkingMainExecutable
&& ((header
->flags() & MH_TWOLEVEL
) == 0) ) {
494 std::vector
<const char*> importNames
;
495 importNames
.reserve(dynamicInfo
->nundefsym());
496 const macho_nlist
<P
>* start
= &symbolTable
[dynamicInfo
->iundefsym()];
497 const macho_nlist
<P
>* end
= &start
[dynamicInfo
->nundefsym()];
498 for (const macho_nlist
<P
>* sym
=start
; sym
< end
; ++sym
) {
499 importNames
.push_back(&strings
[sym
->n_strx()]);
501 _importAtom
= new ImportAtom
<A
>(*this, importNames
);
504 // if the dylib is code signed, look for its Designated Requirement
505 if ( codeSignature
!= NULL
) {
506 const Security::BlobCore
* overallSignature
= (Security::BlobCore
*)((char*)header
+ codeSignature
->dataoff());
507 typedef Security::SuperBlob
<Security::kSecCodeMagicEmbeddedSignature
> EmbeddedSignatureBlob
;
508 typedef Security::SuperBlob
<Security::kSecCodeMagicRequirementSet
> InternalRequirementsBlob
;
509 const EmbeddedSignatureBlob
* signature
= EmbeddedSignatureBlob::specific(overallSignature
);
510 if ( signature
->validateBlob(codeSignature
->datasize()) ) {
511 const InternalRequirementsBlob
* ireq
= signature
->find
<InternalRequirementsBlob
>(Security::cdRequirementsSlot
);
512 if ( (ireq
!= NULL
) && ireq
->validateBlob() ) {
513 const Security::BlobCore
* dr
= ireq
->find(Security::kSecDesignatedRequirementType
);
514 if ( (dr
!= NULL
) && dr
->validateBlob(Security::kSecCodeMagicRequirement
) ) {
515 // <rdar://problem/10968461> make copy because mapped file is about to be unmapped
516 _codeSignatureDR
= ::malloc(dr
->length());
517 ::memcpy((void*)_codeSignatureDR
, dr
, dr
->length());
524 if ( dyldInfo
!= NULL
)
525 buildExportHashTableFromExportInfo(dyldInfo
, fileContent
);
527 buildExportHashTableFromSymbolTable(dynamicInfo
, symbolTable
, strings
, fileContent
);
530 munmap((caddr_t
)fileContent
, fileLength
);
534 // Parses number of form X[.Y[.Z]] into a uint32_t where the nibbles are xxxx.yy.zz
536 template <typename A
>
537 uint32_t File
<A
>::parseVersionNumber32(const char* versionString
)
543 x
= strtoul(versionString
, &end
, 10);
545 y
= strtoul(&end
[1], &end
, 10);
547 z
= strtoul(&end
[1], &end
, 10);
550 if ( (*end
!= '\0') || (x
> 0xffff) || (y
> 0xff) || (z
> 0xff) )
551 throwf("malformed 32-bit x.y.z version number: %s", versionString
);
553 return (x
<< 16) | ( y
<< 8 ) | z
;
556 template <typename A
>
557 void File
<A
>::buildExportHashTableFromSymbolTable(const macho_dysymtab_command
<P
>* dynamicInfo
,
558 const macho_nlist
<P
>* symbolTable
, const char* strings
,
559 const uint8_t* fileContent
)
561 if ( dynamicInfo
->tocoff() == 0 ) {
562 if ( _s_logHashtable
) fprintf(stderr
, "ld: building hashtable of %u toc entries for %s\n", dynamicInfo
->nextdefsym(), this->path());
563 const macho_nlist
<P
>* start
= &symbolTable
[dynamicInfo
->iextdefsym()];
564 const macho_nlist
<P
>* end
= &start
[dynamicInfo
->nextdefsym()];
565 _atoms
.reserve(dynamicInfo
->nextdefsym()); // set initial bucket count
566 for (const macho_nlist
<P
>* sym
=start
; sym
< end
; ++sym
) {
567 this->addSymbol(&strings
[sym
->n_strx()], (sym
->n_desc() & N_WEAK_DEF
) != 0, false, sym
->n_value());
571 int32_t count
= dynamicInfo
->ntoc();
572 _atoms
.reserve(count
); // set initial bucket count
573 if ( _s_logHashtable
) fprintf(stderr
, "ld: building hashtable of %u entries for %s\n", count
, this->path());
574 const struct dylib_table_of_contents
* toc
= (dylib_table_of_contents
*)(fileContent
+ dynamicInfo
->tocoff());
575 for (int32_t i
= 0; i
< count
; ++i
) {
576 const uint32_t index
= E::get32(toc
[i
].symbol_index
);
577 const macho_nlist
<P
>* sym
= &symbolTable
[index
];
578 this->addSymbol(&strings
[sym
->n_strx()], (sym
->n_desc() & N_WEAK_DEF
) != 0, false, sym
->n_value());
582 // special case old libSystem
583 if ( (_dylibInstallPath
!= NULL
) && (strcmp(_dylibInstallPath
, "/usr/lib/libSystem.B.dylib") == 0) )
588 template <typename A
>
589 void File
<A
>::buildExportHashTableFromExportInfo(const macho_dyld_info_command
<P
>* dyldInfo
,
590 const uint8_t* fileContent
)
592 if ( _s_logHashtable
) fprintf(stderr
, "ld: building hashtable from export info in %s\n", this->path());
593 if ( dyldInfo
->export_size() > 0 ) {
594 const uint8_t* start
= fileContent
+ dyldInfo
->export_off();
595 const uint8_t* end
= &start
[dyldInfo
->export_size()];
596 std::vector
<mach_o::trie::Entry
> list
;
597 parseTrie(start
, end
, list
);
598 for (std::vector
<mach_o::trie::Entry
>::iterator it
=list
.begin(); it
!= list
.end(); ++it
)
599 this->addSymbol(it
->name
,
600 it
->flags
& EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION
,
601 (it
->flags
& EXPORT_SYMBOL_FLAGS_KIND_MASK
) == EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL
,
608 void File
<x86_64
>::addDyldFastStub()
610 addSymbol("dyld_stub_binder", false, false, 0);
614 void File
<x86
>::addDyldFastStub()
616 addSymbol("dyld_stub_binder", false, false, 0);
619 template <typename A
>
620 void File
<A
>::addDyldFastStub()
625 template <typename A
>
626 void File
<A
>::addSymbol(const char* name
, bool weakDef
, bool tlv
, pint_t address
)
628 //fprintf(stderr, "addSymbol() %s\n", name);
629 // symbols that start with $ld$ are meta-data to the static linker
630 // <rdar://problem/5182537> need way for ld and dyld to see different exported symbols in a dylib
631 if ( strncmp(name
, "$ld$", 4) == 0 ) {
632 // $ld$ <action> $ <condition> $ <symbol-name>
633 const char* symAction
= &name
[4];
634 const char* symCond
= strchr(symAction
, '$');
635 if ( symCond
!= NULL
) {
637 if ( _macVersionMin
!= ld::macVersionUnset
) {
638 sprintf(curOSVers
, "$os%d.%d$", (_macVersionMin
>> 16), ((_macVersionMin
>> 8) & 0xFF));
640 else if ( _iOSVersionMin
!= ld::iOSVersionUnset
) {
641 sprintf(curOSVers
, "$os%d.%d$", (_iOSVersionMin
>> 16), ((_iOSVersionMin
>> 8) & 0xFF));
644 assert(0 && "targeting neither macosx nor iphoneos");
646 if ( strncmp(symCond
, curOSVers
, strlen(curOSVers
)) == 0 ) {
647 const char* symName
= strchr(&symCond
[1], '$');
648 if ( symName
!= NULL
) {
650 if ( strncmp(symAction
, "hide$", 5) == 0 ) {
651 if ( _s_logHashtable
) fprintf(stderr
, " adding %s to ignore set for %s\n", symName
, this->path());
652 _ignoreExports
.insert(strdup(symName
));
655 else if ( strncmp(symAction
, "add$", 4) == 0 ) {
656 this->addSymbol(symName
, weakDef
, false, 0);
659 else if ( strncmp(symAction
, "install_name$", 13) == 0 ) {
660 _dylibInstallPath
= symName
;
661 _installPathOverride
= true;
662 // <rdar://problem/14448206> CoreGraphics redirects to ApplicationServices, but with wrong compat version
663 if ( strcmp(_dylibInstallPath
, "/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices") == 0 )
664 _dylibCompatibilityVersion
= parseVersionNumber32("1.0");
667 else if ( strncmp(symAction
, "compatibility_version$", 22) == 0 ) {
668 _dylibCompatibilityVersion
= parseVersionNumber32(symName
);
672 warning("bad symbol action: %s in dylib %s", name
, this->path());
678 warning("bad symbol condition: %s in dylib %s", name
, this->path());
682 // add symbol as possible export if we are not supposed to ignore it
683 if ( _ignoreExports
.count(name
) == 0 ) {
686 bucket
.weakDef
= weakDef
;
688 bucket
.address
= address
;
689 if ( _s_logHashtable
) fprintf(stderr
, " adding %s to hash table for %s\n", name
, this->path());
690 _atoms
[strdup(name
)] = bucket
;
695 template <typename A
>
696 bool File
<A
>::forEachAtom(ld::File::AtomHandler
& handler
) const
698 handler
.doFile(*this);
699 // if doing flatnamespace and need all this dylib's imports resolve
700 // add atom which references alls undefines in this dylib
701 if ( _importAtom
!= NULL
) {
702 handler
.doAtom(*_importAtom
);
708 template <typename A
>
709 bool File
<A
>::hasWeakDefinition(const char* name
) const
711 // if supposed to ignore this export, then pretend I don't have it
712 if ( _ignoreExports
.count(name
) != 0 )
715 typename
NameToAtomMap::const_iterator pos
= _atoms
.find(name
);
716 if ( pos
!= _atoms
.end() ) {
717 return pos
->second
.weakDef
;
720 // look in children that I re-export
721 for (typename
std::vector
<Dependent
>::const_iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); ++it
) {
722 if ( it
->reExport
) {
723 //fprintf(stderr, "getJustInTimeAtomsFor: %s NOT found in %s, looking in child %s\n", name, this->path(), (*it)->getInstallPath());
724 typename
NameToAtomMap::iterator cpos
= it
->dylib
->_atoms
.find(name
);
725 if ( cpos
!= it
->dylib
->_atoms
.end() )
726 return cpos
->second
.weakDef
;
734 // <rdar://problem/5529626> If only weak_import symbols are used, linker should use LD_LOAD_WEAK_DYLIB
735 template <typename A
>
736 bool File
<A
>::allSymbolsAreWeakImported() const
738 bool foundNonWeakImport
= false;
739 bool foundWeakImport
= false;
740 //fprintf(stderr, "%s:\n", this->path());
741 for (typename
NameToAtomMap::const_iterator it
= _atoms
.begin(); it
!= _atoms
.end(); ++it
) {
742 const ld::Atom
* atom
= it
->second
.atom
;
743 if ( atom
!= NULL
) {
744 if ( atom
->weakImported() )
745 foundWeakImport
= true;
747 foundNonWeakImport
= true;
748 //fprintf(stderr, " weak_import=%d, name=%s\n", atom->weakImported(), it->first);
752 // don't automatically weak link dylib with no imports
753 // so at least one weak import symbol and no non-weak-imported symbols must be found
754 return foundWeakImport
&& !foundNonWeakImport
;
758 template <typename A
>
759 bool File
<A
>::containsOrReExports(const char* name
, bool* weakDef
, bool* tlv
, pint_t
* defAddress
) const
761 if ( _ignoreExports
.count(name
) != 0 )
765 typename
NameToAtomMap::iterator pos
= _atoms
.find(name
);
766 if ( pos
!= _atoms
.end() ) {
767 *weakDef
= pos
->second
.weakDef
;
768 *tlv
= pos
->second
.tlv
;
769 *defAddress
= pos
->second
.address
;
773 // check dylibs I re-export
774 for (typename
std::vector
<Dependent
>::const_iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); ++it
) {
775 if ( it
->reExport
&& !it
->dylib
->implicitlyLinked() ) {
776 if ( it
->dylib
->containsOrReExports(name
, weakDef
, tlv
, defAddress
) )
785 template <typename A
>
786 bool File
<A
>::justInTimeforEachAtom(const char* name
, ld::File::AtomHandler
& handler
) const
788 // if supposed to ignore this export, then pretend I don't have it
789 if ( _ignoreExports
.count(name
) != 0 )
794 if ( this->containsOrReExports(name
, &bucket
.weakDef
, &bucket
.tlv
, &bucket
.address
) ) {
795 bucket
.atom
= new ExportAtom
<A
>(*this, name
, bucket
.weakDef
, bucket
.tlv
, bucket
.address
);
796 _atoms
[name
] = bucket
;
797 _providedAtom
= true;
798 if ( _s_logHashtable
) fprintf(stderr
, "getJustInTimeAtomsFor: %s found in %s\n", name
, this->path());
799 // call handler with new export atom
800 handler
.doAtom(*bucket
.atom
);
809 template <typename A
>
810 bool File
<A
>::isPublicLocation(const char* pth
)
812 // -no_implicit_dylibs disables this optimization
813 if ( ! _implicitlyLinkPublicDylibs
)
816 // /usr/lib is a public location
817 if ( (strncmp(pth
, "/usr/lib/", 9) == 0) && (strchr(&pth
[9], '/') == NULL
) )
820 // /System/Library/Frameworks/ is a public location
821 if ( strncmp(pth
, "/System/Library/Frameworks/", 27) == 0 ) {
822 const char* frameworkDot
= strchr(&pth
[27], '.');
823 // but only top level framework
824 // /System/Library/Frameworks/Foo.framework/Versions/A/Foo ==> true
825 // /System/Library/Frameworks/Foo.framework/Resources/libBar.dylib ==> false
826 // /System/Library/Frameworks/Foo.framework/Frameworks/Bar.framework/Bar ==> false
827 // /System/Library/Frameworks/Foo.framework/Frameworks/Xfoo.framework/XFoo ==> false
828 if ( frameworkDot
!= NULL
) {
829 int frameworkNameLen
= frameworkDot
- &pth
[27];
830 if ( strncmp(&pth
[strlen(pth
)-frameworkNameLen
-1], &pth
[26], frameworkNameLen
+1) == 0 )
838 template <typename A
>
839 void File
<A
>::processIndirectLibraries(ld::dylib::File::DylibHandler
* handler
, bool addImplicitDylibs
)
842 if ( _indirectDylibsProcessed
)
844 const static bool log
= false;
845 if ( log
) fprintf(stderr
, "processIndirectLibraries(%s)\n", this->installPath());
846 if ( _linkingFlat
) {
847 for (typename
std::vector
<Dependent
>::iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); it
++) {
848 it
->dylib
= (File
<A
>*)handler
->findDylib(it
->path
, this->path());
851 else if ( _noRexports
) {
852 // MH_NO_REEXPORTED_DYLIBS bit set, then nothing to do
855 // two-level, might have re-exports
856 for (typename
std::vector
<Dependent
>::iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); it
++) {
857 if ( it
->reExport
) {
858 if ( log
) fprintf(stderr
, "processIndirectLibraries() parent=%s, child=%s\n", this->installPath(), it
->path
);
859 // a LC_REEXPORT_DYLIB, LC_SUB_UMBRELLA or LC_SUB_LIBRARY says we re-export this child
860 it
->dylib
= (File
<A
>*)handler
->findDylib(it
->path
, this->path());
861 if ( it
->dylib
->hasPublicInstallName() && !it
->dylib
->wrongOS() ) {
862 // promote this child to be automatically added as a direct dependent if this already is
863 if ( (this->explicitlyLinked() || this->implicitlyLinked()) && (strcmp(it
->path
,it
->dylib
->installPath()) == 0) ) {
864 if ( log
) fprintf(stderr
, "processIndirectLibraries() implicitly linking %s\n", it
->dylib
->installPath());
865 it
->dylib
->setImplicitlyLinked();
867 else if ( it
->dylib
->explicitlyLinked() || it
->dylib
->implicitlyLinked() ) {
868 if ( log
) fprintf(stderr
, "processIndirectLibraries() parent is not directly linked, but child is, so no need to re-export child\n");
871 if ( log
) fprintf(stderr
, "processIndirectLibraries() parent is not directly linked, so parent=%s will re-export child=%s\n", this->installPath(), it
->path
);
875 // add all child's symbols to me
876 if ( log
) fprintf(stderr
, "processIndirectLibraries() child is not public, so parent=%s will re-export child=%s\n", this->installPath(), it
->path
);
879 else if ( !_explictReExportFound
) {
880 // see if child contains LC_SUB_FRAMEWORK with my name
881 it
->dylib
= (File
<A
>*)handler
->findDylib(it
->path
, this->path());
882 const char* parentUmbrellaName
= it
->dylib
->parentUmbrella();
883 if ( parentUmbrellaName
!= NULL
) {
884 const char* parentName
= this->path();
885 const char* lastSlash
= strrchr(parentName
, '/');
886 if ( (lastSlash
!= NULL
) && (strcmp(&lastSlash
[1], parentUmbrellaName
) == 0) ) {
887 // add all child's symbols to me
889 if ( log
) fprintf(stderr
, "processIndirectLibraries() umbrella=%s will re-export child=%s\n", this->installPath(), it
->path
);
896 // check for re-export cycles
900 this->assertNoReExportCycles(&chain
);
902 _indirectDylibsProcessed
= true;
905 template <typename A
>
906 void File
<A
>::assertNoReExportCycles(ReExportChain
* prev
)
908 // recursively check my re-exported dylibs
912 for (typename
std::vector
<Dependent
>::iterator it
= _dependentDylibs
.begin(); it
!= _dependentDylibs
.end(); it
++) {
913 if ( it
->reExport
) {
914 ld::File
* child
= it
->dylib
;
915 // check child is not already in chain
916 for (ReExportChain
* p
= prev
; p
!= NULL
; p
= p
->prev
) {
917 if ( p
->file
== child
) {
918 throwf("cycle in dylib re-exports with %s and %s", child
->path(), this->path());
921 if ( it
->dylib
!= NULL
)
922 it
->dylib
->assertNoReExportCycles(&chain
);
928 template <typename A
>
932 typedef typename
A::P P
;
934 static bool validFile(const uint8_t* fileContent
, bool executableOrDyliborBundle
);
935 static const char* fileKind(const uint8_t* fileContent
);
936 static ld::dylib::File
* parse(const uint8_t* fileContent
, uint64_t fileLength
,
937 const char* path
, time_t mTime
,
938 ld::File::Ordinal ordinal
, const Options
& opts
, bool indirectDylib
) {
939 return new File
<A
>(fileContent
, fileLength
, path
, mTime
,
940 ordinal
, opts
.flatNamespace(),
941 opts
.linkingMainExecutable(),
942 opts
.implicitlyLinkIndirectPublicDylibs(),
943 opts
.macosxVersionMin(),
944 opts
.iOSVersionMin(),
945 opts
.allowSimulatorToLinkWithMacOSX(),
946 opts
.addVersionLoadCommand(),
957 bool Parser
<x86
>::validFile(const uint8_t* fileContent
, bool executableOrDyliborBundle
)
959 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
960 if ( header
->magic() != MH_MAGIC
)
962 if ( header
->cputype() != CPU_TYPE_I386
)
964 switch ( header
->filetype() ) {
969 if ( executableOrDyliborBundle
)
972 throw "can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB)";
974 if ( executableOrDyliborBundle
)
977 throw "can't link with a main executable";
984 bool Parser
<x86_64
>::validFile(const uint8_t* fileContent
, bool executableOrDyliborBundle
)
986 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
987 if ( header
->magic() != MH_MAGIC_64
)
989 if ( header
->cputype() != CPU_TYPE_X86_64
)
991 switch ( header
->filetype() ) {
996 if ( executableOrDyliborBundle
)
999 throw "can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB)";
1001 if ( executableOrDyliborBundle
)
1004 throw "can't link with a main executable";
1011 bool Parser
<arm
>::validFile(const uint8_t* fileContent
, bool executableOrDyliborBundle
)
1013 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1014 if ( header
->magic() != MH_MAGIC
)
1016 if ( header
->cputype() != CPU_TYPE_ARM
)
1018 switch ( header
->filetype() ) {
1023 if ( executableOrDyliborBundle
)
1026 throw "can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB)";
1028 if ( executableOrDyliborBundle
)
1031 throw "can't link with a main executable";
1040 bool Parser
<arm64
>::validFile(const uint8_t* fileContent
, bool executableOrDyliborBundle
)
1042 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1043 if ( header
->magic() != MH_MAGIC_64
)
1045 if ( header
->cputype() != CPU_TYPE_ARM64
)
1047 switch ( header
->filetype() ) {
1052 if ( executableOrDyliborBundle
)
1055 throw "can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB)";
1057 if ( executableOrDyliborBundle
)
1060 throw "can't link with a main executable";
1067 bool isDylibFile(const uint8_t* fileContent
, cpu_type_t
* result
, cpu_subtype_t
* subResult
)
1069 if ( Parser
<x86_64
>::validFile(fileContent
, false) ) {
1070 *result
= CPU_TYPE_X86_64
;
1071 const macho_header
<Pointer64
<LittleEndian
> >* header
= (const macho_header
<Pointer64
<LittleEndian
> >*)fileContent
;
1072 *subResult
= header
->cpusubtype();
1075 if ( Parser
<x86
>::validFile(fileContent
, false) ) {
1076 *result
= CPU_TYPE_I386
;
1077 *subResult
= CPU_SUBTYPE_X86_ALL
;
1080 if ( Parser
<arm
>::validFile(fileContent
, false) ) {
1081 *result
= CPU_TYPE_ARM
;
1082 const macho_header
<Pointer32
<LittleEndian
> >* header
= (const macho_header
<Pointer32
<LittleEndian
> >*)fileContent
;
1083 *subResult
= header
->cpusubtype();
1086 if ( Parser
<arm64
>::validFile(fileContent
, false) ) {
1087 *result
= CPU_TYPE_ARM64
;
1088 *subResult
= CPU_SUBTYPE_ARM64_ALL
;
1095 const char* Parser
<x86
>::fileKind(const uint8_t* fileContent
)
1097 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1098 if ( header
->magic() != MH_MAGIC
)
1100 if ( header
->cputype() != CPU_TYPE_I386
)
1106 const char* Parser
<x86_64
>::fileKind(const uint8_t* fileContent
)
1108 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1109 if ( header
->magic() != MH_MAGIC_64
)
1111 if ( header
->cputype() != CPU_TYPE_X86_64
)
1117 const char* Parser
<arm
>::fileKind(const uint8_t* fileContent
)
1119 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1120 if ( header
->magic() != MH_MAGIC
)
1122 if ( header
->cputype() != CPU_TYPE_ARM
)
1124 for (const ArchInfo
* t
=archInfoArray
; t
->archName
!= NULL
; ++t
) {
1125 if ( (t
->cpuType
== CPU_TYPE_ARM
) && ((cpu_subtype_t
)header
->cpusubtype() == t
->cpuSubType
) ) {
1132 #if SUPPORT_ARCH_arm64
1134 const char* Parser
<arm64
>::fileKind(const uint8_t* fileContent
)
1136 const macho_header
<P
>* header
= (const macho_header
<P
>*)fileContent
;
1137 if ( header
->magic() != MH_MAGIC_64
)
1139 if ( header
->cputype() != CPU_TYPE_ARM64
)
1146 // used by linker is error messages to describe mismatched files
1148 const char* archName(const uint8_t* fileContent
)
1150 if ( Parser
<x86_64
>::validFile(fileContent
, true) ) {
1151 return Parser
<x86_64
>::fileKind(fileContent
);
1153 if ( Parser
<x86
>::validFile(fileContent
, true) ) {
1154 return Parser
<x86
>::fileKind(fileContent
);
1156 if ( Parser
<arm
>::validFile(fileContent
, true) ) {
1157 return Parser
<arm
>::fileKind(fileContent
);
1159 #if SUPPORT_ARCH_arm64
1160 if ( Parser
<arm64
>::validFile(fileContent
, false) ) {
1161 return Parser
<arm64
>::fileKind(fileContent
);
1169 // main function used by linker to instantiate ld::Files
1171 ld::dylib::File
* parse(const uint8_t* fileContent
, uint64_t fileLength
,
1172 const char* path
, time_t modTime
, const Options
& opts
, ld::File::Ordinal ordinal
,
1173 bool bundleLoader
, bool indirectDylib
)
1175 switch ( opts
.architecture() ) {
1176 #if SUPPORT_ARCH_x86_64
1177 case CPU_TYPE_X86_64
:
1178 if ( Parser
<x86_64
>::validFile(fileContent
, bundleLoader
) )
1179 return Parser
<x86_64
>::parse(fileContent
, fileLength
, path
, modTime
, ordinal
, opts
, indirectDylib
);
1182 #if SUPPORT_ARCH_i386
1184 if ( Parser
<x86
>::validFile(fileContent
, bundleLoader
) )
1185 return Parser
<x86
>::parse(fileContent
, fileLength
, path
, modTime
, ordinal
, opts
, indirectDylib
);
1188 #if SUPPORT_ARCH_arm_any
1190 if ( Parser
<arm
>::validFile(fileContent
, bundleLoader
) )
1191 return Parser
<arm
>::parse(fileContent
, fileLength
, path
, modTime
, ordinal
, opts
, indirectDylib
);
1194 #if SUPPORT_ARCH_arm64
1195 case CPU_TYPE_ARM64
:
1196 if ( Parser
<arm64
>::validFile(fileContent
, bundleLoader
) )
1197 return Parser
<arm64
>::parse(fileContent
, fileLength
, path
, modTime
, ordinal
, opts
, indirectDylib
);
1205 }; // namespace dylib
1206 }; // namespace mach_o