From fb5fe85156a1fbf99c09beb9d20c8cb9325bd817 Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Fri, 27 Jun 2014 11:36:45 +0000 Subject: [PATCH] [ELF][Mips] Fix recognition of MIPS 64-bit arch in the ELFObjectFile:getArch() method. llvm-svn: 211891 --- include/llvm/Object/ELFObjectFile.h | 14 +++++++--- test/Object/Inputs/program-headers.mips64 | Bin 0 -> 790 bytes test/tools/llvm-readobj/program-headers.test | 28 ++++++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 test/Object/Inputs/program-headers.mips64 diff --git a/include/llvm/Object/ELFObjectFile.h b/include/llvm/Object/ELFObjectFile.h index ae74ebc02c2..deff409c5dd 100644 --- a/include/llvm/Object/ELFObjectFile.h +++ b/include/llvm/Object/ELFObjectFile.h @@ -917,6 +917,7 @@ StringRef ELFObjectFile::getFileFormatName() const { template unsigned ELFObjectFile::getArch() const { + bool IsLittleEndian = ELFT::TargetEndianness == support::little; switch (EF.getHeader()->e_machine) { case ELF::EM_386: return Triple::x86; @@ -929,11 +930,16 @@ unsigned ELFObjectFile::getArch() const { case ELF::EM_HEXAGON: return Triple::hexagon; case ELF::EM_MIPS: - return (ELFT::TargetEndianness == support::little) ? Triple::mipsel - : Triple::mips; + switch (EF.getHeader()->e_ident[ELF::EI_CLASS]) { + case ELF::ELFCLASS32: + return IsLittleEndian ? Triple::mipsel : Triple::mips; + case ELF::ELFCLASS64: + return IsLittleEndian ? Triple::mips64el : Triple::mips64; + default: + report_fatal_error("Invalid ELFCLASS!"); + } case ELF::EM_PPC64: - return (ELFT::TargetEndianness == support::little) ? Triple::ppc64le - : Triple::ppc64; + return IsLittleEndian ? Triple::ppc64le : Triple::ppc64; case ELF::EM_S390: return Triple::systemz; diff --git a/test/Object/Inputs/program-headers.mips64 b/test/Object/Inputs/program-headers.mips64 new file mode 100644 index 0000000000000000000000000000000000000000..ad21c7db08d250ade36b300c723fc9ca346528ed GIT binary patch literal 790 zcmbtSyG{c!5L_FMfJDKgK}r!L(IFu!M0pKV{Db2tmq3vS*<$inArk^4->VF8T8 zlJVYSHBJI_RlhD`n1JId@uR3%y~H-Ry%=H(Il&%l*WI(B1bzdJBUKzj@2FZ!x#zhy zp=BQ1tohy6z~aBwwX=wVWb@CjA0{4l%F* literal 0 HcmV?d00001 diff --git a/test/tools/llvm-readobj/program-headers.test b/test/tools/llvm-readobj/program-headers.test index 7c22f2b529b..f014c039042 100644 --- a/test/tools/llvm-readobj/program-headers.test +++ b/test/tools/llvm-readobj/program-headers.test @@ -4,6 +4,8 @@ RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.elf-x8 RUN: | FileCheck %s -check-prefix ELF-X86-64 RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.mips \ RUN: | FileCheck %s -check-prefix ELF-MIPS +RUN: llvm-readobj -program-headers %p/../../Object/Inputs/program-headers.mips64 \ +RUN: | FileCheck %s -check-prefix ELF-MIPS64 ELF-I386: ProgramHeaders [ ELF-I386-NEXT: ProgramHeader { @@ -75,7 +77,11 @@ ELF-X86-64-NEXT: Alignment: 8 ELF-X86-64-NEXT: } ELF-X86-64-NEXT: ] -ELF-MIPS: ProgramHeaders [ +ELF-MIPS: Format: ELF32-mips +ELF-MIPS-NEXT: Arch: mips +ELF-MIPS-NEXT: AddressSize: 32bit +ELF-MIPS-NEXT: LoadName: +ELF-MIPS-NEXT: ProgramHeaders [ ELF-MIPS-NEXT: ProgramHeader { ELF-MIPS-NEXT: Type: PT_MIPS_REGINFO (0x70000000) ELF-MIPS-NEXT: Offset: 0x74 @@ -102,3 +108,23 @@ ELF-MIPS-NEXT: ] ELF-MIPS-NEXT: Alignment: 65536 ELF-MIPS-NEXT: } ELF-MIPS-NEXT: ] + +ELF-MIPS64: Format: ELF64-mips +ELF-MIPS64-NEXT: Arch: mips64 +ELF-MIPS64-NEXT: AddressSize: 64bit +ELF-MIPS64-NEXT: LoadName: +ELF-MIPS64-NEXT: ProgramHeaders [ +ELF-MIPS64-NEXT: ProgramHeader { +ELF-MIPS64-NEXT: Type: PT_LOAD (0x1) +ELF-MIPS64-NEXT: Offset: 0x0 +ELF-MIPS64-NEXT: VirtualAddress: 0x120000000 +ELF-MIPS64-NEXT: PhysicalAddress: 0x120000000 +ELF-MIPS64-NEXT: FileSize: 136 +ELF-MIPS64-NEXT: MemSize: 136 +ELF-MIPS64-NEXT: Flags [ (0x5) +ELF-MIPS64-NEXT: PF_R (0x4) +ELF-MIPS64-NEXT: PF_X (0x1) +ELF-MIPS64-NEXT: ] +ELF-MIPS64-NEXT: Alignment: 65536 +ELF-MIPS64-NEXT: } +ELF-MIPS64-NEXT: ]