#include <sys/types.h>
#include <sys/stat.h>
#include <mach/vm_prot.h>
+#include <sys/sysctl.h>
#include <mach-o/dyld.h>
#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <spawn.h>
+#include <cxxabi.h>
+#include <Availability.h>
#include <vector>
-#include "configure.h"
#include "Options.h"
#include "Architectures.hpp"
#include "MachOFileAbstraction.hpp"
+#include "Snapshot.h"
// upward dependency on lto::version()
namespace lto {
// magic to place command line in crash reports
const int crashreporterBufferSize = 2000;
-extern "C" char* __crashreporter_info__;
static char crashreporterBuffer[crashreporterBufferSize];
-char* __crashreporter_info__ = crashreporterBuffer;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ #include <CrashReporterClient.h>
+ // hack until ld does not need to build on 10.6 anymore
+ struct crashreporter_annotations_t gCRAnnotations
+ __attribute__((section("__DATA," CRASHREPORTER_ANNOTATIONS_SECTION)))
+ = { CRASHREPORTER_ANNOTATIONS_VERSION, 0, 0, 0, 0, 0, 0 };
+#else
+ extern "C" char* __crashreporter_info__;
+ __attribute__((used))
+ char* __crashreporter_info__ = crashreporterBuffer;
+#endif
+
static bool sEmitWarnings = true;
static bool sFatalWarnings = false;
throw t;
}
+
+bool Options::FileInfo::checkFileExists(const Options& options, const char *p)
+{
+ struct stat statBuffer;
+ if (p == NULL)
+ p = path;
+ if ( stat(p, &statBuffer) == 0 ) {
+ if (p != path) path = strdup(p);
+ fileLen = statBuffer.st_size;
+ modTime = statBuffer.st_mtime;
+ return true;
+ }
+ if ( options.dumpDependencyInfo() )
+ options.dumpDependency(Options::depNotFound, p);
+ return false;
+}
+
+
Options::Options(int argc, const char* argv[])
: fOutputFile("a.out"), fArchitecture(0), fSubArchitecture(0), fArchitectureName("unknown"), fOutputKind(kDynamicExecutable),
fHasPreferredSubType(false), fArchSupportsThumb2(false), fPrebind(false), fBindAtLoad(false), fKeepPrivateExterns(false),
fClientName(NULL),
fUmbrellaName(NULL), fInitFunctionName(NULL), fDotOutputFile(NULL), fExecutablePath(NULL),
fBundleLoader(NULL), fDtraceScriptName(NULL), fSegAddrTablePath(NULL), fMapPath(NULL),
- fDyldInstallPath("/usr/lib/dyld"), fTempLtoObjectPath(NULL),
- fZeroPageSize(ULLONG_MAX), fStackSize(0), fStackAddr(0), fExecutableStack(false),
+ fDyldInstallPath("/usr/lib/dyld"), fTempLtoObjectPath(NULL), fOverridePathlibLTO(NULL), fLtoCpu(NULL),
+ fZeroPageSize(ULLONG_MAX), fStackSize(0), fStackAddr(0), fSourceVersion(0), fSDKVersion(0), fExecutableStack(false),
fNonExecutableHeap(false), fDisableNonExecutableHeap(false),
fMinimumHeaderPad(32), fSegmentAlignment(4096),
fCommonsMode(kCommonsIgnoreDylibs), fUUIDMode(kUUIDContent), fLocalSymbolHandling(kLocalSymbolsAll), fWarnCommons(false),
fSharedRegionEligible(false), fPrintOrderFileStatistics(false),
fReadOnlyx86Stubs(false), fPositionIndependentExecutable(false), fPIEOnCommandLine(false),
fDisablePositionIndependentExecutable(false), fMaxMinimumHeaderPad(false),
- fDeadStripDylibs(false), fAllowTextRelocs(false), fWarnTextRelocs(false),
+ fDeadStripDylibs(false), fAllowTextRelocs(false), fWarnTextRelocs(false), fKextsUseStubs(false),
fUsingLazyDylibLinking(false), fEncryptable(true),
fOrderData(true), fMarkDeadStrippableDylib(false),
fMakeCompressedDyldInfo(true), fMakeCompressedDyldInfoForceOff(false), fNoEHLabels(false),
fVersionLoadCommand(false), fVersionLoadCommandForcedOn(false),
fVersionLoadCommandForcedOff(false), fFunctionStartsLoadCommand(false),
fFunctionStartsForcedOn(false), fFunctionStartsForcedOff(false),
+ fDataInCodeInfoLoadCommand(false), fDataInCodeInfoLoadCommandForcedOn(false), fDataInCodeInfoLoadCommandForcedOff(false),
fCanReExportSymbols(false), fObjcCategoryMerging(true), fPageAlignDataAtoms(false),
+ fNeedsThreadLoadCommand(false), fEntryPointLoadCommand(false),
+ fEntryPointLoadCommandForceOn(false), fEntryPointLoadCommandForceOff(false),
+ fSourceVersionLoadCommand(false),
+ fSourceVersionLoadCommandForceOn(false), fSourceVersionLoadCommandForceOff(false),
+ fDependentDRInfo(false), fDependentDRInfoForcedOn(false), fDependentDRInfoForcedOff(false),
+ fTargetIOSSimulator(false), fExportDynamic(false), fAbsoluteSymbols(false),
+ fAllowSimulatorToLinkWithMacOSX(false), fKeepDwarfUnwind(true),
+ fKeepDwarfUnwindForcedOn(false), fKeepDwarfUnwindForcedOff(false),
+ fVerboseOptimizationHints(false), fIgnoreOptimizationHints(false),
+ fGenerateDtraceDOF(true), fAllowBranchIslands(true),
fDebugInfoStripping(kDebugInfoMinimal), fTraceOutputFile(NULL),
fMacVersionMin(ld::macVersionUnset), fIOSVersionMin(ld::iOSVersionUnset),
- fSaveTempFiles(false)
+ fSaveTempFiles(false), fSnapshotRequested(false), fPipelineFifo(NULL),
+ fDependencyInfoPath(NULL), fDependencyFileDescriptor(-1)
{
this->checkForClassic(argc, argv);
this->parsePreCommandLineEnvironmentSettings();
this->parsePostCommandLineEnvironmentSettings();
this->reconfigureDefaults();
this->checkIllegalOptionCombinations();
+
+ if ( this->dumpDependencyInfo() ) {
+ this->dumpDependency(depOutputFile, fOutputFile);
+ if ( fMapPath != NULL )
+ this->dumpDependency(depOutputFile, fMapPath);
+ }
}
Options::~Options()
{
+ if ( fDependencyFileDescriptor != -1 )
+ ::close(fDependencyFileDescriptor);
}
-
bool Options::errorBecauseOfWarnings() const
{
return (sFatalWarnings && (sWarningsCount > 0));
//
switch ( fOutputKind ) {
case Options::kDynamicExecutable:
+ // <rdar://problem/12839986> Add the -export_dynamic flag
+ return fExportDynamic;
case Options::kStaticExecutable:
+ // <rdar://problem/13361218> Support the -export_dynamic flag for xnu
+ return fExportDynamic;
case Options::kPreload:
// by default unused globals in a main executable are stripped
return false;
return fExecutablePath;
}
-
uint32_t Options::initialSegProtection(const char* segName) const
{
for(std::vector<Options::SegmentProtect>::const_iterator it = fCustomSegmentProtections.begin(); it != fCustomSegmentProtections.end(); ++it) {
uint32_t Options::maxSegProtection(const char* segName) const
{
// iPhoneOS always uses same protection for max and initial
- if ( fIOSVersionMin != ld::iOSVersionUnset )
+ // <rdar://problem/11663436> simulator apps need to use MacOSX max-prot
+ if ( (fIOSVersionMin != ld::iOSVersionUnset) && (fArchitecture != CPU_TYPE_I386) )
return initialSegProtection(segName);
for(std::vector<Options::SegmentProtect>::const_iterator it = fCustomSegmentProtections.begin(); it != fCustomSegmentProtections.end(); ++it) {
::close(fd);
- // parse into symbols and add to hash_set
+ // parse into symbols and add to unordered_set
unsigned int count = 0;
char * const end = &p[stat_buf.st_size];
enum { lineStart, inSymbol, inComment } state = lineStart;
return fForceNotWeakSymbols.containsNonWildcard(symbolName);
}
+bool Options::forceCoalesce(const char* symbolName) const
+{
+ return fForceCoalesceSymbols.contains(symbolName);
+}
+
bool Options::shouldExport(const char* symbolName) const
{
void Options::setArchitecture(cpu_type_t type, cpu_subtype_t subtype)
{
- fArchitecture = type;
- fSubArchitecture = subtype;
- switch ( type ) {
- case CPU_TYPE_I386:
- fArchitectureName = "i386";
- if ( (fMacVersionMin == ld::macVersionUnset) && (fOutputKind != Options::kObjectFile) ) {
- #ifdef DEFAULT_MACOSX_MIN_VERSION
- warning("-macosx_version_min not specificed, assuming " DEFAULT_MACOSX_MIN_VERSION);
- setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
- #else
- warning("-macosx_version_min not specificed, assuming 10.6");
- fMacVersionMin = ld::mac10_6;
- #endif
- }
- if ( !fMakeCompressedDyldInfo && (fMacVersionMin >= ld::mac10_6) && !fMakeCompressedDyldInfoForceOff )
- fMakeCompressedDyldInfo = true;
- break;
- case CPU_TYPE_X86_64:
- fArchitectureName = "x86_64";
- if ( (fMacVersionMin == ld::macVersionUnset) && (fOutputKind != Options::kObjectFile) ) {
- #ifdef DEFAULT_MACOSX_MIN_VERSION
- warning("-macosx_version_min not specificed, assuming " DEFAULT_MACOSX_MIN_VERSION);
- setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
- #else
- warning("-macosx_version_min not specificed, assuming 10.6");
- fMacVersionMin = ld::mac10_6;
- #endif
- }
- if ( !fMakeCompressedDyldInfo && (fMacVersionMin >= ld::mac10_6) && !fMakeCompressedDyldInfoForceOff )
- fMakeCompressedDyldInfo = true;
- break;
- case CPU_TYPE_ARM:
- fHasPreferredSubType = true;
- for (const ARMSubType* t=ARMSubTypes; t->subTypeName != NULL; ++t) {
- if ( t->subType == subtype ) {
- fArchitectureName = t->subTypeName;
- fArchSupportsThumb2 = t->supportsThumb2;
- break;
+ for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) {
+ if ( (type == t->cpuType) && (subtype == t->cpuSubType) ) {
+ fArchitecture = type;
+ fSubArchitecture = subtype;
+ fArchitectureName = t->archName;
+ fHasPreferredSubType = t->isSubType;
+ fArchSupportsThumb2 = t->supportsThumb2;
+ switch ( type ) {
+ case CPU_TYPE_I386:
+ case CPU_TYPE_X86_64:
+ if ( (fMacVersionMin == ld::macVersionUnset) && (fIOSVersionMin == ld::iOSVersionUnset) && (fOutputKind != Options::kObjectFile) ) {
+ #ifdef DEFAULT_MACOSX_MIN_VERSION
+ warning("-macosx_version_min not specified, assuming " DEFAULT_MACOSX_MIN_VERSION);
+ setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
+ #else
+ warning("-macosx_version_min not specified, assuming 10.6");
+ fMacVersionMin = ld::mac10_6;
+ #endif
+ }
+ break;
+ case CPU_TYPE_ARM:
+ case CPU_TYPE_ARM64:
+ if ( (fMacVersionMin == ld::macVersionUnset) && (fIOSVersionMin == ld::iOSVersionUnset) && (fOutputKind != Options::kObjectFile) ) {
+ #if defined(DEFAULT_IPHONEOS_MIN_VERSION)
+ warning("-ios_version_min not specified, assuming " DEFAULT_IPHONEOS_MIN_VERSION);
+ setIOSVersionMin(DEFAULT_IPHONEOS_MIN_VERSION);
+ #else
+ warning("-ios_version_min not specified, assuming 6.0");
+ setIOSVersionMin("6.0");
+ #endif
+ }
+ break;
}
+ fLinkSnapshot.recordArch(fArchitectureName);
+ // only use compressed LINKEDIT for:
+ // Mac OS X 10.6 or later
+ // iOS 3.1 or later
+ if ( !fMakeCompressedDyldInfo && minOS(ld::mac10_6, ld::iOS_3_1) && !fMakeCompressedDyldInfoForceOff )
+ fMakeCompressedDyldInfo = true;
+ // Mac OS X 10.5 and iPhoneOS 2.0 support LC_REEXPORT_DYLIB
+ if ( minOS(ld::mac10_5, ld::iOS_2_0) )
+ fUseSimplifiedDylibReExports = true;
+ return;
}
- assert(fArchitectureName != NULL);
- if ( (fMacVersionMin == ld::macVersionUnset) && (fIOSVersionMin == ld::iOSVersionUnset) && (fOutputKind != Options::kObjectFile) ) {
-#if defined(DEFAULT_IPHONEOS_MIN_VERSION)
- warning("-ios_version_min not specificed, assuming " DEFAULT_IPHONEOS_MIN_VERSION);
- setIOSVersionMin(DEFAULT_IPHONEOS_MIN_VERSION);
-#elif defined(DEFAULT_MACOSX_MIN_VERSION)
- warning("-macosx_version_min not specificed, assuming " DEFAULT_MACOSX_MIN_VERSION);
- setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
-#else
- warning("-macosx_version_min not specificed, assuming 10.6");
- fMacVersionMin = ld::mac10_6;
-#endif
- }
- if ( !fMakeCompressedDyldInfo && minOS(ld::mac10_6, ld::iOS_3_1) && !fMakeCompressedDyldInfoForceOff )
- fMakeCompressedDyldInfo = true;
- break;
- default:
- fArchitectureName = "unknown architecture";
- break;
}
+ fArchitectureName = "unknown architecture";
}
void Options::parseArch(const char* arch)
{
if ( arch == NULL )
throw "-arch must be followed by an architecture string";
- fArchitectureName = arch;
- if ( strcmp(arch, "i386") == 0 ) {
- fArchitecture = CPU_TYPE_I386;
- fSubArchitecture = CPU_SUBTYPE_I386_ALL;
- }
- else if ( strcmp(arch, "x86_64") == 0 ) {
- fArchitecture = CPU_TYPE_X86_64;
- fSubArchitecture = CPU_SUBTYPE_X86_64_ALL;
- }
- else if ( strcmp(arch, "arm") == 0 ) {
- fArchitecture = CPU_TYPE_ARM;
- fSubArchitecture = CPU_SUBTYPE_ARM_ALL;
- }
- else {
- for (const ARMSubType* t=ARMSubTypes; t->subTypeName != NULL; ++t) {
- if ( strcmp(t->subTypeName,arch) == 0 ) {
- fArchitecture = CPU_TYPE_ARM;
- fSubArchitecture = t->subType;
- fArchSupportsThumb2 = t->supportsThumb2;
- fHasPreferredSubType = true;
- return;
- }
+ for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) {
+ if ( strcmp(t->archName,arch) == 0 ) {
+ fArchitectureName = arch;
+ fArchitecture = t->cpuType;
+ fSubArchitecture = t->cpuSubType;
+ fHasPreferredSubType = t->isSubType;
+ fArchSupportsThumb2 = t->supportsThumb2;
+ return;
}
- throwf("unknown/unsupported architecture name for: -arch %s", arch);
}
+ throwf("unknown/unsupported architecture name for: -arch %s", arch);
}
bool Options::checkForFile(const char* format, const char* dir, const char* rootName, FileInfo& result) const
{
- struct stat statBuffer;
char possiblePath[strlen(dir)+strlen(rootName)+strlen(format)+8];
sprintf(possiblePath, format, dir, rootName);
- bool found = (stat(possiblePath, &statBuffer) == 0);
+ bool found = result.checkFileExists(*this, possiblePath);
if ( fTraceDylibSearching )
printf("[Logging for XBS]%sfound library: '%s'\n", (found ? " " : " not "), possiblePath);
- if ( found ) {
- result.path = strdup(possiblePath);
- result.fileLen = statBuffer.st_size;
- result.modTime = statBuffer.st_mtime;
- return true;
- }
- return false;
+ return found;
}
-Options::FileInfo Options::findLibrary(const char* rootName, bool dylibsOnly)
+Options::FileInfo Options::findLibrary(const char* rootName, bool dylibsOnly) const
{
FileInfo result;
const int rootNameLen = strlen(rootName);
// if rootName ends in .o there is no .a vs .dylib choice
if ( (rootNameLen > 3) && (strcmp(&rootName[rootNameLen-2], ".o") == 0) ) {
- for (std::vector<const char*>::iterator it = fLibrarySearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fLibrarySearchPaths.begin();
it != fLibrarySearchPaths.end();
it++) {
const char* dir = *it;
}
}
else {
- bool lookForDylibs = ( fOutputKind != Options::kDyld);
+ bool lookForDylibs = false;
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ case Options::kObjectFile: // <rdar://problem/15914513>
+ lookForDylibs = true;
+ break;
+ case Options::kStaticExecutable:
+ case Options::kDyld:
+ case Options::kPreload:
+ case Options::kKextBundle:
+ lookForDylibs = false;
+ break;
+ }
switch ( fLibrarySearchMode ) {
case kSearchAllDirsForDylibsThenAllDirsForArchives:
// first look in all directories for just for dylibs
if ( lookForDylibs ) {
- for (std::vector<const char*>::iterator it = fLibrarySearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fLibrarySearchPaths.begin();
it != fLibrarySearchPaths.end();
it++) {
const char* dir = *it;
if ( checkForFile("%s/lib%s.dylib", dir, rootName, result) )
return result;
}
- for (std::vector<const char*>::iterator it = fLibrarySearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fLibrarySearchPaths.begin();
it != fLibrarySearchPaths.end();
it++) {
const char* dir = *it;
}
// next look in all directories for just for archives
if ( !dylibsOnly ) {
- for (std::vector<const char*>::iterator it = fLibrarySearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fLibrarySearchPaths.begin();
it != fLibrarySearchPaths.end();
it++) {
const char* dir = *it;
case kSearchDylibAndArchiveInEachDir:
// look in each directory for just for a dylib then for an archive
- for (std::vector<const char*>::iterator it = fLibrarySearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fLibrarySearchPaths.begin();
it != fLibrarySearchPaths.end();
it++) {
const char* dir = *it;
throwf("library not found for -l%s", rootName);
}
-Options::FileInfo Options::findFramework(const char* frameworkName)
+Options::FileInfo Options::findFramework(const char* frameworkName) const
{
if ( frameworkName == NULL )
throw "-framework missing next argument";
return findFramework(name, suffix);
}
-Options::FileInfo Options::findFramework(const char* rootName, const char* suffix)
+Options::FileInfo Options::findFramework(const char* rootName, const char* suffix) const
{
- struct stat statBuffer;
- for (std::vector<const char*>::iterator it = fFrameworkSearchPaths.begin();
+ for (std::vector<const char*>::const_iterator it = fFrameworkSearchPaths.begin();
it != fFrameworkSearchPaths.end();
it++) {
// ??? Shouldn't we be using String here and just initializing it?
strcat(possiblePath, suffix);
}
}
- bool found = (stat(possiblePath, &statBuffer) == 0);
+ FileInfo result;
+ bool found = result.checkFileExists(*this, possiblePath);
if ( fTraceDylibSearching )
printf("[Logging for XBS]%sfound framework: '%s'\n",
(found ? " " : " not "), possiblePath);
if ( found ) {
- FileInfo result;
- result.path = strdup(possiblePath);
- result.fileLen = statBuffer.st_size;
- result.modTime = statBuffer.st_mtime;
return result;
}
}
Options::FileInfo Options::findFile(const char* path) const
{
FileInfo result;
- struct stat statBuffer;
// if absolute path and not a .o file, the use SDK prefix
if ( (path[0] == '/') && (strcmp(&path[strlen(path)-2], ".o") != 0) ) {
if ( possiblePath[sdkPathDirLen-1] == '/' )
possiblePath[sdkPathDirLen-1] = '\0';
strcat(possiblePath, path);
- if ( stat(possiblePath, &statBuffer) == 0 ) {
- result.path = strdup(possiblePath);
- result.fileLen = statBuffer.st_size;
- result.modTime = statBuffer.st_mtime;
+ if ( result.checkFileExists(*this, possiblePath) ) {
return result;
}
}
}
// try raw path
- if ( stat(path, &statBuffer) == 0 ) {
- result.path = strdup(path);
- result.fileLen = statBuffer.st_size;
- result.modTime = statBuffer.st_mtime;
+ if ( result.checkFileExists(*this, path) ) {
return result;
}
strcpy(&addPoint[1], &path[17]);
else
strcpy(newPath, &path[17]);
- if ( stat(newPath, &statBuffer) == 0 ) {
- result.path = strdup(newPath);
- result.fileLen = statBuffer.st_size;
- result.modTime = statBuffer.st_mtime;
+ if ( result.checkFileExists(*this, newPath) ) {
return result;
}
}
// If we didn't find it fall back to findFile.
return findFile(path);
}
-
+
+
void Options::parseSegAddrTable(const char* segAddrPath, const char* installPth)
{
fclose(file);
}
-void Options::loadFileList(const char* fileOfPaths)
+void Options::loadFileList(const char* fileOfPaths, ld::File::Ordinal baseOrdinal)
{
FILE* file;
const char* comma = strrchr(fileOfPaths, ',');
realFileOfPaths[realFileOfPathsLen] = '\0';
file = fopen(realFileOfPaths, "r");
if ( file == NULL )
- throwf("-filelist file not found: %s\n", realFileOfPaths);
+ throwf("-filelist file '%s' could not be opened, errno=%d (%s)\n", realFileOfPaths, errno, strerror(errno));
+ if ( this->dumpDependencyInfo() )
+ this->dumpDependency(Options::depFileList, realFileOfPaths);
}
}
else {
file = fopen(fileOfPaths, "r");
if ( file == NULL )
- throwf("-filelist file not found: %s\n", fileOfPaths);
+ throwf("-filelist file '%s' could not be opened, errno=%d (%s)\n", fileOfPaths, errno, strerror(errno));
+ if ( this->dumpDependencyInfo() )
+ this->dumpDependency(Options::depFileList, fileOfPaths);
}
char path[PATH_MAX];
+ ld::File::Ordinal previousOrdinal = baseOrdinal;
while ( fgets(path, PATH_MAX, file) != NULL ) {
path[PATH_MAX-1] = '\0';
char* eol = strchr(path, '\n');
strcpy(builtPath, prefix);
strcat(builtPath, "/");
strcat(builtPath, path);
- fInputFiles.push_back(findFile(builtPath));
+ if (fPipelineFifo != NULL) {
+ FileInfo info = FileInfo(builtPath);
+ info.ordinal = previousOrdinal.nextFileListOrdinal();
+ previousOrdinal = info.ordinal;
+ info.fromFileList = true;
+ fInputFiles.push_back(info);
+ } else {
+ FileInfo info = findFile(builtPath);
+ info.ordinal = previousOrdinal.nextFileListOrdinal();
+ previousOrdinal = info.ordinal;
+ info.fromFileList = true;
+ fInputFiles.push_back(info);
+ }
}
else {
- fInputFiles.push_back(findFile(path));
+ if (fPipelineFifo != NULL) {
+ FileInfo info = FileInfo(path);
+ info.ordinal = previousOrdinal.nextFileListOrdinal();
+ previousOrdinal = info.ordinal;
+ info.fromFileList = true;
+ fInputFiles.push_back(info);
+ } else {
+ FileInfo info = findFile(path);
+ info.ordinal = previousOrdinal.nextFileListOrdinal();
+ previousOrdinal = info.ordinal;
+ info.fromFileList = true;
+ fInputFiles.push_back(info);
+ }
}
}
fclose(file);
if ( read(fd, p, stat_buf.st_size) != stat_buf.st_size )
throwf("can't read %s file: %s", option, fileOfExports);
+ if ( this->dumpDependencyInfo() )
+ this->dumpDependency(Options::depMisc, fileOfExports);
+
::close(fd);
- // parse into symbols and add to hash_set
+ // parse into symbols and add to unordered_set
char * const end = &p[stat_buf.st_size];
enum { lineStart, inSymbol, inComment } state = lineStart;
char* symbolStart = NULL;
throwf("can't read alias file: %s", fileOfAliases);
p[stat_buf.st_size] = '\n';
::close(fd);
+ if ( this->dumpDependencyInfo() )
+ this->dumpDependency(Options::depMisc, fileOfAliases);
// parse into symbols and add to fAliases
AliasPair pair;
throw "-macosx_version_min argument missing";
if ( (strncmp(version, "10.", 3) == 0) && isdigit(version[3]) ) {
- unsigned int minorVersion = version[3] - '0';
+ unsigned int minorVersion = 0;
+ for (int i=3; isdigit(version[i]); ++i) {
+ minorVersion = minorVersion*10 + (version[i] - '0');
+ }
+ if ( minorVersion > 255 ) {
+ warning("Mac OS X minor version > 255 in '%s'", version);
+ minorVersion = 255;
+ }
fMacVersionMin = (ld::MacVersionMin)(0x000A0000 | (minorVersion << 8));
}
else {
throwf("can't read order file: %s", path);
::close(fd);
p[stat_buf.st_size] = '\n';
+ if ( this->dumpDependencyInfo() )
+ this->dumpDependency(Options::depMisc, path);
// parse into vector of pairs
char * const end = &p[stat_buf.st_size+1];
objFileName = symbolStart;
symbolStart = &colon[3];
}
+ else {
+ colon = strstr(symbolStart, ".o):");
+ if ( colon != NULL ) {
+ colon[3] = '\0';
+ objFileName = symbolStart;
+ symbolStart = &colon[4];
+ }
+ }
// trim leading spaces
while ( isspace(*symbolStart) )
++symbolStart;
fExtraSections.push_back(info);
}
+void Options::addSectionRename(const char* srcSegment, const char* srcSection, const char* dstSegment, const char* dstSection)
+{
+ if ( strlen(srcSegment) > 16 )
+ throw "-rename_section segment name max 16 chars";
+ if ( strlen(srcSection) > 16 )
+ throw "-rename_section section name max 16 chars";
+ if ( strlen(dstSegment) > 16 )
+ throw "-rename_section segment name max 16 chars";
+ if ( strlen(dstSection) > 16 )
+ throw "-rename_section section name max 16 chars";
+
+ SectionRename info;
+ info.fromSegment = srcSegment;
+ info.fromSection = srcSection;
+ info.toSegment = dstSegment;
+ info.toSection = dstSection;
+
+ fSectionRenames.push_back(info);
+}
+
+
void Options::addSectionAlignment(const char* segment, const char* section, const char* alignmentStr)
{
if ( strlen(segment) > 16 )
//
void Options::parse(int argc, const char* argv[])
{
+ // Store the original args in the link snapshot.
+ fLinkSnapshot.recordRawArgs(argc, argv);
+
// pass one builds search list from -L and -F options
this->buildSearchPaths(argc, argv);
const char* arg = argv[i];
if ( arg[0] == '-' ) {
+ // by default, copy one arg to the snapshot link command, and do no file copying
+ int snapshotArgIndex = i;
+ int snapshotArgCount = -1; // -1 means compute count based on change in index
+ int snapshotFileArgIndex = -1; // -1 means no data file parameter to arg
// Since we don't care about the files passed, just the option names, we do this here.
if (fPrintOptions)
fprintf (stderr, "[Logging ld64 options]\t%s\n", arg);
if ( (arg[1] == 'L') || (arg[1] == 'F') ) {
+ snapshotArgCount = 0; // stripped out of link snapshot
if (arg[2] == '\0')
++i;
// previously handled by buildSearchPaths()
fOutputKind = kKextBundle;
}
else if ( strcmp(arg, "-o") == 0 ) {
+ snapshotArgCount = 0;
fOutputFile = argv[++i];
+ fLinkSnapshot.setSnapshotName(fOutputFile);
}
else if ( strncmp(arg, "-lazy-l", 7) == 0 ) {
+ snapshotArgCount = 0;
FileInfo info = findLibrary(&arg[7], true);
info.options.fLazyLoad = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
fUsingLazyDylibLinking = true;
}
+ else if ( strcmp(arg, "-lto_library") == 0 ) {
+ snapshotFileArgIndex = 1;
+ fOverridePathlibLTO = argv[++i];
+ if ( fOverridePathlibLTO == NULL )
+ throw "missing argument to -lto_library";
+ }
else if ( (arg[1] == 'l') && (strncmp(arg,"-lazy_",6) !=0) ) {
- addLibrary(findLibrary(&arg[2]));
+ snapshotArgCount = 0;
+ FileInfo info = findLibrary(&arg[2]);
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
+ addLibrary(info);
}
// This causes a dylib to be weakly bound at
// link time. This corresponds to weak_import.
else if ( strncmp(arg, "-weak-l", 7) == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findLibrary(&arg[7]);
info.options.fWeakImport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
// Avoid lazy binding.
else if ( strcmp(arg, "-force_load") == 0 ) {
FileInfo info = findFile(argv[++i]);
info.options.fForceLoad = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
// Library versioning.
else if ( strcmp(arg, "-sectorder") == 0 ) {
if ( (argv[i+1]==NULL) || (argv[i+2]==NULL) || (argv[i+3]==NULL) )
throw "-sectorder missing <segment> <section> <file-path>";
+ snapshotFileArgIndex = 3;
parseSectionOrderFile(argv[i+1], argv[i+2], argv[i+3]);
i += 3;
}
else if ( strcmp(arg, "-order_file") == 0 ) {
+ snapshotFileArgIndex = 1;
parseOrderFile(argv[++i], false);
}
else if ( strcmp(arg, "-order_file_statistics") == 0 ) {
else if ( (strcmp(arg, "-sectcreate") == 0) || (strcmp(arg, "-segcreate") == 0) ) {
if ( (argv[i+1]==NULL) || (argv[i+2]==NULL) || (argv[i+3]==NULL) )
throw "-sectcreate missing <segment> <section> <file-path>";
+ snapshotFileArgIndex = 3;
addSection(argv[i+1], argv[i+2], argv[i+3]);
i += 3;
}
|| (strcmp(arg, "-dylinker_install_name") == 0)
|| (strcmp(arg, "-install_name") == 0)) {
fDylibInstallName = argv[++i];
- if ( fDylibInstallName == NULL )
+ if ( fDylibInstallName == NULL )
throw "-install_name missing <path>";
}
// Sets the base address of the output.
}
// Same as -@ from the FSF linker.
else if ( strcmp(arg, "-filelist") == 0 ) {
+ snapshotArgCount = 0;
const char* path = argv[++i];
if ( (path == NULL) || (path[0] == '-') )
throw "-filelist missing <path>";
- loadFileList(path);
+ ld::File::Ordinal baseOrdinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
+ loadFileList(path, baseOrdinal);
}
else if ( strcmp(arg, "-keep_private_externs") == 0 ) {
fKeepPrivateExterns = true;
}
}
else if ( strcmp(arg, "-interposable_list") == 0 ) {
+ snapshotFileArgIndex = 1;
fInterposeMode = kInterposeSome;
loadExportFile(argv[++i], "-interposable_list", fInterposeList);
}
fInterposeMode = kInterposeNone;
}
else if ( strcmp(arg, "-exported_symbols_list") == 0 ) {
+ snapshotFileArgIndex = 1;
if ( fExportMode == kDontExportSome )
throw "can't use -exported_symbols_list and -unexported_symbols_list";
fExportMode = kExportSome;
loadExportFile(argv[++i], "-exported_symbols_list", fExportSymbols);
}
else if ( strcmp(arg, "-unexported_symbols_list") == 0 ) {
+ snapshotFileArgIndex = 1;
if ( fExportMode == kExportSome )
throw "can't use -unexported_symbols_list and -exported_symbols_list";
fExportMode = kDontExportSome;
fDontExportSymbols.insert(argv[++i]);
}
else if ( strcmp(arg, "-non_global_symbols_no_strip_list") == 0 ) {
+ snapshotFileArgIndex = 1;
if ( fLocalSymbolHandling == kLocalSymbolsSelectiveExclude )
throw "can't use -non_global_symbols_no_strip_list and -non_global_symbols_strip_list";
fLocalSymbolHandling = kLocalSymbolsSelectiveInclude;
loadExportFile(argv[++i], "-non_global_symbols_no_strip_list", fLocalSymbolsIncluded);
}
else if ( strcmp(arg, "-non_global_symbols_strip_list") == 0 ) {
+ snapshotFileArgIndex = 1;
if ( fLocalSymbolHandling == kLocalSymbolsSelectiveInclude )
throw "can't use -non_global_symbols_no_strip_list and -non_global_symbols_strip_list";
fLocalSymbolHandling = kLocalSymbolsSelectiveExclude;
}
// Similar to -weak-l but uses the absolute path name to the library.
else if ( strcmp(arg, "-weak_library") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFile(argv[++i]);
info.options.fWeakImport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-lazy_library") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFile(argv[++i]);
info.options.fLazyLoad = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
fUsingLazyDylibLinking = true;
}
else if ( strcmp(arg, "-framework") == 0 ) {
- addLibrary(findFramework(argv[++i]));
+ snapshotArgCount = 0;
+ FileInfo info = findFramework(argv[++i]);
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
+ addLibrary(info);
}
else if ( strcmp(arg, "-weak_framework") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFramework(argv[++i]);
info.options.fWeakImport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-lazy_framework") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFramework(argv[++i]);
info.options.fLazyLoad = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
fUsingLazyDylibLinking = true;
}
// previously handled by buildSearchPaths()
}
else if ( strcmp(arg, "-undefined") == 0 ) {
- setUndefinedTreatment(argv[++i]);
+ setUndefinedTreatment(argv[++i]);
}
// Debugging output flag.
else if ( strcmp(arg, "-arch_multiple") == 0 ) {
// Warn, error or make strong a mismatch between weak
// and non-weak references.
else if ( strcmp(arg, "-weak_reference_mismatches") == 0 ) {
- setWeakReferenceMismatchTreatment(argv[++i]);
+ setWeakReferenceMismatchTreatment(argv[++i]);
}
// For a deployment target of 10.3 and earlier ld64 will
// prebind an executable with 0s in all addresses that
// This should probably be deprecated when we respect -L and -F
// when searching for libraries.
else if ( strcmp(arg, "-dylib_file") == 0 ) {
+ // ignore for snapshot because a stub dylib will be created in the snapshot
+ snapshotArgCount = 0;
addDylibOverride(argv[++i]);
}
// What to expand @executable_path to if found in dependent dylibs
}
// ??? Deprecate when we get rid of basing at build time.
else if ( strcmp(arg, "-seg_addr_table") == 0 ) {
+ snapshotFileArgIndex = 1;
const char* name = argv[++i];
if ( name == NULL )
throw "-seg_addr_table missing argument";
i += 2;
}
else if ( strcmp(arg, "-bundle_loader") == 0 ) {
+ snapshotFileArgIndex = 1;
fBundleLoader = argv[++i];
if ( (fBundleLoader == NULL) || (fBundleLoader[0] == '-') )
throw "-bundle_loader missing <path>";
FileInfo info = findFile(fBundleLoader);
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
info.options.fBundleLoader = true;
fInputFiles.push_back(info);
}
}
// Use this flag to set default behavior for deployement targets.
else if ( strcmp(arg, "-macosx_version_min") == 0 ) {
- setMacOSXVersionMin(argv[++i]);
+ const char* macVers = argv[++i];
+ const char* envMacVers = getenv("MACOSX_DEPLOYMENT_TARGET");
+ const char* enviPhoneVers = getenv("IPHONEOS_DEPLOYMENT_TARGET");
+ if ( (envMacVers != NULL) && (enviPhoneVers != NULL) ) {
+ // <rdar://problem/13774329> when conflicting deployments set, break tie by looking at syslibroot
+ warning("both MACOSX_DEPLOYMENT_TARGET and IPHONEOS_DEPLOYMENT_TARGET are set");
+ if ( !fSDKPaths.empty() ) {
+ const char* sysrootPath = fSDKPaths.back();
+ const char* lastSlash = strrchr(sysrootPath, '/');
+ if ( strstr(lastSlash, "Simulator") != NULL )
+ setIOSVersionMin(enviPhoneVers);
+ else
+ setMacOSXVersionMin(macVers);
+ }
+ else {
+ setMacOSXVersionMin(macVers);
+ }
+ }
+ else {
+ setMacOSXVersionMin(macVers);
+ }
}
else if ( (strcmp(arg, "-ios_version_min") == 0) || (strcmp(arg, "-iphoneos_version_min") == 0) ) {
setIOSVersionMin(argv[++i]);
}
else if ( strcmp(arg, "-ios_simulator_version_min") == 0 ) {
setIOSVersionMin(argv[++i]);
+ fTargetIOSSimulator = true;
}
else if ( strcmp(arg, "-multiply_defined") == 0 ) {
//warnObsolete(arg);
// previously handled by buildSearchPaths()
}
else if ( strcmp(arg, "-syslibroot") == 0 ) {
+ snapshotArgCount = 0;
++i;
// previously handled by buildSearchPaths()
}
fUUIDMode = kUUIDRandom;
}
else if ( strcmp(arg, "-dtrace") == 0 ) {
+ snapshotFileArgIndex = 1;
const char* name = argv[++i];
if ( name == NULL )
throw "-dtrace missing argument";
fAliases.push_back(pair);
}
else if ( strcmp(arg, "-alias_list") == 0 ) {
+ snapshotFileArgIndex = 1;
parseAliasFile(argv[++i]);
}
- // put this last so that it does not interfer with other options starting with 'i'
- else if ( strncmp(arg, "-i", 2) == 0 ) {
- const char* colon = strchr(arg, ':');
- if ( colon == NULL )
- throwf("unknown option: %s", arg);
- Options::AliasPair pair;
- char* temp = new char[colon-arg];
- strlcpy(temp, &arg[2], colon-arg-1);
- pair.realName = &colon[1];
- pair.alias = temp;
- fAliases.push_back(pair);
- }
else if ( strcmp(arg, "-save-temps") == 0 ) {
fSaveTempFiles = true;
}
fDisablePositionIndependentExecutable = true;
}
else if ( strncmp(arg, "-reexport-l", 11) == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findLibrary(&arg[11], true);
info.options.fReExport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-reexport_library") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFile(argv[++i]);
info.options.fReExport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-reexport_framework") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFramework(argv[++i]);
info.options.fReExport = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strncmp(arg, "-upward-l", 9) == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findLibrary(&arg[9], true);
info.options.fUpward = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-upward_library") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFile(argv[++i]);
info.options.fUpward = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-upward_framework") == 0 ) {
+ // SNAPSHOT FIXME: what should we do for link snapshots? (ignore for now)
+ snapshotArgCount = 0;
FileInfo info = findFramework(argv[++i]);
info.options.fUpward = true;
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
addLibrary(info);
}
else if ( strcmp(arg, "-dead_strip_dylibs") == 0 ) {
throw "missing argument to -mllvm";
fLLVMOptions.push_back(opts);
}
+ else if ( strcmp(arg, "-mcpu") == 0 ) {
+ const char* cpu = argv[++i];
+ if ( cpu == NULL )
+ throw "missing argument to -mcpu";
+ fLtoCpu = cpu;
+ }
else if ( strcmp(arg, "-no_order_inits") == 0 ) {
fAutoOrderInitializers = false;
}
fMarkDeadStrippableDylib = true;
}
else if ( strcmp(arg, "-exported_symbols_order") == 0 ) {
+ snapshotFileArgIndex = 1;
loadSymbolOrderFile(argv[++i], fExportSymbolsOrder);
}
else if ( strcmp(arg, "-no_compact_linkedit") == 0 ) {
fFunctionStartsForcedOff = true;
fFunctionStartsForcedOn = false;
}
+ else if ( strcmp(arg, "-no_data_in_code_info") == 0 ) {
+ fDataInCodeInfoLoadCommandForcedOff = true;
+ fDataInCodeInfoLoadCommandForcedOn = false;
+ }
+ else if ( strcmp(arg, "-data_in_code_info") == 0 ) {
+ fDataInCodeInfoLoadCommandForcedOn = true;
+ fDataInCodeInfoLoadCommandForcedOff = false;
+ }
else if ( strcmp(arg, "-object_path_lto") == 0 ) {
fTempLtoObjectPath = argv[++i];
if ( fTempLtoObjectPath == NULL )
fObjcCategoryMerging = false;
}
else if ( strcmp(arg, "-force_symbols_weak_list") == 0 ) {
+ snapshotFileArgIndex = 1;
loadExportFile(argv[++i], "-force_symbols_weak_list", fForceWeakSymbols);
}
else if ( strcmp(arg, "-force_symbols_not_weak_list") == 0 ) {
+ snapshotFileArgIndex = 1;
loadExportFile(argv[++i], "-force_symbols_not_weak_list", fForceNotWeakSymbols);
}
else if ( strcmp(arg, "-force_symbol_weak") == 0 ) {
fForceNotWeakSymbols.insert(symbol);
}
else if ( strcmp(arg, "-reexported_symbols_list") == 0 ) {
+ snapshotFileArgIndex = 1;
if ( fExportMode == kExportSome )
throw "can't use -exported_symbols_list and -reexported_symbols_list";
loadExportFile(argv[++i], "-reexported_symbols_list", fReExportSymbols);
}
else if ( strcmp(arg, "-page_align_data_atoms") == 0 ) {
fPageAlignDataAtoms = true;
+ }
+ else if (strcmp(arg, "-debug_snapshot") == 0) {
+ fLinkSnapshot.setSnapshotMode(Snapshot::SNAPSHOT_DEBUG);
+ fSnapshotRequested = true;
+ }
+ else if (strcmp(arg, "-snapshot_dir") == 0) {
+ const char* path = argv[++i];
+ if ( path == NULL )
+ throw "-snapshot_dir missing path";
+ fLinkSnapshot.setSnapshotMode(Snapshot::SNAPSHOT_DEBUG);
+ fLinkSnapshot.setSnapshotPath(path);
+ fSnapshotRequested = true;
+ }
+ else if ( strcmp(arg, "-new_main") == 0 ) {
+ fEntryPointLoadCommandForceOn = true;
+ }
+ else if ( strcmp(arg, "-no_new_main") == 0 ) {
+ fEntryPointLoadCommandForceOff = true;
+ }
+ else if ( strcmp(arg, "-source_version") == 0 ) {
+ const char* vers = argv[++i];
+ if ( vers == NULL )
+ throw "-source_version missing <version>";
+ fSourceVersion = parseVersionNumber64(vers);
+ }
+ else if ( strcmp(arg, "-add_source_version") == 0 ) {
+ fSourceVersionLoadCommandForceOn = true;
+ }
+ else if ( strcmp(arg, "-no_source_version") == 0 ) {
+ fSourceVersionLoadCommandForceOff = true;
+ }
+ else if ( strcmp(arg, "-sdk_version") == 0 ) {
+ const char* vers = argv[++i];
+ if ( vers == NULL )
+ throw "-sdk_version missing <version>";
+ fSDKVersion = parseVersionNumber32(vers);
+ }
+ else if ( strcmp(arg, "-dependent_dr_info") == 0 ) {
+ fDependentDRInfoForcedOn = true;
+ }
+ else if ( strcmp(arg, "-no_dependent_dr_info") == 0 ) {
+ fDependentDRInfoForcedOff = true;
+ }
+ else if ( strcmp(arg, "-kexts_use_stubs") == 0 ) {
+ fKextsUseStubs = true;
+ }
+ else if ( strcmp(argv[i], "-dependency_info") == 0 ) {
+ ++i;
+ // previously handled by buildSearchPaths()
+ }
+ else if ( strcmp(arg, "-export_dynamic") == 0 ) {
+ fExportDynamic = true;
+ }
+ else if ( strcmp(arg, "-force_symbols_coalesce_list") == 0 ) {
+ snapshotFileArgIndex = 1;
+ loadExportFile(argv[++i], "-force_symbols_coalesce_list", fForceCoalesceSymbols);
+ }
+ else if ( strcmp(arg, "-add_linker_option") == 0 ) {
+ // ex: -add_linker_option '-framework Foundation'
+ const char* optString = argv[++i];
+ if ( optString == NULL )
+ throw "-add_linker_option missing <option>";
+ // break up into list of tokens at whitespace
+ std::vector<const char*> opts;
+ char* buffer = strdup(optString);
+ char* start = buffer;
+ for (char* s = buffer; ; ++s) {
+ if ( isspace(*s) ) {
+ *s = '\0';
+ opts.push_back(start);
+ start = s+1;
+ }
+ else if ( *s == '\0' ) {
+ opts.push_back(start);
+ break;
+ }
+ }
+ fLinkerOptions.push_back(opts);
+ }
+ else if ( strcmp(arg, "-allow_simulator_linking_to_macosx_dylibs") == 0 ) {
+ fAllowSimulatorToLinkWithMacOSX = true;
+ }
+ else if ( strcmp(arg, "-keep_dwarf_unwind") == 0 ) {
+ fKeepDwarfUnwindForcedOn = true;
+ fKeepDwarfUnwindForcedOff = false;
+ }
+ else if ( strcmp(arg, "-no_keep_dwarf_unwind") == 0 ) {
+ fKeepDwarfUnwindForcedOn = false;
+ fKeepDwarfUnwindForcedOff = true;
+ }
+ else if ( strcmp(arg, "-verbose_optimization_hints") == 0 ) {
+ fVerboseOptimizationHints = true;
+ }
+ else if ( strcmp(arg, "-ignore_optimization_hints") == 0 ) {
+ fIgnoreOptimizationHints = true;
+ }
+ else if ( strcmp(arg, "-no_dtrace_dof") == 0 ) {
+ fGenerateDtraceDOF = false;
+ }
+ else if ( strcmp(arg, "-rename_section") == 0 ) {
+ if ( (argv[i+1]==NULL) || (argv[i+2]==NULL) || (argv[i+3]==NULL) || (argv[i+4]==NULL) )
+ throw "-rename_section missing <segment> <section> <segment> <section>";
+ addSectionRename(argv[i+1], argv[i+2], argv[i+3], argv[i+4]);
+ i += 4;
+ }
+ else if ( strcmp(arg, "-no_branch_islands") == 0 ) {
+ fAllowBranchIslands = false;
+ }
+ // put this last so that it does not interfer with other options starting with 'i'
+ else if ( strncmp(arg, "-i", 2) == 0 ) {
+ const char* colon = strchr(arg, ':');
+ if ( colon == NULL )
+ throwf("unknown option: %s", arg);
+ Options::AliasPair pair;
+ char* temp = new char[colon-arg];
+ strlcpy(temp, &arg[2], colon-arg-1);
+ pair.realName = &colon[1];
+ pair.alias = temp;
+ fAliases.push_back(pair);
}
else {
throwf("unknown option: %s", arg);
}
+
+ if (snapshotArgCount == -1)
+ snapshotArgCount = i-snapshotArgIndex+1;
+ if (snapshotArgCount > 0)
+ fLinkSnapshot.addSnapshotLinkArg(snapshotArgIndex, snapshotArgCount, snapshotFileArgIndex);
}
else {
FileInfo info = findFile(arg);
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)i);
if ( strcmp(&info.path[strlen(info.path)-2], ".a") == 0 )
addLibrary(info);
else
// if a -lazy option was used, implicitly link in lazydylib1.o
if ( fUsingLazyDylibLinking ) {
- addLibrary(findLibrary("lazydylib1.o"));
+ FileInfo info = findLibrary("lazydylib1.o");
+ info.ordinal = ld::File::Ordinal::makeArgOrdinal((uint16_t)argc);
+ addLibrary(info);
}
+
+ if (fSnapshotRequested)
+ fLinkSnapshot.createSnapshot();
}
fVerbose = true;
extern const char ldVersionString[];
fprintf(stderr, "%s", ldVersionString);
+ fprintf(stderr, "configured to support archs: %s\n", ALL_SUPPORTED_ARCHS);
// if only -v specified, exit cleanly
if ( argc == 2 ) {
const char* ltoVers = lto::version();
if ( ltoVers != NULL )
- fprintf(stderr, "%s\n", ltoVers);
+ fprintf(stderr, "LTO support using: %s\n", ltoVers);
exit(0);
}
}
else if ( strcmp(argv[i], "-fatal_warnings") == 0 ) {
sFatalWarnings = true;
}
+ else if ( strcmp(argv[i], "-dependency_info") == 0 ) {
+ const char* path = argv[++i];
+ if ( path == NULL )
+ throw "-dependency_info missing <path>";
+ fDependencyInfoPath = path;
+ }
}
int standardLibraryPathsStartIndex = libraryPaths.size();
int standardFrameworkPathsStartIndex = frameworkPaths.size();
const char* customDyldPath = getenv("LD_DYLD_PATH");
if ( customDyldPath != NULL )
fDyldInstallPath = customDyldPath;
+
+ const char* debugArchivePath = getenv("LD_DEBUG_SNAPSHOT");
+ if (debugArchivePath != NULL) {
+ fLinkSnapshot.setSnapshotMode(Snapshot::SNAPSHOT_DEBUG);
+ if (strlen(debugArchivePath) > 0)
+ fLinkSnapshot.setSnapshotPath(debugArchivePath);
+ fSnapshotRequested = true;
+ }
+
+ const char* pipeFdString = getenv("LD_PIPELINE_FIFO");
+ if (pipeFdString != NULL) {
+ fPipelineFifo = pipeFdString;
+ }
}
// allow build system to force on -warn_commons
if ( getenv("LD_WARN_COMMONS") != NULL )
fWarnCommons = true;
+
+ // allow B&I to set default -source_version
+ if ( fSourceVersion == 0 ) {
+ const char* vers = getenv("RC_ProjectSourceVersion");
+ if ( vers != NULL )
+ fSourceVersion = parseVersionNumber64(vers);
+ }
}
case CPU_TYPE_X86_64:
if ( (fOutputKind != Options::kObjectFile) && (fOutputKind != Options::kPreload) ) {
#ifdef DEFAULT_MACOSX_MIN_VERSION
- warning("-macosx_version_min not specificed, assuming " DEFAULT_MACOSX_MIN_VERSION);
+ warning("-macosx_version_min not specified, assuming " DEFAULT_MACOSX_MIN_VERSION);
setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
#else
- warning("-macosx_version_min not specificed, assuming 10.6");
+ warning("-macosx_version_min not specified, assuming 10.6");
fMacVersionMin = ld::mac10_6;
#endif
}
case CPU_TYPE_ARM:
if ( (fOutputKind != Options::kObjectFile) && (fOutputKind != Options::kPreload) ) {
#if defined(DEFAULT_IPHONEOS_MIN_VERSION)
- warning("-ios_version_min not specificed, assuming " DEFAULT_IPHONEOS_MIN_VERSION);
+ warning("-ios_version_min not specified, assuming " DEFAULT_IPHONEOS_MIN_VERSION);
setIOSVersionMin(DEFAULT_IPHONEOS_MIN_VERSION);
- #elif defined(DEFAULT_MACOSX_MIN_VERSION)
- warning("-macosx_version_min not specificed, assuming " DEFAULT_MACOSX_MIN_VERSION);
- setMacOSXVersionMin(DEFAULT_MACOSX_MIN_VERSION);
#else
- warning("-macosx_version_min not specificed, assuming 10.6");
- fMacVersionMin = ld::mac10_6;
+ warning("-ios_version_min not specified, assuming 6.0");
+ setIOSVersionMin("6.0");
#endif
}
break;
default:
- // architecture will be infered ;ater by examining .o files
+ // architecture will be infered later by examining .o files
break;
}
}
}
break;
case CPU_TYPE_X86_64:
- if ( fMacVersionMin < ld::mac10_4 ) {
+ if ( (fMacVersionMin < ld::mac10_4) && (fIOSVersionMin == ld::iOSVersionUnset) ) {
//warning("-macosx_version_min should be 10.4 or later for x86_64");
fMacVersionMin = ld::mac10_4;
}
break;
+ case CPU_TYPE_ARM64:
+ if ( fIOSVersionMin < ld::iOS_7_0 ) {
+ //warning("-mios_version_min should be 7.0 or later for arm64");
+ fIOSVersionMin = ld::iOS_7_0;
+ }
+ break;
}
+ // default to adding functions start for dynamic code, static code must opt-in
+ switch ( fOutputKind ) {
+ case Options::kPreload:
+ case Options::kStaticExecutable:
+ case Options::kKextBundle:
+ if ( fDataInCodeInfoLoadCommandForcedOn )
+ fDataInCodeInfoLoadCommand = true;
+ if ( fFunctionStartsForcedOn )
+ fFunctionStartsLoadCommand = true;
+ break;
+ case Options::kObjectFile:
+ if ( !fDataInCodeInfoLoadCommandForcedOff )
+ fDataInCodeInfoLoadCommand = true;
+ if ( fFunctionStartsForcedOn )
+ fFunctionStartsLoadCommand = true;
+ break;
+ case Options::kDynamicExecutable:
+ case Options::kDyld:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ if ( !fDataInCodeInfoLoadCommandForcedOff )
+ fDataInCodeInfoLoadCommand = true;
+ if ( !fFunctionStartsForcedOff )
+ fFunctionStartsLoadCommand = true;
+ break;
+ }
+
// adjust kext type based on architecture
if ( fOutputKind == kKextBundle ) {
switch ( fArchitecture ) {
fAllowTextRelocs = true;
fUndefinedTreatment = kUndefinedDynamicLookup;
break;
+ case CPU_TYPE_ARM64:
+ // arm64 uses new MH_KEXT_BUNDLE type
+ fMakeCompressedDyldInfo = false;
+ fMakeCompressedDyldInfoForceOff = true;
+ fAllowTextRelocs = false;
+ fKextsUseStubs = true;
+ fUndefinedTreatment = kUndefinedDynamicLookup;
+ break;
case CPU_TYPE_ARM:
if ( fIOSVersionMin >= ld::iOS_5_0 ) {
// iOS 5.0 and later use new MH_KEXT_BUNDLE type
fMakeCompressedDyldInfo = false;
fMakeCompressedDyldInfoForceOff = true;
- fAllowTextRelocs = true;
+ // kexts are PIC in iOS 6.0 and later
+ fAllowTextRelocs = (fIOSVersionMin < ld::iOS_6_0);
+ fKextsUseStubs = !fAllowTextRelocs;
fUndefinedTreatment = kUndefinedDynamicLookup;
break;
}
// <rdar://problem/5366363> -r -x implies -S
if ( (fOutputKind == Options::kObjectFile) && (fLocalSymbolHandling == kLocalSymbolsNone) )
fDebugInfoStripping = Options::kDebugInfoNone;
-
+
+ // <rdar://problem/15252891> -r implies -no_uuid
+ if ( fOutputKind == Options::kObjectFile )
+ fUUIDMode = kUUIDNone;
+
// choose how to process unwind info
switch ( fArchitecture ) {
case CPU_TYPE_I386:
case CPU_TYPE_X86_64:
+ case CPU_TYPE_ARM64:
switch ( fOutputKind ) {
case Options::kObjectFile:
case Options::kStaticExecutable:
break;
}
- // only ARM main executables can be encrypted
+ // only iOS main executables should be encrypted
if ( fOutputKind != Options::kDynamicExecutable )
fEncryptable = false;
- if ( fArchitecture != CPU_TYPE_ARM )
+ if ( (fArchitecture != CPU_TYPE_ARM) && (fArchitecture != CPU_TYPE_ARM64) )
fEncryptable = false;
// don't move inits in dyld because dyld wants certain
// only use compressed LINKEDIT for:
- // x86_64 and i386 on Mac OS X 10.6 or later
- // arm on iPhoneOS 3.1 or later
+ // Mac OS X 10.6 or later
+ // iOS 3.1 or later
if ( fMakeCompressedDyldInfo ) {
- switch (fArchitecture) {
- case CPU_TYPE_I386:
- if ( fIOSVersionMin != ld::iOSVersionUnset ) // simulator always uses compressed LINKEDIT
- break;
- case CPU_TYPE_X86_64:
- if ( fMacVersionMin < ld::mac10_6 )
- fMakeCompressedDyldInfo = false;
- break;
- case CPU_TYPE_ARM:
- if ( !minOS(ld::mac10_6, ld::iOS_3_1) )
- fMakeCompressedDyldInfo = false;
- break;
- default:
- fMakeCompressedDyldInfo = false;
- }
+ if ( !minOS(ld::mac10_6, ld::iOS_3_1) )
+ fMakeCompressedDyldInfo = false;
}
+ // only ARM and x86_64 enforces that cpu-sub-types must match
+ switch ( fArchitecture ) {
+ case CPU_TYPE_ARM:
+ case CPU_TYPE_X86_64:
+ break;
+ case CPU_TYPE_I386:
+ case CPU_TYPE_ARM64:
+ fAllowCpuSubtypeMismatches = true;
+ break;
+ }
- // only ARM enforces that cpu-sub-types must match
- if ( fArchitecture != CPU_TYPE_ARM )
- fAllowCpuSubtypeMismatches = true;
// only final linked images can not optimize zero fill sections
if ( fOutputKind == Options::kObjectFile )
if ( fDisablePositionIndependentExecutable )
fPositionIndependentExecutable = false;
+ // arm64 is always PIE
+ if ( (fArchitecture == CPU_TYPE_ARM64) && (fOutputKind == kDynamicExecutable) ) {
+ fPositionIndependentExecutable = true;
+ }
+
// set fOutputSlidable
switch ( fOutputKind ) {
case Options::kObjectFile:
- case Options::kStaticExecutable:
fOutputSlidable = false;
break;
+ case Options::kStaticExecutable:
case Options::kDynamicExecutable:
fOutputSlidable = fPositionIndependentExecutable;
break;
if ( fMacVersionMin >= ld::mac10_7 ) {
fTLVSupport = true;
}
-
+ else if ( (fArchitecture == CPU_TYPE_ARM64) && (fIOSVersionMin >= 0x00080000) ) {
+ fTLVSupport = true;
+ }
+
// default to adding version load command for dynamic code, static code must opt-in
switch ( fOutputKind ) {
case Options::kObjectFile:
case Options::kDynamicBundle:
if ( !fVersionLoadCommandForcedOff )
fVersionLoadCommand = true;
- // <rdar://problem/9945513> for now, don't create version load commands for iOS simulator builds
- if ( fVersionLoadCommand && (fArchitecture == CPU_TYPE_I386) ) {
- for (std::vector<const char*>::iterator sdkit = fSDKPaths.begin(); sdkit != fSDKPaths.end(); sdkit++) {
- if ( strstr(*sdkit, "/iPhoneSimulator.platform/") != NULL )
- fVersionLoadCommand = false;
- }
- }
break;
}
- // default to adding functions start for dynamic code, static code must opt-in
- switch ( fOutputKind ) {
- case Options::kObjectFile:
- fFunctionStartsLoadCommand = false;
- break;
- case Options::kPreload:
- case Options::kStaticExecutable:
- case Options::kKextBundle:
- if ( fFunctionStartsForcedOn )
- fFunctionStartsLoadCommand = true;
- break;
- case Options::kDynamicExecutable:
- case Options::kDyld:
- case Options::kDynamicLibrary:
- case Options::kDynamicBundle:
- if ( !fFunctionStartsForcedOff )
- fFunctionStartsLoadCommand = true;
- break;
- }
-
// support re-export of individual symbols in MacOSX 10.7 and iOS 4.2
if ( (fOutputKind == kDynamicLibrary) && minOS(ld::mac10_7, ld::iOS_4_2) )
fCanReExportSymbols = true;
// on the command line
if ( (fArchitecture == CPU_TYPE_I386) && (fOutputKind == kDynamicExecutable) && !fDisableNonExecutableHeap)
fNonExecutableHeap = true;
+
+ // Use LC_MAIN instead of LC_UNIXTHREAD for newer OSs
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ if ( fEntryPointLoadCommandForceOn ) {
+ fEntryPointLoadCommand = true;
+ fEntryName = "_main";
+ }
+ else if ( fEntryPointLoadCommandForceOff ) {
+ fNeedsThreadLoadCommand = true;
+ }
+ else {
+ if ( minOS(ld::mac10_8, ld::iOS_6_0) ) {
+ fEntryPointLoadCommand = true;
+ fEntryName = "_main";
+ }
+ else
+ fNeedsThreadLoadCommand = true;
+ }
+ break;
+ case Options::kObjectFile:
+ case Options::kKextBundle:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ break;
+
+ case Options::kStaticExecutable:
+ case Options::kPreload:
+ case Options::kDyld:
+ fNeedsThreadLoadCommand = true;
+ break;
+ }
+
+ // add LC_SOURCE_VERSION
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ case Options::kKextBundle:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ case Options::kDyld:
+ case Options::kStaticExecutable:
+ if ( fSourceVersionLoadCommandForceOn ) {
+ fSourceVersionLoadCommand = true;
+ }
+ else if ( fSourceVersionLoadCommandForceOff ) {
+ fSourceVersionLoadCommand = false;
+ }
+ else {
+ if ( minOS(ld::mac10_8, ld::iOS_6_0) ) {
+ fSourceVersionLoadCommand = true;
+ }
+ else
+ fSourceVersionLoadCommand = false;
+ }
+ break;
+ case Options::kObjectFile:
+ case Options::kPreload:
+ fSourceVersionLoadCommand = false;
+ break;
+ }
+
+
+ // add LC_DYLIB_CODE_SIGN_DRS
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ if ( fDependentDRInfoForcedOn ) {
+ fDependentDRInfo = true;
+ }
+ else if ( fDependentDRInfoForcedOff ) {
+ fDependentDRInfo = false;
+ }
+ else {
+ if ( minOS(ld::mac10_8, ld::iOS_6_0) )
+ fDependentDRInfo = true;
+ else
+ fDependentDRInfo = false;
+ }
+ break;
+ case Options::kKextBundle:
+ case Options::kDyld:
+ case Options::kStaticExecutable:
+ case Options::kObjectFile:
+ case Options::kPreload:
+ fDependentDRInfo = false;
+ break;
+ }
+
+ // if -sdk_version not on command line, infer from -syslibroot
+ if ( (fSDKVersion == 0) && (fSDKPaths.size() > 0) ) {
+ const char* sdkPath = fSDKPaths.front();
+ const char* end = &sdkPath[strlen(sdkPath)-1];
+ while ( !isdigit(*end) && (end > sdkPath) )
+ --end;
+ const char* start = end-1;
+ while ( (isdigit(*start) || (*start == '.')) && (start > sdkPath))
+ --start;
+ char sdkVersionStr[32];
+ int len = end-start+1;
+ if ( len > 2 ) {
+ strlcpy(sdkVersionStr, start+1, len);
+ fSDKVersion = parseVersionNumber32(sdkVersionStr);
+ }
+ }
+
+ // if -sdk_version and -syslibroot not used, but targeting MacOSX, use current OS version
+ if ( (fSDKVersion == 0) && (fMacVersionMin != ld::macVersionUnset) ) {
+ // special case if RC_ProjectName and MACOSX_DEPLOYMENT_TARGET are both set that sdkversion=minos
+ if ( getenv("RC_ProjectName") && getenv("MACOSX_DEPLOYMENT_TARGET") ) {
+ fSDKVersion = fMacVersionMin;
+ }
+ else {
+ int mib[2] = { CTL_KERN, KERN_OSRELEASE };
+ char kernVersStr[100];
+ size_t strlen = sizeof(kernVersStr);
+ if ( sysctl(mib, 2, kernVersStr, &strlen, NULL, 0) != -1 ) {
+ uint32_t kernVers = parseVersionNumber32(kernVersStr);
+ int minor = (kernVers >> 16) - 4; // kernel major version is 4 ahead of x in 10.x
+ fSDKVersion = 0x000A0000 + (minor << 8);
+ }
+ }
+ }
+
+ // allow trie based absolute symbols if targeting new enough OS
+ if ( fMakeCompressedDyldInfo ) {
+ if ( minOS(ld::mac10_9, ld::iOS_7_0) ) {
+ // <rdar://problem/13179029> Allow absolute symbols in export trie for device but not simulator
+ if ( !fTargetIOSSimulator )
+ fAbsoluteSymbols = true;
+ }
+ }
+
+ // <rdar://problem/12959510> iOS main executables now default to 16KB page size
+ if ( (fIOSVersionMin != ld::iOSVersionUnset) && (fOutputKind == Options::kDynamicExecutable) ) {
+ // <rdar://problem/13070042> Only third party apps should have 16KB page segments by default
+ if ( fEncryptable ) {
+ if ( fSegmentAlignment == 4096 )
+ fSegmentAlignment = 4096*4;
+ }
+ }
+
+ // <rdar://problem/12258065> ARM64 needs 16KB page size for user land code
+ if ( fArchitecture == CPU_TYPE_ARM64 ) {
+ if ( fSegmentAlignment == 4096 ) {
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ case Options::kDyld:
+ fSegmentAlignment = 4096*4;
+ break;
+ case Options::kStaticExecutable:
+ case Options::kKextBundle:
+ case Options::kObjectFile:
+ case Options::kPreload:
+ break;
+ }
+ }
+ }
+
+ // <rdar://problem/13624134> linker should not convert dwarf unwind if .o file has compact unwind section
+ switch ( fOutputKind ) {
+ case Options::kDynamicExecutable:
+ case Options::kDynamicLibrary:
+ case Options::kDynamicBundle:
+ case Options::kDyld:
+ if ( fKeepDwarfUnwindForcedOn ) {
+ fKeepDwarfUnwind = true;
+ }
+ else if ( fKeepDwarfUnwindForcedOff ) {
+ fKeepDwarfUnwind = false;
+ }
+ else {
+ if ( minOS(ld::mac10_9, ld::iOS_7_0) )
+ fKeepDwarfUnwind = false;
+ else
+ fKeepDwarfUnwind = true;
+ }
+ break;
+ case Options::kKextBundle:
+ case Options::kStaticExecutable:
+ case Options::kObjectFile:
+ case Options::kPreload:
+ fKeepDwarfUnwind = true;
+ break;
+ }
+
}
void Options::checkIllegalOptionCombinations()
if ( strcmp(&lastSlash[1], subUmbrella) == 0 ) {
info.options.fReExport = true;
found = true;
+ fLinkSnapshot.recordSubUmbrella(info.path);
break;
}
}
if ( strncmp(&lastSlash[1], subLibrary, dot-lastSlash-1) == 0 ) {
info.options.fReExport = true;
found = true;
+ fLinkSnapshot.recordSubLibrary(info.path);
break;
}
}
throw "-stack_addr must be < 4G for 32-bit processes";
break;
case CPU_TYPE_X86_64:
+ case CPU_TYPE_ARM64:
break;
}
if ( (fStackAddr & -4096) != fStackAddr )
fStackAddr = 0x2F000000;
if ( fStackAddr > 0x30000000)
throw "-stack_addr must be < 0x30000000 for arm";
+ break;
case CPU_TYPE_X86_64:
if ( fStackAddr == 0 ) {
fStackAddr = 0x00007FFF5C000000LL;
}
break;
+ case CPU_TYPE_ARM64:
+ if ( fStackSize > 0x20000000 )
+ throw "-stack_size must be < 512MB";
+ if ( fStackAddr == 0 ) {
+ fStackAddr = 0x120000000;
+ }
+ break;
}
if ( (fStackSize & -4096) != fStackSize )
throw "-stack_size must be multiples of 4K";
if ( fSetuidSafe && (fOutputKind == Options::kObjectFile) )
throw "-setuid_safe cannot be used with -r";
+ // <rdar://problem/12781832> compiler driver no longer uses -objc_abi_version, it uses -ios_simulator_version_min instead
+ if ( !fObjCABIVersion1Override && !fObjCABIVersion2Override && fTargetIOSSimulator )
+ fObjCABIVersion2Override = true;
+
// rdar://problem/4718189 map ObjC class names to new runtime names
bool alterObjC1ClassNamesToObjC2 = false;
switch (fArchitecture) {
break;
case CPU_TYPE_X86_64:
case CPU_TYPE_ARM:
+ case CPU_TYPE_ARM64:
alterObjC1ClassNamesToObjC2 = true;
break;
}
// first 4KB for 32-bit architectures
fZeroPageSize = 0x1000;
break;
+ case CPU_TYPE_ARM64:
case CPU_TYPE_X86_64:
// first 4GB for x86_64 on all OS's
fZeroPageSize = 0x100000000ULL;
}
}
- // check -pie is only used when building a dynamic main executable for 10.5
if ( fPositionIndependentExecutable ) {
switch ( fOutputKind ) {
case Options::kDynamicExecutable:
+ // check -pie is only used when building a dynamic main executable for 10.5
if ( !minOS(ld::mac10_5, ld::iOS_4_2) ) {
if ( fIOSVersionMin == ld::iOSVersionUnset )
throw "-pie can only be used when targeting Mac OS X 10.5 or later";
throw "-pie can only be used when targeting iOS 4.2 or later";
}
break;
+ case Options::kStaticExecutable:
case Options::kPreload:
+ // -pie is ok with -static or -preload
break;
case Options::kDynamicLibrary:
case Options::kDynamicBundle:
warning("-pie being ignored. It is only used when linking a main executable");
fPositionIndependentExecutable = false;
break;
- case Options::kStaticExecutable:
case Options::kObjectFile:
case Options::kDyld:
case Options::kKextBundle:
// -dyld_env can only be used with main executables
if ( (fOutputKind != Options::kDynamicExecutable) && (fDyldEnvironExtras.size() != 0) )
throw "-dyld_env can only used used when created main executables";
+
+ // -rename_sections can only be used in -r mode
+ if ( (fSectionRenames.size() != 0) && (fOutputKind != Options::kObjectFile) )
+ throw "-rename_sections can only used used in -r mode";
}
bool newLinker = false;
// build command line buffer in case ld crashes
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ CRSetCrashLogMessage(crashreporterBuffer);
+#endif
const char* srcRoot = getenv("SRCROOT");
if ( srcRoot != NULL ) {
strlcpy(crashreporterBuffer, "SRCROOT=", crashreporterBufferSize);
}
}
}
-
- // -dtrace only supported by new linker
- if( dtraceFound )
- return;
-
- if( archFound ) {
- switch ( fArchitecture ) {
- case CPU_TYPE_I386:
- if ( (staticFound || kextFound) && !newLinker ) {
- // this environment variable will disable use of ld_classic for -static links
- if ( getenv("LD_NO_CLASSIC_LINKER_STATIC") == NULL ) {
- this->gotoClassicLinker(argc, argv);
- }
- }
- break;
- }
- }
- else {
- // work around for VSPTool
- if ( staticFound ) {
- warning("using ld_classic");
- this->gotoClassicLinker(argc, argv);
- }
- }
-
}
void Options::gotoClassicLinker(int argc, const char* argv[])
fprintf(stderr, "can't exec ld_classic\n");
exit(1);
}
+
+
+// Note, returned string buffer is own by this function.
+// It should not be freed
+// It will be reused, so clients need to strdup() if they want
+// to use it long term.
+const char* Options::demangleSymbol(const char* sym) const
+{
+ // only try to demangle symbols if -demangle on command line
+ if ( !fDemangle )
+ return sym;
+
+ // only try to demangle symbols that look like C++ symbols
+ if ( strncmp(sym, "__Z", 3) != 0 )
+ return sym;
+
+ static size_t size = 1024;
+ static char* buff = (char*)malloc(size);
+ int status;
+
+ char* result = abi::__cxa_demangle(&sym[1], buff, &size, &status);
+ if ( result != NULL ) {
+ // if demangling successful, keep buffer for next demangle
+ buff = result;
+ return buff;
+ }
+ return sym;
+}
+
+
+void Options::dumpDependency(uint8_t opcode, const char* path) const
+{
+ if ( !this->dumpDependencyInfo() )
+ return;
+
+ // one time open() of -dependency_info file
+ if ( fDependencyFileDescriptor == -1 ) {
+ fDependencyFileDescriptor = open(this->dependencyInfoPath(), O_WRONLY | O_TRUNC | O_CREAT, 0666);
+ if ( fDependencyFileDescriptor == -1 )
+ throwf("Could not open or create -dependency_info file: %s", this->dependencyInfoPath());
+
+ // write header
+ uint8_t version = depLinkerVersion;
+ if ( write(fDependencyFileDescriptor, &version, 1) == -1 )
+ throwf("write() to -dependency_info failed, errno=%d", errno);
+ extern const char ldVersionString[];
+ if ( write(fDependencyFileDescriptor, ldVersionString, strlen(ldVersionString)+1) == -1 )
+ throwf("write() to -dependency_info failed, errno=%d", errno);
+ }
+
+ char realPath[PATH_MAX];
+ if ( path[0] != '/' ) {
+ if ( realpath(path, realPath) != NULL ) {
+ path = realPath;
+ }
+ }
+
+ if ( write(fDependencyFileDescriptor, &opcode, 1) == -1 )
+ throwf("write() to -dependency_info failed, errno=%d", errno);
+ if ( write(fDependencyFileDescriptor, path, strlen(path)+1) == -1 )
+ throwf("write() to -dependency_info failed, errno=%d", errno);
+
+ //fprintf(stderr, "0x%02X %s\n", opcode, path);
+}
+
+
+