]> git.saurik.com Git - apple/ld64.git/commitdiff
ld64-253.6.tar.gz developer-tools-71 v253.6
authorApple <opensource@apple.com>
Wed, 30 Sep 2015 22:01:30 +0000 (22:01 +0000)
committerApple <opensource@apple.com>
Wed, 30 Sep 2015 22:01:30 +0000 (22:01 +0000)
src/ld/InputFiles.cpp
src/ld/Options.cpp
src/ld/Options.h
src/ld/Resolver.cpp
src/ld/ld.hpp
src/ld/parsers/lto_file.cpp
src/ld/parsers/macho_dylib_file.cpp
src/ld/parsers/macho_relocatable_file.cpp
src/ld/parsers/macho_relocatable_file.h
src/ld/passes/bitcode_bundle.cpp
src/other/ObjectDump.cpp

index 9eadc2e264ad25c7105b2521e63ab5e31e720454..839c5bc1f3e7bc90d80a92de028cd77a0fe141af 100644 (file)
@@ -300,12 +300,10 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
        objOpts.subType                         = _options.subArchitecture();
        objOpts.platform                        = _options.platform();
        objOpts.minOSVersion            = _options.minOSversion();
        objOpts.subType                         = _options.subArchitecture();
        objOpts.platform                        = _options.platform();
        objOpts.minOSVersion            = _options.minOSversion();
