使用 -ffunction-sections 标志编译的不同静态库
Distinct static library compiled with -ffunction-sections flag
如何区分使用 -ffunction-sections
编译器标志编译的静态库?
我想确定某些特定的 .a
库是否可以从 -Wl,--gc-sections
标志中受益。
如果有办法列出所有的部分名称,那么我可以对其应用 | wc -l
并推断,部分太多,库可能是用提到的标志编译的。
readelf -S
仅打印存档的 *.o
个文件名。
一个简单的例子:
# Collect function sections
$ readelf -S tmp.o | sed -ne 's/.*\] \.text.\([a-zA-Z0-9_]\+\) .*//p' | sort -u > fun_sec.lst
# Collect function symbols
$ nm tmp.o | grep ' T ' | awk '{print }' | sort -u > fun_sym.lst
# Compare
$ COMM=$(comm -12 fun_sym.lst fun_sec.lst | wc -l)
$ UNIQ=$(comm -3 fun_sym.lst fun_sec.lst | wc -l)
$ if test $COMM -gt $UNIQ; then echo "tmp.o was likely compiled with -ffunction-sections"; fi
如何区分使用 -ffunction-sections
编译器标志编译的静态库?
我想确定某些特定的 .a
库是否可以从 -Wl,--gc-sections
标志中受益。
如果有办法列出所有的部分名称,那么我可以对其应用 | wc -l
并推断,部分太多,库可能是用提到的标志编译的。
readelf -S
仅打印存档的 *.o
个文件名。
一个简单的例子:
# Collect function sections
$ readelf -S tmp.o | sed -ne 's/.*\] \.text.\([a-zA-Z0-9_]\+\) .*//p' | sort -u > fun_sec.lst
# Collect function symbols
$ nm tmp.o | grep ' T ' | awk '{print }' | sort -u > fun_sym.lst
# Compare
$ COMM=$(comm -12 fun_sym.lst fun_sec.lst | wc -l)
$ UNIQ=$(comm -3 fun_sym.lst fun_sec.lst | wc -l)
$ if test $COMM -gt $UNIQ; then echo "tmp.o was likely compiled with -ffunction-sections"; fi