|
|
ce18b3d |
From 5ee5974602b0cd19ebb76c32b718538a328ceb0f Mon Sep 17 00:00:00 2001
|
|
|
ce18b3d |
From: Philipp Knechtges <philipp-dev@knechtges.com>
|
|
|
ce18b3d |
Date: Tue, 24 Nov 2020 21:28:25 +0100
|
|
|
ce18b3d |
Subject: [PATCH 2/2] fix link-time ordering condition
|
|
|
ce18b3d |
|
|
|
ce18b3d |
This fixes a segfault error in cases where the linking order of
|
|
|
ce18b3d |
compilation unit varies. Reason behind the segfault is that one
|
|
|
ce18b3d |
global variable in one compilation unit depends on another global
|
|
|
ce18b3d |
variable in another compilation unit, but there is no gurantee that
|
|
|
ce18b3d |
this other compilation unit is initialized first. The fix forces a
|
|
|
ce18b3d |
reinitialization at the first invocation of the library.
|
|
|
ce18b3d |
---
|
|
|
ce18b3d |
src/core/common/hsa_table_interface.cpp | 10 +++++++++-
|
|
|
ce18b3d |
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
ce18b3d |
|
|
|
ce18b3d |
diff --git a/src/core/common/hsa_table_interface.cpp b/src/core/common/hsa_table_interface.cpp
|
|
|
ce18b3d |
index 11b1e49..6f8c3ed 100644
|
|
|
ce18b3d |
--- a/src/core/common/hsa_table_interface.cpp
|
|
|
ce18b3d |
+++ b/src/core/common/hsa_table_interface.cpp
|
|
|
ce18b3d |
@@ -64,7 +64,15 @@ class Init {
|
|
|
ce18b3d |
static Init LinkAtLoadOrFirstTranslationUnitAccess;
|
|
|
ce18b3d |
|
|
|
ce18b3d |
// Pass through stub functions
|
|
|
ce18b3d |
-hsa_status_t HSA_API hsa_init() { return coreApiTable->hsa_init_fn(); }
|
|
|
ce18b3d |
+hsa_status_t HSA_API hsa_init() {
|
|
|
ce18b3d |
+ // We initialize the api tables here once more since the code above is prone to a
|
|
|
ce18b3d |
+ // link-time ordering condition: This compilation unit here may get its global
|
|
|
ce18b3d |
+ // variables initialized earlier than the global objects in other compilation units.
|
|
|
ce18b3d |
+ // In particular Init::Init may get called earlier than that the underlying hsa_api_table_
|
|
|
ce18b3d |
+ // object in hsa_api_trace.cpp has been initialized.
|
|
|
ce18b3d |
+ rocr::core::LoadInitialHsaApiTable();
|
|
|
ce18b3d |
+ return coreApiTable->hsa_init_fn();
|
|
|
ce18b3d |
+}
|
|
|
ce18b3d |
|
|
|
ce18b3d |
hsa_status_t HSA_API hsa_shut_down() { return coreApiTable->hsa_shut_down_fn(); }
|
|
|
ce18b3d |
|
|
|
ce18b3d |
--
|
|
|
ce18b3d |
2.28.0
|
|
|
ce18b3d |
|