ld could translate --as-needed to -z ignore
GNU ld has an option, --as-needed to only record dynamic dependencies for libraries which are actually referenced.
We have -z ignore which does the same thing, but also ignores unreferenced ELF sections from relocatable objects.
In practice, it should be safe to map --as-needed to -zignore for GNU compatibility. The risk would be to applications which had unreferenced ELF sections which they nevertheless wished to be represented in output and had discovered and passed --as-needed and did so in a way which positionally affected the input object.
This is unlikely.
The obvious code is available from:
Updated by Rich Lowe almost 10 years ago
It should be mentioned that while we can do this part, it doesn't actually help for the specific case in which it is desired, because of some other issues related to C++ exception handling.
Implementing this actually makes the case we care about worse, unless that is fixed