Index: include/lld/Core/Reference.h =================================================================== --- include/lld/Core/Reference.h +++ include/lld/Core/Reference.h @@ -56,7 +56,7 @@ void setKindNamespace(KindNamespace ns) { _kindNamespace = (uint8_t)ns; } // Which architecture the kind value is for. - enum class KindArch { all, AArch64, ARM, Hexagon, Mips, x86, x86_64 }; + enum class KindArch { all, AArch64, AMDGPU, ARM, Hexagon, Mips, x86, x86_64 }; KindArch kindArch() const { return (KindArch)_kindArch; } void setKindArch(KindArch a) { _kindArch = (uint8_t)a; } Index: include/lld/ReaderWriter/ELFLinkingContext.h =================================================================== --- include/lld/ReaderWriter/ELFLinkingContext.h +++ include/lld/ReaderWriter/ELFLinkingContext.h @@ -44,6 +44,7 @@ class ELFWriter; std::unique_ptr createAArch64LinkingContext(llvm::Triple); +std::unique_ptr createAMDGPULinkingContext(llvm::Triple); std::unique_ptr createARMLinkingContext(llvm::Triple); std::unique_ptr createExampleLinkingContext(llvm::Triple); std::unique_ptr createHexagonLinkingContext(llvm::Triple); Index: lib/Driver/CMakeLists.txt =================================================================== --- lib/Driver/CMakeLists.txt +++ lib/Driver/CMakeLists.txt @@ -25,6 +25,7 @@ lldPECOFF lldELF lldAArch64ELFTarget + lldAMDGPUELFTarget lldARMELFTarget lldHexagonELFTarget lldMipsELFTarget Index: lib/Driver/GnuLdDriver.cpp =================================================================== --- lib/Driver/GnuLdDriver.cpp +++ lib/Driver/GnuLdDriver.cpp @@ -329,6 +329,7 @@ GnuLdDriver::createELFLinkingContext(llvm::Triple triple) { std::unique_ptr p; if ((p = elf::createAArch64LinkingContext(triple))) return p; + if ((p = elf::createAMDGPULinkingContext(triple))) return p; if ((p = elf::createARMLinkingContext(triple))) return p; if ((p = elf::createExampleLinkingContext(triple))) return p; if ((p = elf::createHexagonLinkingContext(triple))) return p; Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.h @@ -0,0 +1,34 @@ +//===- lib/ReaderWriter/ELF/AMDGPUELFFile.h -------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_READER_WRITER_ELF_AMDGPU_ELF_FILE_H +#define LLD_READER_WRITER_ELF_AMDGPU_ELF_FILE_H + +#include "ELFReader.h" +#include "AMDGPULinkingContext.h" + +namespace lld { +namespace elf { + +class AMDGPUELFFile : public ELFFile { + typedef llvm::object::Elf_Shdr_Impl Elf_Shdr; + typedef llvm::object::Elf_Sym_Impl Elf_Sym; + +public: + AMDGPUELFFile(std::unique_ptr mb, ELFLinkingContext &ctx) + : ELFFile(std::move(mb), ctx) {} + + bool handleSectionWithNoSymbols(const Elf_Shdr *shdr, + std::vector &syms) const override; +}; + +} // elf +} // lld + +#endif // LLD_READER_WRITER_ELF_AMDGPU_ELF_FILE_H Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.cpp @@ -0,0 +1,22 @@ +//===- lib/ReaderWriter/ELF/AMDGPUELFFile.cpp -----------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUELFFile.h" + +using namespace lld::elf; + +bool AMDGPUELFFile::handleSectionWithNoSymbols(const Elf_Shdr *shdr, + std::vector &syms) const { + // We want to create atoms for note sections, because these sections + // contain information required by the hsa runtime. + if (shdr && shdr->sh_type == llvm::ELF::SHT_NOTE && syms.empty()) + return true; + + return ELFFile::handleSectionWithNoSymbols(shdr, syms); +} Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.h @@ -0,0 +1,43 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.h ---------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef AMDGPU_EXECUTABLE_WRITER_H +#define AMDGPU_EXECUTABLE_WRITER_H + +#include "ExecutableWriter.h" +#include "AMDGPULinkingContext.h" +#include "AMDGPUSymbolTable.h" +#include "AMDGPUTargetHandler.h" + +namespace lld { +namespace elf { + +class AMDGPUTargetLayout; + +class AMDGPUExecutableWriter : public ExecutableWriter { +public: + AMDGPUExecutableWriter(AMDGPULinkingContext &ctx, + AMDGPUTargetLayout &layout); + + unique_bump_ptr> createSymbolTable() { + return unique_bump_ptr>(new (this->_alloc) + AMDGPUSymbolTable(_ctx)); + } + + void createImplicitFiles(std::vector> &Result) override; + void finalizeDefaultAtomValues() override; + +private: + AMDGPULinkingContext &_ctx; + AMDGPUTargetLayout &_targetLayout; +}; + +} // namespace elf +} // namespace lld + +#endif // AMDGPU_EXECUTABLE_WRITER_H Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.cpp @@ -0,0 +1,34 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUExecutableWriter.cpp -------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUExecutableWriter.h" + +using namespace lld::elf; + +AMDGPUExecutableWriter::AMDGPUExecutableWriter(AMDGPULinkingContext &ctx, + AMDGPUTargetLayout &layout) + : ExecutableWriter(ctx, layout), _ctx(ctx), _targetLayout(layout) {} + + +void AMDGPUExecutableWriter::createImplicitFiles( + std::vector> &Result) { + // ExecutableWriter::createImplicitFiles() adds C runtime symbols that we + // don't need, so we use the OutputELFWriter implementation instead. + OutputELFWriter::createImplicitFiles(Result); +} + +void AMDGPUExecutableWriter::finalizeDefaultAtomValues() { + + // ExecutableWriter::finalizeDefaultAtomValues() assumes the presence of + // C runtime symbols. However, since we skip the call to + // ExecutableWriter::createImplicitFiles(), these symbols are never added + // and ExectuableWriter::finalizeDefaultAtomValues() will crash if we call + // it. + OutputELFWriter::finalizeDefaultAtomValues(); +} Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUHSA.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUHSA.h @@ -0,0 +1,39 @@ +//===- lib/ReaderWriter/ELF/AMDGPUHSA.h -----------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_READER_WRITER_ELF_AMDGPU_HSA_H +#define LLD_READER_WRITER_ELF_AMDGPU_HSA_H + +namespace lld { +namespace elf { + +enum { + PT_AMDGPU_HSA_LOAD_GLOBAL_PROGRAM = PT_LOOS, + PT_AMDGPU_HSA_LOAD_GLOBAL_AGENT = PT_LOOS + 1, + PT_AMDGPU_HSA_LOAD_READONLY_AGENT = PT_LOOS + 2, + PT_AMDGPU_HSA_LOAD_CODE_AGENT = PT_LOOS + 3 +}; + +enum { + SHF_AMDGPU_HSA_GLOBAL = (0x00100000 & SHF_MASKOS), + SHF_AMDGPU_HSA_READONLY = (0x00200000 & SHF_MASKOS), + SHF_AMDGPU_HSA_CODE = (0x00400000 & SHF_MASKOS), + SHF_AMDGPU_HSA_AGENT = (0x00800000 & SHF_MASKOS) +}; + +enum { + STT_AMDGPU_HSA_KERNEL = STT_LOOS, + STT_AMDGPU_HSA_INDIRECT_FUNCTION = STT_LOOS + 1, + STT_AMDGPU_HSA_METADATA = STT_LOOS + 2 +}; + +} // ld +} // elf + +#endif // LLD_READER_WRITER_ELF_AMDGPU_HSA_H Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.h @@ -0,0 +1,38 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.h ---------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_LINKING_CONTEXT_H +#define LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_LINKING_CONTEXT_H + +#include "OutputELFWriter.h" +#include "lld/ReaderWriter/ELFLinkingContext.h" +#include "llvm/Object/ELF.h" +#include "llvm/Support/ELF.h" + +namespace lld { +namespace elf { + +class AMDGPULinkingContext final : public ELFLinkingContext { +public: + int getMachineType() const override { return llvm::ELF::EM_AMDGPU; } + AMDGPULinkingContext(llvm::Triple triple); + + void registerRelocationNames(Registry &r) override; + + StringRef entrySymbolName() const override; +}; + +void setAMDGPUELFHeader(ELFHeader &elfHeader); +void setAMDGPUELFHeader(ELFHeader &elfHeader); + + +} // elf +} // lld + +#endif // LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_LINKING_CONTEXT_H Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.cpp @@ -0,0 +1,46 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPULinkingContext.cpp ---------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===------------------------------------------------------------------------===// + +#include "AMDGPULinkingContext.h" +#include "AMDGPUTargetHandler.h" + +namespace lld { +namespace elf { + +std::unique_ptr +createAMDGPULinkingContext(llvm::Triple triple) { + if (triple.getArch() == llvm::Triple::amdgcn) + return llvm::make_unique(triple); + return nullptr; +} + +AMDGPULinkingContext::AMDGPULinkingContext(llvm::Triple triple) + : ELFLinkingContext(triple, llvm::make_unique(*this)) + {} + +static const Registry::KindStrings kindStrings[] = { + LLD_KIND_STRING_END +}; + +void AMDGPULinkingContext::registerRelocationNames(Registry ®istry) { + registry.addKindTable(Reference::KindNamespace::ELF, + Reference::KindArch::AMDGPU, kindStrings); +} + +void setAMDGPUELFHeader(ELFHeader &elfHeader) { } +void setAMDGPUELFHeader(ELFHeader &elfHeader) { + elfHeader.e_ident(llvm::ELF::EI_OSABI, ELFOSABI_AMDGPU_HSA); +} + +StringRef AMDGPULinkingContext::entrySymbolName() const { + return ""; +} + +} // namespace elf +} // namespace lld Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.h @@ -0,0 +1,33 @@ +//===- lld/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.h --------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +#ifndef LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_RELOCATION_HANDLER_H +#define LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_RELOCATION_HANDLER_H + +#include "lld/ReaderWriter/ELFLinkingContext.h" + +namespace lld { +namespace elf { +class AMDGPUTargetHandler; +class AMDGPUTargetLayout; + +class AMDGPUTargetRelocationHandler final : public TargetRelocationHandler { +public: + AMDGPUTargetRelocationHandler(AMDGPUTargetLayout &layout) + : _targetLayout(layout) {} + + std::error_code applyRelocation(ELFWriter &, llvm::FileOutputBuffer &, + const AtomLayout &, + const Reference &) const override; + +private: + AMDGPUTargetLayout &_targetLayout; +}; +} // elf +} // lld +#endif Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.cpp @@ -0,0 +1,18 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPURelocationHandler.cpp -----------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPURelocationHandler.h" + +using namespace lld::elf; + +std::error_code AMDGPUTargetRelocationHandler::applyRelocation( + ELFWriter &writer, llvm::FileOutputBuffer &buf, const AtomLayout &atom, + const Reference &ref) const { + return std::error_code(); +} Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.h @@ -0,0 +1,32 @@ +//===--------- lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.h ------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_SYMBOL_TABLE_H +#define LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_SYMBOL_TABLE_H + +#include "TargetLayout.h" + +namespace lld { +namespace elf { + +/// \brief The SymbolTable class represents the symbol table in a ELF file +class AMDGPUSymbolTable : public SymbolTable { +public: + typedef llvm::object::Elf_Sym_Impl Elf_Sym; + + AMDGPUSymbolTable(const ELFLinkingContext &ctx); + + void addDefinedAtom(Elf_Sym &sym, const DefinedAtom *da, + int64_t addr) override; +}; + +} // elf +} // lld + +#endif Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.cpp @@ -0,0 +1,32 @@ +//===--------- lib/ReaderWriter/ELF/AMDGPU/AMDGPUSymbolTable.cpp ----------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUSymbolTable.h" +#include "AMDGPUHSA.h" +#include "ELFFile.h" +#include "Atoms.h" +#include "SectionChunks.h" + +using namespace lld::elf; + +AMDGPUSymbolTable::AMDGPUSymbolTable(const ELFLinkingContext &ctx) + : SymbolTable(ctx, ".symtab", TargetLayout::ORDER_SYMBOL_TABLE) {} + +void AMDGPUSymbolTable::addDefinedAtom(Elf_Sym &sym, const DefinedAtom *da, + int64_t addr) { + SymbolTable::addDefinedAtom(sym, da, addr); + + // FIXME: Only do this for kernel functions. + sym.setType(STT_AMDGPU_HSA_KERNEL); + + // Make st_value section relative. + // FIXME: This is hack to give kernel symbols a section relative offset. + // Because of this hack only on kernel can be included in a binary file. + sym.st_value = 0; +} Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h @@ -0,0 +1,85 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h ------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef AMDGPU_TARGET_HANDLER_H +#define AMDGPU_TARGET_HANDLER_H + +#include "ELFReader.h" +#include "AMDGPUELFFile.h" +#include "AMDGPURelocationHandler.h" +#include "TargetLayout.h" + +namespace lld { +namespace elf { +class AMDGPULinkingContext; + +class HSATextSection : public AtomSection { +public: + HSATextSection(const ELFLinkingContext &ctx); +}; + + +/// \brief TargetLayout for AMDGPU +class AMDGPUTargetLayout final : public TargetLayout { +public: + AMDGPUTargetLayout(AMDGPULinkingContext &ctx) + : TargetLayout(ctx) {} + + void assignSectionsToSegments() override; +// void assignVirtualAddress() override; + + /// \brief Gets or creates a section. + AtomSection * + createSection(StringRef name, int32_t contentType, + DefinedAtom::ContentPermissions contentPermissions, + TargetLayout::SectionOrder sectionOrder) override { + + if (name == ".note") { + contentType = DefinedAtom::typeRONote; + } + if (name == ".text") { + return new (_allocator) HSATextSection(_ctx); + } + return TargetLayout::createSection(name, contentType, contentPermissions, + sectionOrder); + } + +}; + +/// \brief TargetHandler for AMDGPU +class AMDGPUTargetHandler final : public TargetHandler { +public: + AMDGPUTargetHandler(AMDGPULinkingContext &targetInfo); + + const TargetRelocationHandler &getRelocationHandler() const override { + return *_relocationHandler; + } + + std::unique_ptr getObjReader() override { + return llvm::make_unique>(_ctx); + } + + std::unique_ptr getDSOReader() override { + return llvm::make_unique>>(_ctx); + } + + std::unique_ptr getWriter() override; + +private: + AMDGPULinkingContext &_ctx; + std::unique_ptr _targetLayout; + std::unique_ptr _relocationHandler; +}; + +void finalizeAMDGPURuntimeAtomValues(AMDGPUTargetLayout &layout); + +} // end namespace elf +} // end namespace lld + +#endif Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp @@ -0,0 +1,89 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp ----------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "TargetLayout.h" +#include "AMDGPUExecutableWriter.h" +#include "AMDGPUHSA.h" +#include "AMDGPULinkingContext.h" +#include "AMDGPUTargetHandler.h" +#include "llvm/Support/ELF.h" + +using namespace llvm::ELF; + +using llvm::makeArrayRef; + +namespace lld { +namespace elf { + +AMDGPUTargetHandler::AMDGPUTargetHandler(AMDGPULinkingContext &ctx) + : _ctx(ctx), _targetLayout(new AMDGPUTargetLayout(ctx)), + _relocationHandler(new AMDGPUTargetRelocationHandler(*_targetLayout)) {} + +std::unique_ptr AMDGPUTargetHandler::getWriter() { + switch (_ctx.getOutputELFType()) { + case llvm::ELF::ET_EXEC: + return llvm::make_unique(_ctx, *_targetLayout); + case llvm::ELF::ET_DYN: + llvm_unreachable("TODO: support dynamic libraries"); + case llvm::ELF::ET_REL: + llvm_unreachable("TODO: support -r mode"); + default: + llvm_unreachable("unsupported output type"); + } +} + +using namespace llvm::ELF; + +HSATextSection::HSATextSection(const ELFLinkingContext &ctx) + : AtomSection(ctx, ".text", DefinedAtom::typeCode, 0, 0) { + _type = SHT_PROGBITS; + _flags = SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR | + SHF_AMDGPU_HSA_AGENT | SHF_AMDGPU_HSA_CODE; + + // FIXME: What alignment should we use here? + _alignment = 4096; +} + +void AMDGPUTargetLayout::assignSectionsToSegments() { + + TargetLayout::assignSectionsToSegments(); + for (auto osi : _outputSections) { + for (auto section : osi->sections()) { + StringRef InputSectionName = section->inputSectionName(); + if (InputSectionName != ".text") + continue; + + Segment *segment = + new (_allocator) Segment(_ctx, "PT_AMDGPU_HSA_LOAD_CODE_AGENT", + PT_AMDGPU_HSA_LOAD_CODE_AGENT); + _segments.push_back(segment); + assert(segment); + segment->append(section); + } + } +} + +#if 0 +void AMDGPUTargetLayout::assignVirtualAddress() { + // Override parent's method so that the st_value field of symbols remains a + // section relative offset. + // FIXME: Is this the correct way to handle this? + + + for (auto si : _segments) { + _programHeader->addSegment(si); + si->prepend(_elfHeader); + } + +} +#endif + + +} // namespace elf +} // namespace lld Index: lib/ReaderWriter/ELF/AMDGPU/CMakeLists.txt =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/CMakeLists.txt @@ -0,0 +1,14 @@ +add_llvm_library(lldAMDGPUELFTarget + AMDGPUELFFile.cpp + AMDGPUExecutableWriter.cpp + AMDGPULinkingContext.cpp + AMDGPURelocationHandler.cpp + AMDGPUSymbolTable.cpp + AMDGPUTargetHandler.cpp + LINK_LIBS + lldELF + lldReaderWriter + lldCore + LLVMObject + LLVMSupport + ) Index: lib/ReaderWriter/ELF/CMakeLists.txt =================================================================== --- lib/ReaderWriter/ELF/CMakeLists.txt +++ lib/ReaderWriter/ELF/CMakeLists.txt @@ -27,3 +27,4 @@ add_subdirectory(Hexagon) add_subdirectory(AArch64) add_subdirectory(ARM) +add_subdirectory(AMDGPU) Index: lib/ReaderWriter/ELF/ELFLinkingContext.cpp =================================================================== --- lib/ReaderWriter/ELF/ELFLinkingContext.cpp +++ lib/ReaderWriter/ELF/ELFLinkingContext.cpp @@ -61,6 +61,8 @@ return llvm::ELF::EM_AARCH64; case llvm::Triple::arm: return llvm::ELF::EM_ARM; + case llvm::Triple::amdgcn: + return llvm::ELF::EM_AMDGPU; default: llvm_unreachable("Unhandled arch"); } Index: test/elf/AMDGPU/hsa.test =================================================================== --- /dev/null +++ test/elf/AMDGPU/hsa.test @@ -0,0 +1,39 @@ +# RUN: yaml2obj -format=elf %s > %t.obj +# RUN: lld -flavor gnu -target amdgcn--hsa %t.obj -o %t.exe --noinhibit-exec +# RUN: llvm-readobj -s -symbols %t.exe | FileCheck %s + +# CHECK: Section { +# CHECK: Name: .text +# CHECK: Type: SHT_PROGBITS (0x1) +# CHECK: Flags [ (0xC00007 +# CHECK: SHF_ALLOC (0x2) +# CHECK: SHF_EXECINSTR (0x4) +# CHECK: SHF_WRITE (0x1) + +# CHECK: Symbol { +# CHECK: Name: kernel +# CHECK: Value: 0x0 + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_AMDGPU +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + AddressAlign: 0x0000000000000004 + Content: '' + - Name: .note + Type: SHT_NOTE + AddressAlign: 0x0000000000000001 + Content: '00' +Symbols: + Local: + - Name: kernel + Type: STT_GNU_IFUNC + Section: .text +...