[lld] [LLD][COFF] Store reference to SymbolTable instead of COFFLinkerContext in InputFile (NFC) (PR #119296)
Jacek Caban via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 10 05:34:12 PST 2024
cjacek wrote:
Copying a comment from #119294 for a better context:
With hybrid images and two namespaces, `file->ctx.symtab` isn’t always accurate. EC files should use the hybrid symbol table instead, which would look something like `file->ctx.getSymtab(file->getMachineType())`.
My initial draft followed this approach (encapsulated in an `InputFile` helper) and updated all relevant code to utilize it. However, this approach felt suboptimal - it distributed complexity across the codebase and increased the risk of mistakes or omissions. Instead, storing `symtab` directly in `InputFile` and determining the correct symbol table during object construction made it easier to access and encapsulated the complexity.
I considered storing both `COFFLinkerContext` and `SymbolTable` references in the `InputFile` class. This would allow both `file->ctx` and `file->symtab` to work. However, since the context is easily accessible from the symbol table, this approach felt redundant. To save memory, I opted to store only `symtab`, replacing `file->ctx` with `file->symtab.ctx`.
The required changes to use `file->symtab.ctx` seemed manageable to me. Additionally, with further refactoring, the number of such instances will likely decrease. For instance, commit 48b055dbd4961f4 in #119298 removes many such cases. Another example would be updating `ImportThunkChunk` to store `symtab` instead of `ctx`, further reducing these instances.
https://github.com/llvm/llvm-project/pull/119296
More information about the llvm-commits
mailing list