diff --git a/llvm/test/tools/llvm-objdump/Offloading/binary.test b/llvm/test/tools/llvm-objdump/Offloading/binary.test --- 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 @@ 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 --- a/llvm/test/tools/llvm-objdump/Offloading/content-failure.test +++ b/llvm/test/tools/llvm-objdump/Offloading/content-failure.test @@ -9,7 +9,7 @@ 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 --- a/llvm/test/tools/llvm-objdump/Offloading/failure.test +++ b/llvm/test/tools/llvm-objdump/Offloading/failure.test @@ -8,7 +8,7 @@ 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 --- /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 --- 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 @@ 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 --- a/llvm/tools/llvm-objdump/OffloadDump.cpp +++ b/llvm/tools/llvm-objdump/OffloadDump.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "OffloadDump.h" #include "llvm-objdump.h" +#include "llvm/Object/ELFObjectFile.h" using namespace llvm; using namespace llvm::object; @@ -66,9 +67,14 @@ /// Print the embedded offloading contents of an ObjectFile \p O. void llvm::dumpOffloadBinary(const ObjectFile &O) { - for (SectionRef Sec : O.sections()) { - Expected 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 Contents = Sec.getContents();