[Assembler] Allow non-fatal errors after parsing
[oota-llvm.git] / lib / MC / MCParser / DarwinAsmParser.cpp
index 3c092cdb19bbf2a095a7abb711637c488233c20b..582d43623e83aa17810e90cc9e7bd6c5ea334bee 100644 (file)
@@ -8,14 +8,18 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCObjectFileInfo.h"
+#include "llvm/MC/MCParser/MCAsmLexer.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCParser/MCAsmLexer.h"
-#include "llvm/MC/MCParser/MCAsmParser.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 using namespace llvm;
@@ -25,275 +29,357 @@ namespace {
 /// \brief Implementation of directive handling which is shared across all
 /// Darwin targets.
 class DarwinAsmParser : public MCAsmParserExtension {
-  template<bool (DarwinAsmParser::*Handler)(StringRef, SMLoc)>
-  void AddDirectiveHandler(StringRef Directive) {
-    getParser().AddDirectiveHandler(this, Directive,
-                                    HandleDirective<DarwinAsmParser, Handler>);
+  template<bool (DarwinAsmParser::*HandlerMethod)(StringRef, SMLoc)>
+  void addDirectiveHandler(StringRef Directive) {
+    MCAsmParser::ExtensionDirectiveHandler Handler = std::make_pair(
+        this, HandleDirective<DarwinAsmParser, HandlerMethod>);
+    getParser().addDirectiveHandler(Directive, Handler);
   }
 
-  bool ParseSectionSwitch(const char *Segment, const char *Section,
+  bool parseSectionSwitch(const char *Segment, const char *Section,
                           unsigned TAA = 0, unsigned ImplicitAlign = 0,
                           unsigned StubSize = 0);
 
+  SMLoc LastVersionMinDirective;
+
 public:
   DarwinAsmParser() {}
 
-  virtual void Initialize(MCAsmParser &Parser) {
+  void Initialize(MCAsmParser &Parser) override {
     // Call the base implementation.
     this->MCAsmParserExtension::Initialize(Parser);
 
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDesc>(".desc");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveLsym>(".lsym");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols>(
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveDesc>(".desc");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveIndirectSymbol>(
+      ".indirect_symbol");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveLsym>(".lsym");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveSubsectionsViaSymbols>(
       ".subsections_via_symbols");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".dump");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".load");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSection>(".section");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogUnique>(
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".dump");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveDumpOrLoad>(".load");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveSection>(".section");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectivePushSection>(
+      ".pushsection");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectivePopSection>(
+      ".popsection");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectivePrevious>(".previous");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogUnique>(
       ".secure_log_unique");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogReset>(
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveSecureLogReset>(
       ".secure_log_reset");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveTBSS>(".tbss");
-    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveZerofill>(".zerofill");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveTBSS>(".tbss");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveZerofill>(".zerofill");
+
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegion>(
+      ".data_region");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveDataRegionEnd>(
+      ".end_data_region");
 
     // Special section directives.
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConst>(".const");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstData>(".const_data");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstructor>(".constructor");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveCString>(".cstring");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveData>(".data");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDestructor>(".destructor");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDyld>(".dyld");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit0>(".fvmlib_init0");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit1>(".fvmlib_init1");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>(".lazy_symbol_pointer");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>(".literal16");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>(".literal4");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral8>(".literal8");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModInitFunc>(".mod_init_func");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModTermFunc>(".mod_term_func");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveNonLazySymbolPointers>(".non_lazy_symbol_pointer");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatClsMeth>(".objc_cat_cls_meth");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatInstMeth>(".objc_cat_inst_meth");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCategory>(".objc_category");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClass>(".objc_class");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassNames>(".objc_class_names");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassVars>(".objc_class_vars");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsMeth>(".objc_cls_meth");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsRefs>(".objc_cls_refs");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstMeth>(".objc_inst_meth");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstanceVars>(".objc_instance_vars");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMessageRefs>(".objc_message_refs");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMetaClass>(".objc_meta_class");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMethVarNames>(".objc_meth_var_names");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMethVarTypes>(".objc_meth_var_types");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCModuleInfo>(".objc_module_info");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCProtocol>(".objc_protocol");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSelectorStrs>(".objc_selector_strs");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCStringObject>(".objc_string_object");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSymbols>(".objc_symbols");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectivePICSymbolStub>(".picsymbol_stub");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticConst>(".static_const");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticData>(".static_data");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveSymbolStub>(".symbol_stub");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTData>(".tdata");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveText>(".text");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveThreadInitFunc>(".thread_init_func");
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTLV>(".tlv");
-
-    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveIdent>(".ident");
-  }
-
-  bool ParseDirectiveDesc(StringRef, SMLoc);
-  bool ParseDirectiveDumpOrLoad(StringRef, SMLoc);
-  bool ParseDirectiveLsym(StringRef, SMLoc);
-  bool ParseDirectiveSection(StringRef, SMLoc);
-  bool ParseDirectiveSecureLogReset(StringRef, SMLoc);
-  bool ParseDirectiveSecureLogUnique(StringRef, SMLoc);
-  bool ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
-  bool ParseDirectiveTBSS(StringRef, SMLoc);
-  bool ParseDirectiveZerofill(StringRef, SMLoc);
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveBss>(".bss");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConst>(".const");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstData>(
+      ".const_data");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveConstructor>(
+      ".constructor");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveCString>(
+      ".cstring");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveData>(".data");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDestructor>(
+      ".destructor");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveDyld>(".dyld");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit0>(
+      ".fvmlib_init0");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveFVMLibInit1>(
+      ".fvmlib_init1");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveLazySymbolPointers>(
+        ".lazy_symbol_pointer");
+    addDirectiveHandler<&DarwinAsmParser::parseDirectiveLinkerOption>(
+      ".linker_option");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral16>(
+      ".literal16");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral4>(
+      ".literal4");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveLiteral8>(
+      ".literal8");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModInitFunc>(
+      ".mod_init_func");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveModTermFunc>(
+      ".mod_term_func");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveNonLazySymbolPointers>(
+        ".non_lazy_symbol_pointer");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatClsMeth>(
+      ".objc_cat_cls_meth");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCatInstMeth>(
+      ".objc_cat_inst_meth");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCCategory>(
+      ".objc_category");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClass>(
+      ".objc_class");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassNames>(
+      ".objc_class_names");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClassVars>(
+      ".objc_class_vars");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsMeth>(
+      ".objc_cls_meth");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCClsRefs>(
+      ".objc_cls_refs");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCInstMeth>(
+      ".objc_inst_meth");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveObjCInstanceVars>(
+        ".objc_instance_vars");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMessageRefs>(
+      ".objc_message_refs");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCMetaClass>(
+      ".objc_meta_class");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveObjCMethVarNames>(
+        ".objc_meth_var_names");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveObjCMethVarTypes>(
+        ".objc_meth_var_types");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCModuleInfo>(
+      ".objc_module_info");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCProtocol>(
+      ".objc_protocol");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveObjCSelectorStrs>(
+        ".objc_selector_strs");
+    addDirectiveHandler<
+      &DarwinAsmParser::parseSectionDirectiveObjCStringObject>(
+        ".objc_string_object");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveObjCSymbols>(
+      ".objc_symbols");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectivePICSymbolStub>(
+      ".picsymbol_stub");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticConst>(
+      ".static_const");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveStaticData>(
+      ".static_data");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveSymbolStub>(
+      ".symbol_stub");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTData>(".tdata");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveText>(".text");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveThreadInitFunc>(
+      ".thread_init_func");
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveTLV>(".tlv");
+
+    addDirectiveHandler<&DarwinAsmParser::parseSectionDirectiveIdent>(".ident");
+    addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
+      ".watchos_version_min");
+    addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".tvos_version_min");
+    addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(".ios_version_min");
+    addDirectiveHandler<&DarwinAsmParser::parseVersionMin>(
+      ".macosx_version_min");
+
+    LastVersionMinDirective = SMLoc();
+  }
+
+  bool parseDirectiveDesc(StringRef, SMLoc);
+  bool parseDirectiveIndirectSymbol(StringRef, SMLoc);
+  bool parseDirectiveDumpOrLoad(StringRef, SMLoc);
+  bool parseDirectiveLsym(StringRef, SMLoc);
+  bool parseDirectiveLinkerOption(StringRef, SMLoc);
+  bool parseDirectiveSection(StringRef, SMLoc);
+  bool parseDirectivePushSection(StringRef, SMLoc);
+  bool parseDirectivePopSection(StringRef, SMLoc);
+  bool parseDirectivePrevious(StringRef, SMLoc);
+  bool parseDirectiveSecureLogReset(StringRef, SMLoc);
+  bool parseDirectiveSecureLogUnique(StringRef, SMLoc);
+  bool parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
+  bool parseDirectiveTBSS(StringRef, SMLoc);
+  bool parseDirectiveZerofill(StringRef, SMLoc);
+  bool parseDirectiveDataRegion(StringRef, SMLoc);
+  bool parseDirectiveDataRegionEnd(StringRef, SMLoc);
 
   // Named Section Directive
-  bool ParseSectionDirectiveConst(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__const");
+  bool parseSectionDirectiveBss(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__bss");
   }
-  bool ParseSectionDirectiveStaticConst(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__static_const");
+
+  bool parseSectionDirectiveConst(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__const");
   }
-  bool ParseSectionDirectiveCString(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__cstring",
-                              MCSectionMachO::S_CSTRING_LITERALS);
+  bool parseSectionDirectiveStaticConst(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__static_const");
   }
-  bool ParseSectionDirectiveLiteral4(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__literal4",
-                              MCSectionMachO::S_4BYTE_LITERALS, 4);
+  bool parseSectionDirectiveCString(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__cstring",
+                              MachO::S_CSTRING_LITERALS);
   }
-  bool ParseSectionDirectiveLiteral8(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__literal8",
-                              MCSectionMachO::S_8BYTE_LITERALS, 8);
+  bool parseSectionDirectiveLiteral4(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__literal4",
+                              MachO::S_4BYTE_LITERALS, 4);
   }
-  bool ParseSectionDirectiveLiteral16(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__literal16",
-                              MCSectionMachO::S_16BYTE_LITERALS, 16);
+  bool parseSectionDirectiveLiteral8(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__literal8",
+                              MachO::S_8BYTE_LITERALS, 8);
   }
-  bool ParseSectionDirectiveConstructor(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__constructor");
+  bool parseSectionDirectiveLiteral16(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__literal16",
+                              MachO::S_16BYTE_LITERALS, 16);
   }
-  bool ParseSectionDirectiveDestructor(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__destructor");
+  bool parseSectionDirectiveConstructor(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__constructor");
   }
-  bool ParseSectionDirectiveFVMLibInit0(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__fvmlib_init0");
+  bool parseSectionDirectiveDestructor(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__destructor");
   }
-  bool ParseSectionDirectiveFVMLibInit1(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__fvmlib_init1");
+  bool parseSectionDirectiveFVMLibInit0(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__fvmlib_init0");
   }
-  bool ParseSectionDirectiveSymbolStub(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__symbol_stub",
-                              MCSectionMachO::S_SYMBOL_STUBS |
-                              MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
+  bool parseSectionDirectiveFVMLibInit1(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__fvmlib_init1");
+  }
+  bool parseSectionDirectiveSymbolStub(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__symbol_stub",
+                              MachO::S_SYMBOL_STUBS |
+                              MachO::S_ATTR_PURE_INSTRUCTIONS,
                               // FIXME: Different on PPC and ARM.
                               0, 16);
   }
-  bool ParseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT","__picsymbol_stub",
-                              MCSectionMachO::S_SYMBOL_STUBS |
-                              MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
+  bool parseSectionDirectivePICSymbolStub(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT","__picsymbol_stub",
+                              MachO::S_SYMBOL_STUBS |
+                              MachO::S_ATTR_PURE_INSTRUCTIONS, 0, 26);
   }
-  bool ParseSectionDirectiveData(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__data");
+  bool parseSectionDirectiveData(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__data");
   }
-  bool ParseSectionDirectiveStaticData(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__static_data");
+  bool parseSectionDirectiveStaticData(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__static_data");
   }
-  bool ParseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__nl_symbol_ptr",
-                              MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, 4);
+  bool parseSectionDirectiveNonLazySymbolPointers(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__nl_symbol_ptr",
+                              MachO::S_NON_LAZY_SYMBOL_POINTERS, 4);
   }
-  bool ParseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__la_symbol_ptr",
-                              MCSectionMachO::S_LAZY_SYMBOL_POINTERS, 4);
+  bool parseSectionDirectiveLazySymbolPointers(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__la_symbol_ptr",
+                              MachO::S_LAZY_SYMBOL_POINTERS, 4);
   }
-  bool ParseSectionDirectiveDyld(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__dyld");
+  bool parseSectionDirectiveDyld(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__dyld");
   }
-  bool ParseSectionDirectiveModInitFunc(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__mod_init_func",
-                              MCSectionMachO::S_MOD_INIT_FUNC_POINTERS, 4);
+  bool parseSectionDirectiveModInitFunc(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__mod_init_func",
+                              MachO::S_MOD_INIT_FUNC_POINTERS, 4);
   }
-  bool ParseSectionDirectiveModTermFunc(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__mod_term_func",
-                              MCSectionMachO::S_MOD_TERM_FUNC_POINTERS, 4);
+  bool parseSectionDirectiveModTermFunc(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__mod_term_func",
+                              MachO::S_MOD_TERM_FUNC_POINTERS, 4);
   }
