[lld] b1c3c2e - [lld-macho] Fix order file arch filtering

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon May 10 12:46:38 PDT 2021


Author: Jez Ng
Date: 2021-05-10T15:45:54-04:00
New Revision: b1c3c2e4fc219c23e311fe56d8687fdf6bba3c89

URL: https://github.com/llvm/llvm-project/commit/b1c3c2e4fc219c23e311fe56d8687fdf6bba3c89
DIFF: https://github.com/llvm/llvm-project/commit/b1c3c2e4fc219c23e311fe56d8687fdf6bba3c89.diff

LOG: [lld-macho] Fix order file arch filtering

We had a hardcoded check and a stale TODO, written back when we only had
support for one architecture.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D102154

Added: 
    

Modified: 
    lld/MachO/Driver.cpp
    lld/MachO/InputFiles.cpp
    lld/MachO/Target.h
    lld/test/MachO/order-file.s

Removed: 
    


################################################################################
diff  --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 00c9b41f2a55..a5d74853d3e7 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -421,13 +421,13 @@ static void parseOrderFile(StringRef path) {
                           .StartsWith("ppc:", CPU_TYPE_POWERPC)
                           .StartsWith("ppc64:", CPU_TYPE_POWERPC64)
                           .Default(CPU_TYPE_ANY);
+
+    if (cpuType != CPU_TYPE_ANY && cpuType != target->cpuType)
+      continue;
+
     // Drop the CPU type as well as the colon
     if (cpuType != CPU_TYPE_ANY)
       line = line.drop_until([](char c) { return c == ':'; }).drop_front();
-    // TODO: Update when we extend support for other CPUs
-    if (cpuType != CPU_TYPE_ANY && cpuType != CPU_TYPE_X86_64 &&
-        cpuType != CPU_TYPE_ARM64)
-      continue;
 
     constexpr std::array<StringRef, 2> fileEnds = {".o:", ".o):"};
     for (StringRef fileEnd : fileEnds) {
@@ -869,7 +869,6 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
 
   errorHandler().logName = args::getFilenameWithoutExe(argsArr[0]);
   stderrOS.enable_colors(stderrOS.has_colors());
-  // TODO: Set up error handler properly, e.g. the errorLimitExceededMsg
 
   MachOOptTable parser;
   InputArgList args = parser.parse(argsArr.slice(1));

diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index bab2a7b263a9..26230a0d7a03 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -222,7 +222,7 @@ Optional<MemoryBufferRef> macho::readFile(StringRef path) {
       return None;
     }
 
-    if (read32be(&arch[i].cputype) != target->cpuType ||
+    if (read32be(&arch[i].cputype) != static_cast<uint32_t>(target->cpuType) ||
         read32be(&arch[i].cpusubtype) != target->cpuSubtype)
       continue;
 

diff  --git a/lld/MachO/Target.h b/lld/MachO/Target.h
index eb34c4575132..9141dccddbf4 100644
--- a/lld/MachO/Target.h
+++ b/lld/MachO/Target.h
@@ -70,7 +70,7 @@ class TargetInfo {
   }
 
   uint32_t magic;
-  uint32_t cpuType;
+  llvm::MachO::CPUType cpuType;
   uint32_t cpuSubtype;
 
   uint64_t pageZeroSize;

diff  --git a/lld/test/MachO/order-file.s b/lld/test/MachO/order-file.s
index c185572c2389..63dfca1d8f63 100644
--- a/lld/test/MachO/order-file.s
+++ b/lld/test/MachO/order-file.s
@@ -127,7 +127,7 @@ x86_64:-[Foo doFoo:andBar:]
 _main
 
 #--- ord-arch-nomatch
-ppc:-[Foo doFoo:andBar:]
+arm64:-[Foo doFoo:andBar:]
 _main
 -[Foo doFoo:andBar:]
 


        


More information about the llvm-commits mailing list