mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
tools: Add script to detect unused symbols in libshared
Symbols exported by libshared can't get pruned by the linker, so every unused exported symbol is effectively dead code we ship to users for no good reason. Let's add a script to analyze how many such symbols we have. We also add a meson test to run the script on all of our binaries. Since it detects unused symbols and still has a few false positives, don't enable the test by default similar to the clang-tidy tests. The script was 100% vibe coded by Github Copilot with Claude Sonnet 4.5 as the model. Current results are (without the unused symbols list): Analysis of libsystemd-shared-259.so ====================================================================== Total exported symbols: 4830 (excluding public API symbols starting with 'sd_') Used symbols: 4672 Unused symbols: 158 Usage rate: 96.7%
This commit is contained in:
15
meson.build
15
meson.build
@@ -15,7 +15,7 @@ project('systemd', 'c',
|
||||
|
||||
add_test_setup(
|
||||
'default',
|
||||
exclude_suites : ['clang-tidy', 'integration-tests'],
|
||||
exclude_suites : ['clang-tidy', 'unused-symbols', 'integration-tests'],
|
||||
is_default : true,
|
||||
)
|
||||
|
||||
@@ -3000,6 +3000,19 @@ if meson.version().version_compare('>=1.4.0')
|
||||
endforeach
|
||||
endif
|
||||
|
||||
symbol_analysis_exes = []
|
||||
foreach name, exe : executables_by_name
|
||||
symbol_analysis_exes += exe
|
||||
endforeach
|
||||
|
||||
find_unused_library_symbols = find_program('tools/find-unused-library-symbols.py')
|
||||
test(
|
||||
'libshared-unused-symbols',
|
||||
find_unused_library_symbols,
|
||||
suite : 'unused-symbols',
|
||||
args : [libshared, libcore] + nss_targets + pam_targets + symbol_analysis_exes,
|
||||
)
|
||||
|
||||
run_target(
|
||||
'check-api-docs',
|
||||
depends : [man, libsystemd, libudev],
|
||||
|
||||
Reference in New Issue
Block a user