Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #48, string table identification. #49

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@ int main(int argc, char *argv[])
}
}

if (StringTableDataOffset == 0)
{
printf("Error! Unable to locate ELF string table for symbol names\n");
return EXIT_FAILURE;
}

/* Allocate memory for all of the symbol table entries */
Status = AllocateSymbols();
if (Status != SUCCESS)
Expand All @@ -687,7 +693,7 @@ int main(int argc, char *argv[])
{
printf("Error! Unable to locate '%s' object in '%s'.\n", TBL_DEF_SYMBOL_NAME, SrcFilename);
FreeMemoryAllocations();
return Status;
return EXIT_FAILURE;
}

/* Read in the definition of the table file */
Expand Down Expand Up @@ -1757,7 +1763,15 @@ int32 GetSectionHeader(int32 SectionIndex, union Elf_Shdr *SectionHeader)

case SHT_STRTAB:
sprintf(VerboseStr, "SHT_STRTAB (3)");
if (SectionIndex != get_e_shstrndx(&ElfHeader))
/*
* If the section name is ".strtab" then preferentially use this section for symbol name data
* Otherwise use the first section which is NOT the section header string table (.shstrtab)
*
* Not all compilers generate a separate strtab for section header names; some put everything
* into one string table.
*/
if (strcmp(SectionNamePtrs[SectionIndex],".strtab") == 0 ||
(StringTableDataOffset == 0 && SectionIndex != get_e_shstrndx(&ElfHeader)))
{
StringTableDataOffset = get_sh_offset(SectionHeader);
}
Expand Down