diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -372,10 +372,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_IN_TEST")) == "1" && dylibOrdinal == 1 && + config->outputType == MH_EXECUTE) { + headerSection->addLoadCommand( + make("/usr/lib/libSystem.B.dylib")); + } } void Writer::createHiddenSections() {