title: How can I differentiate static functions with nm or readelf output in C
body: <p>I am trying to process the output of a nm or readelf -s on an executable. However, I am having trouble differentiating static functions from each other in the output.</p>
  
  <p>Here is what I am working with:</p>
  
  <p><strong>test.c</strong></p>
  
  <pre><code>static int foo() {
      int x = 6;
  }
  
  main() {}
  </code></pre>
  
  <p><strong>other.c</strong></p>
  
  <pre><code>static int foo() {
      int x = 5;
  }
  </code></pre>
  
  <p>I compile these like so:</p>
  
  <pre><code>gcc -o test test.c other.c
  </code></pre>
  
  <p>And then run a nm command to get all the symbols:</p>
  
  <pre><code>nm test
  </code></pre>
  
  <p>Among which the following two symbols (for my static functions) appear:</p>
  
  <pre><code>00000000004004ed t foo
  0000000000400500 t foo
  </code></pre>
  
  <p>Is there a method to be able to distinguish which file the specific foo function appeared from? Or will I need to do some magic before compiling to get this to work?</p>
  
  <p>I should add that for my use case, I have access to the final binary and the object files used by it, but I cannot actually build it myself to ensure that it has a symbol table.</p>
  
  <p>Thanks!</p>