Uefi aware compiler to check redundant code - shijunjing/edk2 GitHub Wiki
Current usage
Get the infcheck_llvm70.tgz from Shi Steven firstly, then build as below steps in Ubuntu18.04. If you have different version Linux, please ensure you use the Binutils ld 2.3x as default linker.
$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.30
Below use the NetworkPkg as example, you can change it to your interested Pkg.
$ git clone https://github.com/shijunjing/edk2.git edk2-fork
$ git checkout infcheck
$ tar -xvf infcheck_llvm70.tgz
$ export CLANGTOOL38_BIN=~/wksp_efi/infcheck_llvm70/bin/
$ rm Conf/tools_def.txt
$ rm Conf/target.txt
$ rm Conf/build_rule.txt
$ make -C BaseTools/ clean
$ make -C BaseTools/
$ build -p NetworkPkg/NetworkPkg.dsc -t CLANGTOOL38 -a X64 -b NOOPT -n 5 -DNETWORK_IP6_ENABLE=TRUE -DHTTP_BOOT_ENABLE=TRUE modules
The check report is in Pkg build arch folder. E.g. For NetworkPkg, its report is Build/NetworkPkg/NOOPT_CLANGTOOL38/X64/inflog.txt. And its content is like below:
Unused global variable in file: NetworkPkg/Dhcp6Dxe/Dhcp6Impl.c
malldhcpserversaddress, line 25
Unused global variable in file: NetworkPkg/Application/IpsecConfig/IpSecConfig.c
mstringipsechelptokenid, line 31
Unused global variable in file: NetworkPkg/Application/VConfig/VConfig.c
mstringvconfighelptokenid, line 32
Unused global variable in file: NetworkPkg/IScsiDxe/IScsiConfig.c
mnumberofiscsidevices, line 19
miscsidevicelistupdated, line 18
Have submitted above redundant issues in below tracker: Redundant definitions in NetworkPkg "https://bugzilla.tianocore.org/show_bug.cgi?id=1413":https://bugzilla.tianocore.org/show_bug.cgi?id=1413
A potential better solution is based on the linker to dump dependency graph, the LLVM LLD community is discussing how to support it. We might change our current implementation (based IR level call graph and symbols info which doesn't support assembly code info) when the LLD dependency graph is ready(details see below link). "http://lists.llvm.org/pipermail/llvm-dev/2019-February/130649.html":http://lists.llvm.org/pipermail/llvm-dev/2019-February/130649.html
20190730
The lld is expected to support the file-level dependency output very soon. And I’ve asked the lld owner to add function and global variable level dependency support as well. The lld owner has agreed to support it in the future. I suggest we enable the module dependency feature in our new llvm/lld 10 toolchain in the feature.
Auto-generating build dependency file from lld http://lists.llvm.org/pipermail/llvm-dev/2019-July/134268.html