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@
27 #include <sys/types.h>
30 #include <sys/sysctl.h>
35 #include <mach/mach_time.h>
36 #include <mach/vm_statistics.h>
37 #include <mach/mach_init.h>
38 #include <mach/mach_host.h>
40 #include <mach-o/dyld.h>
41 #include <mach-o/fat.h>
42 #include <sys/sysctl.h>
43 #include <libkern/OSAtomic.h>
52 #include <ext/hash_map>
53 #include <ext/hash_set>
55 #include <AvailabilityMacros.h>
59 #include "InputFiles.h"
60 #include "macho_relocatable_file.h"
61 #include "macho_dylib_file.h"
62 #include "archive_file.h"
64 #include "opaque_section_file.h"
67 const bool _s_logPThreads
= false;
72 class IgnoredFile
: public ld::File
{
74 IgnoredFile(const char* pth
, time_t modTime
, Ordinal ord
, Type type
) : ld::File(pth
, modTime
, ord
, type
) {};
75 virtual bool forEachAtom(AtomHandler
&) const { return false; };
76 virtual bool justInTimeforEachAtom(const char* name
, AtomHandler
&) const { return false; };
80 class DSOHandleAtom
: public ld::Atom
{
82 DSOHandleAtom(const char* nm
, ld::Atom::Scope sc
,
83 ld::Atom::SymbolTableInclusion inc
, bool preload
=false)
84 : ld::Atom(preload
? _s_section_preload
: _s_section
,
85 ld::Atom::definitionRegular
, ld::Atom::combineNever
,
86 sc
, ld::Atom::typeUnclassified
, inc
, true, false, false,
87 ld::Atom::Alignment(1)), _name(nm
) {}
89 virtual ld::File
* file() const { return NULL
; }
90 virtual bool translationUnitSource(const char** dir
, const char** ) const
92 virtual const char* name() const { return _name
; }
93 virtual uint64_t size() const { return 0; }
94 virtual uint64_t objectAddress() const { return 0; }
95 virtual void copyRawContent(uint8_t buffer
[]) const
97 virtual void setScope(Scope
) { }
99 virtual ~DSOHandleAtom() {}
101 static ld::Section _s_section
;
102 static ld::Section _s_section_preload
;
103 static DSOHandleAtom _s_atomAll
;
104 static DSOHandleAtom _s_atomExecutable
;
105 static DSOHandleAtom _s_atomDylib
;
106 static DSOHandleAtom _s_atomBundle
;
107 static DSOHandleAtom _s_atomDyld
;
108 static DSOHandleAtom _s_atomObjectFile
;
109 static DSOHandleAtom _s_atomPreload
;
113 ld::Section
DSOHandleAtom::_s_section("__TEXT", "__mach_header", ld::Section::typeMachHeader
, true);
114 ld::Section
DSOHandleAtom::_s_section_preload("__HEADER", "__mach_header", ld::Section::typeMachHeader
, true);
115 DSOHandleAtom
DSOHandleAtom::_s_atomAll("___dso_handle", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
);
116 DSOHandleAtom
DSOHandleAtom::_s_atomExecutable("__mh_execute_header", ld::Atom::scopeGlobal
, ld::Atom::symbolTableInAndNeverStrip
);
117 DSOHandleAtom
DSOHandleAtom::_s_atomDylib("__mh_dylib_header", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
);
118 DSOHandleAtom
DSOHandleAtom::_s_atomBundle("__mh_bundle_header", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
);
119 DSOHandleAtom
DSOHandleAtom::_s_atomDyld("__mh_dylinker_header", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
);
120 DSOHandleAtom
DSOHandleAtom::_s_atomObjectFile("__mh_object_header", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
);
121 DSOHandleAtom
DSOHandleAtom::_s_atomPreload("__mh_preload_header", ld::Atom::scopeLinkageUnit
, ld::Atom::symbolTableNotIn
, true);
125 class PageZeroAtom
: public ld::Atom
{
127 PageZeroAtom(uint64_t sz
)
128 : ld::Atom(_s_section
, ld::Atom::definitionRegular
, ld::Atom::combineNever
,
129 ld::Atom::scopeTranslationUnit
, ld::Atom::typeZeroFill
,
130 symbolTableNotIn
, true, false, false, ld::Atom::Alignment(12)),
133 virtual ld::File
* file() const { return NULL
; }
134 virtual bool translationUnitSource(const char** dir
, const char** ) const
136 virtual const char* name() const { return "page zero"; }
137 virtual uint64_t size() const { return _size
; }
138 virtual uint64_t objectAddress() const { return 0; }
139 virtual void copyRawContent(uint8_t buffer
[]) const
141 virtual void setScope(Scope
) { }
143 virtual ~PageZeroAtom() {}
145 static ld::Section _s_section
;
146 static DSOHandleAtom _s_atomAll
;
150 ld::Section
PageZeroAtom::_s_section("__PAGEZERO", "__pagezero", ld::Section::typePageZero
, true);
153 class CustomStackAtom
: public ld::Atom
{
155 CustomStackAtom(uint64_t sz
)
156 : ld::Atom(_s_section
, ld::Atom::definitionRegular
, ld::Atom::combineNever
,
157 ld::Atom::scopeTranslationUnit
, ld::Atom::typeZeroFill
,
158 symbolTableNotIn
, false, false, false, ld::Atom::Alignment(12)),
161 virtual ld::File
* file() const { return NULL
; }
162 virtual bool translationUnitSource(const char** dir
, const char** ) const
164 virtual const char* name() const { return "custom stack"; }
165 virtual uint64_t size() const { return _size
; }
166 virtual uint64_t objectAddress() const { return 0; }
167 virtual void copyRawContent(uint8_t buffer
[]) const
169 virtual void setScope(Scope
) { }
171 virtual ~CustomStackAtom() {}
175 static ld::Section _s_section
;
177 ld::Section
CustomStackAtom::_s_section("__UNIXSTACK", "__stack", ld::Section::typeStack
, true);
181 const char* InputFiles::fileArch(const uint8_t* p
, unsigned len
)
183 const char* result
= mach_o::relocatable::archName(p
);
184 if ( result
!= NULL
)
187 result
= lto::archName(p
, len
);
188 if ( result
!= NULL
)
191 if ( strncmp((const char*)p
, "!<arch>\n", 8) == 0 )
194 char *unsupported
= (char *)malloc(128);
195 strcpy(unsupported
, "unsupported file format (");
196 for (unsigned i
=0; i
<len
&& i
< 16; i
++) {
198 sprintf(buf
, " 0x%2x", p
[i
]);
199 strcat(unsupported
, buf
);
201 strcat(unsupported
, " )");
206 ld::File
* InputFiles::makeFile(const Options::FileInfo
& info
, bool indirectDylib
)
209 uint64_t len
= info
.fileLen
;
210 int fd
= ::open(info
.path
, O_RDONLY
, 0);
212 throwf("can't open file, errno=%d", errno
);
213 if ( info
.fileLen
< 20 )
214 throw "file too small";
216 uint8_t* p
= (uint8_t*)::mmap(NULL
, info
.fileLen
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, fd
, 0);
217 if ( p
== (uint8_t*)(-1) )
218 throwf("can't map file, errno=%d", errno
);
220 // if fat file, skip to architecture we want
221 // Note: fat header is always big-endian
222 bool isFatFile
= false;
223 uint32_t sliceToUse
, sliceCount
;
224 const fat_header
* fh
= (fat_header
*)p
;
225 if ( fh
->magic
== OSSwapBigToHostInt32(FAT_MAGIC
) ) {
227 const struct fat_arch
* archs
= (struct fat_arch
*)(p
+ sizeof(struct fat_header
));
228 bool sliceFound
= false;
229 sliceCount
= OSSwapBigToHostInt32(fh
->nfat_arch
);
230 if ( _options
.preferSubArchitecture() ) {
231 // first try to find a slice that match cpu-type and cpu-sub-type
232 for (uint32_t i
=0; i
< sliceCount
; ++i
) {
233 if ( (OSSwapBigToHostInt32(archs
[i
].cputype
) == (uint32_t)_options
.architecture())
234 && (OSSwapBigToHostInt32(archs
[i
].cpusubtype
) == (uint32_t)_options
.subArchitecture()) ) {
242 // look for any slice that matches just cpu-type
243 for (uint32_t i
=0; i
< sliceCount
; ++i
) {
244 if ( OSSwapBigToHostInt32(archs
[i
].cputype
) == (uint32_t)_options
.architecture() ) {
252 uint32_t fileOffset
= OSSwapBigToHostInt32(archs
[sliceToUse
].offset
);
253 len
= OSSwapBigToHostInt32(archs
[sliceToUse
].size
);
254 if ( fileOffset
+len
> info
.fileLen
) {
255 throwf("truncated fat file. Slice from %u to %llu is past end of file with length %llu",
256 fileOffset
, fileOffset
+len
, info
.fileLen
);
258 // if requested architecture is page aligned within fat file, then remap just that portion of file
259 if ( (fileOffset
& 0x00000FFF) == 0 ) {
261 munmap((caddr_t
)p
, info
.fileLen
);
262 // re-map just part we need
263 p
= (uint8_t*)::mmap(NULL
, len
, PROT_READ
, MAP_FILE
| MAP_PRIVATE
, fd
, fileOffset
);
264 if ( p
== (uint8_t*)(-1) )
265 throwf("can't re-map file, errno=%d", errno
);
274 // see if it is an object file
275 mach_o::relocatable::ParserOptions objOpts
;
276 objOpts
.architecture
= _options
.architecture();
277 objOpts
.objSubtypeMustMatch
= !_options
.allowSubArchitectureMismatches();
278 objOpts
.logAllFiles
= _options
.logAllFiles();
279 objOpts
.convertUnwindInfo
= _options
.needsUnwindInfoSection();
280 objOpts
.subType
= _options
.subArchitecture();
281 ld::relocatable::File
* objResult
= mach_o::relocatable::parse(p
, len
, info
.path
, info
.modTime
, info
.ordinal
, objOpts
);
282 if ( objResult
!= NULL
) {
283 OSAtomicAdd64(len
, &_totalObjectSize
);
284 OSAtomicIncrement32(&_totalObjectLoaded
);
288 // see if it is an llvm object file
289 objResult
= lto::parse(p
, len
, info
.path
, info
.modTime
, _options
.architecture(), _options
.subArchitecture(), _options
.logAllFiles());
290 if ( objResult
!= NULL
) {
291 OSAtomicAdd64(len
, &_totalObjectSize
);
292 OSAtomicIncrement32(&_totalObjectLoaded
);
296 // see if it is a dynamic library
297 ld::dylib::File
* dylibResult
= mach_o::dylib::parse(p
, len
, info
.path
, info
.modTime
, _options
, info
.ordinal
, info
.options
.fBundleLoader
, indirectDylib
);
298 if ( dylibResult
!= NULL
) {
302 // see if it is a static library
303 ::archive::ParserOptions archOpts
;
304 archOpts
.objOpts
= objOpts
;
305 archOpts
.forceLoadThisArchive
= info
.options
.fForceLoad
;
306 archOpts
.forceLoadAll
= _options
.fullyLoadArchives();
307 archOpts
.forceLoadObjC
= _options
.loadAllObjcObjectsFromArchives();
308 archOpts
.objcABI2
= _options
.objCABIVersion2POverride();
309 archOpts
.verboseLoad
= _options
.whyLoad();
310 archOpts
.logAllFiles
= _options
.logAllFiles();
311 ld::archive::File
* archiveResult
= ::archive::parse(p
, len
, info
.path
, info
.modTime
, info
.ordinal
, archOpts
);
312 if ( archiveResult
!= NULL
) {
313 OSAtomicAdd64(len
, &_totalArchiveSize
);
314 OSAtomicIncrement32(&_totalArchivesLoaded
);
315 return archiveResult
;
318 // does not seem to be any valid linker input file, check LTO misconfiguration problems
319 if ( lto::archName((uint8_t*)p
, len
) != NULL
) {
320 if ( lto::libLTOisLoaded() ) {
321 throwf("lto file was built for %s which is not the architecture being linked (%s): %s", fileArch(p
, len
), _options
.architectureName(), info
.path
);
324 const char* libLTO
= "libLTO.dylib";
325 char ldPath
[PATH_MAX
];
326 char tmpPath
[PATH_MAX
];
327 char libLTOPath
[PATH_MAX
];
328 uint32_t bufSize
= PATH_MAX
;
329 if ( _options
.overridePathlibLTO() != NULL
) {
330 libLTO
= _options
.overridePathlibLTO();
332 else if ( _NSGetExecutablePath(ldPath
, &bufSize
) != -1 ) {
333 if ( realpath(ldPath
, tmpPath
) != NULL
) {
334 char* lastSlash
= strrchr(tmpPath
, '/');
335 if ( lastSlash
!= NULL
)
336 strcpy(lastSlash
, "/../lib/libLTO.dylib");
338 if ( realpath(tmpPath
, libLTOPath
) != NULL
)
342 throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO
);
347 if ( ((fat_header
*)p
)->magic
== OSSwapBigToHostInt32(FAT_MAGIC
) ) {
348 throwf("missing required architecture %s in file %s (%u slices)", _options
.architectureName(), info
.path
, sliceCount
);
352 throwf("file is universal (%u slices) but does not contain a(n) %s slice: %s", sliceCount
, _options
.architectureName(), info
.path
);
354 throwf("file was built for %s which is not the architecture being linked (%s): %s", fileArch(p
, len
), _options
.architectureName(), info
.path
);
358 void InputFiles::logDylib(ld::File
* file
, bool indirect
)
360 if ( _options
.traceDylibs() ) {
361 const char* fullPath
= file
->path();
362 char realName
[MAXPATHLEN
];
363 if ( realpath(fullPath
, realName
) != NULL
)
365 const ld::dylib::File
* dylib
= dynamic_cast<const ld::dylib::File
*>(file
);
366 if ( (dylib
!= NULL
) && dylib
->willBeUpwardDylib() ) {
367 // don't log upward dylibs when XBS is computing dependencies
368 logTraceInfo("[Logging for XBS] Used upward dynamic library: %s\n", fullPath
);
372 logTraceInfo("[Logging for XBS] Used indirect dynamic library: %s\n", fullPath
);
374 logTraceInfo("[Logging for XBS] Used dynamic library: %s\n", fullPath
);
379 void InputFiles::logArchive(ld::File
* file
) const
381 if ( _options
.traceArchives() && (_archiveFilesLogged
.count(file
) == 0) ) {
382 // <rdar://problem/4947347> LD_TRACE_ARCHIVES should only print out when a .o is actually used from an archive
383 _archiveFilesLogged
.insert(file
);
384 const char* fullPath
= file
->path();
385 char realName
[MAXPATHLEN
];
386 if ( realpath(fullPath
, realName
) != NULL
)
388 logTraceInfo("[Logging for XBS] Used static archive: %s\n", fullPath
);
393 void InputFiles::logTraceInfo(const char* format
, ...) const
395 // one time open() of custom LD_TRACE_FILE
396 static int trace_file
= -1;
397 if ( trace_file
== -1 ) {
398 const char *trace_file_path
= _options
.traceOutputFile();
399 if ( trace_file_path
!= NULL
) {
400 trace_file
= open(trace_file_path
, O_WRONLY
| O_APPEND
| O_CREAT
, 0666);
401 if ( trace_file
== -1 )
402 throwf("Could not open or create trace file: %s", trace_file_path
);
405 trace_file
= fileno(stderr
);
409 char trace_buffer
[MAXPATHLEN
* 2];
411 va_start(ap
, format
);
412 int length
= vsnprintf(trace_buffer
, sizeof(trace_buffer
), format
, ap
);
414 char* buffer_ptr
= trace_buffer
;
417 ssize_t amount_written
= write(trace_file
, buffer_ptr
, length
);
418 if(amount_written
== -1)
419 /* Failure to write shouldn't fail the build. */
421 buffer_ptr
+= amount_written
;
422 length
-= amount_written
;
426 ld::dylib::File
* InputFiles::findDylib(const char* installPath
, const char* fromPath
)
428 //fprintf(stderr, "findDylib(%s, %s)\n", installPath, fromPath);
429 InstallNameToDylib::iterator pos
= _installPathToDylibs
.find(installPath
);
430 if ( pos
!= _installPathToDylibs
.end() ) {
434 // allow -dylib_path option to override indirect library to use
435 for (std::vector
<Options::DylibOverride
>::const_iterator dit
= _options
.dylibOverrides().begin(); dit
!= _options
.dylibOverrides().end(); ++dit
) {
436 if ( strcmp(dit
->installName
,installPath
) == 0 ) {
438 Options::FileInfo info
= _options
.findFile(dit
->useInstead
);
439 _indirectDylibOrdinal
= _indirectDylibOrdinal
.nextIndirectDylibOrdinal();
440 info
.ordinal
= _indirectDylibOrdinal
;
441 ld::File
* reader
= this->makeFile(info
, true);
442 ld::dylib::File
* dylibReader
= dynamic_cast<ld::dylib::File
*>(reader
);
443 if ( dylibReader
!= NULL
) {
444 addDylib(dylibReader
, info
);
445 //_installPathToDylibs[strdup(installPath)] = dylibReader;
446 this->logDylib(dylibReader
, true);
450 throwf("indirect dylib at %s is not a dylib", dit
->useInstead
);
452 catch (const char* msg
) {
453 warning("ignoring -dylib_file option, %s", msg
);
457 char newPath
[MAXPATHLEN
];
458 // handle @loader_path
459 if ( strncmp(installPath
, "@loader_path/", 13) == 0 ) {
460 strcpy(newPath
, fromPath
);
461 char* addPoint
= strrchr(newPath
,'/');
462 if ( addPoint
!= NULL
)
463 strcpy(&addPoint
[1], &installPath
[13]);
465 strcpy(newPath
, &installPath
[13]);
466 installPath
= newPath
;
468 // note: @executable_path case is handled inside findFileUsingPaths()
469 // search for dylib using -F and -L paths
470 Options::FileInfo info
= _options
.findFileUsingPaths(installPath
);
471 _indirectDylibOrdinal
= _indirectDylibOrdinal
.nextIndirectDylibOrdinal();
472 info
.ordinal
= _indirectDylibOrdinal
;
474 ld::File
* reader
= this->makeFile(info
, true);
475 ld::dylib::File
* dylibReader
= dynamic_cast<ld::dylib::File
*>(reader
);
476 if ( dylibReader
!= NULL
) {
477 //assert(_installPathToDylibs.find(installPath) != _installPathToDylibs.end());
478 //_installPathToDylibs[strdup(installPath)] = dylibReader;
479 addDylib(dylibReader
, info
);
480 this->logDylib(dylibReader
, true);
484 throwf("indirect dylib at %s is not a dylib", info
.path
);
486 catch (const char* msg
) {
487 throwf("in %s, %s", info
.path
, msg
);
494 void InputFiles::createIndirectDylibs()
496 _allDirectDylibsLoaded
= true;
497 _indirectDylibOrdinal
= ld::File::Ordinal::indirectDylibBase();
499 // mark all dylibs initially specified as required and check if they can be used
500 for (InstallNameToDylib::iterator it
=_installPathToDylibs
.begin(); it
!= _installPathToDylibs
.end(); it
++) {
501 it
->second
->setExplicitlyLinked();
502 this->checkDylibClientRestrictions(it
->second
);
505 // keep processing dylibs until no more dylibs are added
506 unsigned long lastMapSize
= 0;
507 std::set
<ld::dylib::File
*> dylibsProcessed
;
508 while ( lastMapSize
!= _allDylibs
.size() ) {
509 lastMapSize
= _allDylibs
.size();
510 // can't iterator _installPathToDylibs while modifying it, so use temp buffer
511 std::vector
<ld::dylib::File
*> unprocessedDylibs
;
512 for (std::set
<ld::dylib::File
*>::iterator it
=_allDylibs
.begin(); it
!= _allDylibs
.end(); it
++) {
513 if ( dylibsProcessed
.count(*it
) == 0 )
514 unprocessedDylibs
.push_back(*it
);
516 for (std::vector
<ld::dylib::File
*>::iterator it
=unprocessedDylibs
.begin(); it
!= unprocessedDylibs
.end(); it
++) {
517 dylibsProcessed
.insert(*it
);
518 (*it
)->processIndirectLibraries(this, _options
.implicitlyLinkIndirectPublicDylibs());
522 // go back over original dylibs and mark sub frameworks as re-exported
523 if ( _options
.outputKind() == Options::kDynamicLibrary
) {
524 const char* myLeaf
= strrchr(_options
.installPath(), '/');
525 if ( myLeaf
!= NULL
) {
526 for (std::vector
<class ld::File
*>::const_iterator it
=_inputFiles
.begin(); it
!= _inputFiles
.end(); it
++) {
527 ld::dylib::File
* dylibReader
= dynamic_cast<ld::dylib::File
*>(*it
);
528 if ( dylibReader
!= NULL
) {
529 const char* childParent
= dylibReader
->parentUmbrella();
530 if ( childParent
!= NULL
) {
531 if ( strcmp(childParent
, &myLeaf
[1]) == 0 ) {
532 // mark that this dylib will be re-exported
533 dylibReader
->setWillBeReExported();
543 void InputFiles::createOpaqueFileSections()
545 // extra command line section always at end
546 for (Options::ExtraSection::const_iterator it
=_options
.extraSectionsBegin(); it
!= _options
.extraSectionsEnd(); ++it
) {
547 _inputFiles
.push_back(opaque_section::parse(it
->segmentName
, it
->sectionName
, it
->path
, it
->data
, it
->dataLen
));
553 void InputFiles::checkDylibClientRestrictions(ld::dylib::File
* dylib
)
555 // Check for any restrictions on who can link with this dylib
556 const char* dylibParentName
= dylib
->parentUmbrella() ;
557 const std::vector
<const char*>* clients
= dylib
->allowableClients();
558 if ( (dylibParentName
!= NULL
) || (clients
!= NULL
) ) {
559 // only dylibs that are in an umbrella or have a client list need verification
560 const char* installName
= _options
.installPath();
561 const char* installNameLastSlash
= strrchr(installName
, '/');
562 bool isParent
= false;
563 bool isSibling
= false;
564 bool isAllowableClient
= false;
565 // There are three cases:
566 if ( (dylibParentName
!= NULL
) && (installNameLastSlash
!= NULL
) ) {
567 // starts after last slash
568 const char* myName
= &installNameLastSlash
[1];
569 unsigned int myNameLen
= strlen(myName
);
570 if ( strncmp(myName
, "lib", 3) == 0 )
573 const char* firstDot
= strchr(myName
, '.');
574 if ( firstDot
!= NULL
)
575 myNameLen
= firstDot
- myName
;
576 // up to first underscore
577 const char* firstUnderscore
= strchr(myName
, '_');
578 if ( (firstUnderscore
!= NULL
) && ((firstUnderscore
- myName
) < (int)myNameLen
) )
579 myNameLen
= firstUnderscore
- myName
;
581 // case 1) The dylib has a parent umbrella, and we are creating the parent umbrella
582 isParent
= ( (strlen(dylibParentName
) == myNameLen
) && (strncmp(myName
, dylibParentName
, myNameLen
) == 0) );
584 // case 2) The dylib has a parent umbrella, and we are creating a sibling with the same parent
585 isSibling
= ( (_options
.umbrellaName() != NULL
) && (strcmp(_options
.umbrellaName(), dylibParentName
) == 0) );
588 if ( !isParent
&& !isSibling
&& (clients
!= NULL
) ) {
589 // case 3) the dylib has a list of allowable clients, and we are creating one of them
590 const char* clientName
= _options
.clientName();
591 int clientNameLen
= 0;
592 if ( clientName
!= NULL
) {
593 // use client name as specified on command line
594 clientNameLen
= strlen(clientName
);
597 // infer client name from output path (e.g. xxx/libfoo_variant.A.dylib --> foo, Bar.framework/Bar_variant --> Bar)
598 clientName
= installName
;
599 clientNameLen
= strlen(clientName
);
600 // starts after last slash
601 if ( installNameLastSlash
!= NULL
)
602 clientName
= &installNameLastSlash
[1];
603 if ( strncmp(clientName
, "lib", 3) == 0 )
604 clientName
= &clientName
[3];
606 const char* firstDot
= strchr(clientName
, '.');
607 if ( firstDot
!= NULL
)
608 clientNameLen
= firstDot
- clientName
;
609 // up to first underscore
610 const char* firstUnderscore
= strchr(clientName
, '_');
611 if ( (firstUnderscore
!= NULL
) && ((firstUnderscore
- clientName
) < clientNameLen
) )
612 clientNameLen
= firstUnderscore
- clientName
;
615 // Use clientName to check if this dylib is able to link against the allowable clients.
616 for (std::vector
<const char*>::const_iterator it
= clients
->begin(); it
!= clients
->end(); it
++) {
617 if ( strncmp(*it
, clientName
, clientNameLen
) == 0 )
618 isAllowableClient
= true;
622 if ( !isParent
&& !isSibling
&& !isAllowableClient
) {
623 if ( dylibParentName
!= NULL
) {
624 throwf("cannot link directly with %s. Link against the umbrella framework '%s.framework' instead.",
625 dylib
->path(), dylibParentName
);
628 throwf("cannot link directly with %s", dylib
->path());
635 void InputFiles::inferArchitecture(Options
& opts
, const char** archName
)
637 _inferredArch
= true;
638 // scan all input files, looking for a thin .o file.
639 // the first one found is presumably the architecture to link
640 uint8_t buffer
[sizeof(mach_header_64
)];
641 const std::vector
<Options::FileInfo
>& files
= opts
.getInputFiles();
642 for (std::vector
<Options::FileInfo
>::const_iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
643 int fd
= ::open(it
->path
, O_RDONLY
, 0);
645 ssize_t amount
= read(fd
, buffer
, sizeof(buffer
));
647 if ( amount
>= (ssize_t
)sizeof(buffer
) ) {
649 cpu_subtype_t subtype
;
650 if ( mach_o::relocatable::isObjectFile(buffer
, &type
, &subtype
) ) {
651 opts
.setArchitecture(type
, subtype
);
652 *archName
= opts
.architectureName();
659 // no thin .o files found, so default to same architecture this tool was built as
660 warning("-arch not specified");
662 opts
.setArchitecture(CPU_TYPE_I386
, CPU_SUBTYPE_X86_ALL
);
664 opts
.setArchitecture(CPU_TYPE_X86_64
, CPU_SUBTYPE_X86_64_ALL
);
666 opts
.setArchitecture(CPU_TYPE_ARM
, CPU_SUBTYPE_ARM_V6
);
668 #error unknown default architecture
670 *archName
= opts
.architectureName();
674 InputFiles::InputFiles(Options
& opts
, const char** archName
)
675 : _totalObjectSize(0), _totalArchiveSize(0),
676 _totalObjectLoaded(0), _totalArchivesLoaded(0), _totalDylibsLoaded(0),
677 _options(opts
), _bundleLoader(NULL
),
678 _allDirectDylibsLoaded(false), _inferredArch(false), _fileMonitor(-1),
681 // fStartCreateReadersTime = mach_absolute_time();
682 if ( opts
.architecture() == 0 ) {
683 // command line missing -arch, so guess arch
684 inferArchitecture(opts
, archName
);
687 pthread_mutex_init(&_parseLock
, NULL
);
688 pthread_cond_init(&_parseWorkReady
, NULL
);
689 pthread_cond_init(&_newFileAvailable
, NULL
);
691 const std::vector
<Options::FileInfo
>& files
= _options
.getInputFiles();
692 if ( files
.size() == 0 )
693 throw "no object files specified";
695 _inputFiles
.reserve(files
.size());
697 unsigned int inputFileSlot
= 0;
698 _availableInputFiles
= 0;
701 Options::FileInfo
* entry
;
702 for (std::vector
<Options::FileInfo
>::const_iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
703 entry
= (Options::FileInfo
*)&(*it
);
705 // Assign input file slots to all the FileInfos.
706 // Also chain all FileInfos into one big list to set up for worker threads to do parsing.
707 entry
->inputFileSlot
= inputFileSlot
;
708 entry
->readyToParse
= !entry
->fromFileList
|| !_options
.pipelineEnabled();
709 if (entry
->readyToParse
)
710 _availableInputFiles
++;
711 _inputFiles
.push_back(NULL
);
714 // In the non-threaded case just parse the file now.
715 _inputFiles
.push_back(makeFile(*entry
, false));
720 _remainingInputFiles
= files
.size();
722 // initialize info for parsing input files on worker threads
725 size_t len
= sizeof(ncpus
);
728 if (sysctl(mib
, 2, &ncpus
, &len
, NULL
, 0) != 0) {
731 _availableWorkers
= MIN(ncpus
, files
.size()); // max # workers we permit
734 if (_options
.pipelineEnabled()) {
735 // start up a thread to listen for available input files
736 startThread(InputFiles::waitForInputFiles
);
739 // Start up one parser thread. More start on demand as parsed input files get consumed.
740 startThread(InputFiles::parseWorkerThread
);
743 if (_options
.pipelineEnabled()) {
744 throwf("pipelined linking not supported on this platform");
751 void InputFiles::startThread(void (*threadFunc
)(InputFiles
*)) const {
754 pthread_attr_init(&attr
);
755 // set a nice big stack (same as main thread) because some code uses potentially large stack buffers
756 pthread_attr_setstacksize(&attr
, 8 * 1024 * 1024);
757 pthread_create(&thread
, &attr
, (void *(*)(void*))threadFunc
, (void *)this);
758 pthread_detach(thread
);
759 pthread_attr_destroy(&attr
);
762 // Work loop for input file parsing threads
763 void InputFiles::parseWorkerThread() {
765 const char *exception
= NULL
;
766 pthread_mutex_lock(&_parseLock
);
767 const std::vector
<Options::FileInfo
>& files
= _options
.getInputFiles();
768 if (_s_logPThreads
) printf("worker starting\n");
770 if (_availableInputFiles
== 0) {
772 pthread_cond_wait(&_parseWorkReady
, &_parseLock
);
775 int slot
= _parseCursor
;
776 while (slot
< (int)files
.size() && (_inputFiles
[slot
] != NULL
|| !files
[slot
].readyToParse
))
778 assert(slot
< (int)files
.size());
779 Options::FileInfo
& entry
= (Options::FileInfo
&)files
[slot
];
780 _parseCursor
= slot
+1;
781 _availableInputFiles
--;
782 entry
.readyToParse
= false; // to avoid multiple threads finding this file
783 pthread_mutex_unlock(&_parseLock
);
784 if (_s_logPThreads
) printf("parsing index %u\n", slot
);
786 file
= makeFile(entry
, false);
787 } catch (const char *msg
) {
788 if ( (strstr(msg
, "architecture") != NULL
) && !_options
.errorOnOtherArchFiles() ) {
789 if ( _options
.ignoreOtherArchInputFiles() ) {
790 // ignore, because this is about an architecture not in use
793 warning("ignoring file %s, %s", entry
.path
, msg
);
798 file
= new IgnoredFile(entry
.path
, entry
.modTime
, entry
.ordinal
, ld::File::Other
);
800 pthread_mutex_lock(&_parseLock
);
801 if (_remainingInputFiles
> 0)
802 _remainingInputFiles
--;
803 if (_s_logPThreads
) printf("done with index %u, %d remaining\n", slot
, _remainingInputFiles
);
805 // We are about to die, so set to zero to stop other threads from doing unneeded work.
806 _remainingInputFiles
= 0;
807 _exception
= exception
;
809 _inputFiles
[slot
] = file
;
810 if (_neededFileSlot
== slot
)
811 pthread_cond_signal(&_newFileAvailable
);
814 } while (_remainingInputFiles
);
815 if (_s_logPThreads
) printf("worker exiting\n");
816 pthread_cond_broadcast(&_parseWorkReady
);
817 pthread_cond_signal(&_newFileAvailable
);
818 pthread_mutex_unlock(&_parseLock
);
822 void InputFiles::parseWorkerThread(InputFiles
*inputFiles
) {
823 inputFiles
->parseWorkerThread();
828 ld::File
* InputFiles::addDylib(ld::dylib::File
* reader
, const Options::FileInfo
& info
)
830 _allDylibs
.insert(reader
);
832 if ( (reader
->installPath() == NULL
) && !info
.options
.fBundleLoader
) {
833 // this is a "blank" stub
834 // silently ignore it
837 // store options about how dylib will be used in dylib itself
838 if ( info
.options
.fWeakImport
)
839 reader
->setForcedWeakLinked();
840 if ( info
.options
.fReExport
)
841 reader
->setWillBeReExported();
842 if ( info
.options
.fUpward
) {
843 if ( _options
.outputKind() == Options::kDynamicLibrary
)
844 reader
->setWillBeUpwardDylib();
846 warning("ignoring upward dylib option for %s\n", info
.path
);
848 if ( info
.options
.fLazyLoad
)
849 reader
->setWillBeLazyLoadedDylb();
851 // add to map of loaded dylibs
852 const char* installPath
= reader
->installPath();
853 if ( installPath
!= NULL
) {
854 InstallNameToDylib::iterator pos
= _installPathToDylibs
.find(installPath
);
855 if ( pos
== _installPathToDylibs
.end() ) {
856 _installPathToDylibs
[strdup(installPath
)] = reader
;
859 bool dylibOnCommandLineTwice
= ( strcmp(pos
->second
->path(), reader
->path()) == 0 );
860 bool isSymlink
= false;
861 // ignore if this is a symlink to a dylib we've already loaded
862 if ( !dylibOnCommandLineTwice
) {
863 char existingDylibPath
[PATH_MAX
];
864 if ( realpath(pos
->second
->path(), existingDylibPath
) != NULL
) {
865 char newDylibPath
[PATH_MAX
];
866 if ( realpath(reader
->path(), newDylibPath
) != NULL
) {
867 isSymlink
= ( strcmp(existingDylibPath
, newDylibPath
) == 0 );
871 // remove warning for <rdar://problem/10860629> Same install name for CoreServices and CFNetwork?
872 //if ( !dylibOnCommandLineTwice && !isSymlink )
873 // warning("dylibs with same install name: %s and %s", pos->second->path(), reader->path());
876 else if ( info
.options
.fBundleLoader
)
877 _bundleLoader
= reader
;
879 // log direct readers
880 if ( !_allDirectDylibsLoaded
)
881 this->logDylib(reader
, false);
884 _totalDylibsLoaded
++;
886 _searchLibraries
.push_back(LibraryInfo(reader
));
892 // Called during pipelined linking to listen for available input files.
893 // Available files are enqueued for parsing.
894 void InputFiles::waitForInputFiles()
896 if (_s_logPThreads
) printf("starting pipeline listener\n");
898 const char *fifo
= _options
.pipelineFifo();
900 std::map
<const char *, const Options::FileInfo
*, strcompclass
> fileMap
;
901 const std::vector
<Options::FileInfo
>& files
= _options
.getInputFiles();
902 for (std::vector
<Options::FileInfo
>::const_iterator it
= files
.begin(); it
!= files
.end(); ++it
) {
903 const Options::FileInfo
& entry
= *it
;
904 if (entry
.fromFileList
) {
905 fileMap
[entry
.path
] = &entry
;
908 FILE *fileStream
= fopen(fifo
, "r");
910 throwf("pipelined linking error - failed to open stream. fopen() returns %s for \"%s\"\n", strerror(errno
), fifo
);
911 while (fileMap
.size() > 0) {
912 char path_buf
[PATH_MAX
+1];
913 if (fgets(path_buf
, PATH_MAX
, fileStream
) == NULL
)
914 throwf("pipelined linking error - %lu missing input files", fileMap
.size());
915 int len
= strlen(path_buf
);
916 if (path_buf
[len
-1] == '\n')
918 std::map
<const char *, const Options::FileInfo
*, strcompclass
>::iterator it
= fileMap
.find(path_buf
);
919 if (it
== fileMap
.end())
920 throwf("pipelined linking error - not in file list: %s\n", path_buf
);
921 Options::FileInfo
* inputInfo
= (Options::FileInfo
*)it
->second
;
922 if (!inputInfo
->checkFileExists())
923 throwf("pipelined linking error - file does not exist: %s\n", inputInfo
->path
);
924 pthread_mutex_lock(&_parseLock
);
926 pthread_cond_signal(&_parseWorkReady
);
927 inputInfo
->readyToParse
= true;
928 if (_parseCursor
> inputInfo
->inputFileSlot
)
929 _parseCursor
= inputInfo
->inputFileSlot
;
930 _availableInputFiles
++;
931 if (_s_logPThreads
) printf("pipeline listener: %s slot=%d, _parseCursor=%d, _availableInputFiles = %d remaining = %ld\n", path_buf
, inputInfo
->inputFileSlot
, _parseCursor
, _availableInputFiles
, fileMap
.size()-1);
932 pthread_mutex_unlock(&_parseLock
);
935 } catch (const char *msg
) {
936 pthread_mutex_lock(&_parseLock
);
938 pthread_cond_signal(&_newFileAvailable
);
939 pthread_mutex_unlock(&_parseLock
);
944 void InputFiles::waitForInputFiles(InputFiles
*inputFiles
) {
945 inputFiles
->waitForInputFiles();
950 void InputFiles::forEachInitialAtom(ld::File::AtomHandler
& handler
)
952 // add all direct object, archives, and dylibs
953 const std::vector
<Options::FileInfo
>& files
= _options
.getInputFiles();
955 for (fileIndex
=0; fileIndex
<_inputFiles
.size(); fileIndex
++) {
958 pthread_mutex_lock(&_parseLock
);
960 // this loop waits for the needed file to be ready (parsed by worker thread)
961 while (_inputFiles
[fileIndex
] == NULL
&& _exception
== NULL
) {
962 // We are starved for input. If there are still files to parse and we have
963 // not maxed out the worker thread count start a new worker thread.
964 if (_availableInputFiles
> 0 && _availableWorkers
> 0) {
965 if (_s_logPThreads
) printf("starting worker\n");
966 startThread(InputFiles::parseWorkerThread
);
969 _neededFileSlot
= fileIndex
;
970 if (_s_logPThreads
) printf("consumer blocking for %lu: %s\n", fileIndex
, files
[fileIndex
].path
);
971 pthread_cond_wait(&_newFileAvailable
, &_parseLock
);
977 // The input file is parsed. Assimilate it and call its atom iterator.
978 if (_s_logPThreads
) printf("consuming slot %lu\n", fileIndex
);
979 file
= _inputFiles
[fileIndex
];
980 pthread_mutex_unlock(&_parseLock
);
982 file
= _inputFiles
[fileIndex
];
984 const Options::FileInfo
& info
= files
[fileIndex
];
985 switch (file
->type()) {
986 case ld::File::Reloc
:
988 ld::relocatable::File
* reloc
= (ld::relocatable::File
*)file
;
989 _options
.snapshot().recordObjectFile(reloc
->path());
992 case ld::File::Dylib
:
994 ld::dylib::File
* dylib
= (ld::dylib::File
*)file
;
995 addDylib(dylib
, info
);
998 case ld::File::Archive
:
1000 ld::archive::File
* archive
= (ld::archive::File
*)file
;
1001 // <rdar://problem/9740166> force loaded archives should be in LD_TRACE
1002 if ( (info
.options
.fForceLoad
|| _options
.fullyLoadArchives()) && _options
.traceArchives() )
1003 logArchive(archive
);
1004 _searchLibraries
.push_back(LibraryInfo(archive
));
1007 case ld::File::Other
:
1011 throwf("Unknown file type for %s", file
->path());
1015 file
->forEachAtom(handler
);
1018 createIndirectDylibs();
1019 createOpaqueFileSections();
1021 while (fileIndex
< _inputFiles
.size()) {
1022 ld::File
*file
= _inputFiles
[fileIndex
];
1023 file
->forEachAtom(handler
);
1027 switch ( _options
.outputKind() ) {
1028 case Options::kStaticExecutable
:
1029 case Options::kDynamicExecutable
:
1030 // add implicit __dso_handle label
1031 handler
.doAtom(DSOHandleAtom::_s_atomExecutable
);
1032 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1033 if ( _options
.pageZeroSize() != 0 )
1034 handler
.doAtom(*new PageZeroAtom(_options
.pageZeroSize()));
1035 if ( _options
.hasCustomStack() && !_options
.needsEntryPointLoadCommand() )
1036 handler
.doAtom(*new CustomStackAtom(_options
.customStackSize()));
1038 case Options::kDynamicLibrary
:
1039 // add implicit __dso_handle label
1040 handler
.doAtom(DSOHandleAtom::_s_atomDylib
);
1041 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1043 case Options::kDynamicBundle
:
1044 // add implicit __dso_handle label
1045 handler
.doAtom(DSOHandleAtom::_s_atomBundle
);
1046 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1048 case Options::kDyld
:
1049 // add implicit __dso_handle label
1050 handler
.doAtom(DSOHandleAtom::_s_atomDyld
);
1051 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1053 case Options::kPreload
:
1054 // add implicit __mh_preload_header label
1055 handler
.doAtom(DSOHandleAtom::_s_atomPreload
);
1056 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1058 case Options::kObjectFile
:
1059 handler
.doAtom(DSOHandleAtom::_s_atomObjectFile
);
1061 case Options::kKextBundle
:
1062 // add implicit __dso_handle label
1063 handler
.doAtom(DSOHandleAtom::_s_atomAll
);
1069 bool InputFiles::searchLibraries(const char* name
, bool searchDylibs
, bool searchArchives
, bool dataSymbolOnly
, ld::File::AtomHandler
& handler
) const
1071 // Check each input library.
1072 std::vector
<LibraryInfo
>::const_iterator libIterator
= _searchLibraries
.begin();
1075 while (libIterator
!= _searchLibraries
.end()) {
1076 LibraryInfo lib
= *libIterator
;
1077 if (lib
.isDylib()) {
1079 ld::dylib::File
*dylibFile
= lib
.dylib();
1080 //fprintf(stderr, "searchLibraries(%s), looking in linked %s\n", name, dylibFile->path() );
1081 if ( dylibFile
->justInTimeforEachAtom(name
, handler
) ) {
1082 // we found a definition in this dylib
1083 // done, unless it is a weak definition in which case we keep searching
1084 _options
.snapshot().recordDylibSymbol(dylibFile
, name
);
1085 if ( !dylibFile
->hasWeakExternals() || !dylibFile
->hasWeakDefinition(name
)) {
1088 // else continue search for a non-weak definition
1092 if (searchArchives
) {
1093 ld::archive::File
*archiveFile
= lib
.archive();
1094 if ( dataSymbolOnly
) {
1095 if ( archiveFile
->justInTimeDataOnlyforEachAtom(name
, handler
) ) {
1096 if ( _options
.traceArchives() )
1097 logArchive(archiveFile
);
1098 _options
.snapshot().recordArchive(archiveFile
->path());
1099 // found data definition in static library, done
1104 if ( archiveFile
->justInTimeforEachAtom(name
, handler
) ) {
1105 if ( _options
.traceArchives() )
1106 logArchive(archiveFile
);
1107 _options
.snapshot().recordArchive(archiveFile
->path());
1108 // found definition in static library, done
1117 // search indirect dylibs
1118 if ( searchDylibs
) {
1119 for (InstallNameToDylib::const_iterator it
=_installPathToDylibs
.begin(); it
!= _installPathToDylibs
.end(); ++it
) {
1120 ld::dylib::File
* dylibFile
= it
->second
;
1121 bool searchThisDylib
= false;
1122 if ( _options
.nameSpace() == Options::kTwoLevelNameSpace
) {
1123 // for two level namesapce, just check all implicitly linked dylibs
1124 searchThisDylib
= dylibFile
->implicitlyLinked() && !dylibFile
->explicitlyLinked();
1127 // for flat namespace, check all indirect dylibs
1128 searchThisDylib
= ! dylibFile
->explicitlyLinked();
1130 if ( searchThisDylib
) {
1131 //fprintf(stderr, "searchLibraries(%s), looking in implicitly linked %s\n", name, dylibFile->path() );
1132 if ( dylibFile
->justInTimeforEachAtom(name
, handler
) ) {
1133 // we found a definition in this dylib
1134 // done, unless it is a weak definition in which case we keep searching
1135 _options
.snapshot().recordDylibSymbol(dylibFile
, name
);
1136 if ( !dylibFile
->hasWeakExternals() || !dylibFile
->hasWeakDefinition(name
)) {
1139 // else continue search for a non-weak definition
1149 bool InputFiles::searchWeakDefInDylib(const char* name
) const
1151 // search all relevant dylibs to see if any of a weak-def with this name
1152 for (InstallNameToDylib::const_iterator it
=_installPathToDylibs
.begin(); it
!= _installPathToDylibs
.end(); ++it
) {
1153 ld::dylib::File
* dylibFile
= it
->second
;
1154 if ( dylibFile
->implicitlyLinked() || dylibFile
->explicitlyLinked() ) {
1155 if ( dylibFile
->hasWeakExternals() && dylibFile
->hasWeakDefinition(name
) ) {
1163 static bool vectorContains(const std::vector
<ld::dylib::File
*>& vec
, ld::dylib::File
* key
)
1165 return std::find(vec
.begin(), vec
.end(), key
) != vec
.end();
1168 void InputFiles::dylibs(ld::Internal
& state
)
1170 bool dylibsOK
= false;
1171 switch ( _options
.outputKind() ) {
1172 case Options::kDynamicExecutable
:
1173 case Options::kDynamicLibrary
:
1174 case Options::kDynamicBundle
:
1177 case Options::kStaticExecutable
:
1178 case Options::kDyld
:
1179 case Options::kPreload
:
1180 case Options::kObjectFile
:
1181 case Options::kKextBundle
:
1186 // add command line dylibs in order
1187 for (std::vector
<ld::File
*>::const_iterator it
=_inputFiles
.begin(); it
!= _inputFiles
.end(); ++it
) {
1188 ld::dylib::File
* dylibFile
= dynamic_cast<ld::dylib::File
*>(*it
);
1189 // only add dylibs that are not "blank" dylib stubs
1190 if ( (dylibFile
!= NULL
) && ((dylibFile
->installPath() != NULL
) || (dylibFile
== _bundleLoader
)) ) {
1192 if ( ! vectorContains(state
.dylibs
, dylibFile
) ) {
1193 state
.dylibs
.push_back(dylibFile
);
1197 warning("unexpected dylib (%s) on link line", dylibFile
->path());
1200 // add implicitly linked dylibs
1201 if ( _options
.nameSpace() == Options::kTwoLevelNameSpace
) {
1202 for (InstallNameToDylib::const_iterator it
=_installPathToDylibs
.begin(); it
!= _installPathToDylibs
.end(); ++it
) {
1203 ld::dylib::File
* dylibFile
= it
->second
;
1204 if ( dylibFile
->implicitlyLinked() && dylibsOK
) {
1205 if ( ! vectorContains(state
.dylibs
, dylibFile
) ) {
1206 state
.dylibs
.push_back(dylibFile
);
1212 //fprintf(stderr, "all dylibs:\n");
1213 //for(std::vector<ld::dylib::File*>::iterator it=state.dylibs.begin(); it != state.dylibs.end(); ++it) {
1214 // const ld::dylib::File* dylib = *it;
1215 // fprintf(stderr, " %p %s\n", dylib, dylib->path());
1218 // and -bundle_loader
1219 state
.bundleLoader
= _bundleLoader
;
1221 // <rdar://problem/10807040> give an error when -nostdlib is used and libSystem is missing
1222 if ( (state
.dylibs
.size() == 0) && _options
.needsEntryPointLoadCommand() )
1223 throw "dynamic main executables must link with libSystem.dylib";