Search code examples
macosshared-libraries32bit-64bitdynamic-librarylibtool-xcode

Convert 32 bit dynamic library to 64 bit for osx


How to compile existing dynamic library to 64 bit compatible for mac platform. I don't have code base for library, have only xxx.dylib.

file xxx.dylib

xxx.dylib: Mach-O universal binary with 2 architectures: [ppc:Mach-O dynamically linked shared library ppc] [i386:Mach-O dynamically linked shared library i386] xxx.dylib (for architecture ppc): Mach-O dynamically linked shared library ppc xxx.dylib (for architecture i386): Mach-O dynamically linked shared library i386


Solution

  • You can't. There's no way to recompile the dylib to 64bit without the original source code.

    Worse, even some crazy binary post processing is not really feasible.

    The dylib is in Mach-o final fat binary executable format. The main challenges are:

    • 32bit x86 intel opcodes in i386 slice - you can't effortlessly convert those to x86-64, this would be effectively a different binary
    • most likely 0x1000 origin of virtual memory for __TEXT start (that would typically be 0x1000000 in x86-64), you maybe could get away with it the dylib turns to be not using ASLR / PIE , but still that's very likely to break
    • legacy Mach-O load commands, eventually some might stop being supported by the kernel