<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks Rafael and Kevin<div class=""><br class=""></div><div class="">I will use llvm-objdump for now and the output is much readable for my tests. Whether adding the feature to dump macho load command to readobj is out of the scope for this problem and it will probably trigger more discussion. Here is the updated test:</div><div class=""><br class=""></div>// RUN: llvm-mc -triple x86_64-apple-macosx10.10.0 %s -filetype=obj -o - | llvm-objdump -macho -private-headers - | FileCheck %s<br class="">// RUN: llvm-mc -triple x86_64-apple-ios8.0.0 %s -filetype=obj -o - | llvm-objdump -macho -private-headers - | FileCheck %s --check-prefix=CHECK-IOS<br class="">// RUN: llvm-mc -triple x86_64-apple-darwin %s -filetype=obj -o - | llvm-objdump -macho -private-headers - | FileCheck %s --check-prefix=CHECK-DARWIN<br class=""><br class="">// Test version-min load command should be inferred from triple and should always be generated on Darwin<br class="">// CHECK: Load command 1<br class="">// CHECK:       cmd LC_VERSION_MIN_MACOSX<br class="">// CHECK:   cmdsize 16<br class="">// CHECK:   version 10.10<br class=""><br class="">// CHECK-IOS: Load command 1<br class="">// CHECK-IOS:       cmd LC_VERSION_MIN_IPHONEOS<br class="">// CHECK-IOS:   cmdsize 16<br class="">// CHECK-IOS:   version 8.0<br class=""><br class="">// CHECK-DARWIN-NOT: LC_VERSION_MIN<br class=""><br class=""><div class="">Thanks</div><div class=""><br class=""></div><div class="">Steven </div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 24, 2015, at 10:42 AM, Kevin Enderby <<a href="mailto:enderby@apple.com" class="">enderby@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Steven,<div class=""><br class=""></div><div class="">You might consider using llvm-objdump in your test with the -macho and -private-headers options.  This will print the load commands as the darwin native otool(1) program prints them.</div><div class=""><br class=""></div><div class="">Kev</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 24, 2015, at 9:59 AM, Steven Wu <<a href="mailto:stevenwu@apple.com" class="">stevenwu@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Rafael<div class=""><br class=""></div><div class="">I don’t see anyway to dump out MachO load commands using llvm-readobj. The feature is not implemented yet. I am happy to rewrite my test in the future when readobj is ready. There exists tests for assembly with directive already for iOS and OS X. This patch will not change their behavior. Update the patch to add iOS test and bare darwin macho tests.</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Steven</div><div class=""><br class=""></div><div class="">Here is the updated test:</div><div class=""><br class=""></div><div class="">// RUN: llvm-mc -triple x86_64-apple-macosx10.10.0 %s -filetype=obj -o - | macho-dump | FileCheck %s<br class="">// RUN: llvm-mc -triple x86_64-apple-ios8.0.0 %s -filetype=obj -o - | macho-dump | FileCheck %s --check-prefix=CHECK-IOS<br class="">// RUN: llvm-mc -triple x86_64-apple-darwin %s -filetype=obj -o - | macho-dump | FileCheck %s --check-prefix=CHECK-DARWIN<br class=""><br class="">// Test version-min load command should be inferred from triple and should always be generated on Darwin<br class="">// CHECK:  (('command', 36)<br class="">// CHECK:   ('size', 16)<br class="">// CHECK:   ('version, 657920)<br class="">// CHECK:   ('sdk, 0)<br class="">// CHECK:  ),<br class=""><br class="">// CHECK-IOS:  (('command', 37)<br class="">// CHECK-IOS:   ('size', 16)<br class="">// CHECK-IOS:   ('version, 524288)<br class="">// CHECK-IOS:   ('sdk, 0)<br class="">// CHECK-IOS:  ),<br class=""><br class=""><br class="">// CHECK-DARWIN: ('num_load_commands', 1)<br class="">// CHECK-DARWIN-NOT: 'version'<br class=""><br class=""></div><div class=""><br class=""></div><div class=""></div></div><span id="cid:B6F4C335-BB03-49AD-AF5F-D11A79D0BACB@apple.com" class=""><0001-Force-the-MachO-generated-for-Darwin-to-have-VERSION.patch></span><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""></div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 24, 2015, at 3:49 AM, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com" class="">rafael.espindola@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><p dir="ltr" class="">Strange, Gmail displayed only the first part of the patch.</p><p dir="ltr" class="">Please don't use macho dump on new tests, readobj is far more readable. </p><p dir="ltr" class="">Please explicitly test what happens when there is a directive in the assembly. Also test with a ios, osx and bare metal mach-o triples.</p><p dir="ltr" class="">Cheers, Rafael </p>
<div class="class= gmail_quot<blockquote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jul 23, 2015, at 7:29 PM, Rafael Espíndola <<a href="mailto:rafael.espindola@gmail.com" target="_blank" class="">rafael.espindola@gmail.com</a>> wrote:</div><br class=""><div class=""><p dir="ltr" class="">Testcase? </p></div></blockquote>There is a test case in the patch itself (test/MC/MachO/darwin-version-min-load-command.s). And it is my intention to give every object file a VERSION_MIN load command. It is desired/required (depending on how strong you wish) to have this load command on darwin so the linker can prevent or warn you when linking in object files that are not compatible (for example, linking object built for 10.10 when you want to be 10.5 compatible or linking iPhone simulator objects into OS X binary).</div><div class=""><br class=""></div><div class="">Thanks</div><div class=""><br class=""></div><div class="">Steven<br class=""><blockquote type="cite" class=""><div class=""><p dir="ltr" class="">In particular, is it the intention that an assembly file with no directives will get this load command?</p>
<div class="gmail_quote">On Jul 23, 2015 9:51 PM, "Steven Wu" <<a href="mailto:stevenwu@apple.com" target="_blank" class="">stevenwu@apple.com</a>> wrote:<br type="attribution" class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Jim<br class="">
<br class="">
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.<br class="">
<br class="">
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:<br class="">
<br class="">
diff --git a/lib/MC/MCMachOStreamer.cpp b/lib/MC/MCMachOStreamer.cpp<br class="">
index 53cd131..116ef09 100644<br class="">
--- a/lib/MC/MCMachOStreamer.cpp<br class="">
+++ b/lib/MC/MCMachOStreamer.cpp<br class="">
@@ -493,6 +493,16 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCAsmBackend &MAB,<br class="">
                                       bool LabelSections) {<br class="">
   MCMachOStreamer *S = new MCMachOStreamer(Context, MAB, OS, CE,<br class="">
                                            DWARFMustBeAtTheEnd, LabelSections);<br class="">
+  const Triple &TT = Context.getObjectFileInfo()->getTargetTriple();<br class="">
+  if (TT.isOSDarwin()) {<br class="">
+    unsigned Major, Minor, Update;<br class="">
+    TT.getOSVersion(Major, Minor, Update);<br class="">
+    // If there is a version specified, Major will be non-zero.<br class="">
+    if (Major)<br class="">
+      S->EmitVersionMin((TT.isMacOSX() ?<br class="">
+                        MCVM_OSXVersionMin : MCVM_IOSVersionMin),<br class="">
+                        Major, Minor, Update);<br class="">
+  }<br class="">
   if (RelaxAll)<br class="">
     S->getAssembler().setRelaxAll(true);<br class="">
   return S;<br class="">
<br class="">
Thanks<br class="">
<br class="">
Steven<br class="">
<br class="">
<br class="">_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank" class="">llvm-commits@cs.uiuc.edu</a><br class="">
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class="">
<br class=""></blockquote></div>
</div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br class=""></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div></body></html>