M680x0 / M680x0-mono-repo

Mono-Repo LLVM Backend for Motorola M68000 (Work in Progress)
42 stars 5 forks source link

m68k-linux-gnu triplet is not understood by clang #5

Closed glaubitz closed 4 years ago

glaubitz commented 4 years ago

I have played around with clang a bit and noticed that the m68k-linux-gnu triplet is not working as expected:

glaubitz@epyc:..llvm-build/bin> ./clang-11 -target m68k-linux-gnu ~/hello.c -o hello.m68k
clang-11: error: unknown target triple 'm68k-unknown-linux-gnu', please use -triple or -arch
glaubitz@epyc:..llvm-build/bin>

Trying the same for aarch64 works just fine:

glaubitz@epyc:..llvm-build/bin> ./clang-11 -target aarch64-linux-gnu ~/hello.c -o hello.arm64
glaubitz@epyc:..llvm-build/bin> file hello.arm64
hello.arm64: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, not stripped
glaubitz@epyc:..llvm-build/bin>
glaubitz commented 4 years ago

I have made these changes now which are not enough:

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9a340142a24..fbac8dba23c 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2042,6 +2042,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       "i686-linux-android",   "i386-gnu",              "i486-gnu",
       "i586-gnu",             "i686-gnu"};

+  static const char *const M68kLibDirs[] = {"/lib32", "/lib"};
+  static const char *const M68kTriples[] = {
+       "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"};
+
   static const char *const MIPSLibDirs[] = {"/lib"};
   static const char *const MIPSTriples[] = {
       "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
@@ -2275,6 +2279,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
     }
     break;
+  case llvm::Triple::m68k:
+    LibDirs.append(begin(M68kLibDirs), end(M68kLibDirs));
+    TripleAliases.append(begin(M68kTriples), end(M68kTriples));
+    break;
   case llvm::Triple::mips:
     LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
     TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 99c23e71eb0..6fe2379021e 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -102,6 +102,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
     if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
       return "aarch64_be-linux-gnu";
     break;
+
+  case llvm::Triple::m68k:
+    if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
+      return "m68k-linux-gnu";
+    break;
+
   case llvm::Triple::mips: {
     std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
     if (D.getVFS().exists(SysRoot + "/lib/" + MT))
@@ -468,6 +474,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
     break;
   }
+  case llvm::Triple::m68k:
+    LibDir = "lib";
+    Loader = "ld.so.1";
+    break;
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
   case llvm::Triple::mips64:
@@ -610,6 +620,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
       "/usr/include/armeb-linux-gnueabi"};
   const StringRef ARMEBHFMultiarchIncludeDirs[] = {
       "/usr/include/armeb-linux-gnueabihf"};
+  const StringRef M68kMultiarchIncludeDirs[] = {
+      "/usr/include/m68k-linux-gnu"};
   const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
   const StringRef MIPSELMultiarchIncludeDirs[] = {
       "/usr/include/mipsel-linux-gnu"};

I assume the most important thing is to add would be below clang/lib/Driver/ToolChains/Arch.

glaubitz commented 4 years ago

More changes:


