title: linker --as-needed flag not pruning libraries
body: <p>I'm running into an issue after upgrading gcc from 4.1.1 to 4.7.2.  The problem is that the ld --as-needed flag is not pruning libraries that are not required if enough libraries with inter dependencies are listed.</p>
  
  <p>For example, if I build a simple program that doesn't need any special libraries, but includes them on the build line, as such</p>
  
  <pre><code>gcc -m32 test.c -Wl,--as-needed -L/usr/local/lib -lrt -lprojcommon -lproj -lrte  -o test
  </code></pre>
  
  <p>then it builds fine and the --as-needed flag does it's job pruning out all of the listed libs that are not needed.</p>
  
  <pre><code>ldd test
  linux-gate.so.1 =&gt;  (0x00bfc000)
  libc.so.6 =&gt; /lib/libc.so.6 (0x001ac000)
  /lib/ld-linux.so.2 (0x0018a000
  </code></pre>
  
  <p>However, if I add one more library (in this case crypto), then the build fails with undefined reference errors. </p>
  
  <pre><code>gcc -m32 test.c -Wl,--as-needed -L/usr/local/lib -lcrypto -lrt -lprojcommon -lproj -lrte  -o test
  
  /usr/local/lib/librte.so: error: undefined reference to 'tla_decap_data'
  /usr/local/lib/librte.so: error: undefined reference to 'do_db'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>This exact same build worked with 4.1.1, but started failing with 4.7.2.  </p>
  
  <p>This is part of a general build infra and libraries included on the build line are generic and expected to be pruned via --as-needed.  I could fix this with --allow-shlib-undefined, but I'd prefer to find real unresolved symbols at build time.  If I do set --allow-shlib-undefined, then I end up with the same set of required libs as the build that worked.</p>
  
  <p>Any insight would be appreciated.</p>