Fixed some warn-override tests in SemaCXX (#122680)
[llvm-project.git] / llvm / lib / Target / ARM / MCTargetDesc / ARMWinCOFFObjectWriter.cpp
blob34d9e5a9106361c1aa181e2e8f1934728728c0db
1 //===-- ARMWinCOFFObjectWriter.cpp - ARM Windows COFF Object Writer -- C++ -==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "MCTargetDesc/ARMFixupKinds.h"
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/BinaryFormat/COFF.h"
12 #include "llvm/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCFixup.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/MC/MCValue.h"
18 #include "llvm/MC/MCWinCOFFObjectWriter.h"
19 #include "llvm/Support/ErrorHandling.h"
21 using namespace llvm;
23 namespace {
25 class ARMWinCOFFObjectWriter : public MCWinCOFFObjectTargetWriter {
26 public:
27 ARMWinCOFFObjectWriter()
28 : MCWinCOFFObjectTargetWriter(COFF::IMAGE_FILE_MACHINE_ARMNT) {
31 ~ARMWinCOFFObjectWriter() override = default;
33 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
34 const MCFixup &Fixup, bool IsCrossSection,
35 const MCAsmBackend &MAB) const override;
37 bool recordRelocation(const MCFixup &) const override;
40 } // end anonymous namespace
42 unsigned ARMWinCOFFObjectWriter::getRelocType(MCContext &Ctx,
43 const MCValue &Target,
44 const MCFixup &Fixup,
45 bool IsCrossSection,
46 const MCAsmBackend &MAB) const {
47 MCSymbolRefExpr::VariantKind Modifier =
48 Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
50 unsigned FixupKind = Fixup.getKind();
51 if (IsCrossSection) {
52 if (FixupKind != FK_Data_4) {
53 Ctx.reportError(Fixup.getLoc(), "Cannot represent this expression");
54 return COFF::IMAGE_REL_ARM_ADDR32;
56 FixupKind = FK_PCRel_4;
60 switch (FixupKind) {
61 default: {
62 Ctx.reportError(Fixup.getLoc(), "unsupported relocation type");
63 return COFF::IMAGE_REL_ARM_ABSOLUTE;
65 case FK_Data_4:
66 switch (Modifier) {
67 case MCSymbolRefExpr::VK_COFF_IMGREL32:
68 return COFF::IMAGE_REL_ARM_ADDR32NB;
69 case MCSymbolRefExpr::VK_SECREL:
70 return COFF::IMAGE_REL_ARM_SECREL;
71 default:
72 return COFF::IMAGE_REL_ARM_ADDR32;
74 case FK_PCRel_4:
75 return COFF::IMAGE_REL_ARM_REL32;
76 case FK_SecRel_2:
77 return COFF::IMAGE_REL_ARM_SECTION;
78 case FK_SecRel_4:
79 return COFF::IMAGE_REL_ARM_SECREL;
80 case ARM::fixup_t2_condbranch:
81 return COFF::IMAGE_REL_ARM_BRANCH20T;
82 case ARM::fixup_t2_uncondbranch:
83 case ARM::fixup_arm_thumb_bl:
84 return COFF::IMAGE_REL_ARM_BRANCH24T;
85 case ARM::fixup_arm_thumb_blx:
86 return COFF::IMAGE_REL_ARM_BLX23T;
87 case ARM::fixup_t2_movw_lo16:
88 case ARM::fixup_t2_movt_hi16:
89 return COFF::IMAGE_REL_ARM_MOV32T;
93 bool ARMWinCOFFObjectWriter::recordRelocation(const MCFixup &Fixup) const {
94 return static_cast<unsigned>(Fixup.getKind()) != ARM::fixup_t2_movt_hi16;
97 namespace llvm {
99 std::unique_ptr<MCObjectTargetWriter>
100 createARMWinCOFFObjectWriter() {
101 return std::make_unique<ARMWinCOFFObjectWriter>();
104 } // end namespace llvm