diff --git a/clang/lib/Driver/ToolChains/Arch/M680x0.cpp b/clang/lib/Driver/ToolChains/Arch/M680x0.cpp
new file mode 100644
index 00000000000..9737694ca05
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Arch/M680x0.cpp
@@ -0,0 +1,91 @@
+//===--- M680x0.cpp - M680x0 Helpers for Tools ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "M680x0.h"
+#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/Options.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::tools;
+using namespace clang;
+using namespace llvm::opt;
+
+/// getM680x0TargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting.
+std::string m68k::getM680x0TargetCPU(const ArgList &Args) {
+  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
+    StringRef CPUName = A->getValue();
+
+    if (CPUName == "native") {
+      std::string CPU = std::string(llvm::sys::getHostCPUName());
+      if (!CPU.empty() && CPU != "generic")
+        return CPU;
+      else
+        return "";
+    }
+
+    return llvm::StringSwitch<const char *>(CPUName)
+        .Case("common", "generic")
+        .Case("68000", "68000")
+        .Case("68010", "68000")
+        .Case("68020", "68000")
+        .Case("68030", "68000")
+        .Case("68040", "68000")
+        .Case("68060", "68000")
+        .Default("");
+  }
+
+  return "";
+}
+
+const char *m68k::getM680x0AsmModeForCPU(StringRef Name) {
+  return llvm::StringSwitch<const char *>(Name)
+        .Case("68000", "-m68000")
+        .Case("68010", "-m60010")
+        .Case("68020", "-m680020")
+        .Case("68030", "-m68030")
+        .Case("68040", "-m68040")
+        .Case("68060", "-m68060")
+        .Default("-many");
+}
+
+void ppc::getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                               const ArgList &Args,
+                               std::vector<StringRef> &Features) {
+
+  handleTargetFeaturesGroup(Args, Features, options::OPT_m_m68k_Features_Group);
+
+  m68k::FloatABI FloatABI = ppc::getM680x0FloatABI(D, Args);
+  if (FloatABI == m68k::FloatABI::Soft)
+    Features.push_back("-hard-float");
+
+}
+
+m68k::FloatABI ppc::getM680x0FloatABI(const Driver &D, const ArgList &Args) {
+  m68k::FloatABI ABI = ppc::FloatABI::Invalid;
+  if (Arg *A =
+          Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) {
+
+    if (A->getOption().matches(options::OPT_msoft_float))
+      ABI = m68k::FloatABI::Soft;
+    else if (A->getOption().matches(options::OPT_mhard_float))
+      ABI = m68k::FloatABI::Hard;
+    }
+  }
+
+  // If unspecified, choose the default based on the platform.
+  if (ABI == m68k::FloatABI::Invalid) {
+    ABI = m68k::FloatABI::Hard;
+  }
+
+  return ABI;
+}
diff --git a/clang/lib/Driver/ToolChains/Arch/M680x0.h b/clang/lib/Driver/ToolChains/Arch/M680x0.h
new file mode 100644
index 00000000000..859bd7c0d8c
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Arch/M680x0.h
@@ -0,0 +1,43 @@
+//===--- M680x0.h - M680x0-specific Tool Helpers ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
+
+#include "clang/Driver/Driver.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Option/Option.h"
+#include <string>
+#include <vector>
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace m68k {
+
+enum class FloatABI {
+  Invalid,
+  Soft,
+  Hard,
+};
+
+FloatABI getM680x0FloatABI(const Driver &D, const llvm::opt::ArgList &Args);
+
+std::string getM680x0TargetCPU(const llvm::opt::ArgList &Args);
+const char *getM680x0AsmModeForCPU(StringRef Name);
+
+void getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                          const llvm::opt::ArgList &Args,
+                          std::vector<llvm::StringRef> &Features);
+
+} // end namespace m68k
+} // end namespace target
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9a340142a24..0394d99c6a7 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2042,6 +2042,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       "i686-linux-android",   "i386-gnu",              "i486-gnu",
       "i586-gnu",             "i686-gnu"};

+  static const char *const M680x0LibDirs[] = {"/lib32", "/lib"};
+  static const char *const M680x0Triples[] = {
+       "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"};
+
   static const char *const MIPSLibDirs[] = {"/lib"};
   static const char *const MIPSTriples[] = {
       "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
@@ -2275,6 +2279,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
     }
     break;
+  case llvm::Triple::m68k:
+    LibDirs.append(begin(M680x0LibDirs), end(M680x0LibDirs));
+    TripleAliases.append(begin(M680x0Triples), end(M680x0Triples));
+    break;
   case llvm::Triple::mips:
     LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
     TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 99c23e71eb0..cedb605f324 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -102,6 +102,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
     if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
       return "aarch64_be-linux-gnu";
     break;
+
+  case llvm::Triple::m68k:
+    if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
+      return "m68k-linux-gnu";
+    break;
+
   case llvm::Triple::mips: {
     std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
     if (D.getVFS().exists(SysRoot + "/lib/" + MT))
@@ -468,6 +474,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
     break;
   }
+  case llvm::Triple::m68k:
+    LibDir = "lib";
+    Loader = "ld.so.1";
+    break;
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
   case llvm::Triple::mips64:
@@ -610,6 +620,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
       "/usr/include/armeb-linux-gnueabi"};
   const StringRef ARMEBHFMultiarchIncludeDirs[] = {
       "/usr/include/armeb-linux-gnueabihf"};
+  const StringRef M680x0MultiarchIncludeDirs[] = {
+      "/usr/include/m68k-linux-gnu"};
   const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
   const StringRef MIPSELMultiarchIncludeDirs[] = {
       "/usr/include/mipsel-linux-gnu"};
