Skip to content

Commit

Permalink
[LinkerWrapper] Identify offloading sections using ELF type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Jul 7, 2022
1 parent 8cadfdf commit 42e1035
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 42e1035

Please sign in to comment.