[LLVMdev] Trouble Resolving Objective-C Symbols in lli

Reid Spencer rspencer at reidspencer.com
Fri Jul 20 12:18:44 PDT 2007


Chris / Ralph / Others,

On Fri, 2007-07-20 at 08:14 -0700, Chris Lattner wrote:
> On Fri, 20 Jul 2007, Ralph Corderoy wrote:
> > I could be missing something, but shouldn't the use of dlsym() be
> > The authors of dlsym() realised the return value was overloaded AFAICS.
> 
> Yep, patches welcome :)
> 
> -Chris
> 

I don't recall who originally asked for help with this, but here's a
patch that could fix it. Please try this and let me know if it works. If
so, I'll commit it. The patch isn't complete (it should do something in
the error condition) but it should allow you to find symbols whose
address is 0.

Reid.

Index: DynamicLibrary.cpp
===================================================================
--- DynamicLibrary.cpp  (revision 40112)
+++ DynamicLibrary.cpp  (working copy)
@@ -130,11 +130,19 @@
   if (I != g_symbols.end())
     return I->second;

+  // Clear the error status of the ltdl library
+  lt_dlerror();
+
   // Now search the libraries.
   for (std::vector<lt_dlhandle>::iterator I = OpenedHandles.begin(),
        E = OpenedHandles.end(); I != E; ++I) {
     lt_ptr ptr = lt_dlsym(*I, symbolName);
-    if (ptr)
+
+    // Get the error for the lt_dlsym call. If there was no error and
the result
+    // from lt_dlsym was 0 then 0 is the address of the symbol, not an
+    // indication that it couldn't be found.
+    const char *errmsg = lt_dlerror();
+    if (ptr || !errmsg)
       return ptr;
   }

Please apply to lib/System/DynamicLibrary.cpp. 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DL.patch
Type: text/x-patch
Size: 817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20070720/5ddddf80/attachment.bin>


More information about the llvm-dev mailing list