blob: 8faf70737bff843677eb863310aba05d53a7de00 [file] [log] [blame]
Saleem Abdulrasool64a8cc72014-08-07 02:59:41 +00001//===- lib/MC/MCWinEH.cpp - Windows EH implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ADT/StringRef.h"
11#include "llvm/MC/MCContext.h"
12#include "llvm/MC/MCObjectFileInfo.h"
13#include "llvm/MC/MCSectionCOFF.h"
14#include "llvm/MC/MCSymbol.h"
15#include "llvm/MC/MCWinEH.h"
16#include "llvm/Support/COFF.h"
17
18namespace llvm {
19namespace WinEH {
20const MCSection *UnwindEmitter::GetPDataSection(StringRef Suffix,
21 MCContext &Context) {
22 if (Suffix.empty())
23 return Context.getObjectFileInfo()->getPDataSection();
24 return Context.getCOFFSection((".pdata" + Suffix).str(),
25 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
26 COFF::IMAGE_SCN_MEM_READ,
27 SectionKind::getDataRel());
28}
29
30const MCSection *UnwindEmitter::GetXDataSection(StringRef Suffix,
31 MCContext &Context) {
32 if (Suffix.empty())
33 return Context.getObjectFileInfo()->getXDataSection();
34 return Context.getCOFFSection((".xdata" + Suffix).str(),
35 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
36 COFF::IMAGE_SCN_MEM_READ,
37 SectionKind::getDataRel());
38}
39
40StringRef UnwindEmitter::GetSectionSuffix(const MCSymbol *Function) {
41 if (!Function || !Function->isInSection())
42 return "";
43
44 const MCSection *FunctionSection = &Function->getSection();
45 if (const auto Section = dyn_cast<MCSectionCOFF>(FunctionSection)) {
46 StringRef Name = Section->getSectionName();
47 size_t Dollar = Name.find('$');
48 size_t Dot = Name.find('.', 1);
49
50 if (Dollar == StringRef::npos && Dot == StringRef::npos)
51 return "";
52 if (Dot == StringRef::npos)
53 return Name.substr(Dollar);
54 if (Dollar == StringRef::npos || Dot < Dollar)
55 return Name.substr(Dot);
56
57 return Name.substr(Dollar);
58 }
59
60 return "";
61}
62}
63}
64