Skip to content

Commit 42e1035

Browse files
committed
[LinkerWrapper] Identify offloading sections using ELF type
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.
1 parent 8cadfdf commit 42e1035

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "llvm/Object/Archive.h"
2929
#include "llvm/Object/ArchiveWriter.h"
3030
#include "llvm/Object/Binary.h"
31+
#include "llvm/Object/ELFObjectFile.h"
3132
#include "llvm/Object/IRObjectFile.h"
3233
#include "llvm/Object/ObjectFile.h"
3334
#include "llvm/Object/OffloadBinary.h"
@@ -339,9 +340,8 @@ Error extractOffloadFiles(MemoryBufferRef Contents,
339340
// Extract offloading binaries from an Object file \p Obj.
340341
Error extractFromBinary(const ObjectFile &Obj,
341342
SmallVectorImpl<OffloadFile> &DeviceFiles) {
342-
for (const SectionRef &Sec : Obj.sections()) {
343-
Expected<StringRef> Name = Sec.getName();
344-
if (!Name || !Name->equals(OFFLOAD_SECTION_MAGIC_STR))
343+
for (ELFSectionRef Sec : Obj.sections()) {
344+
if (Sec.getType() != ELF::SHT_LLVM_OFFLOADING)
345345
continue;
346346

347347
Expected<StringRef> Buffer = Sec.getContents();
@@ -433,9 +433,7 @@ Error extractFromBuffer(std::unique_ptr<MemoryBuffer> Buffer,
433433
switch (Type) {
434434
case file_magic::bitcode:
435435
return extractFromBitcode(std::move(Buffer), DeviceFiles);
436-
case file_magic::elf_relocatable:
437-
case file_magic::macho_object:
438-
case file_magic::coff_object: {
436+
case file_magic::elf_relocatable: {
439437
Expected<std::unique_ptr<ObjectFile>> ObjFile =
440438
ObjectFile::createObjectFile(*Buffer, Type);
441439
if (!ObjFile)

0 commit comments

Comments
 (0)