Ensure that symbols that are explicitly assigned a section name are placed into a section with compatible entry sizes. This affects mergeable symbols and non-mergeable symbols that are explicitly assigned to a generic mergeable section name.
The basic mechanism is to create multiple sections with the same name, using LLVM's ", unique," assembly extension (I refer to such sections as unique or uniqued sections) if incompatible symbols are explicitly given the same section name.
The simplest way to implement this would be to put each symbol into its own uniqued section. However, this would increase the size of the generated object files and it would mean that the unique section extension, which is not supported by other assemblers, (although support is being implemented, https://sourceware.org/bugzilla/show_bug.cgi?id=25380) would be used when it is not required.
Instead the implementation:
- Avoids using uniqued sections where possible.
- Tries to create as few SHF_MERGE sections as possible.
The generic section for a given section name is considered mergeable if the name is a mergeable default section name (such as .debug_str), a mergeable implicit section name (such as .rodata.cst4), or MC has already created a mergeable generic section for the given section name in response to a section directive in assembler. Otherwise, non-mergeable symbols are assigned to the generic section for a given section name and mergeable symbols are assigned to uniqued sections.
Symbols with a an explicit assignment to a section name may already be put into uniqued sections to handle COMDATs. The COMDAT uniquing takes precedence; which can make the UniqueID in the generated assembly redundant. This is an outstanding problem with the uniqing mechanism and I have just accepted the redundancy in this patch - it isn't harmful, just confusing. Update: There will be a similar issue for associated symbols once https://reviews.llvm.org/D74006 lands.
- default sections are those always created by MC initially, e.g. .text or .debug_str
- implicit section are those created normally by the MC in response to the symbols that it encounters, i.e. in the absence of an explicit section name assignment on the symbol.
- generic sections are those sections that will be referred to when a uniqueID is not supplied. Typically these are the first section of a given name to be created. Default sections are always generic.
This is a fix for https://bugs.llvm.org/show_bug.cgi?id=43457.
See https://reviews.llvm.org/D68101 for previous discussions leading to this patch.