-       // workaround for strip -S
-       // when ld -r has single input file, set the srcKind to kSourceSingle so __LLVM segment will be kept
-       if (_options.outputKind() == Options::kObjectFile && _options.getInputFiles().size() == 1)
-               objOpts.srcKind                 = ld::relocatable::File::kSourceSingle;
-       else
-               objOpts.srcKind                         = ld::relocatable::File::kSourceObj;
+       objOpts.srcKind                         = ld::relocatable::File::kSourceObj;
+       objOpts.treateBitcodeAsData     = _options.bitcodeKind() == Options::kBitcodeAsData;
+       objOpts.usingBitcode            = _options.bundleBitcode();
+
        ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts);
        if ( objResult != NULL ) {
                OSAtomicAdd64(len, &_totalObjectSize);
        ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts);
        if ( objResult != NULL ) {
                OSAtomicAdd64(len, &_totalObjectSize);
@@ -361,6 +359,9 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
                archOpts.objOpts.srcKind = ld::relocatable::File::kSourceCompilerArchive;
        else
                archOpts.objOpts.srcKind = ld::relocatable::File::kSourceArchive;
                archOpts.objOpts.srcKind = ld::relocatable::File::kSourceCompilerArchive;
        else
                archOpts.objOpts.srcKind = ld::relocatable::File::kSourceArchive;
+       archOpts.objOpts.treateBitcodeAsData = _options.bitcodeKind() == Options::kBitcodeAsData;
+       archOpts.objOpts.usingBitcode = _options.bundleBitcode();
+
        ld::archive::File* archiveResult = ::archive::parse(p, len, info.path, info.modTime, info.ordinal, archOpts);
        if ( archiveResult != NULL ) {
                OSAtomicAdd64(len, &_totalArchiveSize);
        ld::archive::File* archiveResult = ::archive::parse(p, len, info.path, info.modTime, info.ordinal, archOpts);
        if ( archiveResult != NULL ) {
                OSAtomicAdd64(len, &_totalArchiveSize);
index a638cb4c499696f805f50fda2e077bb46c2f5cea..8106e933614f1819569c08748e5e61f933f68b0d 100644 (file)
@@ -186,9 +186,10 @@ Options::Options(int argc, const char* argv[])
          fMarkAppExtensionSafe(false), fCheckAppExtensionSafe(false), fForceLoadSwiftLibs(false),
          fSharedRegionEncodingV2(false), fUseDataConstSegment(false),
          fUseDataConstSegmentForceOn(false), fUseDataConstSegmentForceOff(false),
          fMarkAppExtensionSafe(false), fCheckAppExtensionSafe(false), fForceLoadSwiftLibs(false),
          fSharedRegionEncodingV2(false), fUseDataConstSegment(false),
          fUseDataConstSegmentForceOn(false), fUseDataConstSegmentForceOff(false),
-         fBundleBitcode(false), fHideSymbols(false), fReverseMapUUIDRename(false), fReverseMapPath(NULL), fLTOCodegenOnly(false),
-         fIgnoreAutoLink(false), fPlatform(kPlatformUnknown),
-         fDebugInfoStripping(kDebugInfoMinimal), fTraceOutputFile(NULL),
+         fBundleBitcode(false), fHideSymbols(false), fVerifyBitcode(false),
+         fReverseMapUUIDRename(false), fReverseMapPath(NULL), fLTOCodegenOnly(false),
+         fIgnoreAutoLink(false), fAllowDeadDups(false), fBitcodeKind(kBitcodeProcess),
+         fPlatform(kPlatformUnknown), fDebugInfoStripping(kDebugInfoMinimal), fTraceOutputFile(NULL),
          fMacVersionMin(ld::macVersionUnset), fIOSVersionMin(ld::iOSVersionUnset),
          fSaveTempFiles(false), fSnapshotRequested(false), fPipelineFifo(NULL),
          fDependencyInfoPath(NULL), fDependencyFileDescriptor(-1)
          fMacVersionMin(ld::macVersionUnset), fIOSVersionMin(ld::iOSVersionUnset),
          fSaveTempFiles(false), fSnapshotRequested(false), fPipelineFifo(NULL),
          fDependencyInfoPath(NULL), fDependencyFileDescriptor(-1)
@@ -3063,6 +3064,11 @@ void Options::parse(int argc, const char* argv[])
                                if ( !fBundleBitcode )
                                        warning("-bitcode_hide_symbols is ignored without -bitcode_bundle");
                        }
                                if ( !fBundleBitcode )
                                        warning("-bitcode_hide_symbols is ignored without -bitcode_bundle");
                        }
+                       else if ( strcmp(arg, "-bitcode_verify") == 0 ) {
+                               fVerifyBitcode = true;
+                               if ( !fBundleBitcode )
+                                       warning("-bitcode_verify is ignored without -bitcode_bundle");
+                       }
                        else if ( strcmp(arg, "-bitcode_symbol_map") == 0) {
                                fReverseMapPath = argv[++i];
                                if ( fReverseMapPath == NULL )
                        else if ( strcmp(arg, "-bitcode_symbol_map") == 0) {
                                fReverseMapPath = argv[++i];
                                if ( fReverseMapPath == NULL )
@@ -3087,6 +3093,24 @@ void Options::parse(int argc, const char* argv[])
                        else if ( strcmp(argv[i], "-ignore_auto_link") == 0) {
                                fIgnoreAutoLink = true;
                        }
                        else if ( strcmp(argv[i], "-ignore_auto_link") == 0) {
                                fIgnoreAutoLink = true;
                        }
+                       else if ( strcmp(argv[i], "-allow_dead_duplicates") == 0) {
+                               fAllowDeadDups = true;
+                       }
+                       else if ( strcmp(argv[i], "-bitcode_process_mode") == 0 ) {
+                               const char* bitcode_type = argv[++i];
+                               if ( bitcode_type == NULL )
+                                       throw "missing argument to -bitcode_process_mode";
+                               else if ( strcmp(bitcode_type, "strip") == 0 )
+                                       fBitcodeKind = kBitcodeStrip;
+                               else if ( strcmp(bitcode_type, "marker") == 0 )
+                                       fBitcodeKind = kBitcodeMarker;
+                               else if ( strcmp(bitcode_type, "data") == 0 )
+                                       fBitcodeKind = kBitcodeAsData;
+                               else if ( strcmp(bitcode_type, "bitcode") == 0 )
+                                       fBitcodeKind = kBitcodeProcess;
+                               else
+                                       throw "unknown argument to -bitcode_process_mode {strip,marker,data,bitcode}";
+                       }
                        else if ( strcmp(arg, "-rpath") == 0 ) {
                                const char* path = argv[++i];
                                if ( path == NULL )
                        else if ( strcmp(arg, "-rpath") == 0 ) {
                                const char* path = argv[++i];
                                if ( path == NULL )
@@ -5290,6 +5314,15 @@ void Options::checkIllegalOptionCombinations()
        if ( !fSegmentOrder.empty() && (fOutputKind != Options::kPreload) )
                throw "-segment_order can only used used with -preload output";
 
        if ( !fSegmentOrder.empty() && (fOutputKind != Options::kPreload) )
                throw "-segment_order can only used used with -preload output";
 
+       if ( fBitcodeKind != kBitcodeProcess &&
+                fOutputKind != Options::kObjectFile ) {
+               throw "-bitcode_process_mode can only be used together with -r";
+       }
+       // auto fix up the process type for strip -S.
+       // when there is only one input and output type is object file, downgrade kBitcodeProcess to kBitcodeAsData.
+       if ( fOutputKind == Options::kObjectFile && fInputFiles.size() == 1 && fBitcodeKind == Options::kBitcodeProcess )
+               fBitcodeKind = Options::kBitcodeAsData;
+
        // <rdar://problem/17598404> warn if building an embedded iOS dylib for pre-iOS 8
        // <rdar://problem/18935714> How can we suppress "ld: warning: embedded dylibs/frameworks only run on iOS 8 or laterĂ“ when building XCTest?
        if ( (fOutputKind == Options::kDynamicLibrary) && (fIOSVersionMin != ld::iOSVersionUnset) && (fDylibInstallName != NULL) ) {
        // <rdar://problem/17598404> warn if building an embedded iOS dylib for pre-iOS 8
        // <rdar://problem/18935714> How can we suppress "ld: warning: embedded dylibs/frameworks only run on iOS 8 or laterĂ“ when building XCTest?
        if ( (fOutputKind == Options::kDynamicLibrary) && (fIOSVersionMin != ld::iOSVersionUnset) && (fDylibInstallName != NULL) ) {
index bc70e7feabb904b57feee80c7c4dde1e1ed22559..e7ffff23564e971e0d6be0366187bb94209058af 100644 (file)
@@ -86,6 +86,7 @@ public:
        enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
        enum UUIDMode { kUUIDNone, kUUIDRandom, kUUIDContent };
        enum LocalSymbolHandling { kLocalSymbolsAll, kLocalSymbolsNone, kLocalSymbolsSelectiveInclude, kLocalSymbolsSelectiveExclude };
        enum CommonsMode { kCommonsIgnoreDylibs, kCommonsOverriddenByDylibs, kCommonsConflictsDylibsError };
        enum UUIDMode { kUUIDNone, kUUIDRandom, kUUIDContent };
        enum LocalSymbolHandling { kLocalSymbolsAll, kLocalSymbolsNone, kLocalSymbolsSelectiveInclude, kLocalSymbolsSelectiveExclude };
+       enum BitcodeMode { kBitcodeProcess, kBitcodeAsData, kBitcodeMarker, kBitcodeStrip };
        enum DebugInfoStripping { kDebugInfoNone, kDebugInfoMinimal, kDebugInfoFull };
 #if SUPPORT_APPLE_TV
        enum Platform { kPlatformUnknown, kPlatformOSX, kPlatformiOS, kPlatformWatchOS, kPlatform_tvOS };
        enum DebugInfoStripping { kDebugInfoNone, kDebugInfoMinimal, kDebugInfoFull };
 #if SUPPORT_APPLE_TV
        enum Platform { kPlatformUnknown, kPlatformOSX, kPlatformiOS, kPlatformWatchOS, kPlatform_tvOS };
@@ -412,11 +413,14 @@ public:
        bool                                            forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
        bool                                            bundleBitcode() const { return fBundleBitcode; }
        bool                                            hideSymbols() const { return fHideSymbols; }
        bool                                            forceLoadSwiftLibs() const { return fForceLoadSwiftLibs; }
        bool                                            bundleBitcode() const { return fBundleBitcode; }
        bool                                            hideSymbols() const { return fHideSymbols; }
+       bool                                            verifyBitcode() const { return fVerifyBitcode; }
        bool                                            renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
        const char*                                     reverseSymbolMapPath() const { return fReverseMapPath; }
        std::string                                     reverseMapTempPath() const { return fReverseMapTempPath; }
        bool                                            ltoCodegenOnly() const { return fLTOCodegenOnly; }
        bool                                            ignoreAutoLink() const { return fIgnoreAutoLink; }
        bool                                            renameReverseSymbolMap() const { return fReverseMapUUIDRename; }
        const char*                                     reverseSymbolMapPath() const { return fReverseMapPath; }
        std::string                                     reverseMapTempPath() const { return fReverseMapTempPath; }
        bool                                            ltoCodegenOnly() const { return fLTOCodegenOnly; }
        bool                                            ignoreAutoLink() const { return fIgnoreAutoLink; }
+       bool                                            allowDeadDuplicates() const { return fAllowDeadDups; }
+       BitcodeMode                                     bitcodeKind() const { return fBitcodeKind; }
        bool                                            sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
        bool                                            useDataConstSegment() const { return fUseDataConstSegment; }
        bool                                            hasWeakBitTweaks() const;
        bool                                            sharedRegionEncodingV2() const { return fSharedRegionEncodingV2; }
        bool                                            useDataConstSegment() const { return fUseDataConstSegment; }
        bool                                            hasWeakBitTweaks() const;
@@ -709,11 +713,14 @@ private:
        bool                                                            fUseDataConstSegmentForceOff;
        bool                                                            fBundleBitcode;
        bool                                                            fHideSymbols;
        bool                                                            fUseDataConstSegmentForceOff;
        bool                                                            fBundleBitcode;
        bool                                                            fHideSymbols;
+       bool                                                            fVerifyBitcode;
        bool                                                            fReverseMapUUIDRename;
        const char*                                                     fReverseMapPath;
        std::string                                                     fReverseMapTempPath;
        bool                                                            fLTOCodegenOnly;
        bool                                                            fIgnoreAutoLink;
        bool                                                            fReverseMapUUIDRename;
        const char*                                                     fReverseMapPath;
        std::string                                                     fReverseMapTempPath;
        bool                                                            fLTOCodegenOnly;
        bool                                                            fIgnoreAutoLink;
+       bool                                                            fAllowDeadDups;
+       BitcodeMode                                                     fBitcodeKind;
        Platform                                                        fPlatform;
        DebugInfoStripping                                      fDebugInfoStripping;
        const char*                                                     fTraceOutputFile;
        Platform                                                        fPlatform;
        DebugInfoStripping                                      fDebugInfoStripping;
        const char*                                                     fTraceOutputFile;
index 094c98d0085c73837468b421bd67e7ee111983cf..948906f8de6e0cdd7b2a0a5e1fb4786827cde9d0 100644 (file)
@@ -363,7 +363,6 @@ void Resolver::doFile(const ld::File& file)
                                this->doLinkerOption(*it, file.path());
                        }
                }
                                this->doLinkerOption(*it, file.path());
                        }
                }
-
                // Resolve bitcode section in the object file
                if ( _options.bundleBitcode() ) {
                        if ( objFile->getBitcode() == NULL ) {
                // Resolve bitcode section in the object file
                if ( _options.bundleBitcode() ) {
                        if ( objFile->getBitcode() == NULL ) {
@@ -383,35 +382,25 @@ void Resolver::doFile(const ld::File& file)
                                                           "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.", file.path());
                                                break;
                                        case Options::kPlatformWatchOS:
                                                           "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.", file.path());
                                                break;
                                        case Options::kPlatformWatchOS:
+#if SUPPORT_APPLE_TV
+                                       case Options::kPlatform_tvOS:
+#endif
                                                throwf("'%s' does not contain bitcode. "
                                                                "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor", file.path());
                                                break;
                                                throwf("'%s' does not contain bitcode. "
                                                                "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor", file.path());
                                                break;
-                       #if SUPPORT_APPLE_TV
-                                       case Options::kPlatform_tvOS:
-                                               warning("URGENT: all bitcode will be dropped because '%s' was built without bitcode. "
-                                                               "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor. "
-                                                               "Note: This will be an error in the future.", file.path());
-                                               _internal.filesWithBitcode.clear();
-                                               _internal.dropAllBitcode = true;
-                                               break;
-                       #endif
                                        }
                                }
                        } else {
                                // contains bitcode, check if it is just a marker
                                if ( objFile->getBitcode()->isMarker() ) {
                                        }
                                }
                        } else {
                                // contains bitcode, check if it is just a marker
                                if ( objFile->getBitcode()->isMarker() ) {
-                                       // if the bitcode is just a marker,
-                                       // the executable will be created without bitcode section.
-                                       // Otherwise, create a marker.
-                                       if ( _options.outputKind() != Options::kDynamicExecutable &&
-                                                _options.outputKind() != Options::kStaticExecutable )
-                                               _internal.embedMarkerOnly = true;
-                                       // Issue a warning if the marker is in the static library and filesWithBitcode is not empty.
-                                       // That means there are object files actually compiled with full bitcode but the archive only has marker.
-                                       // Don't warn on normal object files because it can be a debug build using archives with full bitcode.
-                                       if ( !_internal.filesWithBitcode.empty() && objFile->sourceKind() == ld::relocatable::File::kSourceArchive )
-                                               warning("full bitcode bundle could not be generated because '%s' was built only with bitcode marker. "
-                                                               "The library must be generated from Xcode archive build with bitcode enabled (Xcode setting ENABLE_BITCODE)", objFile->path());
+                                       // if -bitcode_verify_bundle is used, check if all the object files participate in the linking have full bitcode embedded.
+                                       // error on any marker encountered.
+                                       if ( _options.verifyBitcode() )
+                                               throwf("bitcode bundle could not be generated because '%s' was built without full bitcode. "
+                                                          "All object files and libraries for bitcode must be generated from Xcode Archive or Install build",
+                                                          objFile->path());
+                                       // update the internal state that marker is encountered.
+                                       _internal.embedMarkerOnly = true;
                                        _internal.filesWithBitcode.clear();
                                        _internal.dropAllBitcode = true;
                                } else if ( !_internal.dropAllBitcode )
                                        _internal.filesWithBitcode.clear();
                                        _internal.dropAllBitcode = true;
                                } else if ( !_internal.dropAllBitcode )
@@ -542,8 +531,8 @@ void Resolver::doFile(const ld::File& file)
        if ( dylibFile != NULL ) {
                // Check dylib for bitcode, if the library install path is relative path or @rpath, it has to contain bitcode
                if ( _options.bundleBitcode() ) {
        if ( dylibFile != NULL ) {
                // Check dylib for bitcode, if the library install path is relative path or @rpath, it has to contain bitcode
                if ( _options.bundleBitcode() ) {
-                       if ( dylibFile->getBitcode() == NULL &&
-                                dylibFile->installPath()[0] != '/' ) {
+                       bool isSystemFramework = ( dylibFile->installPath() != NULL ) && ( dylibFile->installPath()[0] == '/' );
+                       if ( dylibFile->getBitcode() == NULL && !isSystemFramework ) {
                                // Check if the dylib is from toolchain by checking the path
                                char tcLibPath[PATH_MAX];
                                char ldPath[PATH_MAX];
                                // Check if the dylib is from toolchain by checking the path
                                char tcLibPath[PATH_MAX];
                                char ldPath[PATH_MAX];
@@ -574,21 +563,21 @@ void Resolver::doFile(const ld::File& file)
                                                           "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.", file.path());
                                                break;
                                        case Options::kPlatformWatchOS:
                                                           "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target.", file.path());
                                                break;
                                        case Options::kPlatformWatchOS:
+#if SUPPORT_APPLE_TV
+                                       case Options::kPlatform_tvOS:
+#endif
                                                throwf("'%s' does not contain bitcode. "
                                                                "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor", file.path());
                                                break;
                                                throwf("'%s' does not contain bitcode. "
                                                                "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor", file.path());
                                                break;
-                       #if SUPPORT_APPLE_TV
-                                       case Options::kPlatform_tvOS:
-                                               warning("URGENT: all bitcode will be dropped because '%s' was built without bitcode. "
-                                                               "You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE) or obtain an updated library from the vendor. "
-                                                               "Note: This will be an error in the future.", file.path());
-                                               _internal.filesWithBitcode.clear();
-                                               _internal.dropAllBitcode = true;
-                                               break;
-                       #endif
                                        }
                                }
                        }
                                        }
                                }
                        }
