When placing global variables in a previously encountered user defined
section, check that the flags for the new global variable are compatible
with the existing flags on the section, and emit an error if not.
Otherwise, update the section flags with the union of the new and old
flags and emit a remark.
I am not sure if this is the correct approach to take and would welcome
any feedback.
There is already some mitigation for this in clang (e.g.
https://reviews.llvm.org/D93102). However, the problem could still arise
when the global variables are in separate translation units and LTO was enabled.
Some previous discussion about merging sections with values of different size
can be found here:
https://bugs.llvm.org/show_bug.cgi?id=43627 https://reviews.llvm.org/D72194 https://reviews.llvm.org/D68101
Although precise, this looks like it could be difficult to maintain as more section types are added. Reserved section names typically follow a naming convention with a prefix such as .debug for all of the dwarf sections. For example see StringRef getSectionPrefixForGlobal(SectionKind Kind) it may be more maintainable to base this on a prefix.