-  bool ParseSectionDirectiveConstData(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__const");
+  bool parseSectionDirectiveConstData(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__const");
   }
-  bool ParseSectionDirectiveObjCClass(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__class",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCClass(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__class",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCMetaClass(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__meta_class",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCMetaClass(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__meta_class",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__cat_cls_meth",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCCatClsMeth(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__cat_cls_meth",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__cat_inst_meth",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCCatInstMeth(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__cat_inst_meth",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCProtocol(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__protocol",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCProtocol(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__protocol",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCStringObject(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__string_object",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCStringObject(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__string_object",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCClsMeth(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__cls_meth",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCClsMeth(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__cls_meth",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCInstMeth(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__inst_meth",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCInstMeth(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__inst_meth",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__cls_refs",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP |
-                              MCSectionMachO::S_LITERAL_POINTERS, 4);
+  bool parseSectionDirectiveObjCClsRefs(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__cls_refs",
+                              MachO::S_ATTR_NO_DEAD_STRIP |
+                              MachO::S_LITERAL_POINTERS, 4);
   }
-  bool ParseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__message_refs",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP |
-                              MCSectionMachO::S_LITERAL_POINTERS, 4);
+  bool parseSectionDirectiveObjCMessageRefs(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__message_refs",
+                              MachO::S_ATTR_NO_DEAD_STRIP |
+                              MachO::S_LITERAL_POINTERS, 4);
   }
-  bool ParseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__symbols",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCSymbols(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__symbols",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCCategory(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__category",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCCategory(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__category",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCClassVars(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__class_vars",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCClassVars(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__class_vars",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__instance_vars",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCInstanceVars(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__instance_vars",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__module_info",
-                              MCSectionMachO::S_ATTR_NO_DEAD_STRIP);
+  bool parseSectionDirectiveObjCModuleInfo(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__module_info",
+                              MachO::S_ATTR_NO_DEAD_STRIP);
   }
-  bool ParseSectionDirectiveObjCClassNames(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__cstring",
-                              MCSectionMachO::S_CSTRING_LITERALS);
+  bool parseSectionDirectiveObjCClassNames(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__cstring",
+                              MachO::S_CSTRING_LITERALS);
   }
-  bool ParseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__cstring",
-                              MCSectionMachO::S_CSTRING_LITERALS);
+  bool parseSectionDirectiveObjCMethVarTypes(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__cstring",
+                              MachO::S_CSTRING_LITERALS);
   }
