1 //===- lib/MC/MCWinEH.cpp - Windows EH implementation ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
20 const MCSection *UnwindEmitter::GetPDataSection(StringRef Suffix,
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());
30 const MCSection *UnwindEmitter::GetXDataSection(StringRef Suffix,
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());
40 StringRef UnwindEmitter::GetSectionSuffix(const MCSymbol *Function) {
41 if (!Function || !Function->isInSection())
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);
50 if (Dollar == StringRef::npos && Dot == StringRef::npos)
52 if (Dot == StringRef::npos)
53 return Name.substr(Dollar);
54 if (Dollar == StringRef::npos || Dot < Dollar)
55 return Name.substr(Dot);
57 return Name.substr(Dollar);