<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div style="" class=""><span style="" class=""> <br style=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> Hello all,</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br style="" class=""><span style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style:
normal;"><span style="" class=""> I need to get all dependencies of a .so file. I tried using needed_library_begin/needed_library_end but they seem not to give the dependencies but something else (if anything)</span> I cannot quite figure out what. I tried testing with Linux's ls. I ran "ldd ls" (ldd is Linux-only)<span style="" class=""> and got about six dependencies - as an example for one of them I can remember libc. Then I tried this code:</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> <br style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style=""
class=""></span><span style="" class=""> for (auto dep = ObjectFile->needed_library_begin(); dep != ObjectFile->needed_library_end(); ++dep)<br style="" class=""> {<br style="" class=""> llvm::StringRef Path;<br style="" class=""> if (!dep->getPath(Path))</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> </span><span style="" class=""> </span><span style="" class=""> </span><span style="" class=""> ...</span><span style="" class=""><br style="" class=""></span></div><div class=""
style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> }</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br style="" class=""><span style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> where ObjectFile represents the opened *.so - this pointer is guaranteed to be correct because I read all exported symbols from it in the same function. Further, I opened both ls and *.so with a text editor. They
are, of course, binaries, but their dependencies can actually be seen as text fragments inside. So Clang should be able to read them in some manner, I just don't know what. This is why I'll appreciate your help.</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> As a final, hopefully helpful, reference, I'm applying the code I use to successfully get the dependencies of a Windows DLL:</span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""><br></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida
Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> if (auto COFFObjectFile = llvm::dyn_cast<llvm::object::COFFObjectFile>(ObjectFile))<br style="" class=""> {<br style="" class=""> for (auto dep = COFFObjectFile->import_directory_begin(); dep != COFFObjectFile->import_directory_end(); ++dep)<br style="" class=""> {<br style="" class=""> llvm::StringRef Name;<br style="" class=""> if (!dep->getName(Name) && (Name.endswith(".dll") || Name.endswith(".DLL")))<br style=""
class=""> ...<br style="" class=""> }<br style="" class=""> }<br style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""> </span><span style="" class=""> </span><span style="" class=""><br></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span class="tab"> </span>Regards,</div><div class="" style="color: rgb(0, 0, 0); font-size:
16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span class="tab"> </span>Dimitar Dobrev<br><span style="" class=""></span></div><div class="" style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span style="" class=""></span><span style="" class=""> <br style="" class=""></span></div></div></body></html>