COMP: Fix cmELF to build when ET_LOOS, ET_HIOS, ET_LOPROC, ET_HIPROC may not be defined.
This commit is contained in:
parent
137618c37c
commit
e98ee8cf70
@ -334,6 +334,29 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileTypeValid(ELF_Half et)
|
||||||
|
{
|
||||||
|
unsigned int eti = static_cast<unsigned int>(et);
|
||||||
|
if(eti == ET_NONE || eti == ET_REL || eti == ET_EXEC ||
|
||||||
|
eti == ET_DYN || eti == ET_CORE)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#if defined(ET_LOOS) && defined(ET_HIOS)
|
||||||
|
if(eti >= ET_LOOS && eti <= ET_HIOS)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(ET_LOPROC) && defined(ET_HIPROC)
|
||||||
|
if(eti >= ET_LOPROC && eti <= ET_HIPROC)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool Read(ELF_Ehdr& x)
|
bool Read(ELF_Ehdr& x)
|
||||||
{
|
{
|
||||||
// Read the header from the file.
|
// Read the header from the file.
|
||||||
@ -353,18 +376,10 @@ private:
|
|||||||
{
|
{
|
||||||
cmELFByteSwap(et);
|
cmELFByteSwap(et);
|
||||||
}
|
}
|
||||||
unsigned int eti = static_cast<unsigned int>(et);
|
if(!this->FileTypeValid(et))
|
||||||
if(!(eti == ET_NONE || eti == ET_REL || eti == ET_EXEC ||
|
|
||||||
eti == ET_DYN || eti == ET_CORE ||
|
|
||||||
(eti >= ET_LOOS && eti <= ET_HIOS) ||
|
|
||||||
(eti >= ET_LOPROC && eti <= ET_HIPROC)))
|
|
||||||
{
|
{
|
||||||
cmELFByteSwap(et);
|
cmELFByteSwap(et);
|
||||||
eti = static_cast<unsigned int>(et);
|
if(this->FileTypeValid(et))
|
||||||
if(eti == ET_NONE || eti == ET_REL || eti == ET_EXEC ||
|
|
||||||
eti == ET_DYN || eti == ET_CORE ||
|
|
||||||
(eti >= ET_LOOS && eti <= ET_HIOS) ||
|
|
||||||
(eti >= ET_LOPROC && eti <= ET_HIPROC))
|
|
||||||
{
|
{
|
||||||
// The previous byte order guess was wrong. Flip it.
|
// The previous byte order guess was wrong. Flip it.
|
||||||
this->NeedSwap = !this->NeedSwap;
|
this->NeedSwap = !this->NeedSwap;
|
||||||
@ -446,7 +461,7 @@ cmELFInternalImpl<Types>
|
|||||||
switch(this->ELFHeader.e_type)
|
switch(this->ELFHeader.e_type)
|
||||||
{
|
{
|
||||||
case ET_NONE:
|
case ET_NONE:
|
||||||
this->SetErrorMessage("No ELF file type.");
|
this->SetErrorMessage("ELF file type is NONE.");
|
||||||
return;
|
return;
|
||||||
case ET_REL:
|
case ET_REL:
|
||||||
this->ELFType = cmELF::FileTypeRelocatableObject;
|
this->ELFType = cmELF::FileTypeRelocatableObject;
|
||||||
@ -461,22 +476,27 @@ cmELFInternalImpl<Types>
|
|||||||
this->ELFType = cmELF::FileTypeCore;
|
this->ELFType = cmELF::FileTypeCore;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
unsigned int et = static_cast<unsigned int>(this->ELFHeader.e_type);
|
{
|
||||||
if(et >= ET_LOOS && et <= ET_HIOS)
|
unsigned int eti = static_cast<unsigned int>(this->ELFHeader.e_type);
|
||||||
|
#if defined(ET_LOOS) && defined(ET_HIOS)
|
||||||
|
if(eti >= ET_LOOS && eti <= ET_HIOS)
|
||||||
{
|
{
|
||||||
this->ELFType = cmELF::FileTypeSpecificOS;
|
this->ELFType = cmELF::FileTypeSpecificOS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(et >= ET_LOPROC && et <= ET_HIPROC)
|
#endif
|
||||||
|
#if defined(ET_LOPROC) && defined(ET_HIPROC)
|
||||||
|
if(eti >= ET_LOPROC && eti <= ET_HIPROC)
|
||||||
{
|
{
|
||||||
this->ELFType = cmELF::FileTypeSpecificProc;
|
this->ELFType = cmELF::FileTypeSpecificProc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
{
|
cmOStringStream e;
|
||||||
this->SetErrorMessage("Unknown ELF file type.");
|
e << "Unknown ELF file type " << eti;
|
||||||
return;
|
this->SetErrorMessage(e.str().c_str());
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the section headers.
|
// Load the section headers.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user