[hsa-runtime] Add support to hsa-runtime to find symbols from ".dynsym" section.

Earlier, hsa-runtime was unable to find symbols from a stripped ELF-image becasue
no support to find symbols from ".dynsym" section.

Looking for symbols in .dynsym is enabled by LOADER_USE_DYNSYM=1
environment variable

Change-Id: I4f0e8dd0eb053a6066d4d49b670c52e51149531a


[ROCm/ROCR-Runtime commit: 4142a77375]
Этот коммит содержится в:
raghavmedicherla
2022-12-08 16:50:43 -05:00
коммит произвёл Konstantin Zhuravlyov
родитель 8c3acb3974
Коммит 2758da98cd
3 изменённых файлов: 44 добавлений и 4 удалений
+4
Просмотреть файл
@@ -183,6 +183,10 @@ namespace elf {
virtual StringTable* strtab() = 0;
virtual SymbolTable* symtab() = 0;
virtual SymbolTable* getSymtab(uint16_t index) = 0;
virtual SymbolTable* dynsym() = 0;
virtual SymbolTable* getDynsym(uint16_t index) = 0;
virtual SymbolTable* getSymbolTable() = 0;
virtual SymbolTable* getSymbolTable(uint16_t index) = 0;
virtual StringTable* addStringTable(const std::string& name) = 0;
virtual StringTable* getStringTable(uint16_t index) = 0;
+38 -2
Просмотреть файл
@@ -713,7 +713,24 @@ namespace elf {
GElfStringTable* strtab() override;
GElfSymbolTable* getSymtab(uint16_t index) override
{
return static_cast<GElfSymbolTable*>(section(index));
if (section(index)->type() == SHT_SYMTAB)
return static_cast<GElfSymbolTable*>(section(index));
return nullptr;
}
GElfSymbolTable* getDynsym(uint16_t index) override
{
if (section(index)->type() == SHT_DYNSYM)
return static_cast<GElfSymbolTable*>(section(index));
return nullptr;
}
GElfSymbolTable* getSymbolTable() override;
GElfSymbolTable* getSymbolTable(uint16_t index) override
{
const char *UseDynsym = getenv("LOADER_USE_DYNSYM");
if (UseDynsym && std::strncmp(UseDynsym, "0", 1) != 0)
return getDynsym(index);
return getSymtab(index);
}
GElfStringTable* addStringTable(const std::string& name) override;
@@ -721,6 +738,7 @@ namespace elf {
GElfSymbolTable* addSymbolTable(const std::string& name, StringTable* stab = 0) override;
GElfSymbolTable* symtab() override;
GElfSymbolTable* dynsym() override;
GElfSegment* segment(size_t i) override { return segments[i].get(); }
Segment* segmentByVAddr(uint64_t vaddr) override;
@@ -759,6 +777,7 @@ namespace elf {
GElfStringTable* shstrtabSection;
GElfStringTable* strtabSection;
GElfSymbolTable* symtabSection;
GElfSymbolTable* dynsymSection;
GElfNoteSection* noteSection;
std::vector<std::unique_ptr<GElfSegment>> segments;
std::vector<std::unique_ptr<GElfSection>> sections;
@@ -1261,6 +1280,7 @@ namespace elf {
e(0),
shstrtabSection(0), strtabSection(0),
symtabSection(0),
dynsymSection(0),
noteSection(0)
{
if (EV_NONE == elf_version(EV_CURRENT)) {
@@ -1436,6 +1456,7 @@ namespace elf {
if (section->type() == SHT_STRTAB) { strtabSection = static_cast<GElfStringTable*>(section.get()); }
if (section->type() == SHT_SYMTAB) { symtabSection = static_cast<GElfSymbolTable*>(section.get()); }
if (section->type() == SHT_NOTE) { noteSection = static_cast<GElfNoteSection*>(section.get()); }
if (section->type() == SHT_DYNSYM) { dynsymSection = static_cast<GElfSymbolTable*>(section.get()); }
}
size_t phnum;
@@ -1553,7 +1574,7 @@ namespace elf {
}
}
GElfStringTable* GElfImage::addStringTable(const std::string& name)
GElfStringTable* GElfImage::addStringTable(const std::string& name)
{
GElfStringTable* stab = new GElfStringTable(this);
sections.push_back(std::unique_ptr<GElfStringTable>(stab));
@@ -1597,6 +1618,21 @@ namespace elf {
return symtabSection;
}
GElfSymbolTable* GElfImage::dynsym()
{
if (!dynsymSection) {
dynsymSection = addSymbolTable(".dynsym", strtab());
}
return dynsymSection;
}
GElfSymbolTable* GElfImage::getSymbolTable()
{
const char *UseDynsym = getenv("LOADER_USE_DYNSYM");
if (UseDynsym && std::strncmp(UseDynsym, "0", 1) != 0)
return dynsym();
return symtab();
}
GElfNoteSection* GElfImage::note()
{
+2 -2
Просмотреть файл
@@ -1765,8 +1765,8 @@ namespace code {
hsatext = sec;
}
}
for (size_t i = 0; i < img->symtab()->symbolCount(); ++i) {
amd::elf::Symbol* elfsym = img->symtab()->symbol(i);
for (size_t i = 0; i < img->getSymbolTable()->symbolCount(); ++i) {
amd::elf::Symbol* elfsym = img->getSymbolTable()->symbol(i);
Symbol* sym = 0;
switch (elfsym->type()) {
case STT_AMDGPU_HSA_KERNEL: {