[prev in list] [next in list] [prev in thread] [next in thread]
List: llvm-dev
Subject: [LLVMdev] How to get dependencies (linked libraries) from a shared object (*.so)?
From: Dimitar Dobrev <dpldobrev () yahoo ! com>
Date: 2014-08-09 19:32:57
Message-ID: 1407612777.35679.YahooMailNeo () web122402 ! mail ! ne1 ! yahoo ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello all,
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) I cannot quite figure out what. I tried testing with \
Linux's ls. I ran "ldd ls" (ldd is Linux-only)and got about six dependencies - as an \
example for one of them I can remember libc. Then I tried this code:
for (auto dep = ObjectFile->needed_library_begin(); dep != \
ObjectFile->needed_library_end(); ++dep) {
llvm::StringRef Path;
if (!dep->getPath(Path))
...
}
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. As a final, hopefully helpful, reference, I'm applying the code I use to \
successfully get the dependencies of a Windows DLL:
if (auto COFFObjectFile = \
llvm::dyn_cast<llvm::object::COFFObjectFile>(ObjectFile)) {
for (auto dep = COFFObjectFile->import_directory_begin(); dep != \
COFFObjectFile->import_directory_end(); ++dep) {
llvm::StringRef Name;
if (!dep->getName(Name) && (Name.endswith(".dll") || \
Name.endswith(".DLL")))
...
}
}
Regards,
Dimitar Dobrev
[Attachment #5 (text/html)]
<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>
_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic