From f7bf882981e8d13a155fa77952274f744bc50707 Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Sat, 4 Jul 2020 23:15:03 -0400 Subject: [PATCH] Fix static lib crash by setting top init_priority Set top init_priority on affecting global variables so that they will be created firstly and destroyed lastly. Change-Id: Ied59fbecab66ba8195c4a7a02b6bef9fa2fad3af --- rocclr/compiler/lib/utils/options.cpp | 10 ++++++---- rocclr/device/device.cpp | 4 ++-- rocclr/include/top.hpp | 2 ++ rocclr/platform/memory.cpp | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rocclr/compiler/lib/utils/options.cpp b/rocclr/compiler/lib/utils/options.cpp index df2c983f71..9f58337698 100644 --- a/rocclr/compiler/lib/utils/options.cpp +++ b/rocclr/compiler/lib/utils/options.cpp @@ -88,10 +88,12 @@ OptionDescriptor OptDescTable[] = { Any prefix option (-f/-fno, -m/-mno) has no long name, and must have a value separator if it requires a value. */ -std::map OptionNameMap[2]; -std::map NoneSeparatorOptionMap[2]; -std::map FOptionMap; // prefix -f/-fno- options -std::map MOptionMap; // prefix -m/-mno- options +std::map OptionNameMap[2] ROCCLR_INIT_PRIORITY(101); +std::map NoneSeparatorOptionMap[2] ROCCLR_INIT_PRIORITY(101); +// prefix -f/-fno- options +std::map FOptionMap ROCCLR_INIT_PRIORITY(101); +// prefix -m/-mno- options +std::map MOptionMap ROCCLR_INIT_PRIORITY(101); bool setOptionVariable ( OptionDescriptor* oDesc, diff --git a/rocclr/device/device.cpp b/rocclr/device/device.cpp index 979fcb0d47..89eafe84bb 100755 --- a/rocclr/device/device.cpp +++ b/rocclr/device/device.cpp @@ -85,8 +85,8 @@ Context* Device::glb_ctx_ = nullptr; Monitor Device::p2p_stage_ops_("P2P Staging Lock", true); Memory* Device::p2p_stage_ = nullptr; -amd::Monitor MemObjMap::AllocatedLock_("Guards SVM allocation list"); -std::map MemObjMap::MemObjMap_; +Monitor MemObjMap::AllocatedLock_ ROCCLR_INIT_PRIORITY(101) ("Guards MemObjMap allocation list"); +std::map MemObjMap::MemObjMap_ ROCCLR_INIT_PRIORITY(101); size_t MemObjMap::size() { amd::ScopedLock lock(AllocatedLock_); diff --git a/rocclr/include/top.hpp b/rocclr/include/top.hpp index 76a1d6bfc9..5c087393db 100644 --- a/rocclr/include/top.hpp +++ b/rocclr/include/top.hpp @@ -71,9 +71,11 @@ typedef __int32 ssize_t; #if _MSC_VER < 1900 #define snprintf sprintf_s #endif +#define ROCCLR_INIT_PRIORITY(priority) #else /*!_WIN32*/ #define SIZE_T_FMT "%zu" #define PTR_FMT "%p" +#define ROCCLR_INIT_PRIORITY(priority) __attribute__ ((init_priority (priority))) #endif /*!_WIN32*/ typedef uint32_t cl_mem_fence_flags; diff --git a/rocclr/platform/memory.cpp b/rocclr/platform/memory.cpp index 8e179dcea9..b584f5ab6b 100644 --- a/rocclr/platform/memory.cpp +++ b/rocclr/platform/memory.cpp @@ -1430,8 +1430,8 @@ void Image::Format::formatColor(const void* colorRGBA, void* colorFormat) const } } -std::map SvmBuffer::Allocated_; -Monitor SvmBuffer::AllocatedLock_("Guards SVM allocation list"); +Monitor SvmBuffer::AllocatedLock_ ROCCLR_INIT_PRIORITY(101) ("Guards SVM allocation list"); +std::map SvmBuffer::Allocated_ ROCCLR_INIT_PRIORITY(101); void SvmBuffer::Add(uintptr_t k, uintptr_t v) { ScopedLock lock(AllocatedLock_);