[llvm] 15497e6 - [openmp][ELF] Recognize LLVM OpenMP offload specific notes
Vyacheslav Zakharin via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 13:52:15 PDT 2021
Author: Vyacheslav Zakharin
Date: 2021-08-12T13:47:48-07:00
New Revision: 15497e62f64d862484677fe7b1e58fb8270494e7
URL: https://github.com/llvm/llvm-project/commit/15497e62f64d862484677fe7b1e58fb8270494e7
DIFF: https://github.com/llvm/llvm-project/commit/15497e62f64d862484677fe7b1e58fb8270494e7.diff
LOG: [openmp][ELF] Recognize LLVM OpenMP offload specific notes
The new ELF notes are added in clang-offload-wrapper, and llvm-readobj has to visualize them properly.
Differential Revision: https://reviews.llvm.org/D99552
Added:
llvm/test/tools/llvm-readobj/ELF/note-llvmompoffload.test
Modified:
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/note-llvmompoffload.test b/llvm/test/tools/llvm-readobj/ELF/note-llvmompoffload.test
new file mode 100644
index 0000000000000..050ef9a3f465c
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/note-llvmompoffload.test
@@ -0,0 +1,68 @@
+## Test that llvm-readobj is able to recognize LLVMOMPOFFLOAD ELF notes.
+
+# RUN: yaml2obj %s -o %t.64le -DBITS=64 -DENCODING=LSB
+# RUN: llvm-readobj --notes %t.64le | FileCheck %s --match-full-lines --check-prefix=NOTES
+# RUN: llvm-readelf --notes %t.64le | FileCheck %s --match-full-lines --check-prefix=NOTES-GNU
+# RUN: yaml2obj %s -o %t.64be -DBITS=64 -DENCODING=MSB
+# RUN: llvm-readobj --notes %t.64be | FileCheck %s --match-full-lines --check-prefix=NOTES
+# RUN: llvm-readelf --notes %t.64be | FileCheck %s --match-full-lines --check-prefix=NOTES-GNU
+# RUN: yaml2obj %s -o %t.32le -DBITS=32 -DENCODING=LSB
+# RUN: llvm-readobj --notes %t.32le | FileCheck %s --match-full-lines --check-prefix=NOTES
+# RUN: llvm-readelf --notes %t.32le | FileCheck %s --match-full-lines --check-prefix=NOTES-GNU
+# RUN: yaml2obj %s -o %t.32be -DBITS=32 -DENCODING=MSB
+# RUN: llvm-readobj --notes %t.32be | FileCheck %s --match-full-lines --check-prefix=NOTES
+# RUN: llvm-readelf --notes %t.32be | FileCheck %s --match-full-lines --check-prefix=NOTES-GNU
+
+# NOTES: Notes [
+# NOTES-NEXT: NoteSection {
+# NOTES-NEXT: Name: .note.openmp
+# NOTES-NEXT: Offset: {{.*}}
+# NOTES-NEXT: Size: {{.*}}
+# NOTES-NEXT: Note {
+# NOTES-NEXT: Owner: LLVMOMPOFFLOAD
+# NOTES-NEXT: Data size: 0x3
+# NOTES-NEXT: Type: NT_LLVM_OPENMP_OFFLOAD_VERSION (image format version)
+# NOTES-NEXT: Version: 1.0
+# NOTES-NEXT: }
+# NOTES-NEXT: Note {
+# NOTES-NEXT: Owner: LLVMOMPOFFLOAD
+# NOTES-NEXT: Data size: 0x4
+# NOTES-NEXT: Type: NT_LLVM_OPENMP_OFFLOAD_PRODUCER (producing toolchain)
+# NOTES-NEXT: Producer: LLVM
+# NOTES-NEXT: }
+# NOTES-NEXT: Note {
+# NOTES-NEXT: Owner: LLVMOMPOFFLOAD
+# NOTES-NEXT: Data size: 0x9
+# NOTES-NEXT: Type: NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION (producing toolchain version)
+# NOTES-NEXT: Producer version: 13.0.0git
+# NOTES-NEXT: }
+# NOTES-NEXT: }
+# NOTES-NEXT: ]
+
+# NOTES-GNU: Displaying notes found in: .note.openmp
+# NOTES-GNU-NEXT: Owner Data size Description
+# NOTES-GNU-NEXT: LLVMOMPOFFLOAD 0x00000003 NT_LLVM_OPENMP_OFFLOAD_VERSION (image format version)
+# NOTES-GNU-NEXT: Version: 1.0
+# NOTES-GNU-NEXT: LLVMOMPOFFLOAD 0x00000004 NT_LLVM_OPENMP_OFFLOAD_PRODUCER (producing toolchain)
+# NOTES-GNU-NEXT: Producer: LLVM
+# NOTES-GNU-NEXT: LLVMOMPOFFLOAD 0x00000009 NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION (producing toolchain version)
+# NOTES-GNU-NEXT: Producer version: 13.0.0git
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS[[BITS]]
+ Data: ELFDATA2[[ENCODING]]
+ Type: ET_REL
+Sections:
+ - Name: .note.openmp
+ Type: SHT_NOTE
+ Notes:
+ - Name: LLVMOMPOFFLOAD
+ Type: 1 # NT_LLVM_OPENMP_OFFLOAD_VERSION
+ Desc: '312e30'
+ - Name: LLVMOMPOFFLOAD
+ Type: 2 # NT_LLVM_OPENMP_OFFLOAD_PRODUCER
+ Desc: '4c4c564d'
+ - Name: LLVMOMPOFFLOAD
+ Type: 3 # NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION
+ Desc: '31332e302e30676974'
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index f221acba979af..000a10b1c2f81 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -4951,7 +4951,7 @@ static std::string getGNUBuildId(ArrayRef<uint8_t> Desc) {
return OS.str();
}
-static StringRef getGNUGoldVersion(ArrayRef<uint8_t> Desc) {
+static StringRef getDescAsStringRef(ArrayRef<uint8_t> Desc) {
return StringRef(reinterpret_cast<const char *>(Desc.data()), Desc.size());
}
@@ -4975,7 +4975,7 @@ static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
break;
}
case ELF::NT_GNU_GOLD_VERSION:
- OS << " Version: " << getGNUGoldVersion(Desc);
+ OS << " Version: " << getDescAsStringRef(Desc);
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
OS << " Properties:";
@@ -4987,6 +4987,26 @@ static bool printGNUNote(raw_ostream &OS, uint32_t NoteType,
return true;
}
+template <typename ELFT>
+static bool printLLVMOMPOFFLOADNote(raw_ostream &OS, uint32_t NoteType,
+ ArrayRef<uint8_t> Desc) {
+ switch (NoteType) {
+ default:
+ return false;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_VERSION:
+ OS << " Version: " << getDescAsStringRef(Desc);
+ break;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER:
+ OS << " Producer: " << getDescAsStringRef(Desc);
+ break;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION:
+ OS << " Producer version: " << getDescAsStringRef(Desc);
+ break;
+ }
+ OS << '\n';
+ return true;
+}
+
static const EnumEntry<unsigned> FreeBSDFeatureCtlFlags[] = {
{"ASLR_DISABLE", NT_FREEBSD_FCTL_ASLR_DISABLE},
{"PROTMAX_DISABLE", NT_FREEBSD_FCTL_PROTMAX_DISABLE},
@@ -5302,6 +5322,15 @@ static const NoteType AMDGPUNoteTypes[] = {
{ELF::NT_AMDGPU_METADATA, "NT_AMDGPU_METADATA (AMDGPU Metadata)"},
};
+static const NoteType LLVMOMPOFFLOADNoteTypes[] = {
+ {ELF::NT_LLVM_OPENMP_OFFLOAD_VERSION,
+ "NT_LLVM_OPENMP_OFFLOAD_VERSION (image format version)"},
+ {ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER,
+ "NT_LLVM_OPENMP_OFFLOAD_PRODUCER (producing toolchain)"},
+ {ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION,
+ "NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION (producing toolchain version)"},
+};
+
static const NoteType CoreNoteTypes[] = {
{ELF::NT_PRSTATUS, "NT_PRSTATUS (prstatus structure)"},
{ELF::NT_FPREGSET, "NT_FPREGSET (floating point registers)"},
@@ -5395,6 +5424,8 @@ StringRef getNoteTypeName(const typename ELFT::Note &Note, unsigned ELFType) {
return FindNote(AMDNoteTypes);
if (Name == "AMDGPU")
return FindNote(AMDGPUNoteTypes);
+ if (Name == "LLVMOMPOFFLOAD")
+ return FindNote(LLVMOMPOFFLOADNoteTypes);
if (ELFType == ELF::ET_CORE)
return FindNote(CoreNoteTypes);
@@ -5530,6 +5561,9 @@ template <class ELFT> void GNUELFDumper<ELFT>::printNotes() {
OS << " " << N.Type << ":\n " << N.Value << '\n';
return Error::success();
}
+ } else if (Name == "LLVMOMPOFFLOAD") {
+ if (printLLVMOMPOFFLOADNote<ELFT>(OS, Type, Descriptor))
+ return Error::success();
} else if (Name == "CORE") {
if (Type == ELF::NT_FILE) {
DataExtractor DescExtractor(Descriptor,
@@ -6892,7 +6926,7 @@ static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
break;
}
case ELF::NT_GNU_GOLD_VERSION:
- W.printString("Version", getGNUGoldVersion(Desc));
+ W.printString("Version", getDescAsStringRef(Desc));
break;
case ELF::NT_GNU_PROPERTY_TYPE_0:
ListScope D(W, "Property");
@@ -6903,6 +6937,26 @@ static bool printGNUNoteLLVMStyle(uint32_t NoteType, ArrayRef<uint8_t> Desc,
return true;
}
+template <typename ELFT>
+static bool printLLVMOMPOFFLOADNoteLLVMStyle(uint32_t NoteType,
+ ArrayRef<uint8_t> Desc,
+ ScopedPrinter &W) {
+ switch (NoteType) {
+ default:
+ return false;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_VERSION:
+ W.printString("Version", getDescAsStringRef(Desc));
+ break;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER:
+ W.printString("Producer", getDescAsStringRef(Desc));
+ break;
+ case ELF::NT_LLVM_OPENMP_OFFLOAD_PRODUCER_VERSION:
+ W.printString("Producer version", getDescAsStringRef(Desc));
+ break;
+ }
+ return true;
+}
+
static void printCoreNoteLLVMStyle(const CoreNote &Note, ScopedPrinter &W) {
W.printNumber("Page Size", Note.PageSize);
for (const CoreFileMapping &Mapping : Note.Mappings) {
@@ -6970,6 +7024,9 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printNotes() {
W.printString(N.Type, N.Value);
return Error::success();
}
+ } else if (Name == "LLVMOMPOFFLOAD") {
+ if (printLLVMOMPOFFLOADNoteLLVMStyle<ELFT>(Type, Descriptor, W))
+ return Error::success();
} else if (Name == "CORE") {
if (Type == ELF::NT_FILE) {
DataExtractor DescExtractor(Descriptor,
More information about the llvm-commits
mailing list