forked from OSchip/llvm-project
[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
This commit is contained in:
parent
1d2ce4da84
commit
82a0adf0f7
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue