]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/Options.cpp
ld64-97.17.tar.gz
[apple/ld64.git] / src / ld / Options.cpp
index f63a123351f966e163ee92b0e5b8f496726c8333..492d140b4c780eb9b8d695589ad6347c6a12ac85 100644 (file)
@@ -99,12 +99,13 @@ Options::Options(int argc, const char* argv[])
          fVerbose(false), fKeepRelocations(false), fWarnStabs(false),
          fTraceDylibSearching(false), fPause(false), fStatistics(false), fPrintOptions(false),
          fSharedRegionEligible(false), fPrintOrderFileStatistics(false),  
-         fReadOnlyx86Stubs(false), fPositionIndependentExecutable(false), fMaxMinimumHeaderPad(false),
+         fReadOnlyx86Stubs(false), fPositionIndependentExecutable(false), 
+         fDisablePositionIndependentExecutable(false), fMaxMinimumHeaderPad(false),
          fDeadStripDylibs(false),  fAllowTextRelocs(false), fWarnTextRelocs(false), 
          fUsingLazyDylibLinking(false), fEncryptable(true), 
          fOrderData(true), fMarkDeadStrippableDylib(false),
          fMakeClassicDyldInfo(true), fMakeCompressedDyldInfo(true), fAllowCpuSubtypeMismatches(false),
-         fUseSimplifiedDylibReExports(false), fSaveTempFiles(false)
+         fUseSimplifiedDylibReExports(false), fObjCABIVersion2POverride(false), fSaveTempFiles(false)
 {
        this->checkForClassic(argc, argv);
        this->parsePreCommandLineEnvironmentSettings();
@@ -1248,8 +1249,11 @@ void Options::setMacOSXVersionMin(const char* version)
                        case 6:
                                fReaderOptions.fMacVersionMin = ObjectFile::ReaderOptions::k10_6;
                                break;
+                       case 7:
+                               fReaderOptions.fMacVersionMin = ObjectFile::ReaderOptions::k10_7;
+                               break;
                        default:
-                               fReaderOptions.fMacVersionMin = ObjectFile::ReaderOptions::k10_6;
+                               fReaderOptions.fMacVersionMin = ObjectFile::ReaderOptions::k10_7;
                                break;
                        }
        }
@@ -2430,6 +2434,9 @@ void Options::parse(int argc, const char* argv[])
                        else if ( strcmp(arg, "-pie") == 0 ) {
                                fPositionIndependentExecutable = true;
                        }
+                       else if ( strcmp(arg, "-no_pie") == 0 ) {
+                               fDisablePositionIndependentExecutable = true;
+                       }
                        else if ( strncmp(arg, "-reexport-l", 11) == 0 ) {
                                FileInfo info = findLibrary(&arg[11], true);
                                info.options.fReExport = true;
@@ -2504,6 +2511,18 @@ void Options::parse(int argc, const char* argv[])
                        else if ( strcmp(arg, "-no_zero_fill_sections") == 0 ) {
                                fReaderOptions.fOptimizeZeroFill = false;
                        }
+                       else if ( strcmp(arg, "-objc_abi_version") == 0 ) {
+                               const char* version = argv[++i];
+                                if ( version == NULL )
+                                       throw "-objc_abi_version missing version number";
+                               if ( strcmp(version, "2") == 0 )
+                                       fObjCABIVersion2POverride = true;
+                               else
+                                       warning("ignoring unrecognized argument (%s) to -objc_abi_version", version);
+                       }
+                       else if ( strcmp(arg, "-demangle") == 0 ) {
+                               // <rdar://problem/8303976> add -demangle noop to ld64-97
+                       }
                        else {
                                throwf("unknown option: %s", arg);
                        }
@@ -2752,6 +2771,11 @@ void Options::parsePreCommandLineEnvironmentSettings()
                fMakeCompressedDyldInfo = false;
                fMakeClassicDyldInfo = true;
        }
+       // temporary until projects adopt -no_pie
+       if ( getenv("LD_NO_PIE") != NULL ) {
+               warning("LD_NO_PIE being used to disble building a position independent executable");
+               fDisablePositionIndependentExecutable = true;
+       }
 
        sWarningsSideFilePath = getenv("LD_WARN_FILE");
 }
@@ -3179,6 +3203,12 @@ void Options::reconfigureDefaults()
        // Mac OS X 10.5 and iPhoneOS 2.0 support LC_REEXPORT_DYLIB
        if ( minOS(ObjectFile::ReaderOptions::k10_5, ObjectFile::ReaderOptions::k2_0) )
                fUseSimplifiedDylibReExports = true;
+               
+       // x86_64 for MacOSX 10.7 defaults to PIE
+       if ( (fArchitecture == CPU_TYPE_X86_64) && (fOutputKind == kDynamicExecutable)
+                       && (fReaderOptions.fMacVersionMin >= ObjectFile::ReaderOptions::k10_7) ) {
+               fPositionIndependentExecutable = true;
+       }
 }
 
 void Options::checkIllegalOptionCombinations()
@@ -3375,6 +3405,11 @@ void Options::checkIllegalOptionCombinations()
                if ( strncmp(name, ".objc_class_name_", 17) == 0 ) {
                        // rdar://problem/4718189 map ObjC class names to new runtime names
                        switch (fArchitecture) {
+                               case CPU_TYPE_I386:
+                                       // i386 only uses new symbols when using objc2 ABI
+                                       if ( !fObjCABIVersion2POverride )
+                                               break;
+                                       // when using objc2 ABI to same as archs below
                                case CPU_TYPE_POWERPC64:
                                case CPU_TYPE_X86_64:
                            case CPU_TYPE_ARM:
@@ -3486,6 +3521,10 @@ void Options::checkIllegalOptionCombinations()
        if ( fPositionIndependentExecutable ) {
                switch ( fOutputKind ) {
                        case Options::kDynamicExecutable:
+                               // -no_pie anywhere on command line disable PIE
+                               if ( fDisablePositionIndependentExecutable )
+                                       fPositionIndependentExecutable = false;
+                               break;
                        case Options::kPreload:
                                break;
                        case Options::kDynamicLibrary: