From 08c94463de80bdf8d773efee2e79a1e667e496b1 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Wed, 3 Apr 2024 16:29:34 -0400 Subject: [PATCH] loader: allow but skip static relocations for code object v2+ Change-Id: I4ae14cb5e740d7d45810b75038b15a0b94d2bf0b --- runtime/hsa-runtime/loader/executable.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/runtime/hsa-runtime/loader/executable.cpp b/runtime/hsa-runtime/loader/executable.cpp index 150a263650..a6ea83c335 100644 --- a/runtime/hsa-runtime/loader/executable.cpp +++ b/runtime/hsa-runtime/loader/executable.cpp @@ -1624,15 +1624,24 @@ Segment* ExecutableImpl::SectionSegment(hsa_agent_t agent, code::Section* sec) hsa_status_t ExecutableImpl::ApplyRelocations(hsa_agent_t agent, amd::hsa::code::AmdHsaCode *c) { hsa_status_t status = HSA_STATUS_SUCCESS; + + uint32_t majorVersion, minorVersion; + if (!c->GetCodeObjectVersion(&majorVersion, &minorVersion)) { + return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; + } + for (size_t i = 0; i < c->RelocationSectionCount(); ++i) { if (c->GetRelocationSection(i)->targetSection()) { + // Static relocations may be present if --emit-relocs + // option was passed to lld, but they cannot be applied + // again, so skip it for code object v2 and up. + if (majorVersion >= 2) { + continue; + } + status = ApplyStaticRelocationSection(agent, c->GetRelocationSection(i)); } else { // Dynamic relocations are supported starting code object v2.1. - uint32_t majorVersion, minorVersion; - if (!c->GetCodeObjectVersion(&majorVersion, &minorVersion)) { - return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; - } if (majorVersion < 2) { return HSA_STATUS_ERROR_INVALID_CODE_OBJECT; }