Adding VERSION_MIN load command to MachO file on Darwin

Steven Wu stevenwu at apple.com
Thu Jul 23 19:49:35 PDT 2015


> On Jul 23, 2015, at 7:29 PM, Rafael EspĂ­ndola <rafael.espindola at gmail.com> wrote:
> 
> Testcase?
> 
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).

Thanks

Steven
> In particular, is it the intention that an assembly file with no directives will get this load command?
> 
> On Jul 23, 2015 9:51 PM, "Steven Wu" <stevenwu at apple.com <mailto:stevenwu at apple.com>> wrote:
> 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)
>      S->getAssembler().setRelaxAll(true);
>    return S;
> 
> Thanks
> 
> Steven
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150723/57777439/attachment.html>


More information about the llvm-commits mailing list