2014-04-27 11:48:22 +08:00
|
|
|
//===-- ARMWinCOFFObjectWriter.cpp - ARM Windows COFF Object Writer -- C++ -==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MCTargetDesc/ARMFixupKinds.h"
|
2015-02-13 17:09:03 +08:00
|
|
|
#include "llvm/ADT/Twine.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/COFF.h"
|
2015-01-22 12:03:32 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2014-04-27 11:48:22 +08:00
|
|
|
#include "llvm/MC/MCFixup.h"
|
2015-01-22 12:03:32 +08:00
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
2017-10-11 00:28:07 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2014-04-27 11:48:22 +08:00
|
|
|
#include "llvm/MC/MCValue.h"
|
|
|
|
#include "llvm/MC/MCWinCOFFObjectWriter.h"
|
2017-01-28 07:58:02 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include <cassert>
|
2014-04-27 11:48:22 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2014-04-27 11:48:22 +08:00
|
|
|
class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
|
|
|
|
public:
|
|
|
|
ARMWinCOFFObjectWriter(bool Is64Bit)
|
|
|
|
: MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARMNT) {
|
|
|
|
assert(!Is64Bit && "AArch64 support not yet implemented");
|
|
|
|
}
|
2017-01-28 07:58:02 +08:00
|
|
|
|
|
|
|
~ARMWinCOFFObjectWriter() override = default;
|
2014-04-27 11:48:22 +08:00
|
|
|
|
2017-06-23 12:07:44 +08:00
|
|
|
unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
|
|
|
|
const MCFixup &Fixup, bool IsCrossSection,
|
2015-01-22 12:03:32 +08:00
|
|
|
const MCAsmBackend &MAB) const override;
|
2014-05-22 07:17:56 +08:00
|
|
|
|
|
|
|
bool recordRelocation(const MCFixup &) const override;
|
2014-04-27 11:48:22 +08:00
|
|
|
};
|
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
2017-06-23 12:07:44 +08:00
|
|
|
unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
|
|
|
|
const MCValue &Target,
|
2014-04-27 11:48:22 +08:00
|
|
|
const MCFixup &Fixup,
|
2015-01-22 12:03:32 +08:00
|
|
|
bool IsCrossSection,
|
|
|
|
const MCAsmBackend &MAB) const {
|
2014-04-27 11:48:22 +08:00
|
|
|
assert(getMachine() == COFF::IMAGE_FILE_MACHINE_ARMNT &&
|
|
|
|
"AArch64 support not yet implemented");
|
|
|
|
|
|
|
|
MCSymbolRefExpr::VariantKind Modifier =
|
|
|
|
Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
|
|
|
|
|
|
|
|
switch (static_cast<unsigned>(Fixup.getKind())) {
|
2015-01-22 12:03:32 +08:00
|
|
|
default: {
|
|
|
|
const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
|
|
|
|
report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
|
|
|
|
}
|
2014-04-27 11:48:22 +08:00
|
|
|
case FK_Data_4:
|
|
|
|
switch (Modifier) {
|
|
|
|
case MCSymbolRefExpr::VK_COFF_IMGREL32:
|
|
|
|
return COFF::IMAGE_REL_ARM_ADDR32NB;
|
|
|
|
case MCSymbolRefExpr::VK_SECREL:
|
|
|
|
return COFF::IMAGE_REL_ARM_SECREL;
|
|
|
|
default:
|
|
|
|
return COFF::IMAGE_REL_ARM_ADDR32;
|
|
|
|
}
|
2014-05-08 09:35:57 +08:00
|
|
|
case FK_SecRel_2:
|
|
|
|
return COFF::IMAGE_REL_ARM_SECTION;
|
2014-05-05 07:13:15 +08:00
|
|
|
case FK_SecRel_4:
|
|
|
|
return COFF::IMAGE_REL_ARM_SECREL;
|
2014-04-27 11:48:22 +08:00
|
|
|
case ARM::fixup_t2_condbranch:
|
|
|
|
return COFF::IMAGE_REL_ARM_BRANCH20T;
|
|
|
|
case ARM::fixup_t2_uncondbranch:
|
|
|
|
return COFF::IMAGE_REL_ARM_BRANCH24T;
|
|
|
|
case ARM::fixup_arm_thumb_bl:
|
|
|
|
case ARM::fixup_arm_thumb_blx:
|
|
|
|
return COFF::IMAGE_REL_ARM_BLX23T;
|
|
|
|
case ARM::fixup_t2_movw_lo16:
|
|
|
|
case ARM::fixup_t2_movt_hi16:
|
2014-05-22 07:17:56 +08:00
|
|
|
return COFF::IMAGE_REL_ARM_MOV32T;
|
2014-04-27 11:48:22 +08:00
|
|
|
}
|
|
|
|
}
|
2014-05-22 07:17:56 +08:00
|
|
|
|
|
|
|
bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
|
|
|
|
return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
|
|
|
|
}
|
2014-04-27 11:48:22 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-01-28 07:58:02 +08:00
|
|
|
|
2017-10-11 00:28:07 +08:00
|
|
|
std::unique_ptr<MCObjectWriter>
|
|
|
|
createARMWinCOFFObjectWriter(raw_pwrite_stream &OS, bool Is64Bit) {
|
2017-10-10 08:50:29 +08:00
|
|
|
auto MOTW = llvm::make_unique<ARMWinCOFFObjectWriter>(Is64Bit);
|
|
|
|
return createWinCOFFObjectWriter(std::move(MOTW), OS);
|
2014-04-27 11:48:22 +08:00
|
|
|
}
|
|
|
|
|
2017-01-28 07:58:02 +08:00
|
|
|
} // end namespace llvm
|