Index: llvm/test/tools/llvm-readobj/ELF/note-llvmompoffload.test =================================================================== --- /dev/null +++ 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' Index: llvm/tools/llvm-readobj/ELFDumper.cpp =================================================================== --- llvm/tools/llvm-readobj/ELFDumper.cpp +++ llvm/tools/llvm-readobj/ELFDumper.cpp @@ -4906,7 +4906,7 @@ return OS.str(); } -static StringRef getGNUGoldVersion(ArrayRef Desc) { +static StringRef getDescAsStringRef(ArrayRef Desc) { return StringRef(reinterpret_cast(Desc.data()), Desc.size()); } @@ -4930,7 +4930,7 @@ 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:"; @@ -4942,6 +4942,26 @@ return true; } +template +static bool printLLVMOMPOFFLOADNote(raw_ostream &OS, uint32_t NoteType, + ArrayRef 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 FreeBSDFeatureCtlFlags[] = { {"ASLR_DISABLE", NT_FREEBSD_FCTL_ASLR_DISABLE}, {"PROTMAX_DISABLE", NT_FREEBSD_FCTL_PROTMAX_DISABLE}, @@ -5254,6 +5274,15 @@ {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)"}, @@ -5347,6 +5376,8 @@ return FindNote(AMDNoteTypes); if (Name == "AMDGPU") return FindNote(AMDGPUNoteTypes); + if (Name == "LLVMOMPOFFLOAD") + return FindNote(LLVMOMPOFFLOADNoteTypes); if (ELFType == ELF::ET_CORE) return FindNote(CoreNoteTypes); @@ -5482,6 +5513,9 @@ OS << " " << N.Type << ":\n " << N.Value << '\n'; return Error::success(); } + } else if (Name == "LLVMOMPOFFLOAD") { + if (printLLVMOMPOFFLOADNote(OS, Type, Descriptor)) + return Error::success(); } else if (Name == "CORE") { if (Type == ELF::NT_FILE) { DataExtractor DescExtractor(Descriptor, @@ -6728,7 +6762,7 @@ 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"); @@ -6739,6 +6773,26 @@ return true; } +template +static bool printLLVMOMPOFFLOADNoteLLVMStyle(uint32_t NoteType, + ArrayRef 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) { @@ -6806,6 +6860,9 @@ W.printString(N.Type, N.Value); return Error::success(); } + } else if (Name == "LLVMOMPOFFLOAD") { + if (printLLVMOMPOFFLOADNoteLLVMStyle(Type, Descriptor, W)) + return Error::success(); } else if (Name == "CORE") { if (Type == ELF::NT_FILE) { DataExtractor DescExtractor(Descriptor,