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 #33, Resolve print format mismatches on 32-bit host #36

Merged
merged 1 commit into from
Apr 28, 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
52 changes: 26 additions & 26 deletions elf2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void set_st_size(union Elf_Sym *Symbol, uint64_t new_value)
{
Symbol->Sym32.st_size = (uint32_t) new_value;
if (Symbol->Sym32.st_size != new_value) {
printf("ERROR: Sym32.st_size can not hold %lu\n", new_value);
printf("ERROR: Sym32.st_size can not hold %lu\n", (long unsigned int)new_value);
}
}
else
Expand Down Expand Up @@ -1695,7 +1695,7 @@ int32 GetSectionHeader(int32 SectionIndex, union Elf_Shdr *SectionHeader)
}
SymbolTableEntrySize = get_sh_entsize(SectionHeader);
NumSymbols = (get_sh_size(SectionHeader) / get_sh_entsize(SectionHeader)) - 1;
sprintf(VerboseStr, "SHT_SYMTAB (2) - # Symbols = %lu", NumSymbols);
sprintf(VerboseStr, "SHT_SYMTAB (2) - # Symbols = %lu", (long unsigned int)NumSymbols);
break;

case SHT_STRTAB:
Expand Down Expand Up @@ -1794,7 +1794,7 @@ int32 GetSymbol(int32 SymbolIndex, union Elf_Sym *Symbol)
int32 i=0;
if (SeekOffset != calculated_offset)
{
printf("Error: SeekOffset may not be %lu\n", calculated_offset);
printf("Error: SeekOffset may not be %lu\n", (long unsigned int)calculated_offset);
Status = FAILED;
}
else
Expand Down Expand Up @@ -1875,8 +1875,8 @@ void PrintSymbol32(union Elf_Sym *Symbol)

