llvm.org GIT mirror llvm / b5e16af
Some first rudimentary support for ARM EHABI: print exception table in "text mode". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127099 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 9 years ago
10 changed file(s) with 205 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
2525 /// MCAsmInfo - This class is intended to be used as a base class for asm
2626 /// properties and features specific to the target.
2727 namespace ExceptionHandling {
28 enum ExceptionsType { None, DwarfTable, DwarfCFI, SjLj };
28 enum ExceptionsType { None, DwarfTable, DwarfCFI, SjLj, ARM };
2929 }
3030
3131 class MCAsmInfo {
450450 bool isExceptionHandlingDwarf() const {
451451 return
452452 (ExceptionsType == ExceptionHandling::DwarfTable ||
453 ExceptionsType == ExceptionHandling::DwarfCFI);
453 ExceptionsType == ExceptionHandling::DwarfCFI ||
454 ExceptionsType == ExceptionHandling::ARM);
454455 }
455456
456457 bool doesDwarfRequireFrameSection() const {
456456 virtual void EmitRawText(StringRef String);
457457 void EmitRawText(const Twine &String);
458458
459 /// ARM-related methods.
460 /// FIXME: Eventually we should have some "target MC streamer" and move
461 /// these methods there.
462 virtual void EmitFnStart();
463 virtual void EmitFnEnd();
464 virtual void EmitCantUnwind();
465 virtual void EmitPersonality(const MCSymbol *Personality);
466 virtual void EmitHandlerData();
467
459468 /// Finish - Finish emission of machine code.
460469 virtual void Finish() = 0;
461470 };
0 //===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for writing DWARF exception info into asm files.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "DwarfException.h"
14 #include "llvm/Module.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineLocation.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCSection.h"
24 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/MC/MCSymbol.h"
26 #include "llvm/Target/Mangler.h"
27 #include "llvm/Target/TargetData.h"
28 #include "llvm/Target/TargetFrameLowering.h"
29 #include "llvm/Target/TargetLoweringObjectFile.h"
30 #include "llvm/Target/TargetMachine.h"
31 #include "llvm/Target/TargetOptions.h"
32 #include "llvm/Target/TargetRegisterInfo.h"
33 #include "llvm/Support/Dwarf.h"
34 #include "llvm/Support/FormattedStream.h"
35 #include "llvm/ADT/SmallString.h"
36 #include "llvm/ADT/StringExtras.h"
37 #include "llvm/ADT/Twine.h"
38 using namespace llvm;
39
40 ARMException::ARMException(AsmPrinter *A)
41 : DwarfException(A),
42 shouldEmitTable(false), shouldEmitMoves(false), shouldEmitTableModule(false)
43 {}
44
45 ARMException::~ARMException() {}
46
47 void ARMException::EndModule() {
48 }
49
50 /// BeginFunction - Gather pre-function exception information. Assumes it's
51 /// being emitted immediately after the function entry point.
52 void ARMException::BeginFunction(const MachineFunction *MF) {
53 Asm->OutStreamer.EmitFnStart();
54 if (!Asm->MF->getFunction()->doesNotThrow() || UnwindTablesMandatory)
55 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
56 Asm->getFunctionNumber()));
57 }
58
59 /// EndFunction - Gather and emit post-function exception information.
60 ///
61 void ARMException::EndFunction() {
62 if (Asm->MF->getFunction()->doesNotThrow() && !UnwindTablesMandatory)
63 Asm->OutStreamer.EmitCantUnwind();
64 else {
65 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
66 Asm->getFunctionNumber()));
67
68 // Emit references to personality.
69 if (const Function * Personality =
70 MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
71 MCSymbol *PerSym = Asm->Mang->getSymbol(Personality);
72 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
73 Asm->OutStreamer.EmitPersonality(PerSym);
74 }
75
76 // Map all labels and get rid of any dead landing pads.
77 MMI->TidyLandingPads();
78
79 Asm->OutStreamer.EmitHandlerData();
80
81 // Emit actual exception table
82 EmitExceptionTable();
83 }
84
85 Asm->OutStreamer.EmitFnEnd();
86 }
195195 case ExceptionHandling::DwarfCFI:
196196 DE = new DwarfCFIException(this);
197197 break;
198 case ExceptionHandling::ARM:
199 DE = new ARMException(this);
200 break;
198201 }
199202
200203 return false;
236236 virtual void EndFunction();
237237 };
238238
239
240 class ARMException : public DwarfException {
241 /// shouldEmitTable - Per-function flag to indicate if EH tables should
242 /// be emitted.
243 bool shouldEmitTable;
244
245 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
246 /// should be emitted.
247 bool shouldEmitMoves;
248
249 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
250 /// should be emitted.
251 bool shouldEmitTableModule;
252 public:
253 //===--------------------------------------------------------------------===//
254 // Main entry points.
255 //
256 ARMException(AsmPrinter *A);
257 virtual ~ARMException();
258
259 /// EndModule - Emit all exception information that should come after the
260 /// content.
261 virtual void EndModule();
262
263 /// BeginFunction - Gather pre-function exception information. Assumes being
264 /// emitted immediately after the function entry point.
265 virtual void BeginFunction(const MachineFunction *MF);
266
267 /// EndFunction - Gather and emit post-function exception information.
268 virtual void EndFunction();
269 };
270
239271 } // End of namespace llvm
240272
241273 #endif
291291 // FALLTHROUGH
292292 case ExceptionHandling::DwarfCFI:
293293 case ExceptionHandling::DwarfTable:
294 case ExceptionHandling::ARM:
294295 PM.add(createDwarfEHPass(this));
295296 break;
296297 case ExceptionHandling::None:
190190 virtual bool EmitCFIOffset(int64_t Register, int64_t Offset);
191191 virtual bool EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
192192 virtual bool EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
193
194 virtual void EmitFnStart();
195 virtual void EmitFnEnd();
196 virtual void EmitCantUnwind();
197 virtual void EmitPersonality(const MCSymbol *Personality);
198 virtual void EmitHandlerData();
193199
194200 virtual void EmitInstruction(const MCInst &Inst);
195201
858864 }
859865 }
860866
867 void MCAsmStreamer::EmitFnStart() {
868 OS << "\t.fnstart";
869 EmitEOL();
870 }
871
872 void MCAsmStreamer::EmitFnEnd() {
873 OS << "\t.fnend";
874 EmitEOL();
875 }
876
877 void MCAsmStreamer::EmitCantUnwind() {
878 OS << "\t.cantunwind";
879 EmitEOL();
880 }
881
882 void MCAsmStreamer::EmitHandlerData() {
883 OS << "\t.handlerdata";
884 EmitEOL();
885 }
886
887 void MCAsmStreamer::EmitPersonality(const MCSymbol *Personality) {
888 OS << "\t.personality " << Personality->getName();
889 EmitEOL();
890 }
891
861892 void MCAsmStreamer::EmitInstruction(const MCInst &Inst) {
862893 assert(getCurrentSection() && "Cannot emit contents before setting section!");
863894
258258 return false;
259259 }
260260
261 void MCStreamer::EmitFnStart() {
262 errs() << "Not implemented yet\n";
263 abort();
264 }
265
266 void MCStreamer::EmitFnEnd() {
267 errs() << "Not implemented yet\n";
268 abort();
269 }
270
271 void MCStreamer::EmitCantUnwind() {
272 errs() << "Not implemented yet\n";
273 abort();
274 }
275
276 void MCStreamer::EmitHandlerData() {
277 errs() << "Not implemented yet\n";
278 abort();
279 }
280
281 void MCStreamer::EmitPersonality(const MCSymbol *Personality) {
282 errs() << "Not implemented yet\n";
283 abort();
284 }
285
261286 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
262287 /// the specified string in the output .s file. This capability is
263288 /// indicated by the hasRawTextSupport() predicate.
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "ARMMCAsmInfo.h"
14 #include "llvm/Support/CommandLine.h"
15
1416 using namespace llvm;
17
18 static cl::opt
19 EnableARMEHABI("arm-enable-ehabi", cl::Hidden,
20 cl::desc("Generate ARM EHABI tables"),
21 cl::init(false));
22
1523
1624 static const char *const arm_asm_table[] = {
1725 "{r0}", "r0",
6472 DwarfRequiresFrameSection = false;
6573
6674 SupportsDebugInformation = true;
75
76 // Exceptions handling
77 if (EnableARMEHABI)
78 ExceptionsType = ExceptionHandling::ARM;
6779 }
3535 ELF::SHF_WRITE |
3636 ELF::SHF_ALLOC,
3737 SectionKind::getDataRel());
38 LSDASection = NULL;
3839 }
39
40
4041 AttributesSection =
4142 getContext().getELFSection(".ARM.attributes",
4243 ELF::SHT_ARM_ATTRIBUTES,