Working on LLDB, I found that they have plugin loading code which is almost identical to that provided by LLVM's support libraries. There was one minor difference though, which is that on Apple platforms there is an RTLD_FIRST flag that you can pass to dlopen, which will limit symbol seaches to strictly the module that was dlopen'ed. LLDB developers claim that this functionality is required to support LLDB's needs [1, 2].
The attached patch modifies LLVM's DynamicLibrary class to use RTLD_FIRST on Apple platforms, and simulate the effect on non-apple platforms by checking that the address of the located symbol is in the module which was originally dlopen'ed.
Unfortunately I don't know really how to test this, and LLVM seems to have no code that makes use of this DynamicLibrary class.
It looks like DynamicLibrary is supposed to be a thin value type wrapper around native library handles. Adding this string makes it no longer trivially copyable and blows out its size. If we really need this, I think we should delete the copy ctor and eliminate the places where we pass it around by value.