2013-04-16 01:51:21 +08:00
|
|
|
//===-- AMDGPUELFObjectWriter.cpp - AMDGPU ELF Writer ----------------------==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPUMCTargetDesc.h"
|
|
|
|
#include "llvm/MC/MCELFObjectWriter.h"
|
2014-07-21 22:01:14 +08:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2013-04-16 01:51:21 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter {
|
|
|
|
public:
|
2016-06-15 04:29:59 +08:00
|
|
|
AMDGPUELFObjectWriter(bool Is64Bit, bool HasRelocationAddend);
|
2013-04-16 01:51:21 +08:00
|
|
|
protected:
|
2016-01-14 06:56:57 +08:00
|
|
|
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
|
2016-06-21 00:59:44 +08:00
|
|
|
const MCFixup &Fixup, bool IsPCRel) const override;
|
2013-04-16 01:51:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2016-06-15 04:29:59 +08:00
|
|
|
AMDGPUELFObjectWriter::AMDGPUELFObjectWriter(bool Is64Bit,
|
|
|
|
bool HasRelocationAddend)
|
|
|
|
: MCELFObjectTargetWriter(Is64Bit,
|
|
|
|
ELF::ELFOSABI_AMDGPU_HSA,
|
|
|
|
ELF::EM_AMDGPU,
|
|
|
|
HasRelocationAddend) { }
|
2013-04-16 01:51:21 +08:00
|
|
|
|
2016-06-21 00:59:44 +08:00
|
|
|
unsigned AMDGPUELFObjectWriter::getRelocType(MCContext &Ctx,
|
|
|
|
const MCValue &Target,
|
|
|
|
const MCFixup &Fixup,
|
|
|
|
bool IsPCRel) const {
|
2016-10-07 00:20:41 +08:00
|
|
|
if (const auto *SymA = Target.getSymA()) {
|
|
|
|
// SCRATCH_RSRC_DWORD[01] is a special global variable that represents
|
|
|
|
// the scratch buffer.
|
|
|
|
if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD0")
|
|
|
|
return ELF::R_AMDGPU_ABS32_LO;
|
|
|
|
|
|
|
|
if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD1")
|
|
|
|
return ELF::R_AMDGPU_ABS32_HI;
|
|
|
|
}
|
2016-06-21 00:59:44 +08:00
|
|
|
|
2016-06-24 07:11:29 +08:00
|
|
|
switch (Target.getAccessVariant()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case MCSymbolRefExpr::VK_GOTPCREL:
|
|
|
|
return ELF::R_AMDGPU_GOTPCREL;
|
|
|
|
}
|
|
|
|
|
2016-06-21 01:33:43 +08:00
|
|
|
switch (Fixup.getKind()) {
|
|
|
|
default: break;
|
|
|
|
case FK_PCRel_4:
|
|
|
|
return ELF::R_AMDGPU_REL32;
|
2016-07-21 23:29:19 +08:00
|
|
|
case FK_Data_4:
|
2016-06-26 02:24:16 +08:00
|
|
|
case FK_SecRel_4:
|
|
|
|
return ELF::R_AMDGPU_ABS32;
|
2016-06-21 01:33:43 +08:00
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:44 +08:00
|
|
|
llvm_unreachable("unhandled relocation type");
|
|
|
|
}
|
|
|
|
|
2016-06-15 04:29:59 +08:00
|
|
|
|
|
|
|
MCObjectWriter *llvm::createAMDGPUELFObjectWriter(bool Is64Bit,
|
|
|
|
bool HasRelocationAddend,
|
|
|
|
raw_pwrite_stream &OS) {
|
|
|
|
MCELFObjectTargetWriter *MOTW =
|
|
|
|
new AMDGPUELFObjectWriter(Is64Bit, HasRelocationAddend);
|
2013-04-16 01:51:21 +08:00
|
|
|
return createELFObjectWriter(MOTW, OS, true);
|
|
|
|
}
|