Avoid UB in upb by switching to the XCT section, which will run our constructors before the compiler-generated initializers. #test-continuous This is detailed more in https://devblogs.microsoft.com/cppblog/new-compiler-warnings-for-dynamic-initialization/. PiperOrigin-RevId: 920402652
diff --git a/upb/port/def.inc b/upb/port/def.inc index 4616c65..b398a95 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc
@@ -668,10 +668,10 @@ * to prevent optimizers from removing the constructor. Our solution is to * create a dummy exported weak symbol that prevent this stripping. */ -#pragma section(".CRT$XCU", long, read) +#pragma section(".CRT$XCT", read) #define UPB_CONSTRUCTOR(name, unique_name) \ static void __cdecl UPB_PRIVATE(name)(void); \ - __declspec(allocate(".CRT$XCU"), selectany) void( \ + __declspec(allocate(".CRT$XCT"), selectany) void( \ __cdecl * UPB_PRIVATE(name##_))(void) = UPB_PRIVATE(name); \ __declspec(selectany, dllexport) void* UPB_PRIVATE(name##_force_linkage) = \ &UPB_PRIVATE(name##_); \