compiler-rt/cpu_model: Ensure constructor priority is set and align with GCC
GCC recently started setting constructor priority on init_have_lse_atomics [1] to avoid undefined initialization order with respect to other initializers, causing accidental use of ll/sc intrinsics on targets where this was not intended (which presents a minor performance problem as well as a compatibility problem for users wanting to use the rr debugger). I initially thought compiler-rt does not have the same issue as libgcc, since it looks like we're already setting init priority on the constructor. Unfortuantely, it does not appear that the HAVE_INIT_PRIORITY check is ever performed anyway, so despite appearances the init priority was not actually applied. Fix that by applying the init priority unconditionally. It has been supported in clang ever since it was first introduced and in any case for more than 14 years in both gcc and clang. MSVC is already excluded from this code path and we're already using constructors with init priority elsewhere in compiler-rt without additional check (though mostly in the sanitizer runtime, which may have more narrow target support). Regardless, I believe that for our supported compilers, if they support the constructor attribute, they should also support init priorities. While we're here, change the init priority from 101, which is the highest priority for end user applications, to instead use one of the priority levels reserved for implementations (1-100; lower integers are higher priority). GCC ended up using `90`, so this commit aligns the value in compiler-rt to the same value to ensure that there are no subtle initialization order differences between libgcc and compiler-rt. [1] https://github.com/gcc-mirror/gcc/commit/75c4e4909ae2667f56487434f99c2915b4570794 Differential Revision: https://reviews.llvm.org/D126424
Loading
Please sign in to comment