On 10/5/18 12:43 AM, Bernhard Reutner-Fischer wrote: > Hi! > > So i just added archive handling to ease looking at more than just the > plain frontends, applied as r264856.
Running the tools for cc1 does not show anything. Please update the comment in the script with example invocation. > > You can now use the exact files passed to the driver when linking e.g. cc1. > We link libcommon.a twice? Didn't look. > > e.g.: > me@there:.../gcc$ /scratch/src/gcc-trunk/contrib/unused_functions.py > c/c-lang.o c-family/stub-objc.o attribs.o c/c-errors.o c/c-decl.o > c/c-typeck.o c/c-convert.o c/c-aux-info.o c/c-objc-common.o > c/c-parser.o c/c-fold.o c/gimple-parser.o c-family/c-common.o > c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o > c-family/c-gimplify.o c-family/c-indentation.o c-family/c-lex.o > c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o > c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-pretty-print.o > c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-ubsan.o > c-family/known-headers.o c-family/c-attribs.o c-family/c-warn.o > c-family/c-spellcheck.o i386-c.o glibc-c.o cc1-checksum.o > libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a > ../libdecnumber/libdecnumber.a libcommon.a ../libcpp/libcpp.a > ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a > ../libdecnumber/libdecnumber.a > > results in the attached output. > > This properly flags functions like e.g.: init_branch_prob (dead code), > bitwise_mode_for_mode in stor-layout.c (should be static). > > Of course it also complains about cases like supports_one_only() in cc1 > where that is only used in cc1plus. > Likewise constant_pool_empty_p() on i386 which is only used by ppc and spe. > > HTH, > I'm not currently playing with alternative approach. As mentioned I run diagnostics from rtags and it looks they added new functionality --find-dead-functions that lists dead functions. It provides reasonable results, it finds also overloads of functions and class member functions. Similarly I suggested to add --find-dead-variables: https://github.com/Andersbakken/rtags/issues/1234 What's nice about it is that it can also find dead local variables, like: gcc/tree-vect-loop.c:5875:34: widest_int ni, max_loop_value, lhs_max; It's still WIP, needs to be done properly. For the external symbols that can be turned into static, I created issue: https://github.com/Andersbakken/rtags/issues/1235 I'm planning to prepare a patch that will remove the dead symbols. Martin