2017-02-04 07:38:40 +08:00
|
|
|
//===- AMDGPUELFObjectWriter.cpp - AMDGPU ELF Writer ----------------------===//
|
2013-04-16 01:51:21 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AMDGPUMCTargetDesc.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2013-04-16 01:51:21 +08:00
|
|
|
#include "llvm/MC/MCELFObjectWriter.h"
|
2017-02-04 07:38:40 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-07-21 22:01:14 +08:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2017-10-11 00:28:07 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2017-02-04 07:38:40 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2013-04-16 01:51:21 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class AMDGPUELFObjectWriter : public MCELFObjectTargetWriter {
|
|
|
|
public:
|
2017-10-05 06:44:13 +08:00
|
|
|
AMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI, bool HasRelocationAddend);
|
2017-02-04 07:38:40 +08:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-02-04 07:38:40 +08:00
|
|
|
} // end anonymous namespace
|
2013-04-16 01:51:21 +08:00
|
|
|
|
2016-06-15 04:29:59 +08:00
|
|
|
AMDGPUELFObjectWriter::AMDGPUELFObjectWriter(bool Is64Bit,
|
2017-10-05 06:44:13 +08:00
|
|
|
uint8_t OSABI,
|
2016-06-15 04:29:59 +08:00
|
|
|
bool HasRelocationAddend)
|
2017-10-05 06:44:13 +08:00
|
|
|
: MCELFObjectTargetWriter(Is64Bit, OSABI, ELF::EM_AMDGPU,
|
2017-02-04 07:38:40 +08:00
|
|
|
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.
|
AMDGPU: Use an ABS32_LO relocation for SCRATCH_RSRC_DWORD1
Summary:
Using HI here makes no logical sense, since the dword is only
32 bits to begin with.
Current Mesa master does not look at the relocation type at all,
so this change is fine. Future Mesa will rely on this, however.
Change-Id: I91085707834c4ac0370926602b93c94b90e44cb1
Reviewers: arsenm, rampitec, mareko
Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, llvm-commits
Differential Revision: https://reviews.llvm.org/D55369
llvm-svn: 349620
2018-12-19 19:55:03 +08:00
|
|
|
if (SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD0" ||
|
|
|
|
SymA->getSymbol().getName() == "SCRATCH_RSRC_DWORD1")
|
2016-10-07 00:20:41 +08:00
|
|
|
return ELF::R_AMDGPU_ABS32_LO;
|
|
|
|
}
|
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-10-14 12:21:32 +08:00
|
|
|
case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_LO:
|
|
|
|
return ELF::R_AMDGPU_GOTPCREL32_LO;
|
|
|
|
case MCSymbolRefExpr::VK_AMDGPU_GOTPCREL32_HI:
|
|
|
|
return ELF::R_AMDGPU_GOTPCREL32_HI;
|
|
|
|
case MCSymbolRefExpr::VK_AMDGPU_REL32_LO:
|
|
|
|
return ELF::R_AMDGPU_REL32_LO;
|
|
|
|
case MCSymbolRefExpr::VK_AMDGPU_REL32_HI:
|
|
|
|
return ELF::R_AMDGPU_REL32_HI;
|
2018-06-12 05:37:57 +08:00
|
|
|
case MCSymbolRefExpr::VK_AMDGPU_REL64:
|
|
|
|
return ELF::R_AMDGPU_REL64;
|
2016-06-24 07:11:29 +08:00
|
|
|
}
|
|
|
|
|
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-10-08 04:36:58 +08:00
|
|
|
case FK_Data_8:
|
|
|
|
return ELF::R_AMDGPU_ABS64;
|
2016-06-21 01:33:43 +08:00
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:44 +08:00
|
|
|
llvm_unreachable("unhandled relocation type");
|
|
|
|
}
|
|
|
|
|
2018-05-22 03:20:29 +08:00
|
|
|
std::unique_ptr<MCObjectTargetWriter>
|
2017-10-11 00:28:07 +08:00
|
|
|
llvm::createAMDGPUELFObjectWriter(bool Is64Bit, uint8_t OSABI,
|
2018-05-22 03:20:29 +08:00
|
|
|
bool HasRelocationAddend) {
|
|
|
|
return llvm::make_unique<AMDGPUELFObjectWriter>(Is64Bit, OSABI,
|
|
|
|
HasRelocationAddend);
|
2013-04-16 01:51:21 +08:00
|
|
|
}
|