microsoft / SizeBench

SizeBench is a binary size investigation tool for Windows
MIT License
103 stars 14 forks source link

Add support for LLD-linked binaries, Clang _Float16 type, and various package upgrades, etc. #29

Closed Austin-Lamb closed 9 months ago

Austin-Lamb commented 9 months ago

Why is this change being made?

Customers have asked for support for binaries linked by lld/lld-link and up to now SizeBench has rejected everything except things linked with MSVC's link.exe. This is because the binaries and PDBs produced by MSVC have more data in them than LLD-linked ones.

For example, LLD's PDB's don't contain SymTagCoffGroup symbols that account for all the space in a binary, they have gaps for various PE data structures like the IAT or CFG tables. LLD's PE outputs also don't contain any COFF group data at all.

So, this change does its best to add support for LLD-linked binaries by synthesizing data structures to fill these gaps. This has been tested with a couple customer-provided LLD binaries as well as a much smaller and less rigorous test binary in this change.

Along the way I also added support for Clang's _Float16 extension type when looking at type layouts since I can now do clang/lld testing. This is also a customer request.

Fixes #26

Briefly summarize what changed

I parse a variety of data directly out of the PE file if I can't find it in the PDB, such as the CFG table (found via the load config directory), or import tables, delay-load imports, etc. This is in line with how SizeBench already parsed PDATA and XDATA out of PE files since even MSVC does not record much data for those in PDBs.

As I was doing this, I also took the opportunity to upgrade to .NET 8 now that the new LTS release is out. I upgraded all package dependencies that I could to keep up to date for security issues and the like. I then made the code clean for warnings and messages that code analysis enabled due to the new .NET 8 SDK having better analyzers that caught a number of issues or recommended upgrading to newer .NET 8 things like [LibraryImport].

I also moved some hand parsing of PE structures to use System.Reflection.PortableExecutable since I didn't know about it when I wrote the code originally (or it may not have existed then), allowing me to re-use some of that package's work and simplify a bit in SizeBench.

How was the change tested?

PR Checklist