Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.cpp =================================================================== --- lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.cpp +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUELFFile.cpp @@ -43,7 +43,7 @@ // symbol offset, which is section relative, so we can write it to the // symbol table in AMDDGPUSymbolTable::finalize(). bool HasSectionRelativeOffset = false; - if (sectionName == ".hsatext") + if (sectionName == ".hsatext" || sectionName == ".hsarodata_readonly_agent") HasSectionRelativeOffset = true; return new (this->_readerStorage) AMDGPUELFDefinedAtom( Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.h =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.h @@ -0,0 +1,26 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.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_SECTION_CHUNKS_H +#define LLD_READER_WRITER_ELF_AMDGPU_AMDGPU_SECTION_CHUNKS_H + +#include "TargetLayout.h" +#include "SectionChunks.h" + +namespace lld { +namespace elf { + +class HSARoDataReadOnlySection : public AtomSection { +public: + HSARoDataReadOnlySection(const ELFLinkingContext &ctx); +}; + +} // elf +} // lld + +#endif Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.cpp =================================================================== --- /dev/null +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.cpp @@ -0,0 +1,30 @@ +//===- lib/ReaderWriter/ELF/AMDGPU/AMDGPUSectionChunks.cpp ----------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "AMDGPUSectionChunks.h" +#include "AMDGPUELFFile.h" + +namespace lld { +namespace elf { + +HSARoDataReadOnlySection::HSARoDataReadOnlySection(const ELFLinkingContext &ctx) + : AtomSection(ctx, ".hsarodata_readonly_agent", DefinedAtom::typeConstant, + 0, 0) { + + _type = llvm::ELF::SHT_PROGBITS; + _flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_AMDGPU_HSA_READONLY | + llvm::ELF::SHF_AMDGPU_HSA_AGENT; + + // FIXME: What is the correct alignment? + _alignment = 4; + +} + +} // elf +} // lld Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h =================================================================== --- lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.h @@ -13,6 +13,7 @@ #include "AMDGPUELFFile.h" #include "ELFReader.h" #include "AMDGPURelocationHandler.h" +#include "AMDGPUSectionChunks.h" #include "TargetLayout.h" namespace lld { @@ -39,6 +40,9 @@ if (name == ".hsatext") return new (_allocator) HSATextSection(_ctx); + if (name == ".hsarodata_readonly_agent") + return new (_allocator) HSARoDataReadOnlySection(_ctx); + if (name == ".note") contentType = DefinedAtom::typeRONote; Index: lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp =================================================================== --- lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp +++ lib/ReaderWriter/ELF/AMDGPU/AMDGPUTargetHandler.cpp @@ -49,14 +49,21 @@ for (OutputSection *osi : _outputSections) { for (Section *section : osi->sections()) { StringRef InputSectionName = section->inputSectionName(); - if (InputSectionName != ".hsatext") - continue; + if (InputSectionName == ".hsatext") { + 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); + } - auto *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 (InputSectionName == ".hsarodata_readonly_agent") { + Segment *segment = new (_allocator) Segment(_ctx, + "PT_AMDGPU_HSA_LOAD_READONLY_AGENT", PT_AMDGPU_HSA_LOAD_READONLY_AGENT); + _segments.push_back(segment); + segment->append(section); + } } } } Index: lib/ReaderWriter/ELF/AMDGPU/CMakeLists.txt =================================================================== --- lib/ReaderWriter/ELF/AMDGPU/CMakeLists.txt +++ lib/ReaderWriter/ELF/AMDGPU/CMakeLists.txt @@ -3,6 +3,7 @@ AMDGPUExecutableWriter.cpp AMDGPULinkingContext.cpp AMDGPURelocationHandler.cpp + AMDGPUSectionChunks.cpp AMDGPUSymbolTable.cpp AMDGPUTargetHandler.cpp LINK_LIBS Index: test/elf/AMDGPU/hsa-sections.test =================================================================== --- /dev/null +++ test/elf/AMDGPU/hsa-sections.test @@ -0,0 +1,30 @@ +# RUN: yaml2obj -format=elf %s > %t.obj +# RUN: lld -flavor gnu -target amdgcn--hsa %t.obj -o %t.exe --noinhibit-exec +# RUN: llvm-readobj -h -program-headers -s -symbols %t.exe | FileCheck %s + +# CHECK: Section { +# CHECK: Name: .hsarodata_readonly_agent +# CHECK: Type: SHT_PROGBITS +# CHECK: Flags [ (0xA00002 +# CHECK: SHF_ALLOC (0x2) +# CHECK: SHF_AMDGPU_HSA_AGENT (0x800000) +# CHECK: SHF_AMDGPU_HSA_READONLY (0x200000) +# CHECK: ] +# CHECK: } + +# CHECK: ProgramHeader { +# CHECK: Type: PT_AMDGPU_HSA_LOAD_READONLY_AGENT (0x60000002) +# CHECK: } + +--- +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + OSABI: ELFOSABI_GNU + Type: ET_REL + Machine: EM_AMDGPU +Sections: + - Name: .hsarodata_readonly_agent + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_AMDGPU_HSA_AGENT, SHF_AMDGPU_HSA_READONLY ] +...