[llvm] 441afb3 - [llvm-objcopy] Add LoongArch support
Weining Lu via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 25 19:38:17 PDT 2023
Author: WANG Xuerui
Date: 2023-06-26T10:37:31+08:00
New Revision: 441afb3978ce3599b11615d1365a75e32b0fa47c
URL: https://github.com/llvm/llvm-project/commit/441afb3978ce3599b11615d1365a75e32b0fa47c
DIFF: https://github.com/llvm/llvm-project/commit/441afb3978ce3599b11615d1365a75e32b0fa47c.diff
LOG: [llvm-objcopy] Add LoongArch support
Apart from general feature parity, this is also necessary for enabling
ClangBuiltLinux that defaults to using LLVM tools.
While at it, add a missing comment for the Hexagon definition directly
above, so it doesn't get confused with the SPARC definitions.
Reviewed By: SixWeining, MaskRay, jhenderson
Differential Revision: https://reviews.llvm.org/D153609
Added:
Modified:
llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test b/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
index 78fc1435518cf..fc5856691f8dc 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/binary-output-target.test
@@ -42,6 +42,12 @@
# RUN: llvm-objcopy -I binary -O elf32-hexagon %t.txt %t.hexagon.o
# RUN: llvm-readobj --file-headers %t.hexagon.o | FileCheck %s --check-prefixes=CHECK,LE,HEXAGON,32
+# RUN: llvm-objcopy -I binary -O elf32-loongarch %t.txt %t.la32.o
+# RUN: llvm-readobj --file-headers %t.la32.o | FileCheck %s --check-prefixes=CHECK,LE,LA32,32
+
+# RUN: llvm-objcopy -I binary -O elf64-loongarch %t.txt %t.la64.o
+# RUN: llvm-readobj --file-headers %t.la64.o | FileCheck %s --check-prefixes=CHECK,LE,LA64,64
+
# CHECK: Format:
# 32-SAME: elf32-
# 64-SAME: elf64-
@@ -49,6 +55,8 @@
# ARM-SAME: littlearm
# HEXAGON-SAME: hexagon
# I386-SAME: i386
+# LA32-SAME: loongarch{{$}}
+# LA64-SAME: loongarch{{$}}
# MIPS-SAME: mips{{$}}
# RISCV32-SAME: riscv{{$}}
# RISCV64-SAME: riscv{{$}}
@@ -62,6 +70,8 @@
# ARM-NEXT: Arch: arm
# HEXAGON-NEXT: Arch: hexagon
# I386-NEXT: Arch: i386
+# LA32-NEXT: Arch: loongarch32
+# LA64-NEXT: Arch: loongarch64
# MIPS-NEXT: Arch: mips{{$}}
# PPC32BE-NEXT: Arch: powerpc{{$}}
# PPC32LE-NEXT: Arch: powerpcle{{$}}
@@ -97,6 +107,8 @@
# ARM-NEXT: Machine: EM_ARM (0x28)
# HEXAGON-NEXT: Machine: EM_HEXAGON (0xA4)
# I386-NEXT: Machine: EM_386 (0x3)
+# LA32-NEXT: Machine: EM_LOONGARCH (0x102)
+# LA64-NEXT: Machine: EM_LOONGARCH (0x102)
# MIPS-NEXT: Machine: EM_MIPS (0x8)
# PPC32-NEXT: Machine: EM_PPC (0x14)
# PPC64-NEXT: Machine: EM_PPC64 (0x15)
diff --git a/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test b/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
index 98f1b3c644d8b..882940c05e19c 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
@@ -109,6 +109,14 @@
# RUN: llvm-readobj --file-headers %t.elf32_hexagon.o | FileCheck %s --check-prefixes=CHECK,LE,HEXAGON,32,SYSV
# RUN: llvm-readobj --file-headers %t.elf32_hexagon.dwo | FileCheck %s --check-prefixes=CHECK,LE,HEXAGON,32,SYSV
+# RUN: llvm-objcopy %t.o -O elf32-loongarch %t.elf32_loongarch.o --split-dwo=%t.elf32_loongarch.dwo
+# RUN: llvm-readobj --file-headers %t.elf32_loongarch.o | FileCheck %s --check-prefixes=CHECK,LE,LA32,32,SYSV
+# RUN: llvm-readobj --file-headers %t.elf32_loongarch.dwo | FileCheck %s --check-prefixes=CHECK,LE,LA32,32,SYSV
+
+# RUN: llvm-objcopy %t.o -O elf64-loongarch %t.elf64_loongarch.o --split-dwo=%t.elf64_loongarch.dwo
+# RUN: llvm-readobj --file-headers %t.elf64_loongarch.o | FileCheck %s --check-prefixes=CHECK,LE,LA64,64,SYSV
+# RUN: llvm-readobj --file-headers %t.elf64_loongarch.dwo | FileCheck %s --check-prefixes=CHECK,LE,LA64,64,SYSV
+
!ELF
FileHeader:
Class: ELFCLASS32
@@ -144,6 +152,8 @@ Symbols:
# AARCH-SAME: aarch64
# ARM-SAME: littlearm
# HEXAGON-SAME: hexagon
+# LA32-SAME: loongarch{{$}}
+# LA64-SAME: loongarch{{$}}
# MIPS-SAME: mips
# PPCBE-SAME: powerpc{{$}}
# PPCLE-SAME: powerpcle{{$}}
@@ -158,6 +168,8 @@ Symbols:
# AARCH-NEXT: Arch: aarch64
# ARM-NEXT: Arch: arm
# HEXAGON-NEXT: Arch: hexagon
+# LA32-NEXT: Arch: loongarch32
+# LA64-NEXT: Arch: loongarch64
# MIPSBE-NEXT: Arch: mips{{$}}
# MIPSLE-NEXT: Arch: mipsel{{$}}
# MIPS64BE-NEXT: Arch: mips64{{$}}
@@ -190,6 +202,8 @@ Symbols:
# HEXAGON: Machine: EM_HEXAGON (0xA4)
# I386: Machine: EM_386 (0x3)
# IAMCU: Machine: EM_IAMCU (0x6)
+# LA32: Machine: EM_LOONGARCH (0x102)
+# LA64: Machine: EM_LOONGARCH (0x102)
# MIPS: Machine: EM_MIPS (0x8)
# PPC32: Machine: EM_PPC (0x14)
# PPC64: Machine: EM_PPC64 (0x15)
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index 9e634fe024b8b..265e4fc6073c2 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -332,7 +332,11 @@ static const StringMap<MachineInfo> TargetMap{
// SPARC
{"elf32-sparc", {ELF::EM_SPARC, false, false}},
{"elf32-sparcel", {ELF::EM_SPARC, false, true}},
+ // Hexagon
{"elf32-hexagon", {ELF::EM_HEXAGON, false, true}},
+ // LoongArch
+ {"elf32-loongarch", {ELF::EM_LOONGARCH, false, true}},
+ {"elf64-loongarch", {ELF::EM_LOONGARCH, true, true}},
};
static Expected<TargetInfo>
More information about the llvm-commits
mailing list