cc: list trimmed.
On Fri, 1 Feb 2002 23:30:20 -0800,
Chris Wedgwood <cw@f00f.org> wrote:
>compile and link it, have the linker know main or some part of crt0 is
>special, build a graph of the final ELF object, see that bar and blem
>are not connected to 'main' and discard them?
>
>I'm pretty sure (but not 100% certain) that oher compilers can do
>this, maybe someone can test on other platforms?
>
>A really smart linker (if given enough compiler help) could build a
>directional graph and still remove this code even if blem called foo.
AFAICT it has to be done in two stages. Identify extern symbols that
are not referenced and convert them to static, then compile and let gcc
warn about unused statics and remove them.
The two stage approach is required because ld does not have enough
information to identify all function calls. ld views an object as
opaque blobs of text and data with relocation entries that tie them
together. When a function is called from the same source file, gcc/gas
tend to use PC relative branches for the inter-source call. PC
relative local branches do not usually generate relocation entries.
Without a relocation entry, ld cannot detect the inter-source call.
There is also a problem with exported symbols. To ld, EXPORT_SYMBOL
looks like a reference to the symbol, but the export entry is
irrelevant, what really matters is if any module refers to those
symbols. ld cannot distinguish between used and unused exported
symbols. To make matters worse, if you define foo as static and
EXPORT_SYMBOL(foo) in the same source then gcc thinks that the symbol
is used, because of the EXPORT_SYMBOL() reference. Again what really
matters is if any module uses the exported symbol.
The script below runs the .o files for the kernel and identifies extern
symbols with no extern references, i.e. the first part of the problem.
It knows about exported symbols and modules and handles them correctly.
I have not run the script for years, the list of conglomerates and the
list starting with mod_use_count_ will need updating.
Beware that you get a lot of false positives because of the kernel
config mechanism. A symbol may be listed as unused but changing the
config may cause it to be used. This is especially true for exported
symbols.
<davem>What, no initc**l reference?</davem>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Thu Feb 07 2002 - 21:00:21 EST