From d7d1e20dbd905ccbce5a669f512bb8fa564c2da6 Mon Sep 17 00:00:00 2001 From: Dmitrii Ishcheikin Date: Mon, 15 May 2023 15:42:52 +0000 Subject: Fix libart-compiler ReadBarrier flag init order `gCompilerReadBarrierOption` from libart-compiler depends on `gUseReadBarrier` from libart. When both libraries are static linked, the initialization order is not guaranteed to be correct. The fix is to replace `gCompilerReadBarrierOption` with a function, so that it is initialized on first use. Test: m test-art-host-gtest Test: m test-art-host-gtest (with static linked libart/libart-compiler) Bug: 186902856 Change-Id: I386c64c3bd7b42391623b5cded5757366d847b3f --- compiler/optimizing/code_generator.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/optimizing/code_generator.h') diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h index 9872efaa4a..576f363a67 100644 --- a/compiler/optimizing/code_generator.h +++ b/compiler/optimizing/code_generator.h @@ -59,8 +59,12 @@ static int32_t constexpr kPrimIntMax = 0x7fffffff; // Maximum value for a primitive long. static int64_t constexpr kPrimLongMax = INT64_C(0x7fffffffffffffff); -static const ReadBarrierOption gCompilerReadBarrierOption = - gUseReadBarrier ? kWithReadBarrier : kWithoutReadBarrier; +// Depending on configuration, `gUseReadBarrier` can be a static const variable. +// Static variable initialization order across different compilation units is not defined, +// so function is used instead of static variable `gCompilerReadBarrierOption`. +inline ReadBarrierOption GetCompilerReadBarrierOption() { + return gUseReadBarrier ? kWithReadBarrier : kWithoutReadBarrier; +} constexpr size_t status_lsb_position = SubtypeCheckBits::BitStructSizeOf(); constexpr size_t status_byte_offset = -- cgit v1.2.3-59-g8ed1b