Question

I have a binary that I have linked with the -bind_at_load argument to ld. On an ELF system, I'd use -Wl,-z,now and then readelf to verify that the DT_BIND_NOW flag was enabled on the binary. On OS X, how can I verify that the the appropriate flag in the mach header has been ste to honor -bind_at_load? What is the name of the flag, and what value should it be set to?

Was it helpful?

Solution

You can use otool -l /path/to/binary and inspect the LC_DYLD_INFO_ONLY load command. If the binary was linked with -bind_at_load, then the lazy bind offset/size are equal to 0: dyld won’t lazily bind symbols and all symbols are bound when the binary is loaded.

Sample output:

  • With -bind_at_load

    Load command 4
                cmd LC_DYLD_INFO_ONLY
            cmdsize 48
         rebase_off 8192
        rebase_size 8
           bind_off 8200
          bind_size 224
      weak_bind_off 0
     weak_bind_size 0
      lazy_bind_off 0
     lazy_bind_size 0
         export_off 8424
        export_size 48
    
  • Without -bind_at_load

    Load command 4
                cmd LC_DYLD_INFO_ONLY
            cmdsize 48
         rebase_off 8192
        rebase_size 8
           bind_off 8200
          bind_size 128
      weak_bind_off 0
     weak_bind_size 0
      lazy_bind_off 8328
     lazy_bind_size 104
         export_off 8432
        export_size 48
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top