[PATCH] D81326: lld: improve the `-arch` handling for MachO

Saleem Abdulrasool via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 20:04:29 PDT 2020


compnerd created this revision.
compnerd added reviewers: smeenai, int3, Ktwu.
compnerd added a project: lld.
Herald added a project: LLVM.

Use the default target triple configured by the user to determine the
default architecture for `ld64.lld`.  Stash the architecture in the
configuration as when linking against TBDs, we will need to filter out
the symbols based upon the architecture.  Treat the Haswell slice as it
is equivalent to `x86_64` but with the extra Haswell extensions (e.g.
AVX2, FMA3, BMI1, etc).  This will make it easier to add new
architectures in the future.

This change also changes the failure mode where an invalid `-arch`
parameter will result in the linker exiting without further processing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81326

Files:
  lld/MachO/Config.h
  lld/MachO/Driver.cpp


Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -27,6 +27,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/BinaryFormat/Magic.h"
+#include "llvm/Config/config.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
@@ -90,10 +91,16 @@
 }
 
 static TargetInfo *createTargetInfo(opt::InputArgList &args) {
-  StringRef s = args.getLastArgValue(OPT_arch, "x86_64");
-  if (s != "x86_64")
-    error("missing or unsupported -arch " + s);
-  return createX86_64TargetInfo();
+  StringRef arch = llvm::Triple(LLVM_DEFAULT_TARGET_TRIPLE).getArchName();
+  config->arch =
+      llvm::MachO::getArchitectureFromName(args.getLastArgValue(OPT_arch, arch));
+  switch (config->arch) {
+  case llvm::MachO::AK_x86_64:
+  case llvm::MachO::AK_x86_64h:
+    return createX86_64TargetInfo();
+  default:
+    fatal("missing or unsupported -arch " + args.getLastArgValue(OPT_arch));
+  }
 }
 
 static std::vector<StringRef> getSearchPaths(opt::InputArgList &args) {
Index: lld/MachO/Config.h
===================================================================
--- lld/MachO/Config.h
+++ lld/MachO/Config.h
@@ -12,6 +12,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/TextAPI/MachO/Architecture.h"
 
 #include <vector>
 
@@ -26,6 +27,7 @@
   bool hasReexports = false;
   llvm::StringRef installName;
   llvm::StringRef outputFile;
+  llvm::MachO::Architecture arch;
   llvm::MachO::HeaderFileType outputType;
   std::vector<llvm::StringRef> searchPaths;
   llvm::DenseMap<llvm::StringRef, SymbolPriorityEntry> priorities;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81326.268988.patch
Type: text/x-patch
Size: 1774 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200606/232a3495/attachment.bin>


More information about the llvm-commits mailing list