Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper fat Mach-O creation #100

Merged
merged 4 commits into from
Jul 3, 2018
Merged

Proper fat Mach-O creation #100

merged 4 commits into from
Jul 3, 2018

Conversation

woodruffw
Copy link
Member

Closes #99.

Introduces `MachOFile#segment_alignment`, `SegmentCommand#guess_align`,
and `Sections::MAX_SECT_ALIGN`.

Closes #99.
Slightly better than having "\x00"s scattered throughout
the code.
@woodruffw
Copy link
Member Author

woodruffw commented Jul 3, 2018

Could you give the changes in this branch a try, @sashkab?

(I'll be in front of Mac in a few days to test them with lipo myself).

@sashkab
Copy link

sashkab commented Jul 3, 2018

Umm... the only exposure to ruby I have is due to Homebrew. I tried and couldn't figure out how to install updated version into hombrew to test it using my formula. If you can, point me to steps to upgrade the gem?Thanks!

@woodruffw
Copy link
Member Author

The simplest way to test it is probably just to clone the repo:

$ git clone https://github.com/Homebrew/ruby-macho
$ cd ruby-macho

...and then load it into irb:

$ irb -Ilib -rmacho

From there, you should be able to call methods like MachO::Tools.merge_machos with no trouble.

@sashkab
Copy link

sashkab commented Jul 3, 2018

Thanks. Looks good to me now:

irb(main):002:0> libs = ["/tmp/uopenssl-20180702-16887-vjpn5r/openssl-1.0.2o/build-i386/libcrypto.1.0.0.dylib","/tmp/uopenssl-20180702-16887-vjpn5r/openssl-1.0.2o/build-x86_64/libcrypto.1.0.0.dylib"]
=> ["/tmp/uopenssl-20180702-16887-vjpn5r/openssl-1.0.2o/build-i386/libcrypto.1.0.0.dylib", "/tmp/uopenssl-20180702-16887-vjpn5r/openssl-1.0.2o/build-x86_64/libcrypto.1.0.0.dylib"]
irb(main):003:0> MachO::Tools.merge_machos("/tmp/fix1.dylib", *libs)
=> 3649920
$ lipo -info /tmp/fix1.dylib
Architectures in the fat file: /tmp/fix1.dylib are: i386 x86_64
$ file  /tmp/fix1.dylib
/tmp/fix1.dylib: Mach-O universal binary with 2 architectures: [i386:Mach-O dynamically linked shared library i386] [x86_64]
/tmp/fix1.dylib (for architecture i386):	Mach-O dynamically linked shared library i386
/tmp/fix1.dylib (for architecture x86_64):	Mach-O 64-bit dynamically linked shared library x86_64

@woodruffw
Copy link
Member Author

Awesome! I'll do some cleanup on the changes, and hopefully we'll have a fixed version vendored in Homebrew in a day or two 😄

@sashkab
Copy link

sashkab commented Jul 3, 2018

Great, thank you @woodruffw!

This now calculates alignments correctly, and pads the resulting
Fat Mach-O so that individual Mach-O slices are page-aligned.
@woodruffw woodruffw changed the title [WIP] Proper fat Mach-O creation Proper fat Mach-O creation Jul 3, 2018
@woodruffw woodruffw merged commit dcba883 into master Jul 3, 2018
@woodruffw woodruffw deleted the lipo-fixes branch July 3, 2018 15:58
@lock lock bot added the outdated label Jan 1, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unrecognized Mach-O magic
2 participants