On-device compiling

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

On-device compiling

Postby Eso8 » Fri Mar 11, 2016 1:14 am

At the beginning of this year I decided to follow in saurik's footsteps by porting programs to iOS. Through my journey I realised how difficult the actual process is (not to mention compiling all programs solely on device without aid of a Mac, Xcode etc...) I am rather new to programming so it has been a steep learning curve, especially considering how little information and support is available for such a proprietary operating platform.

I would like to share what I have learnt for others to learn, publishing all patches, and build processes of my builds. Before I distribute the binaries and publish such tutorials, I need to ensure the programs are built near perfect and stable as can be, any advice would be greatly appreciated, I have a few particular matters I need to resolve that requires specialist knowledge in the area, which seems nonexistent elsewhere hence this post.

Proprietary SDK's and reliability

All programs are build off a stock iOS SDK, how does one know whether a particular header is genuinely unavailable on iOS or Apple just likes to keep such information away from public. How does one obtain a complete SDK to develop low-level programs? I understand that Apple provides XNU SDK's (Jonathan touches on the topic http://newosxbook.com/tools/iOSBinaries.html) but I am unsure how to safely merge both SDK's together without causing catastrophic failures.

Compiling

Unfortunately GNU's GCC compiler was too complex for me to port, anyone wish to take up the challenge? (looking at you Jonathan ;) ...) For the builds I am using the Clang compiler and trying to figure out the global compiler flags for the 100+ programs, as previously mentioned I am aiming for stability and the longevity of these programs, '-Wall -no-cpp-precomp, -fno-common and -pipe' are heavily utilised, what else could I utilise to get the best builds? (note that I wish to distribute build scripts too, so portability is paramount)

Universal Binaries

I am baffled as to why 99% of Autoconf's configure process breaks compiling when multiple architectures are specified, (i.e., headers scream fatal errors, ld fails with unrecognised architecture for xxx etc...) yet specifying only one architecture compiles perfectly without errors at all. I wish to avoid compiling each program arch specific and merging them with lipo as it will result in many many many files (quite a daunting task), any recommendations are warmly welcomed.

Besides those matters I am rather confident in the compilation process, I tried to retain 'Apple's way' build policy and applied most available patches. I have built and rebuilt all programs many times and now I am just stuck on those specific matters. For the curious, the list below are the programs I compiled, all built on a iOS 8.1 SDK for arm64. (and yes Jonathan, all unnecessarily packaged in Debian format :lol: ). Thanks in advance for the help.

    adv_cmds-163
    apr-1.5.2
    apr-util-1.5.4
    autoconf-2.69
    automake-1.15
    bash-4.3.30
    basic_cmds-55
    berkeleydb-4.6.21
    berkeleydb-6.1.26
    bison-3.0.4
    bootstrap_cmds-93
    bzip2-1.0.6
    ca-certificates
    cctools-877.5
    cmake-3.4.1
    coreutils-8.24
    curl-7.46.0
    dbus-1.11.0
    debugserver
    developer_cmds-62
    diffutils-3.3
    diskdev_cmds-582
    expat-2.1.0
    file-5.25
    file_cmds-251
    findutils-4.6.0
    flex-2.6.0
    gawk-4.1.3
    gcrypt-1.6.4
    gdbm-1.11
    gettext-0.19.7
    git-2.7.0
    glib-2.47.5
    gnupg-2.1.10
    grep-2.22
    groff-1.22.3
    gzip-1.6
    inetutils-1.9.4
    IOKitTools-97
    ld64-253.3
    less-481
    libarchive-3.1.2
    libassuan-2.4.2
    libcxx-3.7.1
    libevent-2.0.22
    libffi-3.2.1
    libgpg-error-1.21
    libiconv-1.14
    libksba-1.3.3
    libpipeline-1.4.1
    libtool-2.4.6
    libxml2-2.9.3
    lsof-53
    m4-1.4.17
    mDNSResponder-576.30.4
    make-4.1
    man-db-2.7.5
    mysql-5.7.10
    nano-2.5.1
    ncurses-6.0
    network_cmds-481.20.1
    openpam-20140912
    openpam-modules-140.20.2
    openssh-7.1p1
    openssl-0.9.8zh
    openssl-1.0.2e
    p7zip-15.09
    pam-32.1
    patch-2.7.5
    pcre-8.37
    perl-5.22.1
    pkg-config-0.29
    python-3.5.1
    readline-6.3
    rsync-3.1.2
    scons-2.4.0
    screen-4.3.1
    sed-4.2.2
    serf-1.3.8
    shell_cmds-187
    sqlite-3.7.17
    subversion-1.9.3
    sudo-1.8.15
    swig-3.0.8
    system_cmds-671.10.3
    tcp_wrappers-20
    texinfo-6.0
    top-107
    unrar-5.3.9
    unzip-6.0
    uuid-1.6.2
    vim-7.4
    wget-1.17.1
    whois-5.2.7
    xml2-0.5
    xz-5.2.2
    zip-30
    zlib-1.2.8
Eso8
 
Posts: 1
Joined: Sun Nov 30, 2014 8:27 pm

Re: On-device compiling

Postby morpheus » Fri Mar 11, 2016 2:55 pm

The short answer to a very long process:

- Most, if not all MacOSX.sdk headers can be copied directly over iPhoneOS.sdk.
- For WatchOS and TvOS, you might need to #undef and #define __WATCHOS/__TVOS_PROHIBITED. Like, who is AAPL to tell us what's allowed and what's not?
- For specific mach/ headers, you need to get rid of #error "unsupported architecture"
- Then for makefiles replace CC=gcc with "gcc-iphone" or "gcc-armv7" or "gcc-armv7k" , as per the small wrapper scripts I've provided.

(though honestly, you do know that if the binaries are anywhere near useful, there's my universal version for that already? Does the world need another binary repository?)
morpheus
Site Admin
 
Posts: 530
Joined: Thu Apr 11, 2013 6:24 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 1 guest