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,14 @@ } } - // 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")); + // dyld requires us to load libSystem. This environment variable is used in + // tests, as we may also run those tests on non-OSX systems which do not + // have libSystem. + if (StringRef(getenv("LLD_FORCE_LOAD_LIBSYSTEM")) == "1" && + dylibOrdinal == 1 && config->outputType == MH_EXECUTE) { + 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'), ]