[llvm] 1ec03f3 - [dsymutil] Emit an error when the Mach-O exceeds the 4GB limit.

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 16:30:18 PDT 2021


Author: Jonas Devlieghere
Date: 2021-05-24T16:29:06-07:00
New Revision: 1ec03f3de5d580d85cc256058cc0d2dd254b9e1a

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

LOG: [dsymutil] Emit an error when the Mach-O exceeds the 4GB limit.

The Mach-O object file format is limited to 4GB because its used of
32-bit offsets in the header. It is possible for dsymutil to (silently)
emit an invalid binary. Instead of having consumers deal with this, emit
an error instead.

Added: 
    

Modified: 
    llvm/tools/dsymutil/dsymutil.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp
index 14dbaa9cbec6..f615d36b55fd 100644
--- a/llvm/tools/dsymutil/dsymutil.cpp
+++ b/llvm/tools/dsymutil/dsymutil.cpp
@@ -689,6 +689,19 @@ int main(int argc, char **argv) {
                                                Options.LinkOpts, SDKPath))
         return EXIT_FAILURE;
     }
+
+    // The Mach-O object file format is limited to 4GB. Make sure that we print
+    // an error when we emit an invalid Mach-O companion file. Leave the
+    // invalid object file around on disk for inspection.
+    ErrorOr<vfs::Status> stat =
+        Options.LinkOpts.VFS->status(OutputLocationOrErr->DWARFFile);
+    if (stat) {
+      if (stat->getSize() > std::numeric_limits<uint32_t>::max()) {
+        WithColor::error() << "the linked debug info exceeds the 4GB Mach-O "
+                              "object file format.";
+        return EXIT_FAILURE;
+      }
+    }
   }
 
   return EXIT_SUCCESS;


        


More information about the llvm-commits mailing list