-  bool ParseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__cstring",
-                              MCSectionMachO::S_CSTRING_LITERALS);
+  bool parseSectionDirectiveObjCMethVarNames(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__cstring",
+                              MachO::S_CSTRING_LITERALS);
   }
-  bool ParseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) {
-    return ParseSectionSwitch("__OBJC", "__selector_strs",
-                              MCSectionMachO::S_CSTRING_LITERALS);
+  bool parseSectionDirectiveObjCSelectorStrs(StringRef, SMLoc) {
+    return parseSectionSwitch("__OBJC", "__selector_strs",
+                              MachO::S_CSTRING_LITERALS);
   }
-  bool ParseSectionDirectiveTData(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__thread_data",
-                              MCSectionMachO::S_THREAD_LOCAL_REGULAR);
+  bool parseSectionDirectiveTData(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__thread_data",
+                              MachO::S_THREAD_LOCAL_REGULAR);
   }
-  bool ParseSectionDirectiveText(StringRef, SMLoc) {
-    return ParseSectionSwitch("__TEXT", "__text",
-                              MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
+  bool parseSectionDirectiveText(StringRef, SMLoc) {
+    return parseSectionSwitch("__TEXT", "__text",
+                              MachO::S_ATTR_PURE_INSTRUCTIONS);
   }
-  bool ParseSectionDirectiveTLV(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__thread_vars",
-                              MCSectionMachO::S_THREAD_LOCAL_VARIABLES);
+  bool parseSectionDirectiveTLV(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__thread_vars",
+                              MachO::S_THREAD_LOCAL_VARIABLES);
   }
-  bool ParseSectionDirectiveIdent(StringRef, SMLoc) {
+  bool parseSectionDirectiveIdent(StringRef, SMLoc) {
     // Darwin silently ignores the .ident directive.
-    getParser().EatToEndOfStatement();
+    getParser().eatToEndOfStatement();
     return false;
   }
-  bool ParseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
-    return ParseSectionSwitch("__DATA", "__thread_init",
-                         MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS);
+  bool parseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
+    return parseSectionSwitch("__DATA", "__thread_init",
+                         MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS);
   }
+  bool parseVersionMin(StringRef, SMLoc);
 
 };
 
