diff options
author | Brad King <brad.king@kitware.com> | 2008-03-03 13:48:37 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2008-03-03 13:48:37 (GMT) |
commit | e98ee8cf7012563a5a613d29a3f8df0ee4137a96 (patch) | |
tree | 03a6222d74fa7cb83ecbfacccd8ce0043cccdfa3 /Source/cmELF.cxx | |
parent | 137618c37c5681c8f84413bf2ff9bfcd71a194c2 (diff) | |
download | CMake-e98ee8cf7012563a5a613d29a3f8df0ee4137a96.zip CMake-e98ee8cf7012563a5a613d29a3f8df0ee4137a96.tar.gz CMake-e98ee8cf7012563a5a613d29a3f8df0ee4137a96.tar.bz2 |
COMP: Fix cmELF to build when ET_LOOS, ET_HIOS, ET_LOPROC, ET_HIPROC may not be defined.
Diffstat (limited to 'Source/cmELF.cxx')
-rw-r--r-- | Source/cmELF.cxx | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index d7d9ef5..a6440ed 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -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) { // Read the header from the file. @@ -353,18 +376,10 @@ private: { cmELFByteSwap(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 || - (eti >= ET_LOOS && eti <= ET_HIOS) || - (eti >= ET_LOPROC && eti <= ET_HIPROC))) + if(!this->FileTypeValid(et)) { cmELFByteSwap(et); - eti = static_cast<unsigned int>(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)) + if(this->FileTypeValid(et)) { // The previous byte order guess was wrong. Flip it. this->NeedSwap = !this->NeedSwap; @@ -446,7 +461,7 @@ cmELFInternalImpl<Types> switch(this->ELFHeader.e_type) { case ET_NONE: - this->SetErrorMessage("No ELF file type."); + this->SetErrorMessage("ELF file type is NONE."); return; case ET_REL: this->ELFType = cmELF::FileTypeRelocatableObject; @@ -461,22 +476,27 @@ cmELFInternalImpl<Types> this->ELFType = cmELF::FileTypeCore; break; 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; 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; break; } - else - { - this->SetErrorMessage("Unknown ELF file type."); - return; - } +#endif + cmOStringStream e; + e << "Unknown ELF file type " << eti; + this->SetErrorMessage(e.str().c_str()); + return; + } } // Load the section headers. |