void PrintSymbol64(union Elf_Sym *Symbol)
{
if (Verbose) printf(" st_value = 0x%lx\n", Symbol->Sym64.st_value);
if (Verbose) printf(" st_size = 0x%08lx\n", Symbol->Sym64.st_size);
if (Verbose) printf(" st_value = 0x%lx\n", (long unsigned int)Symbol->Sym64.st_value);
if (Verbose) printf(" st_size = 0x%08lx\n", (long unsigned int)Symbol->Sym64.st_size);
if (Verbose) printf(" st_info = 0x%02x\n", Symbol->Sym64.st_info);
if (Verbose) printf(" st_other = 0x%02x\n", Symbol->Sym64.st_other);
if (Verbose) printf(" st_shndx = 0x%04x\n", Symbol->Sym64.st_shndx);
Expand All @@ -1895,13 +1895,13 @@ void PrintSectionHeader32(union Elf_Shdr *SectionHeader)

void PrintSectionHeader64(union Elf_Shdr *SectionHeader)
{
if (Verbose) printf(" sh_addr = 0x%lx\n", SectionHeader->Shdr64.sh_addr);
if (Verbose) printf(" sh_offset = 0x%08lx\n", SectionHeader->Shdr64.sh_offset);
if (Verbose) printf(" sh_size = 0x%08lx\n", SectionHeader->Shdr64.sh_size);
if (Verbose) printf(" sh_addr = 0x%lx\n", (long unsigned int)SectionHeader->Shdr64.sh_addr);
if (Verbose) printf(" sh_offset = 0x%08lx\n", (long unsigned int)SectionHeader->Shdr64.sh_offset);
if (Verbose) printf(" sh_size = 0x%08lx\n", (long unsigned int)SectionHeader->Shdr64.sh_size);
if (Verbose) printf(" sh_link = 0x%08x\n", SectionHeader->Shdr64.sh_link);
if (Verbose) printf(" sh_info = 0x%08x\n", SectionHeader->Shdr64.sh_info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance wouldn't the "sh_link" and "sh_info" need the same cast? (these are also words of different lengths depending on arch/binary format).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarified pull request, urgent fix is for vxworks6.9, MCP750. As you mention, likely requires more casts for other systems but not a certification priority.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to VxWorks exactly? The tool runs on the host machine, not on VxWorks. Are the mismatches specific to running it on a 32-bit host machine vs 64-bit host machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True enough, this is a 32 bit host. I only fixed the issues that showed up for the vxworks build on the 32 bit host. I should have better described the test system.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that makes more sense. But I'm still not an advocate of just minimally squelching the visible warnings on a specific 32-bit host (IIRC the machine with the VxWorks 6.9 tools is a 32-bit RHEL 6.x host). Other compilers/libraries might flag other printfs. Unless we actually add all the needed casts, warnings are likely reappear again as soon as someone builds on another system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a step in the right direction, and removes a cert blocker. Making it work across compilers/libraries is a very valid open source concern, but not my priority.

if (Verbose) printf(" sh_addralign = 0x%08lx\n", SectionHeader->Shdr64.sh_addralign);
if (Verbose) printf(" sh_entsize = 0x%08lx\n", SectionHeader->Shdr64.sh_entsize);
if (Verbose) printf(" sh_addralign = 0x%08lx\n", (long unsigned int)SectionHeader->Shdr64.sh_addralign);
if (Verbose) printf(" sh_entsize = 0x%08lx\n", (long unsigned int)SectionHeader->Shdr64.sh_entsize);
}

void PrintElfHeader32(union Elf_Ehdr ElfHeader)
Expand All @@ -1922,9 +1922,9 @@ void PrintElfHeader32(union Elf_Ehdr ElfHeader)
void PrintElfHeader64(union Elf_Ehdr ElfHeader)
{
if (Verbose) printf(" e_version = %d\n", get_e_version(&ElfHeader));
if (Verbose) printf(" e_entry = 0x%lx\n", ElfHeader.Ehdr64.e_entry);
if (Verbose) printf(" e_phoff = 0x%08lx (%lu)\n", ElfHeader.Ehdr64.e_phoff, ElfHeader.Ehdr64.e_phoff);
if (Verbose) printf(" e_shoff = 0x%08lx (%lu)\n", ElfHeader.Ehdr64.e_shoff, ElfHeader.Ehdr64.e_shoff);
if (Verbose) printf(" e_entry = 0x%lx\n", (long unsigned int)ElfHeader.Ehdr64.e_entry);
if (Verbose) printf(" e_phoff = 0x%08lx (%lu)\n", (long unsigned int)ElfHeader.Ehdr64.e_phoff, (long unsigned int)ElfHeader.Ehdr64.e_phoff);
if (Verbose) printf(" e_shoff = 0x%08lx (%lu)\n", (long unsigned int)ElfHeader.Ehdr64.e_shoff, (long unsigned int)ElfHeader.Ehdr64.e_shoff);
if (Verbose) printf(" e_flags = 0x%08x\n", ElfHeader.Ehdr64.e_flags);
if (Verbose) printf(" e_ehsize = %d\n", ElfHeader.Ehdr64.e_ehsize);
if (Verbose) printf(" e_phentsize = %d\n", ElfHeader.Ehdr64.e_phentsize);
Expand Down Expand Up @@ -2117,8 +2117,8 @@ int32 GetTblDefInfo(void)
/* Read the data to be used to format the CFE File and Table Headers */
if ((get_st_size(SymbolPtrs[TblDefSymbolIndex]) != sizeof(CFE_TBL_FileDef_t)) && (get_st_size(SymbolPtrs[TblDefSymbolIndex]) != 0))
{
printf("Error! '%s' is not properly defined in '%s'. Size of object is incorrect (%ld).\n",
TBL_DEF_SYMBOL_NAME, SrcFilename, get_st_size(SymbolPtrs[TblDefSymbolIndex]));
printf("Error! '%s' is not properly defined in '%s'. Size of object is incorrect (%lu).\n",
TBL_DEF_SYMBOL_NAME, SrcFilename, (long unsigned int)get_st_size(SymbolPtrs[TblDefSymbolIndex]));
Status = FAILED;
}
else
Expand All @@ -2128,7 +2128,7 @@ int32 GetTblDefInfo(void)
SeekOffset = (uint32_t) (calculated_offset);
if (SeekOffset != calculated_offset)
{
printf("Error: SeekOffset may not be %lu\n", calculated_offset);
printf("Error: SeekOffset may not be %lu\n", (long unsigned int)calculated_offset);
Status = FAILED;
}
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Expand Down Expand Up @@ -2179,7 +2179,7 @@ int32 LocateAndReadUserObject(void)
uint8 AByte;

/* Search the symbol table for the user defined object */
if (Verbose) printf("\nTrying to match ObjectName '%s'... (length %ld)",TblFileDef.ObjectName,strlen(TblFileDef.ObjectName));
if (Verbose) printf("\nTrying to match ObjectName '%s'... (length %lu)",TblFileDef.ObjectName,(long unsigned int)strlen(TblFileDef.ObjectName));
while (i<NumSymbols)
{
if (Verbose) printf("\nSymbol Search loop %d: SymbolName ='%s' ",i,SymbolNames[i]);
Expand Down Expand Up @@ -2208,21 +2208,21 @@ int32 LocateAndReadUserObject(void)

if (Verbose)
{
printf("strstr[%d] = %s; strlenSN = %ld; strlenON = %ld\n",i,strstr(SymbolNames[i], TblFileDef.ObjectName),
strlen(SymbolNames[i]),
strlen(TblFileDef.ObjectName));
printf("strstr[%d] = %s; strlenSN = %lu; strlenON = %lu\n",i,strstr(SymbolNames[i], TblFileDef.ObjectName),
(long unsigned int)strlen(SymbolNames[i]),
(long unsigned int)strlen(TblFileDef.ObjectName));
}

i++;
}

if (Verbose)
{
printf("\ni = %d, NumSymbols = %lu\n", i, NumSymbols);
printf("\ni = %d, NumSymbols = %lu\n", i, (long unsigned int)NumSymbols);
if (i < NumSymbols)
{
printf("\nSymbolName = '%s', ObjectName = '%s'\n",SymbolNames[i], TblFileDef.ObjectName);
printf("\nSymbolName length = %ld, ObjectName length = %ld\n",strlen(SymbolNames[i]), strlen(TblFileDef.ObjectName));
printf("\nSymbolName length = %lu, ObjectName length = %lu\n",(long unsigned int)strlen(SymbolNames[i]), (long unsigned int)strlen(TblFileDef.ObjectName));
}
}

Expand Down Expand Up @@ -2263,7 +2263,7 @@ int32 LocateAndReadUserObject(void)
SeekOffset = (uint32_t) (calculated_offset);
if (SeekOffset != calculated_offset)
{
printf("Error: SeekOffset may not be %lu\n", calculated_offset);
printf("Error: SeekOffset may not be %lu\n", (long unsigned int)calculated_offset);
Status = FAILED;
}
fseek(SrcFileDesc, SeekOffset, SEEK_SET);
Expand All @@ -2274,14 +2274,14 @@ int32 LocateAndReadUserObject(void)
/* Check to see if the size in the elf file agrees with the size specified in our table def structure */
if (get_st_size(SymbolPtrs[UserObjSymbolIndex]) != TblFileDef.ObjectSize)
{
printf("ELF file indicates object '%s' is of size %ld but table definition structure indicates size %d",
TblFileDef.ObjectName, get_st_size(SymbolPtrs[UserObjSymbolIndex]), TblFileDef.ObjectSize);
printf("ELF file indicates object '%s' is of size %lu but table definition structure indicates size %d",
TblFileDef.ObjectName, (long unsigned int)get_st_size(SymbolPtrs[UserObjSymbolIndex]), TblFileDef.ObjectSize);
if (TblFileDef.ObjectSize < get_st_size(SymbolPtrs[UserObjSymbolIndex]))
{
set_st_size(SymbolPtrs[UserObjSymbolIndex], TblFileDef.ObjectSize);
}

printf("Size of %ld is assumed.\n", get_st_size(SymbolPtrs[UserObjSymbolIndex]));
printf("Size of %lu is assumed.\n", (long unsigned int)get_st_size(SymbolPtrs[UserObjSymbolIndex]));
}
}
else
Expand Down