blob: 7b52cf58cac23b172246c254414f1fe3b868f0be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
//===- 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 "AMDGPULinkingContext.h"
#include "AMDGPUTargetHandler.h"
#include "llvm/Support/ELF.h"
namespace lld {
namespace elf {
AMDGPUTargetHandler::AMDGPUTargetHandler(AMDGPULinkingContext &ctx)
: _ctx(ctx), _targetLayout(new AMDGPUTargetLayout(ctx)),
_relocationHandler(new AMDGPUTargetRelocationHandler(*_targetLayout)) {}
std::unique_ptr<Writer> AMDGPUTargetHandler::getWriter() {
switch (_ctx.getOutputELFType()) {
case llvm::ELF::ET_EXEC:
return llvm::make_unique<AMDGPUExecutableWriter>(_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");
}
}
HSATextSection::HSATextSection(const ELFLinkingContext &ctx)
: AtomSection(ctx, ".hsatext", 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 (OutputSection<ELF64LE> *osi : _outputSections) {
for (Section<ELF64LE> *section : osi->sections()) {
StringRef InputSectionName = section->inputSectionName();
if (InputSectionName != ".hsatext")
continue;
Segment<ELF64LE> *segment = new (_allocator) Segment<ELF64LE>(
_ctx, "PT_AMDGPU_HSA_LOAD_CODE_AGENT", PT_AMDGPU_HSA_LOAD_CODE_AGENT);
_segments.push_back(segment);
assert(segment);
segment->append(section);
}
}
}
} // namespace elf
} // namespace lld
|