From 2caf2b783324ba1f045984d4a32685851f7a1c22 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 30 Nov 2016 06:53:56 -0500
Subject: [PATCH] P4 to Git Change 1347598 by atamazov@ata_h1 on 2016/11/30
06:48:06
SWDEV-79309 - [ROCm][OCLonLC][AMDGPU asm] OclElf: Correctly skip symbols which have special section indexes.
[Issues]
Kernels which contain absolute symbols can't be run. Error message looks like:
"OclElf::getSymbolInfo() failed in gelf_getshdr() - Invalid argument."
[Reason]
Symbols which have special section indexes (e.g. absolute symbols)
are incorrectly handled by the compiler library.
[Solution]
Correctly skip symbols which have special section indexes in the loader.
Promote the fix into compiler/legacy-lib at once.
[Remarks/Misc]
Absolute symbols do not normally produced by OpenCL compiler,
but may come from kernels written in assembly language.
AMDGPU asm exports all symbols, even ABSOLUTE LOCAL HIDDEN INTERNAL etc.
Impossibility to disable export of useless symbols is known issue of llvm-mc
core, see https://llvm.org/bugs/show_bug.cgi?id=27201.
Note that presence of useless symbols does not make ELF invalid.
[Review] http://ocltc.amd.com/reviews/r/11921/
Evgeny Mankov (OK)
[Tests]
Tested that issue with asm kernels has gone.
PASS TeamCity - Pre-checkin for CL1347161 timestamped:2016-11-29 21:54:40 Rev:0063
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/legacy-lib/loaders/elf/elf.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/loaders/elf/elf.cpp#36 edit
[ROCm/clr commit: 71f5fb7e8f12a38e1233da2af7b181233f2a936a]
---
projects/clr/rocclr/compiler/lib/loaders/elf/elf.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/projects/clr/rocclr/compiler/lib/loaders/elf/elf.cpp b/projects/clr/rocclr/compiler/lib/loaders/elf/elf.cpp
index 3d64698ab9..c5df0afcf4 100644
--- a/projects/clr/rocclr/compiler/lib/loaders/elf/elf.cpp
+++ b/projects/clr/rocclr/compiler/lib/loaders/elf/elf.cpp
@@ -957,6 +957,10 @@ OclElf::nextSymbol(Sym_Handle symHandle) const
/*
Given a symbol handle, return info for this symbol
+
+ Fails with symbols which have special section indexes (like absolute symbols).
+ It is impossible to return valid SymbolInfo for such symbols because
+ correct section names are unknown (unspecified in ELF).
*/
bool
OclElf::getSymbolInfo(Sym_Handle symHandle, SymbolInfo* symInfo) const
@@ -970,6 +974,9 @@ OclElf::getSymbolInfo(Sym_Handle symHandle, SymbolInfo* symInfo) const
if (_eclass == ELFCLASS64) {
Elf64_Sym* sym64 = reinterpret_cast(symHandle);
+ if (sym64->st_shndx >= SHN_LORESERVE && sym64->st_shndx <= SHN_HIRESERVE) {
+ return false;
+ }
sym_name = elf_strptr(_e, _strtab_ndx, sym64->st_name);
st_value = (Elf64_Addr)(sym64->st_value);
@@ -980,6 +987,9 @@ OclElf::getSymbolInfo(Sym_Handle symHandle, SymbolInfo* symInfo) const
}
else {
Elf32_Sym* sym32 = reinterpret_cast(symHandle);
+ if (sym32->st_shndx >= SHN_LORESERVE && sym32->st_shndx <= SHN_HIRESERVE) {
+ return false;
+ }
sym_name = elf_strptr(_e, _strtab_ndx, sym32->st_name);
st_value = (Elf64_Addr)(sym32->st_value);