llvm::objcopy::elf::*Section::classof matches Type and Flags, yet Type
and Flags are mutable (setSectionFlagsAndTypes and upcoming
--only-keep-debug feature). Add OriginalType & OriginalFlags to be used
in classof, to prevent classof results from changing.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
For some section types, we call their classof (via isa or dyn_cast) before mutation, so using either OriginalType or Type does not matter, e.g. DynamicSymbolTableSection, GroupSection. Some classof methods are unused, e.g. DynamicSection::classof.
This seems like a good idea to me. It makes our classof results immutable after all, leading to a more robust program.
One thought I had: did you consider adding just a new "Kind" enum instead, with the various kinds of sections recorded? That would add one field to the section class rather than two. I don't know if the Original* flags really have any other usage, and it would allow us to add further types later on which are not identified by flag/type whilst simplifying the classof functions to a basic comparison.
We are tackling an expression problem. classof member functions are indeed the only place that OriginalType and OriginalFlag are read. If we introduce SectionBase::Kind as a new member variable, we can avoid OriginalType and OriginalFlag, but the classof logic will have to be centralized in one place, because we need to initialize Kind when a section is created.