Right now we handle each CsectGroup(ProgramCodeCsects, BSSCsects) individually when assigning indices, writing symbol table, and writing section raw data. However, there is already a pattern there, and we could common up those actions for every CsectGroup. This will make adding new CsectGroup(Read Write data, Read only data, TC/TOC, mergeable string) easier, and less error prone.
I believe right now we are always emitting a label def for csects that support them even if it could be skipped, however there has been discussion to skip them when appropriate. UseLabelDefinition to me sounds like its saying implying yes to both the global and local criteria. In that light maybe enum values of 'LabelDefSupported' and 'LabelDefUnsupported' are more appropriate. (Or we can adjust the names when we implement the selective label def emission).
Minor nit: IIUC this is all the sections, as opposed to the non-empty sections. We can determine if a section is non-empty when it has been assigned a valid section index.
Should we maintain CurrentAddressLocation across groups to make sure there is no padding between groups?
I think we should consider using llvm::all_of to check if all the groups are empty and continue if they are. Then the section initialization can be done before processing any of the csects, without having to gate the initialization on if its section index is already valid , as well as adjust the size after processing the csects without an addition check to see if the section was initialized or not.
I think a fatal error would be more appropriate.
Minor nit: should we be creating a named constant for readability/documentation.
Address Sean's comment.
Do you mean maintain CurrentAddressLocation across Sections? Since it's currently already maintained across groups.
I still need a guard for
But I do think using a specific guard for that is better than just comparing UninitializedIndex everywhere.
It might be Okay depending on how we write our code later. But there is a chance we could run into risks of needing differentiate a special section number with a truely uninitialized section. So I would prefer to pick a section number that's not used to represent other things.
Thanks. I will address.