[LinkerWrapper] Identify offloading sections using ELF type
authorJoseph Huber <jhuber6@vols.utk.edu>
Thu, 7 Jul 2022 16:23:44 +0000 (12:23 -0400)
committerJoseph Huber <jhuber6@vols.utk.edu>
Thu, 7 Jul 2022 16:38:00 +0000 (12:38 -0400)
Summary:
A previous patch added a new ELF section type for LLVM offloading. We
should use this when extracting the offloading sections rather than
checking the string. This pach also removes the implicit support for
COFF and MACH-O because we don't support those currently and should not
be included.

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

index e7214eb..8f98bb8 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
+#include "llvm/Object/ELFObjectFile.h"
 #include "llvm/Object/IRObjectFile.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Object/OffloadBinary.h"
@@ -339,9 +340,8 @@ Error extractOffloadFiles(MemoryBufferRef Contents,
 // Extract offloading binaries from an Object file \p Obj.
 Error extractFromBinary(const ObjectFile &Obj,
                         SmallVectorImpl<OffloadFile> &DeviceFiles) {
-  for (const SectionRef &Sec : Obj.sections()) {
-    Expected<StringRef> Name = Sec.getName();
-    if (!Name || !Name->equals(OFFLOAD_SECTION_MAGIC_STR))
+  for (ELFSectionRef Sec : Obj.sections()) {
+    if (Sec.getType() != ELF::SHT_LLVM_OFFLOADING)
       continue;
 
     Expected<StringRef> Buffer = Sec.getContents();
@@ -433,9 +433,7 @@ Error extractFromBuffer(std::unique_ptr<MemoryBuffer> Buffer,
   switch (Type) {
   case file_magic::bitcode:
     return extractFromBitcode(std::move(Buffer), DeviceFiles);
-  case file_magic::elf_relocatable:
-  case file_magic::macho_object:
-  case file_magic::coff_object: {
+  case file_magic::elf_relocatable: {
     Expected<std::unique_ptr<ObjectFile>> ObjFile =
         ObjectFile::createObjectFile(*Buffer, Type);
     if (!ObjFile)