Revert "Centralize the information about which object format we are using."
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 14 Aug 2015 15:48:41 +0000 (15:48 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 14 Aug 2015 15:48:41 +0000 (15:48 +0000)
This reverts commit r245047.

It was failing on the darwin bots. The problem was that when running

./bin/llc -march=msp430

llc gets to

  if (TheTriple.getTriple().empty())
    TheTriple.setTriple(sys::getDefaultTargetTriple());

Which means that we go with an arch of msp430 but a triple of
x86_64-apple-darwin14.4.0 which fails badly.

That code has to be updated to select a triple based on the value of
march, but that is not a trivial fix.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245062 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCObjectFileInfo.h
lib/MC/MCContext.cpp
lib/MC/MCObjectFileInfo.cpp
lib/MC/MCParser/AsmParser.cpp
lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/CodeGen/X86/statepoint-stackmap-format.ll
test/MC/COFF/ARM/directive-type-diagnostics.s [new file with mode: 0644]

index 571189790d296b35bde1bdb9ec097474ef33ffc1..b9cea06161d0df16839d48a971b01b00bfc240f3 100644 (file)
@@ -331,9 +331,13 @@ public:
     return EHFrameSection;
   }
 
+  enum Environment { IsMachO, IsELF, IsCOFF };
+  Environment getObjectFileType() const { return Env; }
+
   Reloc::Model getRelocM() const { return RelocM; }
 
 private:
+  Environment Env;
   Reloc::Model RelocM;
   CodeModel::Model CMModel;
   MCContext *Ctx;
