<div dir="ltr"><div>Oops. Sorry for missing them. Committed them in r173941. I'm sorry for the breakage.<br><br></div>Logan<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jan 30, 2013 at 11:42 PM, Anton Korobeynikov <span dir="ltr"><<a href="mailto:anton@korobeynikov.info" target="_blank">anton@korobeynikov.info</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Logan,<br>
<br>
Looks like you forgot to add the file :)<br>
<div class="HOEnZb"><div class="h5"><br>
On Wed, Jan 30, 2013 at 7:39 PM, Logan Chien <<a href="mailto:tzuhsiang.chien@gmail.com">tzuhsiang.chien@gmail.com</a>> wrote:<br>
> Author: logan<br>
> Date: Wed Jan 30 09:39:04 2013<br>
> New Revision: 173939<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=173939&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=173939&view=rev</a><br>
> Log:<br>
> Override virtual function for ARM EH directives.<br>
><br>
><br>
> Modified:<br>
> llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp<br>
><br>
> Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=173939&r1=173938&r2=173939&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=173939&r1=173938&r2=173939&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (original)<br>
> +++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp Wed Jan 30 09:39:04 2013<br>
> @@ -13,6 +13,7 @@<br>
> //<br>
> //===----------------------------------------------------------------------===//<br>
><br>
> +#include "ARMUnwindOp.h"<br>
> #include "llvm/ADT/SmallPtrSet.h"<br>
> #include "llvm/ADT/Twine.h"<br>
> #include "llvm/MC/MCAsmBackend.h"<br>
> @@ -56,11 +57,25 @@ public:<br>
> ARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,<br>
> raw_ostream &OS, MCCodeEmitter *Emitter, bool IsThumb)<br>
> : MCELFStreamer(Context, TAB, OS, Emitter),<br>
> - IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None) {<br>
> + IsThumb(IsThumb), MappingSymbolCounter(0), LastEMS(EMS_None),<br>
> + ExTab(0), FnStart(0), Personality(0), CantUnwind(false) {<br>
> }<br>
><br>
> ~ARMELFStreamer() {}<br>
><br>
> + // ARM exception handling directives<br>
> + virtual void EmitFnStart();<br>
> + virtual void EmitFnEnd();<br>
> + virtual void EmitCantUnwind();<br>
> + virtual void EmitPersonality(const MCSymbol *Per);<br>
> + virtual void EmitHandlerData();<br>
> + virtual void EmitSetFP(unsigned NewFpReg,<br>
> + unsigned NewSpReg,<br>
> + int64_t Offset = 0);<br>
> + virtual void EmitPad(int64_t Offset);<br>
> + virtual void EmitRegSave(const SmallVectorImpl<unsigned> &RegList,<br>
> + bool isVector);<br>
> +<br>
> virtual void ChangeSection(const MCSection *Section) {<br>
> // We have to keep track of the mapping symbol state of any sections we<br>
> // use. Each one should start off as EMS_None, which is provided as the<br>
> @@ -172,6 +187,15 @@ private:<br>
> SD.setFlags(SD.getFlags() | ELF_Other_ThumbFunc);<br>
> }<br>
><br>
> + // Helper functions for ARM exception handling directives<br>
> + void Reset();<br>
> +<br>
> + void EmitPersonalityFixup(StringRef Name);<br>
> +<br>
> + void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,<br>
> + SectionKind Kind, const MCSymbol &Fn);<br>
> + void SwitchToExTabSection(const MCSymbol &FnStart);<br>
> + void SwitchToExIdxSection(const MCSymbol &FnStart);<br>
><br>
> bool IsThumb;<br>
> int64_t MappingSymbolCounter;<br>
> @@ -179,10 +203,200 @@ private:<br>
> DenseMap<const MCSection *, ElfMappingSymbol> LastMappingSymbols;<br>
> ElfMappingSymbol LastEMS;<br>
><br>
> - /// @}<br>
> + // ARM Exception Handling Frame Information<br>
> + MCSymbol *ExTab;<br>
> + MCSymbol *FnStart;<br>
> + const MCSymbol *Personality;<br>
> + bool CantUnwind;<br>
> };<br>
> }<br>
><br>
> +inline void ARMELFStreamer::SwitchToEHSection(const char *Prefix,<br>
> + unsigned Type,<br>
> + unsigned Flags,<br>
> + SectionKind Kind,<br>
> + const MCSymbol &Fn) {<br>
> + const MCSectionELF &FnSection =<br>
> + static_cast<const MCSectionELF &>(Fn.getSection());<br>
> +<br>
> + // Create the name for new section<br>
> + StringRef FnSecName(FnSection.getSectionName());<br>
> + SmallString<128> EHSecName(Prefix);<br>
> + if (FnSecName != ".text") {<br>
> + EHSecName += FnSecName;<br>
> + }<br>
> +<br>
> + // Get .ARM.extab or .ARM.exidx section<br>
> + const MCSectionELF *EHSection = NULL;<br>
> + if (const MCSymbol *Group = FnSection.getGroup()) {<br>
> + EHSection = getContext().getELFSection(<br>
> + EHSecName, Type, Flags | ELF::SHF_GROUP, Kind,<br>
> + FnSection.getEntrySize(), Group->getName());<br>
> + } else {<br>
> + EHSection = getContext().getELFSection(EHSecName, Type, Flags, Kind);<br>
> + }<br>
> + assert(EHSection);<br>
> +<br>
> + // Switch to .ARM.extab or .ARM.exidx section<br>
> + SwitchSection(EHSection);<br>
> + EmitCodeAlignment(4, 0);<br>
> +}<br>
> +<br>
> +inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) {<br>
> + SwitchToEHSection(".ARM.extab",<br>
> + ELF::SHT_PROGBITS,<br>
> + ELF::SHF_ALLOC,<br>
> + SectionKind::getDataRel(),<br>
> + FnStart);<br>
> +}<br>
> +<br>
> +inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) {<br>
> + SwitchToEHSection(".ARM.exidx",<br>
> + ELF::SHT_ARM_EXIDX,<br>
> + ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER,<br>
> + SectionKind::getDataRel(),<br>
> + FnStart);<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::Reset() {<br>
> + ExTab = NULL;<br>
> + FnStart = NULL;<br>
> + Personality = NULL;<br>
> + CantUnwind = false;<br>
> +}<br>
> +<br>
> +// Add the R_ARM_NONE fixup at the same position<br>
> +void ARMELFStreamer::EmitPersonalityFixup(StringRef Name) {<br>
> + const MCSymbol *PersonalitySym = getContext().GetOrCreateSymbol(Name);<br>
> +<br>
> + const MCSymbolRefExpr *PersonalityRef =<br>
> + MCSymbolRefExpr::Create(PersonalitySym,<br>
> + MCSymbolRefExpr::VK_ARM_NONE,<br>
> + getContext());<br>
> +<br>
> + AddValueSymbols(PersonalityRef);<br>
> + MCDataFragment *DF = getOrCreateDataFragment();<br>
> + DF->getFixups().push_back(<br>
> + MCFixup::Create(DF->getContents().size(), PersonalityRef,<br>
> + MCFixup::getKindForSize(4, false)));<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitFnStart() {<br>
> + assert(FnStart == 0);<br>
> + FnStart = getContext().CreateTempSymbol();<br>
> + EmitLabel(FnStart);<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitFnEnd() {<br>
> + assert(FnStart && ".fnstart must preceeds .fnend");<br>
> +<br>
> + // Emit unwind opcodes if there is no .handlerdata directive<br>
> + int PersonalityIndex = -1;<br>
> + if (!ExTab && !CantUnwind) {<br>
> + // For __aeabi_unwind_cpp_pr1, we have to emit opcodes in .ARM.extab.<br>
> + SwitchToExTabSection(*FnStart);<br>
> +<br>
> + // Create .ARM.extab label for offset in .ARM.exidx<br>
> + ExTab = getContext().CreateTempSymbol();<br>
> + EmitLabel(ExTab);<br>
> +<br>
> + PersonalityIndex = 1;<br>
> +<br>
> + uint32_t Entry = 0;<br>
> + uint32_t NumExtraEntryWords = 0;<br>
> + Entry |= NumExtraEntryWords << 24;<br>
> + Entry |= (EHT_COMPACT | PersonalityIndex) << 16;<br>
> +<br>
> + // TODO: This should be generated according to .save, .vsave, .setfp<br>
> + // directives. Currently, we are simply generating FINISH opcode.<br>
> + Entry |= UNWIND_OPCODE_FINISH << 8;<br>
> + Entry |= UNWIND_OPCODE_FINISH;<br>
> +<br>
> + EmitIntValue(Entry, 4, 0);<br>
> + }<br>
> +<br>
> + // Emit the exception index table entry<br>
> + SwitchToExIdxSection(*FnStart);<br>
> +<br>
> + if (PersonalityIndex == 1)<br>
> + EmitPersonalityFixup("__aeabi_unwind_cpp_pr1");<br>
> +<br>
> + const MCSymbolRefExpr *FnStartRef =<br>
> + MCSymbolRefExpr::Create(FnStart,<br>
> + MCSymbolRefExpr::VK_ARM_PREL31,<br>
> + getContext());<br>
> +<br>
> + EmitValue(FnStartRef, 4, 0);<br>
> +<br>
> + if (CantUnwind) {<br>
> + EmitIntValue(EXIDX_CANTUNWIND, 4, 0);<br>
> + } else {<br>
> + const MCSymbolRefExpr *ExTabEntryRef =<br>
> + MCSymbolRefExpr::Create(ExTab,<br>
> + MCSymbolRefExpr::VK_ARM_PREL31,<br>
> + getContext());<br>
> + EmitValue(ExTabEntryRef, 4, 0);<br>
> + }<br>
> +<br>
> + // Clean exception handling frame information<br>
> + Reset();<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitCantUnwind() {<br>
> + CantUnwind = true;<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitHandlerData() {<br>
> + SwitchToExTabSection(*FnStart);<br>
> +<br>
> + // Create .ARM.extab label for offset in .ARM.exidx<br>
> + assert(!ExTab);<br>
> + ExTab = getContext().CreateTempSymbol();<br>
> + EmitLabel(ExTab);<br>
> +<br>
> + // Emit Personality<br>
> + assert(Personality && ".personality directive must preceed .handlerdata");<br>
> +<br>
> + const MCSymbolRefExpr *PersonalityRef =<br>
> + MCSymbolRefExpr::Create(Personality,<br>
> + MCSymbolRefExpr::VK_ARM_PREL31,<br>
> + getContext());<br>
> +<br>
> + EmitValue(PersonalityRef, 4, 0);<br>
> +<br>
> + // Emit unwind opcodes<br>
> + uint32_t Entry = 0;<br>
> + uint32_t NumExtraEntryWords = 0;<br>
> +<br>
> + // TODO: This should be generated according to .save, .vsave, .setfp<br>
> + // directives. Currently, we are simply generating FINISH opcode.<br>
> + Entry |= NumExtraEntryWords << 24;<br>
> + Entry |= UNWIND_OPCODE_FINISH << 16;<br>
> + Entry |= UNWIND_OPCODE_FINISH << 8;<br>
> + Entry |= UNWIND_OPCODE_FINISH;<br>
> +<br>
> + EmitIntValue(Entry, 4, 0);<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitPersonality(const MCSymbol *Per) {<br>
> + Personality = Per;<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitSetFP(unsigned NewFpReg,<br>
> + unsigned NewSpReg,<br>
> + int64_t Offset) {<br>
> + // TODO: Not implemented<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitPad(int64_t Offset) {<br>
> + // TODO: Not implemented<br>
> +}<br>
> +<br>
> +void ARMELFStreamer::EmitRegSave(const SmallVectorImpl<unsigned> &RegList,<br>
> + bool IsVector) {<br>
> + // TODO: Not implemented<br>
> +}<br>
> +<br>
> namespace llvm {<br>
> MCELFStreamer* createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB,<br>
> raw_ostream &OS, MCCodeEmitter *Emitter,<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
With best regards, Anton Korobeynikov<br>
Faculty of Mathematics and Mechanics, Saint Petersburg State University<br>
</font></span></blockquote></div><br></div>