diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -351,10 +351,13 @@ } } - // TODO: dyld requires libSystem to be loaded. libSystem is a universal - // binary and we don't have support for that yet, so mock it out here. - headerSection->addLoadCommand( - make("/usr/lib/libSystem.B.dylib")); + if (dylibOrdinal == 1 && config->outputType == MH_EXECUTE) { + // Used in tests, as we also run those tests on non-OSX systems. + if (StringRef(getenv("LLD_FORCE_LOAD_LIBSYSTEM")) == "1") { + headerSection->addLoadCommand( + make("/usr/lib/libSystem.B.dylib")); + } + } } void Writer::createHiddenSections() { diff --git a/lld/test/MachO/lit.local.cfg b/lld/test/MachO/lit.local.cfg --- a/lld/test/MachO/lit.local.cfg +++ b/lld/test/MachO/lit.local.cfg @@ -1,3 +1,4 @@ +config.environment['LLD_FORCE_LOAD_LIBSYSTEM'] = '1' config.substitutions += [ ('%lld', 'lld -flavor darwinnew'), ]