[llvm] [AMDGPU] Add AMDGPU support for llvm-objcopy (PR #92066)
Aakanksha Patil via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 18 09:49:31 PDT 2024
https://github.com/aakanksha555 updated https://github.com/llvm/llvm-project/pull/92066
>From 07f69db8ddb08971ad66e8b62552351491232c4a Mon Sep 17 00:00:00 2001
From: Aakanksha Patil <paakan at amd.com>
Date: Tue, 7 May 2024 15:40:39 -0400
Subject: [PATCH 1/2] [AMDGPU] Add AMDGPU support for llvm-objcopy
---
.../ELF/amdgpu-cross-arch-headers.test | 57 +++++++++++++++++++
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 2 +
2 files changed, 59 insertions(+)
create mode 100644 llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
diff --git a/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test b/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
new file mode 100644
index 0000000000000..a7242385950a8
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
@@ -0,0 +1,57 @@
+# Show that the --output-format correctly configures both the main output file
+# and DWO output.
+# Note that we don't actually need any DWARF to produce the DWO file.
+
+# RUN: yaml2obj %s -o %t.o
+
+# Without --output-format, the format should match the input.
+
+# RUN: llvm-objcopy %t.o -O elf64-amdgpu %t.elf64_amdgpu.o --split-dwo=%t.elf64_amdgpu.dwo
+# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.o | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
+# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.dwo | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ # Arbitrary values that do not match any value we convert to via --output-format.
+ Machine: EM_AMDGPU
+ OSABI: ELFOSABI_STANDALONE
+ Flags: [EF_AMDGPU_MACH_AMDGCN_GFX900]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+Symbols:
+ - Name: foo
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x1234
+ Binding: STB_GLOBAL
+ - Name: bar
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0xabcd
+ Binding: STB_GLOBAL
+
+# CHECK: Format:
+# AMDGPU-SAME: elf64-amdgpu
+
+# AMDGPU-NEXT: Arch: amdgcn
+
+# 64-NEXT: AddressSize: 64bit
+
+# 64: Class: 64-bit
+# LE: DataEncoding: LittleEndian
+
+# SYSV: OS/ABI: SystemV (0x0)
+
+# AMDGPU: Machine: EM_AMDGPU (0xE0)
+
+# 64: HeaderSize: 64
+
+# 64: SectionHeaderEntrySize: 64
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index a1897334cff2e..0fd1f9eac40f4 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -319,6 +319,8 @@ static const StringMap<MachineInfo> TargetMap{
{"elf64-loongarch", {ELF::EM_LOONGARCH, true, true}},
// SystemZ
{"elf64-s390", {ELF::EM_S390, true, false}},
+ // AMDGPU
+ {"elf64-amdgpu", {ELF::EM_AMDGPU, true, true}},
};
static Expected<TargetInfo>
>From 03fad14c55233123d6929f578131d0973388bd4b Mon Sep 17 00:00:00 2001
From: Aakanksha Patil <paakan at amd.com>
Date: Tue, 18 Jun 2024 12:47:45 -0400
Subject: [PATCH 2/2] [AMDGPU] Add AMDGPU support for llvm-objcopy
Add amdgpu support in cross-arch-headers.test instead of its own test
---
.../ELF/amdgpu-cross-arch-headers.test | 57 -------------------
.../llvm-objcopy/ELF/cross-arch-headers.test | 9 +++
2 files changed, 9 insertions(+), 57 deletions(-)
delete mode 100644 llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
diff --git a/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test b/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
deleted file mode 100644
index a7242385950a8..0000000000000
--- a/llvm/test/tools/llvm-objcopy/ELF/amdgpu-cross-arch-headers.test
+++ /dev/null
@@ -1,57 +0,0 @@
-# Show that the --output-format correctly configures both the main output file
-# and DWO output.
-# Note that we don't actually need any DWARF to produce the DWO file.
-
-# RUN: yaml2obj %s -o %t.o
-
-# Without --output-format, the format should match the input.
-
-# RUN: llvm-objcopy %t.o -O elf64-amdgpu %t.elf64_amdgpu.o --split-dwo=%t.elf64_amdgpu.dwo
-# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.o | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
-# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.dwo | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
-
-!ELF
-FileHeader:
- Class: ELFCLASS32
- Data: ELFDATA2LSB
- Type: ET_EXEC
- # Arbitrary values that do not match any value we convert to via --output-format.
- Machine: EM_AMDGPU
- OSABI: ELFOSABI_STANDALONE
- Flags: [EF_AMDGPU_MACH_AMDGCN_GFX900]
-Sections:
- - Name: .text
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- - Name: .data
- Type: SHT_PROGBITS
- Flags: [ SHF_ALLOC ]
-Symbols:
- - Name: foo
- Type: STT_FUNC
- Section: .text
- Value: 0x1234
- Binding: STB_GLOBAL
- - Name: bar
- Type: STT_OBJECT
- Section: .data
- Value: 0xabcd
- Binding: STB_GLOBAL
-
-# CHECK: Format:
-# AMDGPU-SAME: elf64-amdgpu
-
-# AMDGPU-NEXT: Arch: amdgcn
-
-# 64-NEXT: AddressSize: 64bit
-
-# 64: Class: 64-bit
-# LE: DataEncoding: LittleEndian
-
-# SYSV: OS/ABI: SystemV (0x0)
-
-# AMDGPU: Machine: EM_AMDGPU (0xE0)
-
-# 64: HeaderSize: 64
-
-# 64: SectionHeaderEntrySize: 64
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 9a8128611792d..2d9222673c12c 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/cross-arch-headers.test
@@ -3,6 +3,7 @@
# Note that we don't actually need any DWARF to produce the DWO file.
# RUN: yaml2obj %s -o %t.o
+# RUN: yaml2obj -DFLAGS=[EF_AMDGPU_MACH_AMDGCN_GFX900] %s -o %t.o
# Without --output-format, the format should match the input.
# RUN: llvm-objcopy %t.o %t.default.o --split-dwo=%t.default.dwo
@@ -121,6 +122,10 @@
# RUN: llvm-readobj --file-headers %t.elf64_s390.o | FileCheck %s --check-prefixes=CHECK,BE,S390X,64,SYSV
# RUN: llvm-readobj --file-headers %t.elf64_s390.dwo | FileCheck %s --check-prefixes=CHECK,BE,S390X,64,SYSV
+# RUN: llvm-objcopy %t.o -O elf64-amdgpu %t.elf64_amdgpu.o --split-dwo=%t.elf64_amdgpu.dwo
+# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.o | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
+# RUN: llvm-readobj --file-headers %t.elf64_amdgpu.dwo | FileCheck %s --check-prefixes=CHECK,LE,AMDGPU,64,SYSV
+
!ELF
FileHeader:
Class: ELFCLASS32
@@ -129,6 +134,7 @@ FileHeader:
# Arbitrary values that do not match any value we convert to via --output-format.
Machine: EM_NONE
OSABI: ELFOSABI_STANDALONE
+ Flags: [[FLAGS=<none>]]
Sections:
- Name: .text
Type: SHT_PROGBITS
@@ -154,6 +160,7 @@ Symbols:
# I386-SAME: i386
# IAMCU-SAME: iamcu
# AARCH-SAME: aarch64
+# AMDGPU-SAME: elf64-amdgpu
# ARM-SAME: littlearm
# HEXAGON-SAME: hexagon
# LA32-SAME: loongarch{{$}}
@@ -171,6 +178,7 @@ Symbols:
# I386-NEXT: Arch: i386
# IAMCU-NEXT: Arch: i386
# AARCH-NEXT: Arch: aarch64
+# AMDGPU-NEXT: Arch: amdgcn
# ARM-NEXT: Arch: arm
# HEXAGON-NEXT: Arch: hexagon
# LA32-NEXT: Arch: loongarch32
@@ -204,6 +212,7 @@ Symbols:
# DEFAULT: OS/ABI: Standalone (0xFF)
# AARCH: Machine: EM_AARCH64 (0xB7)
+# AMDGPU: Machine: EM_AMDGPU (0xE0)
# ARM: Machine: EM_ARM (0x28)
# HEXAGON: Machine: EM_HEXAGON (0xA4)
# I386: Machine: EM_386 (0x3)
More information about the llvm-commits
mailing list