[lld] [LLD][COFF] Create COFFObjectFile instance when constructing ObjFile (NFC) (PR #120144)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 13:02:49 PST 2024


cjacek wrote:

This change prepares for re-landing #119294. Determining the machine type of the object is necessary when constructing `InputFile`, as it dictates which symbol table to use. Initially, the machine type was read directly from the memory buffer, which works for regular COFF files but requires different handling for bigobj files. While it would be feasible to implement that logic directly, the necessary handling already exists in the `COFFObjectFile` implementation (and `identify_magic`), making it seems better to leverage that instead.

Currently, the creation of `COFFObjectFile` instances is postponed until the file is parsed. This PR moves the creation earlier in the process. Since these instances are created regardless, this change does not introduce additional work but simply schedules it earlier.

This change introduces no memory overhead for fully parsed files. However, it does affect objects that are lazily parsed, such as those in thin libraries or wholearchive imports. Currently, a temporary `COFFObjectFile` is created in `parseLazy` and recreated if the file is later used. With this PR, `parseLazy` reuses the object stored in `ObjFile`, making it non-temporary. While this changes memory usage, the impact is minimal since `COFFObjectFile` is primarily a set of pointers to the memory buffer, which is already stored. For fully parsed files, this PR avoids constructing the object twice, offering a slight performance improvement.

Creating the underlying object to represent the binary type is not a new approach, as it is already done for LTO input files.

With this PR, it becomes possible to use `COFFObjectFile::getMachine()` directly in `ObjFile::create` as part of #119294.

https://github.com/llvm/llvm-project/pull/120144


More information about the llvm-commits mailing list