llvm.org GIT mirror llvm / 3f6dea4
ARM: fail less catastrophically on invalid Windows input Windows supports a restricted set of relocations (compared to ARM ELF). In some cases, we may end up generating an unsupported relocation. This can occur with bad input to the assembler in particular (the frontend should never generate code that cannot be compiled). Generate an error rather than just aborting. The change in the API is driven by the desire to provide a slightly more helpful message for debugging purposes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226779 91177308-0d34-0410-b5e6-96231b3b80d8 Saleem Abdulrasool 5 years ago
5 changed file(s) with 40 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
1010 #define LLVM_MC_MCWINCOFFOBJECTWRITER_H
1111
1212 namespace llvm {
13 class MCFixup;
14 class MCObjectWriter;
15 class MCValue;
16 class raw_ostream;
13 class MCAsmBackend;
14 class MCFixup;
15 class MCObjectWriter;
16 class MCValue;
17 class raw_ostream;
1718
1819 class MCWinCOFFObjectTargetWriter {
1920 virtual void anchor();
2627 virtual ~MCWinCOFFObjectTargetWriter() {}
2728
2829 unsigned getMachine() const { return Machine; }
29 virtual unsigned getRelocType(const MCValue &Target,
30 const MCFixup &Fixup,
31 bool IsCrossSection) const = 0;
30 virtual unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
31 bool IsCrossSection,
32 const MCAsmBackend &MAB) const = 0;
3233 virtual bool recordRelocation(const MCFixup &) const { return true; }
3334 };
3435
736736 ++Reloc.Symb->Relocations;
737737
738738 Reloc.Data.VirtualAddress += Fixup.getOffset();
739 Reloc.Data.Type = TargetObjectWriter->getRelocType(Target, Fixup,
740 CrossSection);
739 Reloc.Data.Type =
740 TargetObjectWriter->getRelocType(Target, Fixup, CrossSection,
741 Asm.getBackend());
741742
742743 // FIXME: Can anyone explain what this does other than adjust for the size
743744 // of the offset?
77 //===----------------------------------------------------------------------===//
88
99 #include "MCTargetDesc/ARMFixupKinds.h"
10 #include "llvm/MC/MCAsmBackend.h"
1011 #include "llvm/MC/MCFixup.h"
12 #include "llvm/MC/MCFixupKindInfo.h"
1113 #include "llvm/MC/MCValue.h"
1214 #include "llvm/MC/MCWinCOFFObjectWriter.h"
15 #include "llvm/ADT/Twine.h"
1316 #include "llvm/Support/COFF.h"
1417 #include "llvm/Support/Debug.h"
1518
2528 virtual ~ARMWinCOFFObjectWriter() { }
2629
2730 unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
28 bool IsCrossSection) const override;
31 bool IsCrossSection,
32 const MCAsmBackend &MAB) const override;
2933
3034 bool recordRelocation(const MCFixup &) const override;
3135 };
3236
3337 unsigned ARMWinCOFFObjectWriter::getRelocType(const MCValue &Target,
3438 const MCFixup &Fixup,
35 bool IsCrossSection) const {
39 bool IsCrossSection,
40 const MCAsmBackend &MAB) const {
3641 assert(getMachine() == COFF::IMAGE_FILE_MACHINE_ARMNT &&
3742 "AArch64 support not yet implemented");
3843
4045 Target.isAbsolute() ? MCSymbolRefExpr::VK_None : Target.getSymA()->getKind();
4146
4247 switch (static_cast(Fixup.getKind())) {
43 default: llvm_unreachable("unsupported relocation type");
48 default: {
49 const MCFixupKindInfo &Info = MAB.getFixupKindInfo(Fixup.getKind());
50 report_fatal_error(Twine("unsupported relocation type: ") + Info.Name);
51 }
4452 case FK_Data_4:
4553 switch (Modifier) {
4654 case MCSymbolRefExpr::VK_COFF_IMGREL32:
2727 virtual ~X86WinCOFFObjectWriter();
2828
2929 unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup,
30 bool IsCrossSection) const override;
30 bool IsCrossSection,
31 const MCAsmBackend &MAB) const override;
3132 };
3233 }
3334
3940
4041 unsigned X86WinCOFFObjectWriter::getRelocType(const MCValue &Target,
4142 const MCFixup &Fixup,
42 bool IsCrossSection) const {
43 bool IsCrossSection,
44 const MCAsmBackend &MAB) const {
4345 unsigned FixupKind = IsCrossSection ? FK_PCRel_4 : Fixup.getKind();
4446
4547 MCSymbolRefExpr::VariantKind Modifier = Target.isAbsolute() ?
0 # RUN: not llvm-mc -triple thumbv7-windows -filetype obj -o /dev/null 2>&1 %s \
1 # RUN: | FileCheck %s
2
3 .def invalid_relocation
4 .type 32
5 .scl 2
6 .endef
7 .global invalid_relocation
8 .thumb_func
9 invalid_relocation:
10 adr r0, invalid_relocation+1
11
12 # CHECK: LLVM ERROR: unsupported relocation type: fixup_t2_adr_pcrel_12
13