Skip to content
/ Localizer Public

A simple tool to find functions which can be made static

License

Notifications You must be signed in to change notification settings

yugr/Localizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Build Status codecov Total alerts

What is this

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.

How to run

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.

How to test

Run

$ test/run_tests.sh

Limitations

By design the tool is unable to detect conditional uses of symbols which are hidden under #ifdefs.

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).

Cross-compilation

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

Findings

TODO

  • 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)

About

A simple tool to find functions which can be made static

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages