-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[AMDGPU] Add AMDGPU support for llvm-objcopy #92066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@llvm/pr-subscribers-objectyaml @llvm/pr-subscribers-backend-amdgpu Author: Aakanksha Patil (aakanksha555) Changeshttps://reviews.llvm.org/D143539 Full diff: https://github.com/llvm/llvm-project/pull/92066.diff 2 Files Affected:
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>
|
jh7370
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR appears to have the same issues as I highlighted in the original Phabricator review. Please see https://reviews.llvm.org/D143539#4527049.
|
Hi @Pierre-vh, can you help with the questions/issues in https://reviews.llvm.org/D143539#4527049 |
|
I agree that this should probably go in That being said, I'm not sure I agree with having the GPU name in the -O flag unless it's done dynamically. I'd like to avoid enumerating all GPUs in yet another place if it can be avoided. So either populate the map automatically, or parse the target into a flag, etc. |
|
Hi, considering both of your feedback I'm trying to have amdgpu go into cross-arch-headers.test with a flag as suggested. But, adding "Flags: [[FLAGS=<none>]]" to the FileHeader: gives- Any suggestions on how I can go about incorporating the flag? |
What happens if you use another default value for the flag, like 0? Can you just update this patch with the cross-arch-headers.test instead, even if the test is broken? Just put a comment with the error. It'll be much easier to review this way |
Add amdgpu support in cross-arch-headers.test instead of its own test
| # 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're overwriting the older file here which is a bigger issue
I now agree a separate test file is needed, so feel free to revert to the previous approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now agree a separate test file is needed, so feel free to revert to the previous approach
Please don't.
jh7370
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please could you use meaningful commit descriptions for fixups describing what has changed, rather than just repeating the PR title.
Let's go back to this conversation though:
(From Phabricator)
That all being said, the requirement for the flag is troubling me. Is there prior art to how to specify the ADMGPU target for an llvm-objcopy-like tool? The existing test shows that you can convert from one target (EM_NONE in the original test) to another target using the -O option, but the new test you've written doesn't demonstrate this behaviour (if I'm not mistaken, if you omitted the -O option, you'd get the same output, as the output target is derived from the input if not otherwise specified). Questions that I have are 1) if the input target was EM_AMDGPU and somebody specified e.g. -O elf32-hexagon, what should happen to any AMDGPU EF_* flag? 2) Similarly, how would you get a different AMDGPU flag? In other words, how would you get llvm-objcopy to add the EF_AMDGPU_MACH_* flag if it wasn't already present?
I don't think these questions have been addressed at all. What is your proposal for this?
| # 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now agree a separate test file is needed, so feel free to revert to the previous approach
Please don't.
Pierre-vh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add a test in binary-output-target.test
|
Hi, |
I think that works, @jh7370 ? |
Functionally, it works, but I'd still prefer a yaml2obj enhancement to accept the "<none>" value for flags, as with other fields, as it will be cleaner in the test. I experimented with this and the change required is simple. Essentially, in the YAML code, you just need to make the header flags field optional and remove the default value from the |
Got it, thanks for the feedback. Looking into it! |
jh7370
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a problem with obj2yaml now, which should be fairly trivial to fix. Also, could you split off the yaml2obj/obj2yaml changes into a separate PR, that this one relies on, please? It's functionally useful on its own.
llvm/test/Object/obj2yaml.test
Outdated
| # ELF-X86-64-NEXT: OSABI: ELFOSABI_GNU | ||
| # ELF-X86-64-NEXT: Type: ET_REL | ||
| # ELF-X86-64-NEXT: Machine: EM_X86_64 | ||
| # ELF-X86-64-NEXT: Flags: [ ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an undesirable outcome: if the Flags are empty, we shouldn't end up with a Flags entry in the output.
Split up the "FLAGS=" changes in the above PR |
… field (#143845) llvm/llvm-project#92066 will be dependent on this change
…m#143845) llvm#92066 will be dependent on this change
jh7370
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the yaml2obj improvements. This PR now looks a lot cleaner. However, I've still yet to see responses to my queries referenced in this comment. Please take a look and respond.
| # 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 | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove duplicate blank line.
| Type: ET_REL | ||
| Machine: EM_MIPS | ||
| Flags: [ ] | ||
| Flags: [ ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reinstate the indentation so that the value part lines up with the other fields.
https://reviews.llvm.org/D143539