diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -1160,7 +1160,7 @@ case ELF::EM_MSP430: return "elf32-msp430"; case ELF::EM_PPC: - return "elf32-powerpc"; + return (IsLittleEndian ? "elf32-powerpcle" : "elf32-powerpc"); case ELF::EM_RISCV: return "elf32-littleriscv"; case ELF::EM_CSKY: @@ -1236,7 +1236,7 @@ case ELF::EM_MSP430: return Triple::msp430; case ELF::EM_PPC: - return Triple::ppc; + return IsLittleEndian ? Triple::ppcle : Triple::ppc; case ELF::EM_PPC64: return IsLittleEndian ? Triple::ppc64le : Triple::ppc64; case ELF::EM_RISCV: diff --git a/llvm/lib/Object/RelocationResolver.cpp b/llvm/lib/Object/RelocationResolver.cpp --- a/llvm/lib/Object/RelocationResolver.cpp +++ b/llvm/lib/Object/RelocationResolver.cpp @@ -687,6 +687,7 @@ switch (Obj.getArch()) { case Triple::x86: return {supportsX86, resolveX86}; + case Triple::ppcle: case Triple::ppc: return {supportsPPC32, resolvePPC32}; case Triple::arm: diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test b/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test --- a/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test +++ b/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test @@ -15,8 +15,17 @@ # RUN: llvm-objcopy -I binary -O elf32-bigmips %t.txt %t.mips.o # RUN: llvm-readobj --file-headers %t.mips.o | FileCheck %s --check-prefixes=CHECK,BE,MIPS,32 +# RUN: llvm-objcopy -I binary -O elf32-powerpc %t.txt %t.ppc32be.o +# RUN: llvm-readobj --file-headers %t.ppc32be.o | FileCheck %s --check-prefixes=CHECK,BE,PPC32,PPC32BE,32 + +# RUN: llvm-objcopy -I binary -O elf32-powerpcle %t.txt %t.ppc32le.o +# RUN: llvm-readobj --file-headers %t.ppc32le.o | FileCheck %s --check-prefixes=CHECK,LE,PPC32,PPC32LE,32 + +# RUN: llvm-objcopy -I binary -O elf64-powerpc %t.txt %t.ppc64be.o +# RUN: llvm-readobj --file-headers %t.ppc64be.o | FileCheck %s --check-prefixes=CHECK,BE,PPC64,PPC64BE,64 + # RUN: llvm-objcopy -I binary -O elf64-powerpcle %t.txt %t.ppc64le.o -# RUN: llvm-readobj --file-headers %t.ppc64le.o | FileCheck %s --check-prefixes=CHECK,LE,PPC64,64 +# RUN: llvm-readobj --file-headers %t.ppc64le.o | FileCheck %s --check-prefixes=CHECK,LE,PPC64,PPC64LE,64 # RUN: llvm-objcopy -I binary -O elf32-littleriscv %t.txt %t.rv32.o # RUN: llvm-readobj --file-headers %t.rv32.o | FileCheck %s --check-prefixes=CHECK,LE,RISCV32,32 @@ -43,8 +52,8 @@ # MIPS-SAME: mips{{$}} # RISCV32-SAME: riscv{{$}} # RISCV64-SAME: riscv{{$}} -# PPC-SAME: powerpc{{$}} -# PPC64le-SAME: powerpc{{$}} +# PPCBE-SAME: powerpc{{$}} +# PPCLE-SAME: powerpcle{{$}} # SPARC-SAME: sparc # SPARCEL-SAME: sparc # X86-64-SAME: x86-64 @@ -54,8 +63,10 @@ # HEXAGON-NEXT: Arch: hexagon # I386-NEXT: Arch: i386 # MIPS-NEXT: Arch: mips{{$}} -# PPC-NEXT: Arch: powerpc{{$}} -# PPC64-NEXT: Arch: powerpc64le +# PPC32BE-NEXT: Arch: powerpc{{$}} +# PPC32LE-NEXT: Arch: powerpcle{{$}} +# PPC64BE-NEXT: Arch: powerpc64{{$}} +# PPC64LE-NEXT: Arch: powerpc64le{{$}} # RISCV32-NEXT: Arch: riscv32 # RISCV64-NEXT: Arch: riscv64 # SPARC-NEXT: Arch: sparc{{$}} @@ -87,7 +98,7 @@ # HEXAGON-NEXT: Machine: EM_HEXAGON (0xA4) # I386-NEXT: Machine: EM_386 (0x3) # MIPS-NEXT: Machine: EM_MIPS (0x8) -# PPC-NEXT: Machine: EM_PPC (0x14) +# PPC32-NEXT: Machine: EM_PPC (0x14) # PPC64-NEXT: Machine: EM_PPC64 (0x15) # RISCV32-NEXT: Machine: EM_RISCV (0xF3) # RISCV64-NEXT: Machine: EM_RISCV (0xF3) diff --git a/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test b/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test --- a/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test +++ b/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test @@ -34,25 +34,25 @@ # RUN: llvm-readobj --file-headers %t.elf64_littleaarch64.dwo | FileCheck %s --check-prefixes=CHECK,LE,AARCH,64,SYSV # RUN: llvm-objcopy %t.o -O elf32-powerpc %t.elf32_powerpc.o --split-dwo=%t.elf32_powerpc.dwo -# RUN: llvm-readobj --file-headers %t.elf32_powerpc.o | FileCheck %s --check-prefixes=CHECK,BE,PPC,32,SYSV -# RUN: llvm-readobj --file-headers %t.elf32_powerpc.dwo | FileCheck %s --check-prefixes=CHECK,BE,PPC,32,SYSV +# RUN: llvm-readobj --file-headers %t.elf32_powerpc.o | FileCheck %s --check-prefixes=CHECK,BE,PPC32,PPCBE,PPC32BE,32,SYSV +# RUN: llvm-readobj --file-headers %t.elf32_powerpc.dwo | FileCheck %s --check-prefixes=CHECK,BE,PPC32,PPCBE,PPC32BE,32,SYSV # RUN: llvm-objcopy %t.o -O elf64-powerpc %t.elf64_powerpc.o --split-dwo=%t.elf64_powerpc.dwo -# RUN: llvm-readobj --file-headers %t.elf64_powerpc.o | FileCheck %s --check-prefixes=CHECK,BE,PPC64BE,64,SYSV -# RUN: llvm-readobj --file-headers %t.elf64_powerpc.dwo | FileCheck %s --check-prefixes=CHECK,BE,PPC64BE,64,SYSV +# RUN: llvm-readobj --file-headers %t.elf64_powerpc.o | FileCheck %s --check-prefixes=CHECK,BE,PPC64,PPCBE,PPC64BE,64,SYSV +# RUN: llvm-readobj --file-headers %t.elf64_powerpc.dwo | FileCheck %s --check-prefixes=CHECK,BE,PPC64,PPCBE,PPC64BE,64,SYSV # RUN: llvm-objcopy %t.o -O elf32-powerpcle %t.elf32_ppcle.o --split-dwo=%t.elf32_ppcle.dwo -# RUN: llvm-readobj --file-headers %t.elf32_ppcle.o | FileCheck %s --check-prefixes=CHECK,LE,PPC,32,SYSV -# RUN: llvm-readobj --file-headers %t.elf32_ppcle.dwo | FileCheck %s --check-prefixes=CHECK,LE,PPC,32,SYSV +# RUN: llvm-readobj --file-headers %t.elf32_ppcle.o | FileCheck %s --check-prefixes=CHECK,LE,PPC32,PPCLE,PPC32LE,32,SYSV +# RUN: llvm-readobj --file-headers %t.elf32_ppcle.dwo | FileCheck %s --check-prefixes=CHECK,LE,PPC32,PPCLE,PPC32LE,32,SYSV + +# RUN: llvm-objcopy %t.o -O elf64-powerpcle %t.elf64_ppcle.o --split-dwo=%t.elf64_ppcle.dwo +# RUN: llvm-readobj --file-headers %t.elf64_ppcle.o | FileCheck %s --check-prefixes=CHECK,LE,PPC64,PPCLE,PPC64LE,64,SYSV +# RUN: llvm-readobj --file-headers %t.elf64_ppcle.dwo | FileCheck %s --check-prefixes=CHECK,LE,PPC64,PPCLE,PPC64LE,64,SYSV # RUN: llvm-objcopy %t.o -O elf32-x86-64 %t.elf32_x86_64.o --split-dwo=%t.elf32_x86_64.dwo # RUN: llvm-readobj --file-headers %t.elf32_x86_64.o | FileCheck %s --check-prefixes=CHECK,LE,X86-64,32,SYSV # RUN: llvm-readobj --file-headers %t.elf32_x86_64.dwo | FileCheck %s --check-prefixes=CHECK,LE,X86-64,32,SYSV -# RUN: llvm-objcopy %t.o -O elf64-powerpcle %t.elf64_ppcle.o --split-dwo=%t.elf64_ppcle.dwo -# RUN: llvm-readobj --file-headers %t.elf64_ppcle.o | FileCheck %s --check-prefixes=CHECK,LE,PPC64LE,64,SYSV -# RUN: llvm-readobj --file-headers %t.elf64_ppcle.dwo | FileCheck %s --check-prefixes=CHECK,LE,PPC64LE,64,SYSV - # RUN: llvm-objcopy %t.o -O elf32-littleriscv %t.elf32_littleriscv.o --split-dwo=%t.elf32_littleriscv.dwo # RUN: llvm-readobj --file-headers %t.elf32_littleriscv.o | FileCheck %s --check-prefixes=CHECK,LE,RISCV32,32,SYSV # RUN: llvm-readobj --file-headers %t.elf32_littleriscv.dwo | FileCheck %s --check-prefixes=CHECK,LE,RISCV32,32,SYSV @@ -145,9 +145,8 @@ # ARM-SAME: littlearm # HEXAGON-SAME: hexagon # MIPS-SAME: mips -# PPC-SAME: powerpc{{$}} -# PPC64BE-SAME: powerpc{{$}} -# PPC64LE-SAME: powerpcle{{$}} +# PPCBE-SAME: powerpc{{$}} +# PPCLE-SAME: powerpcle{{$}} # RISCV32-SAME: riscv{{$}} # RISCV64-SAME: riscv{{$}} # SPARC-SAME: sparc @@ -163,9 +162,10 @@ # MIPSLE-NEXT: Arch: mipsel{{$}} # MIPS64BE-NEXT: Arch: mips64{{$}} # MIPS64LE-NEXT: Arch: mips64el{{$}} -# PPC-NEXT: Arch: powerpc{{$}} +# PPC32BE-NEXT: Arch: powerpc{{$}} +# PPC32LE-NEXT: Arch: powerpcle{{$}} # PPC64BE-NEXT: Arch: powerpc64{{$}} -# PPC64LE-NEXT: Arch: powerpc64le +# PPC64LE-NEXT: Arch: powerpc64le{{$}} # RISCV32-NEXT: Arch: riscv32 # RISCV64-NEXT: Arch: riscv64 # SPARC-NEXT: Arch: sparc{{$}} @@ -191,7 +191,7 @@ # I386: Machine: EM_386 (0x3) # IAMCU: Machine: EM_IAMCU (0x6) # MIPS: Machine: EM_MIPS (0x8) -# PPC: Machine: EM_PPC (0x14) +# PPC32: Machine: EM_PPC (0x14) # PPC64: Machine: EM_PPC64 (0x15) # RISCV32: Machine: EM_RISCV (0xF3) # RISCV64: Machine: EM_RISCV (0xF3) diff --git a/llvm/test/tools/llvm-objdump/ELF/PowerPC/branch-offset.s b/llvm/test/tools/llvm-objdump/ELF/PowerPC/branch-offset.s --- a/llvm/test/tools/llvm-objdump/ELF/PowerPC/branch-offset.s +++ b/llvm/test/tools/llvm-objdump/ELF/PowerPC/branch-offset.s @@ -1,11 +1,14 @@ -# RUN: llvm-mc -triple=powerpc -filetype=obj %s -o %t.32.o -# RUN: llvm-objdump -d --no-show-raw-insn %t.32.o | FileCheck --check-prefixes=ELF32,CHECK %s +# RUN: llvm-mc -triple=powerpc -filetype=obj %s -o %t.32be.o +# RUN: llvm-objdump -d --no-show-raw-insn %t.32be.o | FileCheck --check-prefixes=ELF32,CHECK %s -# RUN: llvm-mc -triple=powerpc64le -filetype=obj %s -o %t.64.o -# RUN: llvm-objdump -d --no-show-raw-insn %t.64.o | FileCheck --check-prefixes=ELF64,CHECK %s +# RUN: llvm-mc -triple=powerpcle -filetype=obj %s -o %t.32le.o +# RUN: llvm-objdump -d --no-show-raw-insn %t.32le.o | FileCheck --check-prefixes=ELF32,CHECK %s -# RUN: llvm-mc -triple=powerpc64 -filetype=obj %s -o %t.64.o -# RUN: llvm-objdump -d --no-show-raw-insn %t.64.o | FileCheck --check-prefixes=ELF64,CHECK %s +# RUN: llvm-mc -triple=powerpc64 -filetype=obj %s -o %t.64be.o +# RUN: llvm-objdump -d --no-show-raw-insn %t.64be.o | FileCheck --check-prefixes=ELF64,CHECK %s + +# RUN: llvm-mc -triple=powerpc64le -filetype=obj %s -o %t.64le.o +# RUN: llvm-objdump -d --no-show-raw-insn %t.64le.o | FileCheck --check-prefixes=ELF64,CHECK %s # CHECK-LABEL: : # ELF32-NEXT: bl 0xfffffffc diff --git a/llvm/unittests/Object/ELFObjectFileTest.cpp b/llvm/unittests/Object/ELFObjectFileTest.cpp --- a/llvm/unittests/Object/ELFObjectFileTest.cpp +++ b/llvm/unittests/Object/ELFObjectFileTest.cpp @@ -174,7 +174,7 @@ } TEST(ELFObjectFileTest, MachineTestForPPC) { - std::array Formats = {"elf32-powerpc", "elf32-powerpc", + std::array Formats = {"elf32-powerpcle", "elf32-powerpc", "elf64-unknown", "elf64-unknown"}; size_t I = 0; for (const DataForTest &D : generateData(ELF::EM_PPC))