使用 -ffunction-sections 标志编译的不同静态库



如何区分使用编译器标志编译-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_]+) .*/1/p' | sort -u > fun_sec.lst
# Collect function symbols
$ nm tmp.o | grep ' T ' | awk '{print $3}' | 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

最新更新