[lld] r217486 - [mach-o]: implement -image_base option on Darwin.

Nick Kledzik kledzik at apple.com
Wed Sep 10 13:37:18 PDT 2014


Tim,

Thanks for breaking this out.

On Sep 10, 2014, at 3:39 AM, Tim Northover <tnorthover at apple.com> wrote:
> Author: tnorthover
> Date: Wed Sep 10 05:39:57 2014
> New Revision: 217486
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=217486&view=rev
> Log:
> [mach-o]: implement -image_base option on Darwin.
> 
> 
> Modified: lld/trunk/lib/Driver/DarwinLdOptions.td
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdOptions.td?rev=217486&r1=217485&r2=217486&view=diff
> ==============================================================================
> --- lld/trunk/lib/Driver/DarwinLdOptions.td (original)
> +++ lld/trunk/lib/Driver/DarwinLdOptions.td Wed Sep 10 05:39:57 2014
> @@ -142,6 +142,7 @@ def arch : Separate<["-"], "arch">,
> def sectalign : MultiArg<["-"], "sectalign", 3>,
>      MetaVarName<"<segname> <sectname> <alignment>">,
>      HelpText<"alignment for segment/section">;
> +def image_base : Separate<["-"], "image_base">;
> def t : Flag<["-"], "t">,
>      HelpText<"Print the names of the input files as ld processes them">;
> def v : Flag<["-"], "v”>,
Please add the alias “-seg1addr”. It is actually used more often.


> 
> Added: lld/trunk/test/mach-o/image-base.yaml
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/image-base.yaml?rev=217486&view=auto
> ==============================================================================
> --- lld/trunk/test/mach-o/image-base.yaml (added)
> +++ lld/trunk/test/mach-o/image-base.yaml Wed Sep 10 05:39:57 2014
> @@ -0,0 +1,14 @@
> +# RUN: lld -flavor darwin -arch x86_64 -macosx_version_min 10.9 %s -o %t -image_base 31415926530 %p/Inputs/libSystem.yaml
> +# RUN: macho-dump %t | FileCheck %s
> +
> +--- !native
> +defined-atoms:
> +   - name:            _main
> +     scope:           global
> +     content:         []
> +
> +  # Unfortunately, llvm-objdump and llvm-readobj are too generic and don't give
> +  # us easy access to the MachO segment model, so we have to check the uglier
> +  # macho-dump output.
> +# CHECK: 'segment_name', '__TEXT
> +# CHECK-NEXT: 'vm_addr', 3384796144944

This test case should actually be an error/warning.  The value for -image_base has to be page aligned (for final executables).

     [/tmp]> cc hello.c -seg1addr 31415926530
     ld: warning: -seg1addr not 4096 byte aligned, rounding up

But the page size (or segment alignment) can be changed by other command line options.  So either the check needs to be done in the validate() method, or the code in DarwinLdDriver::parse() needs to come after any options that can change the segment  size or alignment.

-Nick


> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list