index e8fb6a95ebe04896fce4898e5614c0b2b15fe526..c601c56f3952d1406f24ab1954d989af18758466 100644 (file)
@@ -162,15 +162,13 @@ MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
                                       bool IsTemporary) {
   if (MOFI) {
-    switch (MOFI->getTargetTriple().getObjectFormat()) {
-    case Triple::COFF:
+    switch (MOFI->getObjectFileType()) {
+    case MCObjectFileInfo::IsCOFF:
       return new (Name, *this) MCSymbolCOFF(Name, IsTemporary);
-    case Triple::ELF:
+    case MCObjectFileInfo::IsELF:
       return new (Name, *this) MCSymbolELF(Name, IsTemporary);
-    case Triple::MachO:
+    case MCObjectFileInfo::IsMachO:
       return new (Name, *this) MCSymbolMachO(Name, IsTemporary);
-    case Triple::UnknownObjectFormat:
-      break;
     }
   }
   return new (Name, *this) MCSymbol(MCSymbol::SymbolKindUnset, Name,
index ade4b496ec7f69d6fbbb19f917c89b8b8c8eb1e3..576827a72d56f372d0cc096697addcd8c5c20e3b 100644 (file)
@@ -767,19 +767,25 @@ void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
 
   TT = TheTriple;
 
-  Triple::ObjectFormatType Format = TT.getObjectFormat();
-  switch (Format) {
-  case Triple::MachO:
+  Triple::ArchType Arch = TT.getArch();
+  // FIXME: Checking for Arch here to filter out bogus triples such as
+  // cellspu-apple-darwin. Perhaps we should fix in Triple?
+  if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
+       Arch == Triple::arm || Arch == Triple::thumb ||
+       Arch == Triple::aarch64 ||
+       Arch == Triple::ppc || Arch == Triple::ppc64 ||
+       Arch == Triple::UnknownArch) &&
+      TT.isOSBinFormatMachO()) {
+    Env = IsMachO;
     initMachOMCObjectFileInfo(TT);
-    break;
-  case Triple::COFF:
+  } else if ((Arch == Triple::x86 || Arch == Triple::x86_64 ||
+              Arch == Triple::arm || Arch == Triple::thumb) &&
+             (TT.isOSWindows() && TT.getObjectFormat() == Triple::COFF)) {
+    Env = IsCOFF;
     initCOFFMCObjectFileInfo(TT);
-    break;
-  case Triple::ELF:
+  } else {
+    Env = IsELF;
     initELFMCObjectFileInfo(TT);
-    break;
-  case Triple::UnknownObjectFormat:
-    break;
   }
 }
 
@@ -795,9 +801,7 @@ MCSection *MCObjectFileInfo::getDwarfTypesSection(uint64_t Hash) const {
 }
 
 void MCObjectFileInfo::InitEHFrameSection() {
-  Triple::ObjectFormatType Format = TT.getObjectFormat();
-  switch (Format) {
-  case Triple::MachO:
+  if (Env == IsMachO)
     EHFrameSection =
       Ctx->getMachOSection("__TEXT", "__eh_frame",
                            MachO::S_COALESCED |
@@ -805,20 +809,14 @@ void MCObjectFileInfo::InitEHFrameSection() {
                            MachO::S_ATTR_STRIP_STATIC_SYMS |
                            MachO::S_ATTR_LIVE_SUPPORT,
                            SectionKind::getReadOnly());
-    break;
-  case Triple::ELF:
+  else if (Env == IsELF)
     EHFrameSection =
         Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);
-    break;
-  case Triple::COFF:
+  else
     EHFrameSection =
       Ctx->getCOFFSection(".eh_frame",
                           COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |
                           COFF::IMAGE_SCN_MEM_READ |
                           COFF::IMAGE_SCN_MEM_WRITE,
                           SectionKind::getDataRel());
-    break;
-  case Triple::UnknownObjectFormat:
-    break;
-  }
 }
index 0089f8f4ebcc883aad729951f11b98253bd2bd3c..3f45b3d85a38683294cc6187f908681683e82b6e 100644 (file)
@@ -513,19 +513,17 @@ AsmParser::AsmParser(SourceMgr &SM, MCContext &Ctx, MCStreamer &Out,
   Lexer.setBuffer(SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer());
 
   // Initialize the platform / file format parser.
-  switch (Ctx.getObjectFileInfo()->getTargetTriple().getObjectFormat()) {
-  case Triple::COFF:
+  switch (Ctx.getObjectFileInfo()->getObjectFileType()) {
+  case MCObjectFileInfo::IsCOFF:
     PlatformParser.reset(createCOFFAsmParser());
     break;
-  case Triple::MachO:
+  case MCObjectFileInfo::IsMachO:
     PlatformParser.reset(createDarwinAsmParser());
     IsDarwin = true;
     break;
-  case Triple::ELF:
+  case MCObjectFileInfo::IsELF:
     PlatformParser.reset(createELFAsmParser());
     break;
-  case Triple::UnknownObjectFormat:
-    break;
   }
 
   PlatformParser->Initialize(*this);
index 7d7a09f2694edbc657509bc1ea89871f55deb9bc..9292f660735a5714dd32e9f471d33f4c3042b9c8 100644 (file)
@@ -4055,10 +4055,10 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
 
 /// ParseDirective parses the arm specific directives
 bool AArch64AsmParser::ParseDirective(AsmToken DirectiveID) {
-  Triple::ObjectFormatType Format =
-      getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
-  bool IsMachO = Format == Triple::MachO;
-  bool IsCOFF = Format == Triple::COFF;
+  const MCObjectFileInfo::Environment Format =
+    getContext().getObjectFileInfo()->getObjectFileType();
+  bool IsMachO = Format == MCObjectFileInfo::IsMachO;
+  bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
 
   StringRef IDVal = DirectiveID.getIdentifier();
   SMLoc Loc = DirectiveID.getLoc();
index 21414b085ffd431a5385649df5b2310d99860ab0..2d291bf8652cbcd5128a05d32364b5610016aef1 100644 (file)
@@ -5173,11 +5173,18 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
     return true;
   }
 
+  enum {
+    COFF = (1 << MCObjectFileInfo::IsCOFF),
+    ELF = (1 << MCObjectFileInfo::IsELF),
+    MACHO = (1 << MCObjectFileInfo::IsMachO)
+  };
   static const struct PrefixEntry {
     const char *Spelling;
     ARMMCExpr::VariantKind VariantKind;
+    uint8_t SupportedFormats;
   } PrefixEntries[] = {
-      {"lower16", ARMMCExpr::VK_ARM_LO16}, {"upper16", ARMMCExpr::VK_ARM_HI16},
+    { "lower16", ARMMCExpr::VK_ARM_LO16, COFF | ELF | MACHO },
+    { "upper16", ARMMCExpr::VK_ARM_HI16, COFF | ELF | MACHO },
   };
 
   StringRef IDVal = Parser.getTok().getIdentifier();
@@ -5192,6 +5199,25 @@ bool ARMAsmParser::parsePrefix(ARMMCExpr::VariantKind &RefKind) {
     return true;
   }
 
+  uint8_t CurrentFormat;
+  switch (getContext().getObjectFileInfo()->getObjectFileType()) {
+  case MCObjectFileInfo::IsMachO:
+    CurrentFormat = MACHO;
+    break;
+  case MCObjectFileInfo::IsELF:
+    CurrentFormat = ELF;
+    break;
+  case MCObjectFileInfo::IsCOFF:
+    CurrentFormat = COFF;
+    break;
+  }
+
+  if (~Prefix->SupportedFormats & CurrentFormat) {
+    Error(Parser.getTok().getLoc(),
+          "cannot represent relocation in the current file format");
+    return true;
+  }
+
   RefKind = Prefix->VariantKind;
   Parser.Lex();
 
@@ -8665,10 +8691,10 @@ bool ARMAsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
 
 /// parseDirective parses the arm specific directives
 bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
-  Triple::ObjectFormatType Format =
-      getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
-  bool IsMachO = Format == Triple::MachO;
-  bool IsCOFF = Format == Triple::COFF;
+  const MCObjectFileInfo::Environment Format =
+    getContext().getObjectFileInfo()->getObjectFileType();
+  bool IsMachO = Format == MCObjectFileInfo::IsMachO;
+  bool IsCOFF = Format == MCObjectFileInfo::IsCOFF;
 
   StringRef IDVal = DirectiveID.getIdentifier();
   if (IDVal == ".word")
@@ -8833,9 +8859,8 @@ void ARMAsmParser::onLabelParsed(MCSymbol *Symbol) {
 ///  ::= .thumbfunc symbol_name
 bool ARMAsmParser::parseDirectiveThumbFunc(SMLoc L) {
   MCAsmParser &Parser = getParser();
-  Triple::ObjectFormatType Format =
-      getContext().getObjectFileInfo()->getTargetTriple().getObjectFormat();
-  bool IsMachO = Format == Triple::MachO;
+  const auto Format = getContext().getObjectFileInfo()->getObjectFileType();
+  bool IsMachO = Format == MCObjectFileInfo::IsMachO;
 
   // Darwin asm has (optionally) function name after .thumb_func direction
   // ELF doesn't
index 2b7f077a4b293c8de526bb335ada3ca5653d77fc..e18476cee53c50c756c0d5ac6bad68fc1a6d93b7 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llc < %s -mtriple="x86_64-pc-linux-gnu" | FileCheck %s
-; RUN: llc < %s -mtriple="x86_64-pc-unknown-elf" | FileCheck %s
+; RUN: llc < %s -mtriple="x86_64-pc-win64-coff" | FileCheck %s
 
 ; This test is a sanity check to ensure statepoints are generating StackMap
 ; sections correctly.  This is not intended to be a rigorous test of the 
diff --git a/test/MC/COFF/ARM/directive-type-diagnostics.s b/test/MC/COFF/ARM/directive-type-diagnostics.s
new file mode 100644 (file)
index 0000000..f8a52cd
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: not llvm-mc -triple arm-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
+// RUN: not llvm-mc -triple armeb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
+// RUN: not llvm-mc -triple thumb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
+// RUN: not llvm-mc -triple thumbeb-coff -filetype asm -o /dev/null %s 2>&1 | FileCheck %s
+
+        .type symbol 32
+// CHECK: error: expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '%<type>' or "<type>"
+// CHECK: .type symbol 32
+// CHECK:              ^
+