title: Is there a reliable way to know what libraries could be dlopen()ed in an elf binary?
body: <p>Basically, I want to get a list of libraries a binary might load.</p>
  
  <p>The unreliable way I came up with that seems to work (with possible false-positives):</p>
  
  <pre><code>comm -13 &lt;(ldd elf_file | sed 's|\s*\([^ ]*\)\s.*|\1|'| sort -u) &lt;(strings -a elf_file | egrep '^(|.*/)lib[^:/]*\.so(|\.[0-9]+)$' | sort -u)
  </code></pre>
  
  <p>This is not reliable. But it gives useful information, even if the binary was stripped.</p>
  
  <p>Is there a reliable way to get this information without possible false-positives?</p>
  
  <p><strong>EDIT</strong>: More context.</p>
  
  <p>Firefox is transitioning from using <code>gstreamer</code> to using <code>ffmpeg</code>.
  I was wondering what versions of <code>libavcodec.so</code> will work.
  <code>libxul.so</code> uses <code>dlopen()</code> for many optional features.
  And the library names are hard-coded. So, the above command helps
  in this case.</p>
  
  <p>I also have a general interest in package management and binary dependencies.
  I know you can get direct dependencies with <code>readelf -d</code>, dependencies of
  dependencies with <code>ldd</code>. And I was wondering about optional dependencies, hence the question.</p>