glaubitz commented 4 years ago

Another update, still not working:

diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
index 6f25d3588eb..e703cff5824 100644
--- a/clang/lib/Driver/CMakeLists.txt
+++ b/clang/lib/Driver/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangDriver
   ToolChain.cpp
   ToolChains/Arch/AArch64.cpp
   ToolChains/Arch/ARM.cpp
+  ToolChains/Arch/M680x0.cpp
   ToolChains/Arch/Mips.cpp
   ToolChains/Arch/PPC.cpp
   ToolChains/Arch/RISCV.cpp
diff --git a/clang/lib/Driver/ToolChains/Arch/M680x0.cpp b/clang/lib/Driver/ToolChains/Arch/M680x0.cpp
new file mode 100644
index 00000000000..bfb80fc547f
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Arch/M680x0.cpp
@@ -0,0 +1,88 @@
+//===--- M680x0.cpp - M680x0 Helpers for Tools ------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "M680x0.h"
+#include "ToolChains/CommonArgs.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Driver/Options.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::tools;
+using namespace clang;
+using namespace llvm::opt;
+
+/// getM680x0TargetCPU - Get the (LLVM) name of the 68000 cpu we are targeting.
+std::string m68k::getM680x0TargetCPU(const ArgList &Args) {
+  if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
+    StringRef CPUName = A->getValue();
+
+    if (CPUName == "native") {
+      std::string CPU = std::string(llvm::sys::getHostCPUName());
+      if (!CPU.empty() && CPU != "generic")
+        return CPU;
+      else
+        return "";
+    }
+
+    return llvm::StringSwitch<const char *>(CPUName)
+        .Case("common", "generic")
+        .Case("68000", "68000")
+        .Case("68010", "68000")
+        .Case("68020", "68000")
+        .Case("68030", "68000")
+        .Case("68040", "68000")
+        .Case("68060", "68000")
+        .Default("");
+  }
+
+  return "";
+}
+
+const char *m68k::getM680x0AsmModeForCPU(StringRef Name) {
+  return llvm::StringSwitch<const char *>(Name)
+        .Case("68000", "-m68000")
+        .Case("68010", "-m60010")
+        .Case("68020", "-m680020")
+        .Case("68030", "-m68030")
+        .Case("68040", "-m68040")
+        .Case("68060", "-m68060")
+        .Default("-many");
+}
+
+void m68k::getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                               const ArgList &Args,
+                               std::vector<StringRef> &Features) {
+
+  m68k::FloatABI FloatABI = m68k::getM680x0FloatABI(D, Args);
+  if (FloatABI == m68k::FloatABI::Soft)
+    Features.push_back("-hard-float");
+
+}
+
+m68k::FloatABI m68k::getM680x0FloatABI(const Driver &D, const ArgList &Args) {
+  m68k::FloatABI ABI = m68k::FloatABI::Invalid;
+  if (Arg *A =
+          Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float)) {
+
+    if (A->getOption().matches(options::OPT_msoft_float))
+      ABI = m68k::FloatABI::Soft;
+    else if (A->getOption().matches(options::OPT_mhard_float))
+      ABI = m68k::FloatABI::Hard;
+  }
+
+  // If unspecified, choose the default based on the platform.
+  if (ABI == m68k::FloatABI::Invalid) {
+    ABI = m68k::FloatABI::Hard;
+  }
+
+  return ABI;
+}
diff --git a/clang/lib/Driver/ToolChains/Arch/M680x0.h b/clang/lib/Driver/ToolChains/Arch/M680x0.h
new file mode 100644
index 00000000000..859bd7c0d8c
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/Arch/M680x0.h
@@ -0,0 +1,43 @@
+//===--- M680x0.h - M680x0-specific Tool Helpers ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
+
+#include "clang/Driver/Driver.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Option/Option.h"
+#include <string>
+#include <vector>
+
+namespace clang {
+namespace driver {
+namespace tools {
+namespace m68k {
+
+enum class FloatABI {
+  Invalid,
+  Soft,
+  Hard,
+};
+
+FloatABI getM680x0FloatABI(const Driver &D, const llvm::opt::ArgList &Args);
+
+std::string getM680x0TargetCPU(const llvm::opt::ArgList &Args);
+const char *getM680x0AsmModeForCPU(StringRef Name);
+
+void getM680x0TargetFeatures(const Driver &D, const llvm::Triple &Triple,
+                          const llvm::opt::ArgList &Args,
+                          std::vector<llvm::StringRef> &Features);
+
+} // end namespace m68k
+} // end namespace target
+} // end namespace driver
+} // end namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_M680X0_H
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 9a340142a24..0394d99c6a7 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2042,6 +2042,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       "i686-linux-android",   "i386-gnu",              "i486-gnu",
       "i586-gnu",             "i686-gnu"};

