When linking against a Mach-O dylib that reexports other dylibs, lld searches for the reexported dylibs in multiple places: it tries the full path referenced by LC_REEXPORT_DYLIB (with and without sysroot prepended), and also searches in -L directories for a library matching the basename of that path. This patch fixes two bugs related to that search:
- When looking in -L paths, MachOLinkingContext::findIndirectDylib() passed the full basename to searchLibrary(), e.g. "libfoo.dylib". But searchLibrary() prepends "lib" and appends ".dylib", so it ended up looking for "liblibfoo.dylib.dylib". Fix findIndirectDylib() to strip "lib" and ".dylib".
- If the library is not found for whatever reason, there was no error handling. entry.file would just be set to null, which would later trigger an assert "assert(dylib.file)" in a different function. To fix this, print an error if find() returns; since that (intentionally) does not abort the process and still leaves entry.file as null, change the function with the assert to tolerate that case.