Localizer is a simple experimental tool
which tries to detect symbols which could localized within their module
i.e. be marked as static
or moved to anon. namespace.
Localization of symbols is beneficial because it enables optimizations and prevents interface pollution.
The tool works by intercepting calls to linker and analyzing symbol imports and exports.
Run your build script under find-locals.py
script:
$ make clean
$ find-locals.py make -j10 all
If you want to ignore symbols which are present in headers, do
$ find-locals.py --ignore-header-symbols $PWD make ...
In many cases symbols are exported so that they can be used in unit tests so you may need to build tests as well:
$ find-locals.py 'make -j10 && make -j10 check'
For more options, run find-locals.py -h
.
Run
$ test/run_tests.sh
By design the tool is unable to detect conditional uses of symbols
which are hidden under #ifdef
s.
Sometimes compiler is also clever enough to optimize out function calls even if they are present in text (e.g. by propagating constant arguments into static functions). For this reason it's recommended to run the tool on unoptimized build, to disable function inlining and cloning. For Autotools-enabled projects just do
$ ./configure CFLAGS='-g -O0' CXXFLAGS='-g -O0'
Finally, there's no need to report unused C++ methods as there's no way to localize them. But I still do this because they can't be distinguished from symbols in namespaces which can be localized (by moving them to anon. namespaces).
To support cross-compilation you may need to add a symlink to appropriate
cross-linker in bin/
directory e.g.
$ ln -s ld aarch64-linux-gnu-ld
- 15 symbols in GNU awk (fix merged)
- 4 symbols in GNU bc (private communication)
- 18 symbols in GNU screen
- 6 symbols in GNU make
- 100+ symbols in QEMU
- Integrate LGTM, Codecov and Travis
- Do not report virtual methods (they aren't directly used in other files)
- Report C++ symbols only if they are in namespaces (not classes)