{"id":18627516,"url":"https://github.com/yugr/localizer","last_synced_at":"2025-06-25T08:36:53.457Z","repository":{"id":41436457,"uuid":"343142563","full_name":"yugr/Localizer","owner":"yugr","description":"A simple tool to find functions which can be made static","archived":false,"fork":false,"pushed_at":"2023-02-07T19:21:03.000Z","size":36,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T14:04:58.868Z","etag":null,"topics":["interfaces","linker","static-analysis"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yugr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-28T15:43:38.000Z","updated_at":"2022-12-21T19:11:09.000Z","dependencies_parsed_at":"2023-02-11T14:00:48.359Z","dependency_job_id":null,"html_url":"https://github.com/yugr/Localizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yugr/Localizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2FLocalizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2FLocalizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2FLocalizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2FLocalizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yugr","download_url":"https://codeload.github.com/yugr/Localizer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yugr%2FLocalizer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261836829,"owners_count":23217304,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interfaces","linker","static-analysis"],"created_at":"2024-11-07T04:42:39.260Z","updated_at":"2025-06-25T08:36:53.433Z","avatar_url":"https://github.com/yugr.png","language":"Python","readme":"[![License](http://img.shields.io/:license-MIT-blue.svg)](https://github.com/yugr/Localizer/blob/master/LICENSE.txt)\n[![Build Status](https://github.com/yugr/Localizer/actions/workflows/ci.yml/badge.svg)](https://github.com/yugr/Localizer/actions)\n[![codecov](https://codecov.io/gh/yugr/Localizer/branch/master/graph/badge.svg)](https://codecov.io/gh/yugr/Localizer)\n[![Total alerts](https://img.shields.io/lgtm/alerts/g/yugr/Localizer.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/yugr/Localizer/alerts/)\n\n# What is this\n\nLocalizer is a simple experimental tool\nwhich tries to detect symbols which could localized within their module\ni.e. be marked as `static` or moved to anon. namespace.\n\nLocalization of symbols is beneficial because it\n[enables optimizations](https://embeddedgurus.com/stack-overflow/2008/12/efficient-c-tips-5-make-local-functions-static/)\nand prevents interface pollution.\n\nThe tool works by intercepting calls to linker and\nanalyzing symbol imports and exports.\n\n# How to run\n\nRun your build script under `find-locals.py` script:\n```\n$ make clean\n$ find-locals.py make -j10 all\n```\n\nIf you want to ignore symbols which are present in headers, do\n```\n$ find-locals.py --ignore-header-symbols $PWD make ...\n```\n\nIn many cases symbols are exported so that they can be used in unit tests\nso you may need to build tests as well:\n```\n$ find-locals.py 'make -j10 \u0026\u0026 make -j10 check'\n```\n\nFor more options, run `find-locals.py -h`.\n\n# How to test\n\nRun\n```\n$ test/run_tests.sh\n```\n\n# Limitations\n\nBy design the tool is unable to detect conditional uses of symbols\nwhich are hidden under `#ifdef`s.\n\nSometimes compiler is also clever enough to optimize out function calls\neven if they are present in text (e.g. by propagating constant arguments\ninto static functions). For this reason it's recommended to run the tool\non _unoptimized_ build, to disable function inlining and cloning.\nFor Autotools-enabled projects just do\n```\n$ ./configure CFLAGS='-g -O0' CXXFLAGS='-g -O0'\n```\n\nFinally, there's no need to report unused C++ methods\nas there's no way to localize them. But I still do this\nbecause they can't be distinguished from symbols in namespaces\nwhich _can_ be localized (by moving them to anon. namespaces).\n\n# Cross-compilation\n\nTo support cross-compilation you may need to add a symlink to appropriate\ncross-linker in `bin/` directory e.g.\n```\n$ ln -s ld aarch64-linux-gnu-ld\n```\n\n# Findings\n\n* 15 symbols in [GNU awk](https://lists.gnu.org/archive/html/bug-gawk/2021-03/msg00001.html) (fix [merged](http://git.savannah.gnu.org/cgit/gawk.git/commit/?id=f285f960bdfb5acb50a8ec7ed4b98f17d0bd624a))\n* 4 symbols in GNU bc (private communication)\n* 18 symbols in [GNU screen](https://lists.gnu.org/archive/html/screen-devel/2021-03/msg00000.html)\n* 6 symbols in [GNU make](https://lists.gnu.org/archive/html/bug-make/2021-03/msg00021.html)\n* 100+ symbols in [QEMU](https://mail.gnu.org/archive/html/qemu-devel/2021-03/msg07706.html)\n\n# TODO\n\n* Integrate LGTM, Codecov and Travis\n* Do not report virtual methods (they aren't directly used in other files)\n* Report C++ symbols only if they are in namespaces (not classes)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugr%2Flocalizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyugr%2Flocalizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyugr%2Flocalizer/lists"}