[llvm] 82a0adf - [llvm-objdump] Update offload dumping to use SHT_LLVM_OFFLOADING
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 7 09:20:56 PDT 2022
Author: Joseph Huber
Date: 2022-07-07T12:20:35-04:00
New Revision: 82a0adf0f78d5be8a727d9537627e2a6f7e8e105
URL: https://github.com/llvm/llvm-project/commit/82a0adf0f78d5be8a727d9537627e2a6f7e8e105
DIFF: https://github.com/llvm/llvm-project/commit/82a0adf0f78d5be8a727d9537627e2a6f7e8e105.diff
LOG: [llvm-objdump] Update offload dumping to use SHT_LLVM_OFFLOADING
In order to be more in-line with ELF semantics, a previous patch added
support for a new ELF section type to indicate if a section contains
offloading data. This allows us to now check using this rather than
checking the section name directly. This patch updates the logic to
check the type now instead.
I chose to make this emit a warning if the input is not an ELF-object
file. I could have made the logic fall-back to the section name, but
this offloading in LLVM is currently not supported on any other targets
so it's probably best to emit a warning until we improve support.
Depends on D129052
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D129053
Added:
llvm/test/tools/llvm-objdump/Offloading/non-elf.test
Modified:
llvm/test/tools/llvm-objdump/Offloading/binary.test
llvm/test/tools/llvm-objdump/Offloading/content-failure.test
llvm/test/tools/llvm-objdump/Offloading/failure.test
llvm/test/tools/llvm-objdump/Offloading/warning.test
llvm/tools/llvm-objdump/OffloadDump.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objdump/Offloading/binary.test b/llvm/test/tools/llvm-objdump/Offloading/binary.test
index fab988233c8d..880bab2ec533 100644
--- a/llvm/test/tools/llvm-objdump/Offloading/binary.test
+++ b/llvm/test/tools/llvm-objdump/Offloading/binary.test
@@ -4,8 +4,7 @@
## Check that we can dump an offloading binary inside of an ELF section.
# RUN: yaml2obj %s -o %t.elf
-# RUN: llvm-objcopy --add-section .llvm.offloading=%t.bin %t.elf
-# RUN: llvm-objcopy --set-section-alignment .llvm.offloading=8 %t.elf
+# RUN: llvm-objcopy --update-section .llvm.offloading=%t.bin %t.elf
# RUN: llvm-objdump --offloading %t.elf | FileCheck %s --check-prefixes=CHECK,ELF --match-full-lines --strict-whitespace --implicit-check-not={{.}}
!ELF
@@ -13,6 +12,11 @@ FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
+Sections:
+ - Name: .llvm.offloading
+ Type: SHT_LLVM_OFFLOADING
+ Flags: [ SHF_EXCLUDE ]
+ AddressAlign: 0x0000000000000008
# ELF:{{.*}}file format elf64-unknown
# ELF-EMPTY:
diff --git a/llvm/test/tools/llvm-objdump/Offloading/content-failure.test b/llvm/test/tools/llvm-objdump/Offloading/content-failure.test
index d445226ce516..5089edae0450 100644
--- a/llvm/test/tools/llvm-objdump/Offloading/content-failure.test
+++ b/llvm/test/tools/llvm-objdump/Offloading/content-failure.test
@@ -9,7 +9,7 @@ FileHeader:
Type: ET_EXEC
Sections:
- Name: .llvm.offloading
- Type: SHT_PROGBITS
+ Type: SHT_LLVM_OFFLOADING
Flags: [ SHF_EXCLUDE ]
Address: 0x0
ShOffset: 0x99999
diff --git a/llvm/test/tools/llvm-objdump/Offloading/failure.test b/llvm/test/tools/llvm-objdump/Offloading/failure.test
index 854d8e00f3fa..5b4cbdb29b0e 100644
--- a/llvm/test/tools/llvm-objdump/Offloading/failure.test
+++ b/llvm/test/tools/llvm-objdump/Offloading/failure.test
@@ -8,7 +8,7 @@ FileHeader:
Type: ET_EXEC
Sections:
- Name: .llvm.offloading
- Type: SHT_PROGBITS
+ Type: SHT_LLVM_OFFLOADING
Flags: [ SHF_EXCLUDE ]
Address: 0x0
AddressAlign: 0x0000000000000008
diff --git a/llvm/test/tools/llvm-objdump/Offloading/non-elf.test b/llvm/test/tools/llvm-objdump/Offloading/non-elf.test
new file mode 100644
index 000000000000..955556f0567b
--- /dev/null
+++ b/llvm/test/tools/llvm-objdump/Offloading/non-elf.test
@@ -0,0 +1,14 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-objdump --offloading %t 2>&1 | FileCheck -DFILENAME=%t %s
+
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .rdata
+ Characteristics: []
+ SectionData: 00
+symbols:
+
+# CHECK: warning: '[[FILENAME]]': --offloading is currently only supported for ELF targets
diff --git a/llvm/test/tools/llvm-objdump/Offloading/warning.test b/llvm/test/tools/llvm-objdump/Offloading/warning.test
index aaf796b5b9e1..a4be54ebf6dc 100644
--- a/llvm/test/tools/llvm-objdump/Offloading/warning.test
+++ b/llvm/test/tools/llvm-objdump/Offloading/warning.test
@@ -3,8 +3,7 @@
# RUN: yaml2obj %S/Inputs/malformed.yaml -o %t-bad.bin
# RUN: cat %t-bad.bin >> %t-good.bin
# RUN: yaml2obj %s -o %t.elf
-# RUN: llvm-objcopy --add-section .llvm.offloading=%t-good.bin %t.elf
-# RUN: llvm-objcopy --set-section-alignment .llvm.offloading=8 %t.elf
+# RUN: llvm-objcopy --update-section .llvm.offloading=%t-good.bin %t.elf
# RUN: llvm-objdump --offloading %t.elf 2>&1 | FileCheck %s -DFILENAME=%t.elf
!ELF
@@ -12,6 +11,11 @@ FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
+Sections:
+ - Name: .llvm.offloading
+ Type: SHT_LLVM_OFFLOADING
+ Flags: [ SHF_EXCLUDE ]
+ AddressAlign: 0x0000000000000008
# CHECK: OFFLOADING IMAGE [0]:
# CHECK: warning: '[[FILENAME]]': while parsing offloading files: The end of the file was unexpectedly encountered
diff --git a/llvm/tools/llvm-objdump/OffloadDump.cpp b/llvm/tools/llvm-objdump/OffloadDump.cpp
index 7d4461f0a70e..b3302d40e2bc 100644
--- a/llvm/tools/llvm-objdump/OffloadDump.cpp
+++ b/llvm/tools/llvm-objdump/OffloadDump.cpp
@@ -12,13 +12,12 @@
//===----------------------------------------------------------------------===//
#include "OffloadDump.h"
#include "llvm-objdump.h"
+#include "llvm/Object/ELFObjectFile.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::objdump;
-constexpr const char OffloadSectionString[] = ".llvm.offloading";
-
/// Get the printable name of the image kind.
static StringRef getImageName(const OffloadBinary &OB) {
switch (OB.getImageKind()) {
@@ -66,9 +65,14 @@ static Error visitAllBinaries(const OffloadBinary &OB) {
/// Print the embedded offloading contents of an ObjectFile \p O.
void llvm::dumpOffloadBinary(const ObjectFile &O) {
- for (SectionRef Sec : O.sections()) {
- Expected<StringRef> Name = Sec.getName();
- if (!Name || !Name->startswith(OffloadSectionString))
+ if (!O.isELF()) {
+ reportWarning("--offloading is currently only supported for ELF targets",
+ O.getFileName());
+ return;
+ }
+
+ for (ELFSectionRef Sec : O.sections()) {
+ if (Sec.getType() != ELF::SHT_LLVM_OFFLOADING)
continue;
Expected<StringRef> Contents = Sec.getContents();
More information about the llvm-commits
mailing list