The primary problem with the existing approach is that --gc-sections
will only regard non-COMDAT notes as GC roots, and so will happily GC
our ABI note, which happens when building base's LLVM. The use of COMDAT
was chosen in the first place to allow crti to be optional, but crt1 is
only used for executables, so shared libraries that don't use crti still
end up lacking an ABI note, which is precisely what the original commit
was trying to solve. Notably, for CHERI's CheriABI, we don't provide a
crti, as we fully remove support for legacy _init/_fini; we could
provide a dummy crti, but the motivation for using COMDAT in the first
place was to allow crti to be optional, so this seems silly.
Instead, just put the ELF note in crtbegin (and its S and T variants),
as this file is included in all of PDEs, PIEs and DSOs.
Note: other operating systems are in disagreement about what the right
approach is. OpenBSD puts the note in crtbegin, like this commit. NetBSD
puts the note in crti, like we could do if we made crti mandatory (and
provided it for CheriABI downstream), but doesn't seem to have any
benefit over crtbegin. Linux's glibc puts the note in crt1, which is
what we used to do, and means only executables get notes, and not shared
libraries.