--- ld64-530/src/ld/InputFiles.cpp 2020-11-23 12:35:01.000000000 -0600 +++ ld64-530/src/ld/InputFiles.cpp 2020-11-23 12:34:38.000000000 -0600 @@ -60,7 +60,9 @@ #include "macho_dylib_file.h" #include "textstub_dylib_file.hpp" #include "archive_file.h" +#ifdef LTO #include "lto_file.h" +#endif #include "opaque_section_file.h" #include "MachOFileAbstraction.hpp" #include "Snapshot.h" @@ -205,9 +207,11 @@ return result; } +#ifdef LTO result = lto::archName(p, len); if ( result != NULL ) return result; +#endif const char* archiveArchName; if ( ::archive::isArchiveFile(p, len, &platform, &archiveArchName) ) @@ -355,6 +359,7 @@ return objResult; } +#ifdef LTO // see if it is an llvm object file objResult = lto::parse(p, len, info.path, info.modTime, info.ordinal, _options.architecture(), _options.subArchitecture(), _options.logAllFiles(), _options.verboseOptimizationHints()); if ( objResult != NULL ) { @@ -362,6 +367,7 @@ OSAtomicIncrement32(&_totalObjectLoaded); return objResult; } +#endif // see if it is a dynamic library (or text-based dynamic library) ld::dylib::File* dylibResult; @@ -413,6 +419,7 @@ return archiveResult; } +#ifdef LTO // does not seem to be any valid linker input file, check LTO misconfiguration problems if ( lto::archName((uint8_t*)p, len) != NULL ) { if ( lto::libLTOisLoaded() ) { @@ -442,6 +449,7 @@ throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO); } } +#endif if ( dylibsNotAllowed ) { cpu_type_t dummy1; --- ld64-530/src/ld/ld.cpp 2019-09-22 19:04:19.000000000 -0500 +++ ld64-530/src/ld/ld.cpp 2020-11-23 12:38:45.000000000 -0600 @@ -81,13 +81,17 @@ #include "passes/branch_shim.h" #include "passes/objc.h" #include "passes/dylibs.h" +#ifdef LTO #include "passes/bitcode_bundle.h" +#endif #include "passes/code_dedup.h" #include "parsers/archive_file.h" #include "parsers/macho_relocatable_file.h" #include "parsers/macho_dylib_file.h" +#ifdef LTO #include "parsers/lto_file.h" +#endif #include "parsers/opaque_section_file.h" @@ -1381,7 +1385,9 @@ ld::passes::branch_island::doPass(options, state); // must be after stubs and order pass ld::passes::dtrace::doPass(options, state); ld::passes::compact_unwind::doPass(options, state); // must be after order pass +#ifdef LTO ld::passes::bitcode_bundle::doPass(options, state); // must be after dylib +#endif // Sort again so that we get the segments in order. state.sortSections(); --- ld64-530/src/ld/Options.cpp 2020-04-08 15:46:11.000000000 -0500 +++ ld64-530/src/ld/Options.cpp 2020-11-23 12:41:50.000000000 -0600 @@ -53,12 +53,14 @@ #define VAL(x) #x #define STRINGIFY(x) VAL(x) +#ifdef LTO // upward dependency on lto::version() namespace lto { extern const char* version(); extern unsigned static_api_version(); extern unsigned runtime_api_version(); } +#endif // magic to place command line in crash reports const int crashreporterBufferSize = 2000; @@ -4127,10 +4129,12 @@ fprintf(stderr, "configured to support archs: %s\n", ALL_SUPPORTED_ARCHS); // if only -v specified, exit cleanly if ( argc == 2 ) { +#ifdef LTO const char* ltoVers = lto::version(); if ( ltoVers != NULL ) fprintf(stderr, "LTO support using: %s (static support for %d, runtime is %d)\n", ltoVers, lto::static_api_version(), lto::runtime_api_version()); +#endif fprintf(stderr, "TAPI support using: %s\n", tapi::Version::getFullVersionAsString().c_str()); exit(0); } @@ -4153,6 +4157,7 @@ } fprintf(stdout, "\n\t],\n"); +#ifdef LTO const char* ltoVers = lto::version(); if ( ltoVers != NULL ) { fprintf(stdout, "\t\"lto\": {\n"); @@ -4161,6 +4166,7 @@ fprintf(stdout, "\t\t\"version_string\": \"%s\"\n", ltoVers); fprintf(stdout, "\t},\n"); } +#endif fprintf(stdout, "\t\"tapi\": {\n"); fprintf(stdout, "\t\t\"version\": \"%s\",\n", tapi::Version::getAsString().c_str()); --- ld64-530/src/ld/parsers/archive_file.cpp 2020-04-08 15:46:10.000000000 -0500 +++ ld64-530/src/ld/parsers/archive_file.cpp 2020-11-23 12:48:10.000000000 -0600 @@ -92,8 +92,10 @@ static bool validMachOFile(const uint8_t* fileContent, uint64_t fileLength, const mach_o::relocatable::ParserOptions& opts); +#ifdef LTO static bool validLTOFile(const uint8_t* fileContent, uint64_t fileLength, const mach_o::relocatable::ParserOptions& opts); +#endif static cpu_type_t architecture(); class Entry : ar_hdr @@ -237,6 +239,7 @@ return mach_o::relocatable::isObjectFile(fileContent, fileLength, opts); } +#ifdef LTO template bool File::validLTOFile(const uint8_t* fileContent, uint64_t fileLength, const mach_o::relocatable::ParserOptions& opts) { @@ -247,6 +250,7 @@ return false; return lto::isObjectFile(fileContent, fileLength, opts.architecture, opts.subType); } +#endif @@ -271,7 +275,11 @@ continue; #endif // archive is valid if first .o file is valid - return (validMachOFile(p->content(), p->contentSize(), opts) || validLTOFile(p->content(), p->contentSize(), opts)); + return (validMachOFile(p->content(), p->contentSize(), opts) +#ifdef LTO + || validLTOFile(p->content(), p->contentSize(), opts) +#endif + ); } // empty archive return true; @@ -407,6 +415,7 @@ _instantiatedEntries[member] = state; return _instantiatedEntries[member]; } +#ifdef LTO // see if member is llvm bitcode file result = lto::parse(member->content(), member->contentSize(), mPath, member->modificationTime(), ordinal, @@ -416,8 +425,13 @@ _instantiatedEntries[member] = state; return _instantiatedEntries[member]; } +#endif - throwf("archive member '%s' with length %d is not mach-o or llvm bitcode", memberName, member->contentSize()); + throwf("archive member '%s' with length %d is not mach-o" +#ifdef LTO + " or llvm bitcode" +#endif + , memberName, member->contentSize()); } catch (const char* msg) { throwf("in %s, %s", memberPath, msg); @@ -490,6 +504,7 @@ if ( (member==start) && ((strcmp(mname, SYMDEF_64_SORTED) == 0) || (strcmp(mname, SYMDEF_64) == 0)) ) continue; #endif +#ifdef LTO if ( validMachOFile(member->content(), member->contentSize(), _objOpts) ) { MemberState& state = this->makeObjectFileForMember(member); // only look at files not already loaded @@ -513,6 +528,7 @@ } } } +#endif } } return didSome; --- ld64-530/src/ld/passes/bitcode_bundle.cpp 2018-02-09 15:44:05.000000000 -0600 +++ ld64-530/src/ld/passes/bitcode_bundle.cpp 2020-11-23 12:50:58.000000000 -0600 @@ -22,6 +22,7 @@ * @APPLE_LICENSE_HEADER_END@ */ +#ifdef LTO #include #include #include @@ -1084,3 +1085,4 @@ } // namespace bitcode_bundle } // namespace passes } // namespace ld +#endif --- ld64-530/src/ld/Resolver.cpp 2019-07-16 19:36:00.000000000 -0500 +++ ld64-530/src/ld/Resolver.cpp 2020-11-23 12:52:49.000000000 -0600 @@ -56,7 +56,9 @@ #include "InputFiles.h" #include "SymbolTable.h" #include "Resolver.h" +#ifdef LTO #include "parsers/lto_file.h" +#endif #include "configure.h" @@ -1749,6 +1751,7 @@ void Resolver::linkTimeOptimize() { +#ifdef LTO // only do work here if some llvm obj files where loaded if ( ! _haveLLVMObjs ) return; @@ -1887,6 +1890,9 @@ } _symbolTable.removeDeadUndefs(_atoms, mustPreserve); } +#else + return; +#endif } --- ld64-530/src/other/ObjectDump.cpp 2020-04-08 15:46:11.000000000 -0500 +++ ld64-530/src/other/ObjectDump.cpp 2020-11-23 12:55:05.000000000 -0600 @@ -33,7 +33,9 @@ #include "MachOFileAbstraction.hpp" #include "parsers/macho_relocatable_file.h" +#ifdef LTO #include "parsers/lto_file.h" +#endif const ld::VersionSet ld::File::_platforms; @@ -1279,10 +1281,12 @@ if ( objResult != NULL ) return objResult; +#ifdef LTO // see if it is an llvm object file objResult = lto::parse(p, fileLen, path, stat_buf.st_mtime, ld::File::Ordinal::NullOrdinal(), sPreferredArch, sPreferredSubArch, false, true); if ( objResult != NULL ) return objResult; +#endif throwf("not a mach-o object file: %s", path); #else