Adding VERSION_MIN load command to MachO file on Darwin

Steven Wu stevenwu at
Thu Jul 23 18:49:33 PDT 2015

Hi Jim

Here is a patch that forces all the MachO objects on Darwin to have version_min load command. When MCObjectStreamer is created, it will inferred the default version_min from target triple. When there is a version_min directive in the assembly input, it will overwrite the default. By doing so, it will not affect the assembly source that already have version_min directive, but force a version_min load command on the others.

The only relevant part of the change is following and the rest is just updating the test for correct load command number and offset in the file:

diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp
index 53cd131..116ef09 100644
--- a/lib/MC/MCMachOStreamer.cpp
+++ b/lib/MC/MCMachOStreamer.cpp
@@ -493,6 +493,16 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB,
                                       bool LabelSections) {
   MCMachOStreamer *S = new MCMachOStreamer(Context, MAB, OS, CE,
                                            DWARFMustBeAtTheEnd, LabelSections);
+  const Triple &TT = Context.getObjectFileInfo()->getTargetTriple();
+  if (TT.isOSDarwin()) {
+    unsigned Major, Minor, Update;
+    TT.getOSVersion(Major, Minor, Update);
+    // If there is a version specified, Major will be non-zero.
+    if (Major)
+      S->EmitVersionMin((TT.isMacOSX() ?
+                        MCVM_OSXVersionMin : MCVM_IOSVersionMin),
+                        Major, Minor, Update);
+  }
   if (RelaxAll)
   return S;



-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Force-the-MachO-generated-for-Darwin-to-have-VERSION.patch
Type: application/octet-stream
Size: 117995 bytes
Desc: not available
URL: <>

More information about the llvm-commits mailing list