Menu

#240 Code signing compressed executable not working for cross-compiled binaries

None
pending
nobody
None
5
2015-03-31
2015-03-08
No

UPX is a fantastic utility and I think it could be of benefit in helping me reduce the size of an app I would like to submit to the iOS App Store. As you know code signing makes executables less compressible, but if you compress them first with UPX then code sign, you keep the space savings.

Unfortunately, while UPX + code signing seems to work just fine for executables for Mac apps, it doesn't work when generating an iOS executable (usually armv7 or arm64 architecture).

I have put together a small example at https://github.com/sseefried/upx-apple-cross-compile-bug.

The error message I receive is:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate: object: /Users/sseefried/code/scratch/upx-apple-cross-compile/test malformed object (size field of section 0 in LC_SEGMENT command 2 greater than the segment)

test: the codesign_allocate helper tool cannot be found or used

In other bugs reports you have asked for a dump of the headers using "otool -l". I have provided these in the repo in the file otool-diff-uncompressed-vs-compressed.txt (You can view the file directly at http://goo.gl/AtkEHD)

As I said, it works fine when I'm produce an x86_64 executable, but when I'm trying to cross compile to armv7 or arm64 I get the error above.

Discussion

  • Sean Seefried

    Sean Seefried - 2015-03-08

    I'm sorry, that link above has a period on the end of it. The correct link is:
    https://github.com/sseefried/upx-apple-cross-compile-bug

     
  • Sean Seefried

    Sean Seefried - 2015-03-08

    I am very happy to provide more information, promptly, upon request. I realise you may
    not have a Mac machine to test on.

     
  • John Reiser

    John Reiser - 2015-03-25

    Decoding the error message "(size field of section 0 in LC_SEGMENT command 2 greater than the segment)" while refering to file otool-diff-uncompressed-vs-compressed.txt: "LC_SEGMENT command 2" is the one in the righthand column with segname=__TEXT; it has vmsize=0x1078 and filesize=3522. "Section 0" of that LC_SEGMENT is sectname=__text (the only one) with size 0xe78 which is 3704. Now 3704 is greater than 3522 by 182, so that difference is the complaint.

    Now to investigate why. (I have a Mac Mini with Yosemite, but last weekend the 5 GB download of Xcode failed. Trying again...)

     
  • John Reiser

    John Reiser - 2015-03-28
    • status: open --> pending
     
  • John Reiser

    John Reiser - 2015-03-28

    Fixed in changeset: 2405:d00b712eb763
    (file src/p_mach.cpp)
    repository at https://www.pysol.org:4443/hg/upx.hg

     
  • Sean Seefried

    Sean Seefried - 2015-03-31

    Great! Thank you so much. Is there a way to donate monetarily to this project?

     

    Last edit: Sean Seefried 2015-03-31
  • Sean Seefried

    Sean Seefried - 2015-03-31

    John, because of your fix I have been able to reduce the size of my app on the app store from 46.7M to 8.5M! Just incredible.

     

Log in to post a comment.

MongoDB Logo MongoDB