Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit e13ccf3

Browse files
committed
Fix bugs with name expression map APIs and test
For the API, switch to using section names instead of flags to identify specific sections. It appears the flags set may differ across machines. For the test, correctly set up nameExpressions and symbolNames to have two different name expressions, one for each example in the test source code. This fixes an invalid memory read that causes errors on some systems. Also fix map fetch to correctly check code object instead of bitcode in second part of test. Change-Id: I4217f616995635515c637d38fac40303225ee6f7
1 parent a4cd0c7 commit e13ccf3

2 files changed

Lines changed: 27 additions & 11 deletions

File tree

lib/comgr/src/comgr.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,17 +2005,31 @@ amd_comgr_populate_name_expression_map(amd_comgr_data_t Data,
20052005

20062006
Elf_Shdr_Impl<ELF64LE> dynsymShdr, relaShdr, rodataShdr;
20072007
for (auto Shdr : Sections) {
2008-
if (Shdr.sh_type == llvm::ELF::SHT_DYNSYM)
2008+
2009+
if (Shdr.sh_type == ELF::SHT_DYNSYM)
20092010
dynsymShdr = Shdr;
20102011

2011-
if (Shdr.sh_type == ELF::SHT_RELA)
2012+
// Check sh_info to differentiate .rela.dyn and not .rela
2013+
if (Shdr.sh_type == ELF::SHT_RELA && Shdr.sh_info == 0)
20122014
relaShdr = Shdr;
20132015

2014-
if ((Shdr.sh_type == ELF::SHT_PROGBITS) &&
2015-
!(Shdr.sh_flags & ELF::SHF_WRITE) &&
2016-
!(Shdr.sh_flags & ELF::SHF_EXECINSTR) &&
2017-
!(Shdr.sh_flags & ELF::SHF_MASKPROC) )
2018-
rodataShdr = Shdr;
2016+
// We can't uniquely identify the .rodata section using the type and flag
2017+
// because other sections may use the exact same flags and type (i.e.
2018+
// .interp). For correctness, we can check the name instead
2019+
if (Shdr.sh_type == ELF::SHT_PROGBITS &&
2020+
(Shdr.sh_flags & ELF::SHF_ALLOC)) {
2021+
2022+
Expected<StringRef> SecNameOrError = ELFFile.getSectionName(Shdr);
2023+
if (!SecNameOrError) {
2024+
llvm::logAllUnhandledErrors(SecNameOrError.takeError(),
2025+
llvm::errs(), "ELFObj creation error: ");
2026+
return AMD_COMGR_STATUS_ERROR;
2027+
}
2028+
StringRef SecName = std::move(SecNameOrError.get());
2029+
2030+
if (SecName.equals(StringRef(".rodata")))
2031+
rodataShdr = Shdr;
2032+
}
20192033
}
20202034

20212035
// .dynsym - Find name expressions with amdgcn_name_expr and store their
@@ -2097,9 +2111,9 @@ amd_comgr_populate_name_expression_map(amd_comgr_data_t Data,
20972111

20982112
// Collect an unmangled name for each name expression
20992113
for (auto expData : nameExpDataVec) {
2100-
// TODO: If/when an accessor API becomes availble to get the starting
2114+
// TODO: If/when an accessor API becomes available to get the starting
21012115
// address for the section, switch to that
2102-
int offset = expData->RodataOffset - rodataShdr.sh_offset;
2116+
size_t offset = expData->RodataOffset - rodataShdr.sh_offset;
21032117

21042118
// Store from the offset up until the first '\0'
21052119
const char *unmangled =

lib/comgr/test/name_expression_map_test.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ int main(int argc, char *argv[]) {
131131
exit(1);
132132
}
133133

134-
char *nameExpressions[] = {"my_kernel_BOO<static_cast<int>(2+1),float >"};
135-
char *symbolNames[] = {"_Z13my_kernel_BOOILi3EfEvPT0_"};
134+
char *nameExpressions[] = {"my_kernel_BOO<static_cast<int>(2+1),float >",
135+
"my_kernel_FOO<static_cast<int>(2+1),float >"};
136+
char *symbolNames[] = {"_Z13my_kernel_BOOILi3EfEvPT0_",
137+
"_Z13my_kernel_FOOILi3EfEvPT0_"};
136138

137139
for (size_t I = 0; I < numNames; ++I) {
138140
size_t Size;

0 commit comments

Comments
 (0)