From e126f7254c8efddcaff96e8392685ccc8c74e797 Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Tue, 2 Apr 2019 17:28:06 -0400 Subject: [PATCH] minor workaround for lazy binding --- include/hip/hcc_detail/code_object_bundle.hpp | 9 +++++---- src/code_object_bundle.cpp | 8 +------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/hip/hcc_detail/code_object_bundle.hpp b/include/hip/hcc_detail/code_object_bundle.hpp index 89b341afa7..8b1ae8aa49 100644 --- a/include/hip/hcc_detail/code_object_bundle.hpp +++ b/include/hip/hcc_detail/code_object_bundle.hpp @@ -89,9 +89,10 @@ struct Bundled_code { std::vector blob; }; +#define magic_string_ "__CLANG_OFFLOAD_BUNDLE__" + class Bundled_code_header { // DATA - STATICS - static constexpr const char magic_string_[] = "__CLANG_OFFLOAD_BUNDLE__"; static constexpr auto magic_string_sz_ = sizeof(magic_string_) - 1; // DATA @@ -143,12 +144,12 @@ class Bundled_code_header { std::vector{std::istreambuf_iterator{is}, std::istreambuf_iterator{}}, x); } - // FRIENDS - ACCESSORS friend inline bool valid(const Bundled_code_header& x) { - return std::equal(magic_string_, magic_string_ + magic_string_sz_, - x.header_.bundler_magic_string_); + const std::string ms = {magic_string_}; + return std::equal(ms.begin(), ms.end(), x.header_.bundler_magic_string_); } + friend inline const std::vector& bundles(const Bundled_code_header& x) { return x.bundles_; } diff --git a/src/code_object_bundle.cpp b/src/code_object_bundle.cpp index 6285cb3828..feef90a61a 100644 --- a/src/code_object_bundle.cpp +++ b/src/code_object_bundle.cpp @@ -10,9 +10,6 @@ using namespace std; -// DATA - STATICS -constexpr const char hip_impl::Bundled_code_header::magic_string_[]; - // CREATORS hip_impl::Bundled_code_header::Bundled_code_header(const vector& x) : Bundled_code_header{x.cbegin(), x.cend()} {} @@ -22,12 +19,9 @@ hip_impl::Bundled_code_header::Bundled_code_header( // hipLoadModuleData is so poorly specified (for no fault of its own). if (!p) return; + if (!valid(*static_cast(p))) return; auto ph = static_cast(p); - if (!equal(magic_string_, magic_string_ + magic_string_sz_, ph->bundler_magic_string_)) { - return; - } - size_t sz = sizeof(Header_) + ph->bundle_cnt_ * sizeof(Bundled_code::Header); auto pb = static_cast(p) + sizeof(Header_); auto n = ph->bundle_cnt_;