+                       // Error on bitcode marker in non-system frameworks if -bitcode_verify is used
+                       if ( _options.verifyBitcode() && !isSystemFramework &&
+                                dylibFile->getBitcode() != NULL && dylibFile->getBitcode()->isMarker() )
+                               throwf("bitcode bundle could not be generated because '%s' was built without full bitcode. "
+                                          "All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build",
+                                          dylibFile->path());
                }
 
                // update which form of ObjC dylibs are being linked
                }
 
                // update which form of ObjC dylibs are being linked
@@ -729,7 +718,7 @@ void Resolver::doAtom(const ld::Atom& atom)
 
        // tell symbol table about non-static atoms
        if ( atom.scope() != ld::Atom::scopeTranslationUnit ) {
 
        // tell symbol table about non-static atoms
        if ( atom.scope() != ld::Atom::scopeTranslationUnit ) {
-               _symbolTable.add(atom, _options.deadCodeStrip() && _completedInitialObjectFiles);
+               _symbolTable.add(atom, _options.deadCodeStrip() && (_completedInitialObjectFiles || _options.allowDeadDuplicates()));
                
                // add symbol aliases defined on the command line
                if ( _options.haveCmdLineAliases() ) {
                
                // add symbol aliases defined on the command line
                if ( _options.haveCmdLineAliases() ) {
index c8f272e8985edd75f88822d333175a9cd8655eaa..e297036efe41243d1241d73b821df7b860f64e51 100644 (file)
@@ -202,7 +202,7 @@ namespace relocatable {
        {
        public:
                enum DebugInfoKind { kDebugInfoNone=0, kDebugInfoStabs=1, kDebugInfoDwarf=2, kDebugInfoStabsUUID=3 };
        {
        public:
                enum DebugInfoKind { kDebugInfoNone=0, kDebugInfoStabs=1, kDebugInfoDwarf=2, kDebugInfoStabsUUID=3 };
-               enum SourceKind { kSourceUnknown=0, kSourceObj, kSourceLTO, kSourceArchive, kSourceCompilerArchive, kSourceSingle };
+               enum SourceKind { kSourceUnknown=0, kSourceObj, kSourceLTO, kSourceArchive, kSourceCompilerArchive };
                struct Stab {
                        const class Atom*       atom;
                        uint8_t                         type;
                struct Stab {
                        const class Atom*       atom;
                        uint8_t                         type;
index 26d70be8492c5b14d1842fd05abcb491f588a35a..d81e833994c1e4b82de353fcee02f99b8d2b25cd 100644 (file)
@@ -315,6 +315,8 @@ ld::relocatable::File* Parser::parseMachOFile(const uint8_t* p, size_t len, cons
        objOpts.platform                        = options.platform;
        objOpts.subType                         = 0;
        objOpts.srcKind                         = ld::relocatable::File::kSourceLTO;
        objOpts.platform                        = options.platform;
        objOpts.subType                         = 0;
        objOpts.srcKind                         = ld::relocatable::File::kSourceLTO;
+       objOpts.treateBitcodeAsData = false;
+       objOpts.usingBitcode            = options.bitcodeBundle;
        
        // mach-o parsing is done in-memory, but need path for debug notes
        const char* path = "/tmp/lto.o";
        
        // mach-o parsing is done in-memory, but need path for debug notes
        const char* path = "/tmp/lto.o";
index 0ba962cf36d98b52df86aef6401028a70eac279c..573f06c211ffd1b9379e621c32051913244388ac 100644 (file)
@@ -147,7 +147,7 @@ public:
                                                                                                        Options::Platform platform, uint32_t linkMinOSVersion, bool allowSimToMacOSX,
                                                                                                        bool addVers,  bool buildingForSimulator,
                                                                                                        bool logAllFiles, const char* installPath,
                                                                                                        Options::Platform platform, uint32_t linkMinOSVersion, bool allowSimToMacOSX,
                                                                                                        bool addVers,  bool buildingForSimulator,
                                                                                                        bool logAllFiles, const char* installPath,
-                                                                                                       bool indirectDylib, bool ignoreMismatchPlatform);
+                                                                                                       bool indirectDylib, bool ignoreMismatchPlatform, bool usingBitcode);
        virtual                                                                 ~File() {}
 
        // overrides of ld::File
        virtual                                                                 ~File() {}
 
        // overrides of ld::File
@@ -238,6 +238,7 @@ private:
        bool                                                                            _installPathOverride;
        bool                                                                            _indirectDylibsProcessed;
        bool                                                                            _appExtensionSafe;
        bool                                                                            _installPathOverride;
        bool                                                                            _indirectDylibsProcessed;
        bool                                                                            _appExtensionSafe;
+       bool                                                                            _usingBitcode;
        uint32_t                                                                        _minVersionInDylib;
        uint32_t                                                                        _platformInDylib;
        std::unique_ptr<ld::Bitcode>                            _bitcode;
        uint32_t                                                                        _minVersionInDylib;
        uint32_t                                                                        _platformInDylib;
        std::unique_ptr<ld::Bitcode>                            _bitcode;
@@ -260,7 +261,7 @@ template <typename A>
 File<A>::File(const uint8_t* fileContent, uint64_t fileLength, const char* pth, time_t mTime, ld::File::Ordinal ord,
                                bool linkingFlatNamespace, bool linkingMainExecutable, bool hoistImplicitPublicDylibs,
                                Options::Platform platform, uint32_t linkMinOSVersion, bool allowSimToMacOSX, bool addVers, bool buildingForSimulator,
 File<A>::File(const uint8_t* fileContent, uint64_t fileLength, const char* pth, time_t mTime, ld::File::Ordinal ord,
                                bool linkingFlatNamespace, bool linkingMainExecutable, bool hoistImplicitPublicDylibs,
                                Options::Platform platform, uint32_t linkMinOSVersion, bool allowSimToMacOSX, bool addVers, bool buildingForSimulator,
-                               bool logAllFiles, const char* targetInstallPath, bool indirectDylib, bool ignoreMismatchPlatform)
+                               bool logAllFiles, const char* targetInstallPath, bool indirectDylib, bool ignoreMismatchPlatform, bool usingBitcode)
        : ld::dylib::File(strdup(pth), mTime, ord), 
        _platform(platform), _linkMinOSVersion(linkMinOSVersion), _allowSimToMacOSXLinking(allowSimToMacOSX), _addVersionLoadCommand(addVers), 
        _linkingFlat(linkingFlatNamespace), _implicitlyLinkPublicDylibs(hoistImplicitPublicDylibs),
        : ld::dylib::File(strdup(pth), mTime, ord), 
        _platform(platform), _linkMinOSVersion(linkMinOSVersion), _allowSimToMacOSXLinking(allowSimToMacOSX), _addVersionLoadCommand(addVers), 
        _linkingFlat(linkingFlatNamespace), _implicitlyLinkPublicDylibs(hoistImplicitPublicDylibs),
@@ -271,7 +272,7 @@ File<A>::File(const uint8_t* fileContent, uint64_t fileLength, const char* pth,
        _noRexports(false), _hasWeakExports(false), 
        _deadStrippable(false), _hasPublicInstallName(false), 
         _providedAtom(false), _explictReExportFound(false), _wrongOS(false), _installPathOverride(false), 
        _noRexports(false), _hasWeakExports(false), 
        _deadStrippable(false), _hasPublicInstallName(false), 
         _providedAtom(false), _explictReExportFound(false), _wrongOS(false), _installPathOverride(false), 
-       _indirectDylibsProcessed(false), _appExtensionSafe(false),
+       _indirectDylibsProcessed(false), _appExtensionSafe(false), _usingBitcode(usingBitcode),
        _minVersionInDylib(0), _platformInDylib(Options::kPlatformUnknown)
 {
        const macho_header<P>* header = (const macho_header<P>*)fileContent;
        _minVersionInDylib(0), _platformInDylib(Options::kPlatformUnknown)
 {
        const macho_header<P>* header = (const macho_header<P>*)fileContent;
@@ -437,7 +438,11 @@ File<A>::File(const uint8_t* fileContent, uint64_t fileLength, const char* pth,
        #if SUPPORT_APPLE_TV
                                                case Options::kPlatform_tvOS:
                                                        // tvOS is a warning temporarily. rdar://problem/21746965
        #if SUPPORT_APPLE_TV
                                                case Options::kPlatform_tvOS:
                                                        // tvOS is a warning temporarily. rdar://problem/21746965
-                                                       if (platform == Options::kPlatform_tvOS)
+                                                       if ( usingBitcode )
+                                                               throwf("building for %s simulator, but linking against dylib built for %s,",
+                                                                          Options::platformName(platform),
+                                                                          Options::platformName(lcPlatform));
+                                                       else
                                                                warning("URGENT: building for %s simulator, but linking against dylib (%s) built for %s. "
                                                                                "Note: This will be an error in the future.",
                                                                                Options::platformName(platform), path(),
                                                                warning("URGENT: building for %s simulator, but linking against dylib (%s) built for %s. "
                                                                                "Note: This will be an error in the future.",
                                                                                Options::platformName(platform), path(),
@@ -466,7 +471,11 @@ File<A>::File(const uint8_t* fileContent, uint64_t fileLength, const char* pth,
        #if SUPPORT_APPLE_TV
                                        case Options::kPlatform_tvOS:
                                                // tvOS is a warning temporarily. rdar://problem/21746965
        #if SUPPORT_APPLE_TV
                                        case Options::kPlatform_tvOS:
                                                // tvOS is a warning temporarily. rdar://problem/21746965
-                                               if (platform == Options::kPlatform_tvOS)
+                                               if ( _usingBitcode )
+                                                       throwf("building for %s, but linking against dylib built for %s,",
+                                                                  Options::platformName(platform),
+                                                                  Options::platformName(lcPlatform));
+                                               else
                                                        warning("URGENT: building for %s, but linking against dylib (%s) built for %s. "
                                                                        "Note: This will be an error in the future.",
                                                                        Options::platformName(platform), path(),
                                                        warning("URGENT: building for %s, but linking against dylib (%s) built for %s. "
                                                                        "Note: This will be an error in the future.",
                                                                        Options::platformName(platform), path(),
@@ -1000,7 +1009,8 @@ public:
                                                                                                                                                        opts.logAllFiles(),
                                                                                                                                                        opts.installPath(),
                                                                                                                                                        indirectDylib,
                                                                                                                                                        opts.logAllFiles(),
                                                                                                                                                        opts.installPath(),
                                                                                                                                                        indirectDylib,
-                                                                                                                                                       opts.outputKind() == Options::kPreload);
+                                                                                                                                                       opts.outputKind() == Options::kPreload,
+                                                                                                                                                       opts.bundleBitcode());
                                                                                                                }
 
 };
                                                                                                                }
 
 };
index c023f37c8c893cf552197cc39a6908713ab98146..2fa41b9f269b9a123b8ea6669d26381bbc4a3144 100644 (file)
@@ -107,7 +107,6 @@ public:
        virtual uint8_t                                                                         swiftVersion() const                    { return _swiftVersion; }
        virtual ld::Bitcode*                                                            getBitcode() const                              { return _bitcode.get(); }
        virtual SourceKind                                                                      sourceKind() const                              { return _srcKind; }
        virtual uint8_t                                                                         swiftVersion() const                    { return _swiftVersion; }
        virtual ld::Bitcode*                                                            getBitcode() const                              { return _bitcode.get(); }
        virtual SourceKind                                                                      sourceKind() const                              { return _srcKind; }
-       virtual void                                                                            setSourceKind(SourceKind src)   { _srcKind = src; }
        
        const uint8_t*                                                                          fileContent()                                   { return _fileContent; }
 private:
        
        const uint8_t*                                                                          fileContent()                                   { return _fileContent; }
 private:
@@ -1255,6 +1254,8 @@ private:
        bool                                                                            _verboseOptimizationHints;
        bool                                                                            _armUsesZeroCostExceptions;
        bool                                                                            _ignoreMismatchPlatform;
        bool                                                                            _verboseOptimizationHints;
        bool                                                                            _armUsesZeroCostExceptions;
        bool                                                                            _ignoreMismatchPlatform;
+       bool                                                                            _treateBitcodeAsData;
+       bool                                                                            _usingBitcode;
        unsigned int                                                            _stubsSectionNum;
        const macho_section<P>*                                         _stubsMachOSection;
        std::vector<const char*>                                        _dtraceProviderInfo;
        unsigned int                                                            _stubsSectionNum;
        const macho_section<P>*                                         _stubsMachOSection;
        std::vector<const char*>                                        _dtraceProviderInfo;
@@ -1714,8 +1715,11 @@ ld::relocatable::File* Parser<A>::parse(const ParserOptions& opts)
        // create file object
        _file = new File<A>(_path, _modTime, _fileContent, _ordinal);
 
        // create file object
        _file = new File<A>(_path, _modTime, _fileContent, _ordinal);
 
-       // set input source
-       _file->setSourceKind(opts.srcKind);
+       // set sourceKind
+       _file->_srcKind = opts.srcKind;
+       // set treatBitcodeAsData
+       _treateBitcodeAsData = opts.treateBitcodeAsData;
+       _usingBitcode = opts.usingBitcode;
 
        // respond to -t option
        if ( opts.logAllFiles )
 
        // respond to -t option
        if ( opts.logAllFiles )
@@ -2108,8 +2112,12 @@ bool Parser<A>::parseLoadCommands(Options::Platform platform, uint32_t linkMinOS
                                        break;
        #if SUPPORT_APPLE_TV
                                case Options::kPlatform_tvOS:
                                        break;
        #if SUPPORT_APPLE_TV
                                case Options::kPlatform_tvOS:
-                                       // tvOS is a warning temporarily. rdar://problem/21746965
-                                       if (platform == Options::kPlatform_tvOS)
+                                       // Error when using bitcocde, warning otherwise.
+                                       if (_usingBitcode)
+                                               throwf("building for %s%s, but linking in object file built for %s,",
+                                                          Options::platformName(platform), (simulator ? " simulator" : ""),
+                                                          Options::platformName(lcPlatform));
+                                       else
                                                warning("URGENT: building for %s%s, but linking in object file (%s) built for %s. "
                                                                "Note: This will be an error in the future.",
                                                                Options::platformName(platform), (simulator ? " simulator" : ""), path(),
                                                warning("URGENT: building for %s%s, but linking in object file (%s) built for %s. "
                                                                "Note: This will be an error in the future.",
                                                                Options::platformName(platform), (simulator ? " simulator" : ""), path(),
@@ -2471,6 +2479,7 @@ void Parser<A>::makeSections()
                        }
                }
                if ( strcmp(sect->segname(), "__LLVM") == 0 ) {
                        }
                }
                if ( strcmp(sect->segname(), "__LLVM") == 0 ) {
+                       // Process bitcode segement
                        if ( strncmp(sect->sectname(), "__bitcode", 9) == 0 ) {
                                bitcodeSect = sect;
                        } else if ( strncmp(sect->sectname(), "__cmdline", 9) == 0 ) {
                        if ( strncmp(sect->sectname(), "__bitcode", 9) == 0 ) {
                                bitcodeSect = sect;
                        } else if ( strncmp(sect->sectname(), "__cmdline", 9) == 0 ) {
@@ -2482,9 +2491,8 @@ void Parser<A>::makeSections()
                        } else if ( strncmp(sect->sectname(), "__asm", 5) == 0 ) {
                                bitcodeAsm = true;
                        }
                        } else if ( strncmp(sect->sectname(), "__asm", 5) == 0 ) {
                                bitcodeAsm = true;
                        }
-                       // If it is not single input for ld -r, don't count the section
-                       // otherwise, fall through and add it to the sections.
-                       if (_file->sourceKind() != ld::relocatable::File::kSourceSingle)
+                       // If treat the bitcode as data, continue to parse as a normal section.
+                       if ( !_treateBitcodeAsData )
                                continue;
                }
                // ignore empty __OBJC sections
                                continue;
                }
                // ignore empty __OBJC sections
index 40f02d65d25c35ca8f93d516152fd0ef7aa3397c..ca1e5ccd9ef4251d6b4bd17262099d6f99119fe8 100644 (file)
@@ -47,6 +47,8 @@ struct ParserOptions {
        Options::Platform platform;
        uint32_t                minOSVersion;
        ld::relocatable::File::SourceKind       srcKind;
        Options::Platform platform;
        uint32_t                minOSVersion;
        ld::relocatable::File::SourceKind       srcKind;
+       bool                    treateBitcodeAsData;
+       bool                    usingBitcode;
 };
 
 extern ld::relocatable::File* parse(const uint8_t* fileContent, uint64_t fileLength, 
 };
 
 extern ld::relocatable::File* parse(const uint8_t* fileContent, uint64_t fileLength, 
index bafad0b52a0f460b6e1ef2b5d610d3106b57d21c..9e1da55cf10789850ea7f7bb6a65c3970a1e1d91 100644 (file)
@@ -488,12 +488,19 @@ void ObjectHandler::obfuscateAndWriteToPath(BitcodeObfuscator *obfuscator, const
 
 void BitcodeBundle::doPass()
 {
 
 void BitcodeBundle::doPass()
 {
-    if ( _state.embedMarkerOnly ) {
-        assert( _options.outputKind() != Options::kDynamicExecutable &&
-                _options.outputKind() != Options::kStaticExecutable &&
-                "Don't emit marker for executables");
-        BitcodeAtom* marker = new BitcodeAtom();
-        _state.addAtom(*marker);
+    if ( _options.bitcodeKind() == Options::kBitcodeStrip ||
+         _options.bitcodeKind() == Options::kBitcodeAsData )
+        // if emit no bitcode or emit bitcode segment as data, no need to generate bundle.
+        return;
+    else if ( _state.embedMarkerOnly || _options.bitcodeKind() == Options::kBitcodeMarker ) {
+        // if the bitcode is just a marker,
+        // the executable will be created without bitcode section.
+        // Otherwise, create a marker.
+        if( _options.outputKind() != Options::kDynamicExecutable &&
+            _options.outputKind() != Options::kStaticExecutable ) {
+            BitcodeAtom* marker = new BitcodeAtom();
+            _state.addAtom(*marker);
+        }
         return;
     }
 
         return;
     }
 
@@ -730,22 +737,23 @@ void BitcodeBundle::doPass()
         throwf("could not add SDK version to bitcode bundle");
 
     // Write dylibs
         throwf("could not add SDK version to bitcode bundle");
 
     // Write dylibs
-    const char* sdkRoot = NULL;
-    if ( !_options.sdkPaths().empty() )
-        sdkRoot = _options.sdkPaths().front();
+    char sdkRoot[PATH_MAX];
+    if ( _options.sdkPaths().empty() || (realpath(_options.sdkPaths().front(), sdkRoot) == NULL) )
+        strcpy(sdkRoot, "/");
     if ( !_state.dylibs.empty() ) {
     if ( !_state.dylibs.empty() ) {
-        std::vector<const char*> SDKPaths = _options.sdkPaths();
         char dylibPath[PATH_MAX];
         for ( auto &dylib : _state.dylibs ) {
         char dylibPath[PATH_MAX];
         for ( auto &dylib : _state.dylibs ) {
-            // For every dylib/framework, figure out if it is coming from a SDK
-            // if it is coming from some SDK, we parse the path to figure out which SDK
-            // If -syslibroot is pointing to a SDK, it should end with PlatformX.Y.sdk/
-            if (sdkRoot && strncmp(dylib->path(), sdkRoot, strlen(sdkRoot)) == 0) {
-                // dylib/framework from one of the -syslibroot
+            // For every dylib/framework, figure out if it is coming from a SDK.
+            // The dylib/framework from SDK must begin with '/' and user framework must begin with '@'.
+            if (dylib->installPath()[0] == '/') {
+                // Verify the path of the framework is within the SDK.
+                char dylibRealPath[PATH_MAX];
+                if ( realpath(dylib->path(), dylibRealPath) != NULL && strncmp(sdkRoot, dylibRealPath, strlen(sdkRoot)) != 0 )
+                    warning("%s has install name beginning with \"/\" but it is not from the specified SDK", dylib->path());
                 // The path start with a string template
                 // The path start with a string template
-                strcpy(dylibPath, "{SDKPATH}/");
+                strcpy(dylibPath, "{SDKPATH}");
                 // append the path of dylib/frameowrk in the SDK
                 // append the path of dylib/frameowrk in the SDK
-                strcat(dylibPath, dylib->path() + strlen(sdkRoot));
+                strcat(dylibPath, dylib->installPath());
             } else {
                 // Not in any SDKs, then assume it is a user dylib/framework
                 // strip off all the path in the front
             } else {
                 // Not in any SDKs, then assume it is a user dylib/framework
                 // strip off all the path in the front
index dfadf71d518ba37760a34d9708ad2de3d912ec3a..867f3133439febfd6556511420adc96fb7223756 100644 (file)
@@ -1244,7 +1244,8 @@ static ld::relocatable::File* createReader(const char* path)
        objOpts.verboseOptimizationHints = true;
        objOpts.armUsesZeroCostExceptions = true;
        objOpts.subType                         = sPreferredSubArch;
        objOpts.verboseOptimizationHints = true;
        objOpts.armUsesZeroCostExceptions = true;
        objOpts.subType                         = sPreferredSubArch;
-       objOpts.srcKind                         = ld::relocatable::File::kSourceObj;
+       objOpts.treateBitcodeAsData  = false;
+       objOpts.usingBitcode            = true;
 #if 1
        if ( ! foundFatSlice ) {
                cpu_type_t archOfObj;
 #if 1
        if ( ! foundFatSlice ) {
                cpu_type_t archOfObj;