+  static const char *const M680x0LibDirs[] = {"/lib32", "/lib"};
+  static const char *const M680x0Triples[] = {
+       "m68k-linux-gnu", "m68k-unknown-linux-gnu", "m68k-suse-linux"};
+
   static const char *const MIPSLibDirs[] = {"/lib"};
   static const char *const MIPSTriples[] = {
       "mips-linux-gnu", "mips-mti-linux", "mips-mti-linux-gnu",
@@ -2275,6 +2279,10 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
       BiarchTripleAliases.append(begin(X86_64Triples), end(X86_64Triples));
     }
     break;
+  case llvm::Triple::m680x0:
+    LibDirs.append(begin(M680x0LibDirs), end(M680x0LibDirs));
+    TripleAliases.append(begin(M680x0Triples), end(M680x0Triples));
+    break;
   case llvm::Triple::mips:
     LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs));
     TripleAliases.append(begin(MIPSTriples), end(MIPSTriples));
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
index 99c23e71eb0..cedb605f324 100644
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -102,6 +102,12 @@ std::string Linux::getMultiarchTriple(const Driver &D,
     if (D.getVFS().exists(SysRoot + "/lib/aarch64_be-linux-gnu"))
       return "aarch64_be-linux-gnu";
     break;
+
+  case llvm::Triple::m680x0:
+    if (D.getVFS().exists(SysRoot + "/lib/m68k-linux-gnu"))
+      return "m68k-linux-gnu";
+    break;
+
   case llvm::Triple::mips: {
     std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
     if (D.getVFS().exists(SysRoot + "/lib/" + MT))
@@ -468,6 +474,10 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
     Loader = HF ? "ld-linux-armhf.so.3" : "ld-linux.so.3";
     break;
   }
+  case llvm::Triple::m680x0:
+    LibDir = "lib";
+    Loader = "ld.so.1";
+    break;
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
   case llvm::Triple::mips64:
@@ -610,6 +620,8 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
       "/usr/include/armeb-linux-gnueabi"};
   const StringRef ARMEBHFMultiarchIncludeDirs[] = {
       "/usr/include/armeb-linux-gnueabihf"};
+  const StringRef M680x0MultiarchIncludeDirs[] = {
+      "/usr/include/m68k-linux-gnu"};
   const StringRef MIPSMultiarchIncludeDirs[] = {"/usr/include/mips-linux-gnu"};
   const StringRef MIPSELMultiarchIncludeDirs[] = {
       "/usr/include/mipsel-linux-gnu"};
-- 
2.27.0

Not sure what I'm missing.

glaubitz commented 4 years ago

I think there must be a bug in the target mapping code in llvm/lib/Support/Triple.cpp.

glaubitz commented 4 years ago

Okay, it's the linker format mapping that was missing which caused this error.

This fixes this particular problem:

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 0394d99c6a7..335e7295094 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -270,6 +270,9 @@ static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
   case llvm::Triple::armeb:
   case llvm::Triple::thumbeb:
     return isArmBigEndian(T, Args) ? "armelfb_linux_eabi" : "armelf_linux_eabi";
+  case llvm::Triple::m680x0:
+    return "m68kelf";
   case llvm::Triple::ppc:
     return "elf32ppclinux";
   case llvm::Triple::ppc64:
glaubitz commented 4 years ago

Okay, finally got it working:

glaubitz@epyc:/tmp/llvm-build> ./bin/clang -target m68k-linux-gnu ~/hello.c -o hello.m68k
glaubitz@epyc:/tmp/llvm-build> file hello.m68k 
hello.m68k: ELF 32-bit MSB executable, Motorola m68k, 68020, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux 3.2.0, not stripped
glaubitz@epyc:/tmp/llvm-build>
mshockwave commented 4 years ago

Fixed by #7