-}
+} // end anonymous namespace
 
-bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
+bool DarwinAsmParser::parseSectionSwitch(const char *Segment,
                                          const char *Section,
                                          unsigned TAA, unsigned Align,
                                          unsigned StubSize) {
@@ -302,7 +388,7 @@ bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
   Lex();
 
   // FIXME: Arch specific.
-  bool isText = StringRef(Segment) == "__TEXT";  // FIXME: Hack.
+  bool isText = TAA & MachO::S_ATTR_PURE_INSTRUCTIONS;
   getStreamer().SwitchSection(getContext().getMachOSection(
                                 Segment, Section, TAA, StubSize,
                                 isText ? SectionKind::getText()
@@ -317,27 +403,27 @@ bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
   // is no good reason for someone to intentionally emit incorrectly sized
   // values into the implicitly aligned sections.
   if (Align)
-    getStreamer().EmitValueToAlignment(Align, 0, 1, 0);
+    getStreamer().EmitValueToAlignment(Align);
 
   return false;
 }
 
-/// ParseDirectiveDesc
+/// parseDirectiveDesc
 ///  ::= .desc identifier , expression
-bool DarwinAsmParser::ParseDirectiveDesc(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveDesc(StringRef, SMLoc) {
   StringRef Name;
-  if (getParser().ParseIdentifier(Name))
+  if (getParser().parseIdentifier(Name))
     return TokError("expected identifier in directive");
 
   // Handle the identifier as the key symbol.
-  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+  MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in '.desc' directive");
   Lex();
 
   int64_t DescValue;
-  if (getParser().ParseAbsoluteExpression(DescValue))
+  if (getParser().parseAbsoluteExpression(DescValue))
     return true;
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
@@ -351,9 +437,42 @@ bool DarwinAsmParser::ParseDirectiveDesc(StringRef, SMLoc) {
   return false;
 }
 
-/// ParseDirectiveDumpOrLoad
+/// parseDirectiveIndirectSymbol
+///  ::= .indirect_symbol identifier
+bool DarwinAsmParser::parseDirectiveIndirectSymbol(StringRef, SMLoc Loc) {
+  const MCSectionMachO *Current = static_cast<const MCSectionMachO*>(
+                                       getStreamer().getCurrentSection().first);
+  MachO::SectionType SectionType = Current->getType();
+  if (SectionType != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
+      SectionType != MachO::S_LAZY_SYMBOL_POINTERS &&
+      SectionType != MachO::S_SYMBOL_STUBS)
+    return Error(Loc, "indirect symbol not in a symbol pointer or stub "
+                      "section");
+
+  StringRef Name;
+  if (getParser().parseIdentifier(Name))
+    return TokError("expected identifier in .indirect_symbol directive");
+
+  MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
+
+  // Assembler local symbols don't make any sense here. Complain loudly.
+  if (Sym->isTemporary())
+    return TokError("non-local symbol required in directive");
+
+  if (!getStreamer().EmitSymbolAttribute(Sym, MCSA_IndirectSymbol))
+    return TokError("unable to emit indirect symbol attribute for: " + Name);
+
+  if (getLexer().isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.indirect_symbol' directive");
+
+  Lex();
+
+  return false;
+}
+
+/// parseDirectiveDumpOrLoad
 ///  ::= ( .dump | .load ) "filename"
-bool DarwinAsmParser::ParseDirectiveDumpOrLoad(StringRef Directive,
+bool DarwinAsmParser::parseDirectiveDumpOrLoad(StringRef Directive,
                                                SMLoc IDLoc) {
   bool IsDump = Directive == ".dump";
   if (getLexer().isNot(AsmToken::String))
@@ -369,29 +488,54 @@ bool DarwinAsmParser::ParseDirectiveDumpOrLoad(StringRef Directive,
   // FIXME: If/when .dump and .load are implemented they will be done in the
   // the assembly parser and not have any need for an MCStreamer API.
   if (IsDump)
-    Warning(IDLoc, "ignoring directive .dump for now");
+    return Warning(IDLoc, "ignoring directive .dump for now");
   else
-    Warning(IDLoc, "ignoring directive .load for now");
+    return Warning(IDLoc, "ignoring directive .load for now");
+}
 
+/// ParseDirectiveLinkerOption
+///  ::= .linker_option "string" ( , "string" )*
+bool DarwinAsmParser::parseDirectiveLinkerOption(StringRef IDVal, SMLoc) {
+  SmallVector<std::string, 4> Args;
+  for (;;) {
+    if (getLexer().isNot(AsmToken::String))
+      return TokError("expected string in '" + Twine(IDVal) + "' directive");
+
+    std::string Data;
+    if (getParser().parseEscapedString(Data))
+      return true;
+
+    Args.push_back(Data);
+
+    Lex();
+    if (getLexer().is(AsmToken::EndOfStatement))
+      break;
+
+    if (getLexer().isNot(AsmToken::Comma))
+      return TokError("unexpected token in '" + Twine(IDVal) + "' directive");
+    Lex();
+  }
+
+  getStreamer().EmitLinkerOptions(Args);
   return false;
 }
 
-/// ParseDirectiveLsym
+/// parseDirectiveLsym
 ///  ::= .lsym identifier , expression
-bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveLsym(StringRef, SMLoc) {
   StringRef Name;
-  if (getParser().ParseIdentifier(Name))
+  if (getParser().parseIdentifier(Name))
     return TokError("expected identifier in directive");
 
   // Handle the identifier as the key symbol.
-  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+  MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in '.lsym' directive");
   Lex();
 
   const MCExpr *Value;
-  if (getParser().ParseExpression(Value))
+  if (getParser().parseExpression(Value))
     return true;
 
   if (getLexer().isNot(AsmToken::EndOfStatement))
@@ -406,13 +550,13 @@ bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) {
   return TokError("directive '.lsym' is unsupported");
 }
 
-/// ParseDirectiveSection:
+/// parseDirectiveSection:
 ///   ::= .section identifier (',' identifier)*
-bool DarwinAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveSection(StringRef, SMLoc) {
   SMLoc Loc = getLexer().getLoc();
 
   StringRef SectionName;
-  if (getParser().ParseIdentifier(SectionName))
+  if (getParser().parseIdentifier(SectionName))
     return Error(Loc, "expected identifier after '.section' directive");
 
   // Verify there is a following comma.
@@ -444,6 +588,29 @@ bool DarwinAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
   if (!ErrorStr.empty())
     return Error(Loc, ErrorStr.c_str());
 
+  // Issue a warning if the target is not powerpc and Section is a *coal* section.
+  Triple TT = getParser().getContext().getObjectFileInfo()->getTargetTriple();
+  Triple::ArchType ArchTy = TT.getArch();
+
+  if (ArchTy != Triple::ppc && ArchTy != Triple::ppc64) {
+    StringRef NonCoalSection = StringSwitch<StringRef>(Section)
+                                   .Case("__textcoal_nt", "__text")
+                                   .Case("__const_coal", "__const")
+                                   .Case("__datacoal_nt", "__data")
+                                   .Default(Section);
+
+    if (!Section.equals(NonCoalSection)) {
+      StringRef SectionVal(Loc.getPointer());
+      size_t B = SectionVal.find(',') + 1, E = SectionVal.find(',', B);
+      SMLoc BLoc = SMLoc::getFromPointer(SectionVal.data() + B);
+      SMLoc ELoc = SMLoc::getFromPointer(SectionVal.data() + E);
+      getParser().Warning(Loc, "section \"" + Section + "\" is deprecated",
+                          SMRange(BLoc, ELoc));
+      getParser().Note(Loc, "change section name to \"" + NonCoalSection +
+                       "\"", SMRange(BLoc, ELoc));
+    }
+  }
+
   // FIXME: Arch specific.
   bool isText = Segment == "__TEXT";  // FIXME: Hack.
   getStreamer().SwitchSection(getContext().getMachOSection(
@@ -453,37 +620,69 @@ bool DarwinAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
   return false;
 }
 
+/// ParseDirectivePushSection:
+///   ::= .pushsection identifier (',' identifier)*
+bool DarwinAsmParser::parseDirectivePushSection(StringRef S, SMLoc Loc) {
+  getStreamer().PushSection();
+
+  if (parseDirectiveSection(S, Loc)) {
+    getStreamer().PopSection();
+    return true;
+  }
+
+  return false;
+}
+
+/// ParseDirectivePopSection:
+///   ::= .popsection
+bool DarwinAsmParser::parseDirectivePopSection(StringRef, SMLoc) {
+  if (!getStreamer().PopSection())
+    return TokError(".popsection without corresponding .pushsection");
+  return false;
+}
+
+/// ParseDirectivePrevious:
+///   ::= .previous
+bool DarwinAsmParser::parseDirectivePrevious(StringRef DirName, SMLoc) {
+  MCSectionSubPair PreviousSection = getStreamer().getPreviousSection();
+  if (!PreviousSection.first)
+    return TokError(".previous without corresponding .section");
+  getStreamer().SwitchSection(PreviousSection.first, PreviousSection.second);
+  return false;
+}
+
 /// ParseDirectiveSecureLogUnique
 ///  ::= .secure_log_unique ... message ...
-bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
-  StringRef LogMessage = getParser().ParseStringToEndOfStatement();
+bool DarwinAsmParser::parseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
+  StringRef LogMessage = getParser().parseStringToEndOfStatement();
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.secure_log_unique' directive");
 
-  if (getContext().getSecureLogUsed() != false)
+  if (getContext().getSecureLogUsed())
     return Error(IDLoc, ".secure_log_unique specified multiple times");
 
   // Get the secure log path.
   const char *SecureLogFile = getContext().getSecureLogFile();
-  if (SecureLogFile == NULL)
+  if (!SecureLogFile)
     return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE "
                  "environment variable unset.");
 
   // Open the secure log file if we haven't already.
   raw_ostream *OS = getContext().getSecureLog();
-  if (OS == NULL) {
-    std::string Err;
-    OS = new raw_fd_ostream(SecureLogFile, Err, raw_fd_ostream::F_Append);
-    if (!Err.empty()) {
+  if (!OS) {
+    std::error_code EC;
+    OS = new raw_fd_ostream(SecureLogFile, EC,
+                            sys::fs::F_Append | sys::fs::F_Text);
+    if (EC) {
        delete OS;
        return Error(IDLoc, Twine("can't open secure log file: ") +
-                    SecureLogFile + " (" + Err + ")");
+                               SecureLogFile + " (" + EC.message() + ")");
     }
     getContext().setSecureLog(OS);
   }
 
   // Write the message.
-  int CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
+  unsigned CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
   *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
       << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":"
       << LogMessage + "\n";
@@ -495,7 +694,7 @@ bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
 
 /// ParseDirectiveSecureLogReset
 ///  ::= .secure_log_reset
-bool DarwinAsmParser::ParseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
+bool DarwinAsmParser::parseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.secure_log_reset' directive");
 
@@ -506,9 +705,9 @@ bool DarwinAsmParser::ParseDirectiveSecureLogReset(StringRef, SMLoc IDLoc) {
   return false;
 }
 
-/// ParseDirectiveSubsectionsViaSymbols
+/// parseDirectiveSubsectionsViaSymbols
 ///  ::= .subsections_via_symbols
-bool DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.subsections_via_symbols' directive");
 
@@ -521,14 +720,14 @@ bool DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc) {
 
 /// ParseDirectiveTBSS
 ///  ::= .tbss identifier, size, align
-bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) {
   SMLoc IDLoc = getLexer().getLoc();
   StringRef Name;
-  if (getParser().ParseIdentifier(Name))
+  if (getParser().parseIdentifier(Name))
     return TokError("expected identifier in directive");
 
   // Handle the identifier as the key symbol.
-  MCSymbol *Sym = getContext().GetOrCreateSymbol(Name);
+  MCSymbol *Sym = getContext().getOrCreateSymbol(Name);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
@@ -536,7 +735,7 @@ bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
 
   int64_t Size;
   SMLoc SizeLoc = getLexer().getLoc();
-  if (getParser().ParseAbsoluteExpression(Size))
+  if (getParser().parseAbsoluteExpression(Size))
     return true;
 
   int64_t Pow2Alignment = 0;
@@ -544,7 +743,7 @@ bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
   if (getLexer().is(AsmToken::Comma)) {
     Lex();
     Pow2AlignmentLoc = getLexer().getLoc();
-    if (getParser().ParseAbsoluteExpression(Pow2Alignment))
+    if (getParser().parseAbsoluteExpression(Pow2Alignment))
       return true;
   }
 
@@ -567,7 +766,7 @@ bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
 
   getStreamer().EmitTBSSSymbol(getContext().getMachOSection(
                                  "__DATA", "__thread_bss",
-                                 MCSectionMachO::S_THREAD_LOCAL_ZEROFILL,
+                                 MachO::S_THREAD_LOCAL_ZEROFILL,
                                  0, SectionKind::getThreadBSS()),
                                Sym, Size, 1 << Pow2Alignment);
 
@@ -577,9 +776,9 @@ bool DarwinAsmParser::ParseDirectiveTBSS(StringRef, SMLoc) {
 /// ParseDirectiveZerofill
 ///  ::= .zerofill segname , sectname [, identifier , size_expression [
 ///      , align_expression ]]
-bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
+bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) {
   StringRef Segment;
-  if (getParser().ParseIdentifier(Segment))
+  if (getParser().parseIdentifier(Segment))
     return TokError("expected segment name after '.zerofill' directive");
 
   if (getLexer().isNot(AsmToken::Comma))
@@ -587,7 +786,7 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   Lex();
 
   StringRef Section;
-  if (getParser().ParseIdentifier(Section))
+  if (getParser().parseIdentifier(Section))
     return TokError("expected section name after comma in '.zerofill' "
                     "directive");
 
@@ -596,7 +795,7 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   if (getLexer().is(AsmToken::EndOfStatement)) {
     // Create the zerofill section but no symbol
     getStreamer().EmitZerofill(getContext().getMachOSection(
-                                 Segment, Section, MCSectionMachO::S_ZEROFILL,
+                                 Segment, Section, MachO::S_ZEROFILL,
                                  0, SectionKind::getBSS()));
     return false;
   }
@@ -607,11 +806,11 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
 
   SMLoc IDLoc = getLexer().getLoc();
   StringRef IDStr;
-  if (getParser().ParseIdentifier(IDStr))
+  if (getParser().parseIdentifier(IDStr))
     return TokError("expected identifier in directive");
 
   // handle the identifier as the key symbol.
-  MCSymbol *Sym = getContext().GetOrCreateSymbol(IDStr);
+  MCSymbol *Sym = getContext().getOrCreateSymbol(IDStr);
 
   if (getLexer().isNot(AsmToken::Comma))
     return TokError("unexpected token in directive");
@@ -619,7 +818,7 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
 
   int64_t Size;
   SMLoc SizeLoc = getLexer().getLoc();
-  if (getParser().ParseAbsoluteExpression(Size))
+  if (getParser().parseAbsoluteExpression(Size))
     return true;
 
   int64_t Pow2Alignment = 0;
@@ -627,7 +826,7 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   if (getLexer().is(AsmToken::Comma)) {
     Lex();
     Pow2AlignmentLoc = getLexer().getLoc();
-    if (getParser().ParseAbsoluteExpression(Pow2Alignment))
+    if (getParser().parseAbsoluteExpression(Pow2Alignment))
       return true;
   }
 
@@ -654,17 +853,117 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   //
   // FIXME: Arch specific.
   getStreamer().EmitZerofill(getContext().getMachOSection(
-                               Segment, Section, MCSectionMachO::S_ZEROFILL,
+                               Segment, Section, MachO::S_ZEROFILL,
                                0, SectionKind::getBSS()),
                              Sym, Size, 1 << Pow2Alignment);
 
   return false;
 }
 
+/// ParseDirectiveDataRegion
+///  ::= .data_region [ ( jt8 | jt16 | jt32 ) ]
+bool DarwinAsmParser::parseDirectiveDataRegion(StringRef, SMLoc) {
+  if (getLexer().is(AsmToken::EndOfStatement)) {
+    Lex();
+    getStreamer().EmitDataRegion(MCDR_DataRegion);
+    return false;
+  }
+  StringRef RegionType;
+  SMLoc Loc = getParser().getTok().getLoc();
+  if (getParser().parseIdentifier(RegionType))
+    return TokError("expected region type after '.data_region' directive");
+  int Kind = StringSwitch<int>(RegionType)
+    .Case("jt8", MCDR_DataRegionJT8)
+    .Case("jt16", MCDR_DataRegionJT16)
+    .Case("jt32", MCDR_DataRegionJT32)
+    .Default(-1);
+  if (Kind == -1)
+    return Error(Loc, "unknown region type in '.data_region' directive");
+  Lex();
+
+  getStreamer().EmitDataRegion((MCDataRegionType)Kind);
+  return false;
+}
+
+/// ParseDirectiveDataRegionEnd
+///  ::= .end_data_region
+bool DarwinAsmParser::parseDirectiveDataRegionEnd(StringRef, SMLoc) {
+  if (getLexer().isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.end_data_region' directive");
+
+  Lex();
+  getStreamer().EmitDataRegion(MCDR_DataRegionEnd);
+  return false;
+}
+
+/// parseVersionMin
+///  ::= .ios_version_min major,minor[,update]
+///  ::= .macosx_version_min major,minor[,update]
+bool DarwinAsmParser::parseVersionMin(StringRef Directive, SMLoc Loc) {
+  int64_t Major = 0, Minor = 0, Update = 0;
+  int Kind = StringSwitch<int>(Directive)
+    .Case(".watchos_version_min", MCVM_WatchOSVersionMin)
+    .Case(".tvos_version_min", MCVM_TvOSVersionMin)
+    .Case(".ios_version_min", MCVM_IOSVersionMin)
+    .Case(".macosx_version_min", MCVM_OSXVersionMin);
+  // Get the major version number.
+  if (getLexer().isNot(AsmToken::Integer))
+    return TokError("invalid OS major version number");
+  Major = getLexer().getTok().getIntVal();
+  if (Major > 65535 || Major <= 0)
+    return TokError("invalid OS major version number");
+  Lex();
+  if (getLexer().isNot(AsmToken::Comma))
+    return TokError("minor OS version number required, comma expected");
+  Lex();
+  // Get the minor version number.
+  if (getLexer().isNot(AsmToken::Integer))
+    return TokError("invalid OS minor version number");
+  Minor = getLexer().getTok().getIntVal();
+  if (Minor > 255 || Minor < 0)
+    return TokError("invalid OS minor version number");
+  Lex();
+  // Get the update level, if specified
+  if (getLexer().isNot(AsmToken::EndOfStatement)) {
+    if (getLexer().isNot(AsmToken::Comma))
+      return TokError("invalid update specifier, comma expected");
+    Lex();
+    if (getLexer().isNot(AsmToken::Integer))
+      return TokError("invalid OS update number");
+    Update = getLexer().getTok().getIntVal();
+  if (Update > 255 || Update < 0)
+    return TokError("invalid OS update number");
+    Lex();
+  }
+
+  const Triple &T = getContext().getObjectFileInfo()->getTargetTriple();
+  Triple::OSType ExpectedOS = Triple::UnknownOS;
+  switch ((MCVersionMinType)Kind) {
+  case MCVM_WatchOSVersionMin: ExpectedOS = Triple::WatchOS; break;
+  case MCVM_TvOSVersionMin:    ExpectedOS = Triple::TvOS;    break;
+  case MCVM_IOSVersionMin:     ExpectedOS = Triple::IOS;     break;
+  case MCVM_OSXVersionMin:     ExpectedOS = Triple::MacOSX;  break;
+  }
+  if (T.getOS() != ExpectedOS)
+    Warning(Loc, Directive + " should only be used for " +
+            Triple::getOSTypeName(ExpectedOS) + " targets");
+
+  if (LastVersionMinDirective.isValid()) {
+    Warning(Loc, "overriding previous version_min directive");
+    Note(LastVersionMinDirective, "previous definition is here");
+  }
+  LastVersionMinDirective = Loc;
+
+  // We've parsed a correct version specifier, so send it to the streamer.
+  getStreamer().EmitVersionMin((MCVersionMinType)Kind, Major, Minor, Update);
+
+  return false;
+}
+
 namespace llvm {
 
 MCAsmParserExtension *createDarwinAsmParser() {
   return new DarwinAsmParser;
 }
 
-}
+} // end llvm namespace