diff options
author | Thomas Haller <thaller@redhat.com> | 2016-10-11 16:40:00 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-13 21:33:33 +0200 |
commit | b171fbc9ca86223dc055f81a12c0e1f4c4318dde (patch) | |
tree | 7729a646a804736546d9d983faebd52a075aae86 /tools/create-exports-NetworkManager.sh | |
parent | 76a057b4ec50ae71b778a1cf44277dec162bab09 (diff) | |
download | NetworkManager-b171fbc9ca86223dc055f81a12c0e1f4c4318dde.tar.gz |
build: explicitly whitelist symbols in NetworkManager binary
- this allows the linker to drop unused symbols via link-time optimization
or with --gc-sections:
git clean -fdx
./autogen.sh --enable-ld-gc --enable-ifcfg-rh --enable-ifupdown \
--enable-ifnet --enable-ibft --enable-teamdctl --enable-wifi \
--with-modem-manager-1 --with-ofono --with-more-asserts \
--with-more-logging
make -j20
strip ./src/NetworkManager
gives 2822840 vs. 2625960 bytes (-7%).
- this also gives more control over the symbols that are used by the
plugins. Yes, it means if you modify a plugin to use a new symbols,
you have to extend NetworkManager.ver file.
You can run the script to create the version file:
$ ./tools/create-exports-NetworkManager.sh update
but be sure that your current configuration enables all plugins
and debugging options to actually use all symbols that are in use.
- If you compile with certain plugins enabled, you could theoretically
re-compile NetworkManager to expose less symbols. Try:
$ ./tools/create-exports-NetworkManager.sh build
- note that we have `make check` tests to ensure that all used
symbols of the plugins can be found. So, it should not be possible
to accidentally forget to expose a symbol.
Diffstat (limited to 'tools/create-exports-NetworkManager.sh')
-rwxr-xr-x | tools/create-exports-NetworkManager.sh | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/tools/create-exports-NetworkManager.sh b/tools/create-exports-NetworkManager.sh new file mode 100755 index 0000000000..f0cdd419f9 --- /dev/null +++ b/tools/create-exports-NetworkManager.sh @@ -0,0 +1,104 @@ +#!/bin/bash + +set -e + +# generates the linker version script src/NetworkManager.ver +# by looking at the symbols needed by the device and settings +# plugins. Note that this depends on how NetworkManager and +# the plugins are build. For example, compiling without +# --with-more-asserts will yield less symbols. +# +# _build re-builds NetworkManager with relevant compile time +# options to yield the most symbols. +_build() { + git clean -fdx + ./autogen.sh --enable-ld-gc --enable-ifcfg-rh --enable-ifupdown \ + --enable-ifnet --enable-ibft --enable-teamdctl --enable-wifi \ + --with-modem-manager-1 --with-ofono --with-more-asserts \ + --with-more-logging + make -j20 +} + +_sort() { + LANG=C sort -u +} + +call_nm() { + nm "$1" | + sed -n 's/^................ \(.\) \(.*\)$/\1 \2/p' +} + +get_symbols_nm () { + call_nm ./src/NetworkManager | + sed -n 's/^[tTDR] //p' | + _sort +} + +get_symbols_explict() { + cat <<EOF | _sort +_IO_stdin_used +EOF +} + +get_symbols_missing() { + (for f in ./src/settings/plugins/*/.libs/*.so ./src/devices/*/.libs/*.so; do + call_nm "$f" | + sed -n 's/^\([U]\) \(\(nm_\|nmp_\|_nm\|NM\|_NM\).*\)$/\2/p' + done) | + _sort | + grep -Fx -f <(get_symbols_explict) -v | + grep -Fx -f <(get_symbols_nm) +} + +pretty() { + sed 's/.*/\t\0;/' +} + +do_build() { + do_update + touch src/main.c + make +} + +do_rebuild() { + _build + do_build +} + +do_update() { + do_generate > ./src/NetworkManager.ver +} + +do_generate() { + cd "$(realpath $(dirname "$0"))/.." + test -f ./src/NetworkManager + + cat <<EOF +# this file is generated by $0 +{ +global: +$(get_symbols_missing | pretty) + +$(get_symbols_explict | pretty) +local: + *; +}; +EOF +} + + +case "$1" in + rebuild) + do_rebuild + ;; + build) + do_build + ;; + update) + do_update + ;; + *) + do_generate + ;; +esac + |