Apple cctools and ld64 port for Linux, *BSD and macOS

Overview

Apple cctools and ld64 port for Linux, *BSD and macOS

Current Version: cctools: 973.0.1, ld64: 609.
Originally ported by cjacker.

SUPPORTED HOSTS

SUPPORTED OPERATING SYSTEMS:

Linux, Android (Termux), FreeBSD,
Mac OS X, iOS, OpenBSD and NetBSD

SUPPORTED HOST ARCHITECTURES:

x86, x86_64, arm, arm64/aarch64

SUPPORTED TARGET ARCHITECTURES

armv6, armv7, armv7s, arm64, arm64e,
arm64_32 (untested), i386, x86_64, x86_64h,
armv6m, armv7k, armv7m and armv7em

arm64e requires Apple LLVM/Clang.

SUPPORTED TARGET OPERATING SYSTEMS

macOS, iOS, tvOS, watchOS, bridgeOS, Mac Catalyst,
iOS Simluator, watchOS Simulator, DriverKit

Not all of the targets have been tested.

DEPENDENCIES

Clang 3.4+

SDKs with .tdb stubs (>= Xcode 7) require the TAPI library to be installed.
=> https://github.com/tpoechtrager/apple-libtapi

musl-libc based systems require the musl-fts library to be installed. => https://github.com/pullmoll/musl-fts

Optional, but recommended:

llvm-devel (For Link Time Optimization Support)
uuid-devel (For ld64 -random_uuid Support)
llvm-devel + xar-devel (For ld64 -bitcode_bundle Support)
libdispatch (For parallelism in ld64 / libcodedirectory.c)

You can find xar here.
Do not install libxar-dev on Ubuntu, it's a different package.

INSTALLATION

Install Apple's TAPI library:

This step is only required if you intend to use SDKs with .tdb stubs.

git clone https://github.com/tpoechtrager/apple-libtapi.git
cd apple-libtapi
[INSTALLPREFIX=/home/user/cctools] ./build.sh
./install.sh

Install cctools and ld64:

git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/cctools
./configure \
    [--prefix=/home/user/cctools] \
    [--with-libtapi=/home/user/cctools] \
    [--target=
   
    ] \
    [--with-llvm-config=...]
make
make install

   

target = i386-apple-darwin11, x86_64-apple-darwin11, arm-apple-darwin11, ...

TRAVIS CI

Build Status

Issues
  • arm64 support

    arm64 support

    I am trying to build cctools for arm64 under Fedora Linux

    ./configure --target=arm64-apple-darwin checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... Invalid configuration arm64-apple-darwin': machinearm64-apple' not recognized configure: error: /bin/sh ./config.sub arm64-apple-darwin failed

    Maybe you know what can cause this issue?

    opened by dmigous 29
  • Build failed on Cygwin

    Build failed on Cygwin

    Hi, I tried building the cctools , but when I run make it fails at this point

    make[1]: Entering directory '/home/Damilare/cctools-port/cctools/libobjc2'
    /bin/sh ../libtool    --mode=compile gcc -DPACKAGE_NAME=\"cctools\" -DPACKAGE_TARNAME=\"cctools\" -DPACKAGE_VERSION=\"877.5\" -DPACKAGE_STRING=\"cctools\ 877.5\" -DPACKAGE_BUGREPORT=\"[email protected]\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DEMULATED_HOST_CPU_TYPE=12 -DEMULATED_HOST_CPU_SUBTYPE=0 -D__STDC_LIMIT_MACROS=1 -D__STDC_CONSTANT_MACROS=1 -DHAVE_UUID_UUID_H=1 -I.  -DTYPE_DEPENDENT_DISPATCH -DGNUSTEP -D__OBJC_RUNTIME_INTERNAL__=1 -D_XOPEN_SOURCE=500 -D__BSD_VISIBLE=1 -D_DEFAULT_SOURCE=1 -DNO_SELECTOR_MISMATCH_WARNINGS  -std=gnu99 -Wall -O3 -D__LARGE64_FILES -fno-PIC -c -o libobjc_la-NSBlocks.lo `test -f 'NSBlocks.m' || echo './'`NSBlocks.m
    libtool: compile:  gcc -DPACKAGE_NAME=\"cctools\" -DPACKAGE_TARNAME=\"cctools\" -DPACKAGE_VERSION=\"877.5\" "-DPACKAGE_STRING=\"cctools 877.5\"" -DPACKAGE_BUGREPORT=\"[email protected]\" -DPACKAGE_URL=\"\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -DEMULATED_HOST_CPU_TYPE=12 -DEMULATED_HOST_CPU_SUBTYPE=0 -D__STDC_LIMIT_MACROS=1 -D__STDC_CONSTANT_MACROS=1 -DHAVE_UUID_UUID_H=1 -I. -DTYPE_DEPENDENT_DISPATCH -DGNUSTEP -D__OBJC_RUNTIME_INTERNAL__=1 -D_XOPEN_SOURCE=500 -D__BSD_VISIBLE=1 -D_DEFAULT_SOURCE=1 -DNO_SELECTOR_MISMATCH_WARNINGS -std=gnu99 -Wall -O3 -D__LARGE64_FILES -fno-PIC -c NSBlocks.m  -DDLL_EXPORT -DPIC -o .libs/libobjc_la-NSBlocks.o
    gcc: error: spawn: No such file or directory
    Makefile:545: recipe for target 'libobjc_la-NSBlocks.lo' failed
    make[1]: *** [libobjc_la-NSBlocks.lo] Error 1
    make[1]: Leaving directory '/home/Damilare/cctools-port/cctools/libobjc2'
    Makefile:402: recipe for target 'all-recursive' failed
    make: *** [all-recursive] Error 1
    
    opened by darmie 23
  • Unable to create target

    Unable to create target

    After I finally got all dependencies compiled including cctools, I am getting this error

     ./arm-apple-darwin11-clang ../../test.c -arch arm64 -c
    error: unable to create target: 'No available targets are compatible with this triple.'
    1 error generated.
    
    opened by darmie 15
  • Any chance for an iPhoneSimulator build?

    Any chance for an iPhoneSimulator build?

    I tried building the cross tools against the iOS simulator SDK. It successfully compiles everything, but then fils in the final step when checking the toolchain.

    *** checking toolchain ***
    
    ld: file not found: /usr/lib/system/libsystem_kernel.dylib for architecture i386
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    Indeed that particular file does not exist, as it's named libsystem_sim_kernel.dylib in the simulator SDK. Any ideas where I should look to correct this one last issue?

    Out of curiosity I tried simlinking the above file to the version without _sim_ in the name, but it got me an infinite linker loop or something i386-apple-darwin11-ld: ./ld.hpp:109: const ld::File::Ordinal ld::File::Ordinal::nextCounter() const: Assertioncounter() < 0xffff' failed.`

    opened by karalabe 12
  • debug builds

    debug builds

    When I tried to build debug builds with clang-3.5 it complained that cant find dsymutil. And back then I couldn't find dsymutil port for linux that will work for me. Now I discovered that clang-3.7 has some llvm-dsymutil, I made symlink /usr/bin/dsymutil => llvm-dsymutil

    And now I am getting following error once any -g flag e.g -g3 present

    [email protected]:/vagrant/target/ios/arm-apple-darwin/armv7/debug/ambrosia_adapters/tmp$ /vagrant/target/native/release/apple_cctools/arm-apple-darwin/usr/bin/arm-apple-darwin-clang -DHAVE_CONFIG_H  -miphoneos-version-min=7.1 -target arm-apple-darwin -arch armv7 -pipe -isysroot /home/vagrant/SDKs/iOS/iPhoneOS7.1.sdk -stdlib=libstdc++ -isystem /home/vagrant/SDKs/iOS/iPhoneOS7.1.sdk/usr/include/c++/4.2.1 -O0 -g ./conftest.c 
    error: failed to compute relocation: ARM_RELOC_VANILLA
    error: failed to compute relocation: ARM_RELOC_VANILLA
    error: failed to compute relocation: ARM_RELOC_VANILLA
    error: failed to compute relocation: ARM_RELOC_VANILLA
    error: failed to compute relocation: ARM_RELOC_VANILLA
    

    If somebody can help me, I'll be happy :-)

    opened by dmigous 10
  • Toolchain points to the wrong ldid executable

    Toolchain points to the wrong ldid executable

    How do I fix this? Toolchain is trying to use the ldid.exe that came along with cygwin64, do you have any idea how I can correct this?

          6 [main] ldid (12968) C:\cygwin64\bin\ldid.exe: *** fatal error - cygheap base mismatch detected - 0x1802F3408/0x180304408.
    This problem is probably due to using incompatible versions of the cygwin DLL.
    Search for cygwin1.dll using the Windows Start->Find/Search facility
    and delete all but the most recent version.  The most recent version *should*
    reside in x:\cygwin\bin, where 'x' is the drive on which you have
    installed the cygwin distribution.  Rebooting is also suggested if you
    are unable to find another cygwin DLL.
    
    opened by darmie 8
  • Fix sign issues in PowerPC relocation code.

    Fix sign issues in PowerPC relocation code.

    Now negative numbers are properly sign extended again. Fixes linking of STLport, which failed to link in the exception handling related section.

    The important part is that operands in arithemtic are signed again. Thus, if a substraction results in a negative number it is properly saved in an (u)int64_t value, formerly all upper 32bits were always unsed causing issues.

    opened by lordhoto 8
  • Usage example

    Usage example

    It is not exactly a issue, is more a begginer request.

    Could be nice have some usage example with a 'hello world' or a start point. I have compiled in Arch Linux i686 system and now i want make a 'hello world' to run on iPhone 3G but i don´t know how start it or where see an example.

    Could anyone put me in correct way please?

    Thanks in advance!

    opened by semeion 8
  • openssl issue while build iOS tool chain

    openssl issue while build iOS tool chain

    I got below erros while build iOS tool chain cctools$ ./configure --prefix=<path>/cctools --with-libtapi=<path>/cctools cctools$ make

    fatal error: too many errors emitted, stopping now [-ferror-limit=] 20 errors generated. Makefile:460: recipe for target 'libstuff_la-arch.lo' failed make[1]: *** [libstuff_la-arch.lo] Error 1 make[1]: Leaving directory '/mnt/hdd/opt/code/x-compiler/cctools-port/cctools/libstuff' Makefile:416: recipe for target 'all-recursive' failed make: *** [all-recursive] Error 1

    Please help me with above issue.

    opened by Dayananda87 7
  • arm64e display not support.

    arm64e display not support.

    It seems that support for arm64e has been substantially completed, but it is not supported on the display by the file command.

    arm-apple-darwin11-clang -arch arm64e -o hello hello.c
    file hello
    hello: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>
    
    # iPhone7 Plus iOS11.2 jailbroken (arm64)
    sudo ldid -Sent.xml hello && sudo mv hello /usr/bin/
    hello
    Bad CPU type in executable
    
    opened by okanon 7
  • SDK version 10.0 and up not noticed by build.sh

    SDK version 10.0 and up not noticed by build.sh

    change the line where the SDK-Version is read from the archive name to: SDK_VERSION=$(echo $1 | grep -P -o "[0-9][0-9].[0-9]+" | head -1) if [ -z "$SDK_VERSION" ]; then SDK_VERSION=$(echo $1 | grep -P -o "[0-9].[0-9]+" | head -1) if [ -z "$SDK_VERSION" ]; then echo "iPhoneOS Version must be in the SDK filename!" 1>&2 exit 1 fi fi (there is surely a better way to do this, I am not very familiar with sh scripts) or something similar so that version 10.0 and up are noticed by the script.

    opened by SimonSuckut 7
  • codesign issue with files with space

    codesign issue with files with space

    Hi,

    Thank you very much for the sigtool addition! Just a small remark, it fails to sign files with spaces.

    In file /cctools/include/stuff/port.h On line 60: snprintf(codesign_command, sizeof(codesign_command), "%s -s - -f %s", codesign, filename);
    Can be replaced with something like (quotes added): snprintf(codesign_command, sizeof(codesign_command), "%s -s - -f '%s'", codesign, filename); \

    opened by etrinh 1
  • ld64: macOS LTO doesn’t get linked

    ld64: macOS LTO doesn’t get linked

    When compiling ld64 doesn’t have an install name for liblto.dylib after doing some digging I did the following change https://github.com/Gcenx/cctools-port/commit/83269d6b8fc72806a3a8e643a98d5104989e4f76

    After this (and regenerating Makefile.in) ld64 compiled and does contain an libLTO install name of @rpath/libLTO.1.dylib and there’s a correctly configured path to said dylib.

    opened by Gcenx 0
  • [bug] ld doesn't support ppc

    [bug] ld doesn't support ppc

    When cctools is configured to target powerpc-apple-darwin, as assembles powerpc assembly without issue, but ld will not link it.

    [email protected]:~/test/helloworld$ powerpc-apple-darwin-ld a.out -o test -arch ppc
    ld: unknown/unsupported architecture name for: -arch ppc
    [email protected]:~/test/helloworld$ powerpc-apple-darwin-ld -v
    @(#)PROGRAM:ld  PROJECT:ld64-609
    BUILD 17:46:02 Mar  3 2022
    configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
    LTO support using: LLVM version 10.0.0 (static support for 26, runtime is 26)```
    opened by ChrisNonyminus 1
  • Turn off outputIsMappableFile when building to osx-arm64

    Turn off outputIsMappableFile when building to osx-arm64

    This fixes #117.

    Further investigation shows that with the newest version of cctools-port + sigtool for signing then whenever the outputIsMappableFile=true which triggers wholeBuffer = (uint8_t *)mmap(NULL, _fileSize, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); then the output binary will not work on M1 macs. This can be triggered when either (a) the file already exists, or (b) the path is explicitly specified (relative or absolute). I'm not sure why the mmap option is necessary, and everything appears to run fine turning it off (and it is off in regular usage when you target a new file without a path specified!).

    opened by erykoff 0
  • Using compilers with `-o absolute-path/to/target` is broken for recent cctools

    Using compilers with `-o absolute-path/to/target` is broken for recent cctools

    With the latest build of cctools in conda-forge, using Clang or GFortran with an absolute path to the output target results in a broken binary.

    Here is a simple reproducer for Fortran code. With a test file sanitycheckf.f90:

    program main; print *, "Fortran compilation is working."; end program
    

    And using the arm64-apple-darwin20.0.0-gfortran compiler, I see the following on an arm64 Macbook:

    % rm sanitycheckf
    % gfortran build/meson-private/sanitycheckf.f90 -o /Users/rgommers/code/scipy/sanitycheckf       
    % ./sanitycheckf 
    zsh: killed     ./sanitycheckf
    % rm sanitycheckf
    % gfortran build/meson-private/sanitycheckf.f90 -o sanitycheckf 
    % ./sanitycheckf                                              
     Fortran compilation is working.
    

    Showing that a simple absolute path is enough to trigger the problem.

    On https://github.com/conda-forge/cctools-and-ld64-feedstock/issues/50#issuecomment-1047433827 @erykoff observed the same issue with a hello world C program and Clang.

    Copying the produced binary (cp sanitycheckf sanitycheckf2 && cp sanitycheckf2 sanitycheckf) makes the problem go away. Downgrading to an older cctools version also made the problem go away.

    opened by rgommers 3
Releases(cctools-877.8-ld64-253.9-1)
Owner
Thomas Pöchtrager
Thomas Pöchtrager
Tiny implementation of the GNU/Linux CGroupFS (sans resource controllers) as a PUFFS or FUSE filesystem for BSD platforms

CGrpFS CGrpFS is a tiny implementation of the GNU/Linux CGroup filesystem for BSD platforms. It takes the form of a either a PUFFS or FUSE filesystem,

null 11 Jan 10, 2022
Qt5 "Hello, world!" app for Linux, BSD, Windows, Mac.

hello world in qt5 Contributions in all forms (code, bug reports, community engagement, localization, etc) are warmly welcomed. Development activity I

Jakob Flierl 2 Jan 26, 2022
Allows to swap the Fn key and left Control key and other tweaks on Macbook Pro and Apple keyboards in GNU/Linux

A patched hid-apple kernel module UPDATE August 2020: swap_fn_leftctrl is now built-in in Linux 5.8 ?? UPDATE Jun 2020: New feature added (swap_fn_f13

Zakhar Semenov 298 Aug 6, 2022
My experiments with Linux for the Apple M1 platform, based on Asahi and Corellium patches

Linux kernel ============ There are several guides for kernel developers and users. These guides can be rendered in a number of formats, like HTML an

Danny Lin 9 Oct 24, 2021
Utility to install kexts, Frameworks and PrivateFrameworks in the System of macOS. For macOS Monterey 12 and Big Sur 11

Command-Line-SnapShot-Mounter Credit: chris1111 Apple This utility uses the macOS terminal Command Line SnapShot Mounter is an utility that allows you

chris1111 19 Jul 15, 2022
Macos-arm64-emulation - A guide for emulating macOS arm64e on an x86-based host.

macos-arm64-emulation Use the following guide to download and configure all of the necessary tools and files for emulating the macOS arm64e kernel. Th

Cylance 218 Jul 28, 2022
BSD-licensed Yamaha FM sound cores (OPM, OPN, OPL, and others)

ymfm ymfm is a collection of BSD-licensed Yamaha FM sound cores (OPM, OPN, OPL, and others), written by Aaron Giles Supported environments This code s

Aaron Giles 145 Jul 29, 2022
A bootloader and experimentation playground for Apple Silicon

m1n1: an experimentation playground for Apple Silicon (And to some extent a Linux bootloader) Building You need an aarch64-linux-gnu-gcc cross-compile

Asahi Linux 2.1k Aug 5, 2022
Upload arbitrary data via Apple's Find My network.

Send My Send My allows you to to upload abritrary data from devices without an internet connection by (ab)using Apple's Find My network. The data is b

Positive Security 1.5k Aug 7, 2022
Apple TV 2/3 Jailbreak

Blackb0x Apple TV 2/3 Jailbreak Untethered jailbreak tool that runs on modern versions of macOS. Devices supported: Apple TV 3,2 (A1469) (iOS 8.4.x un

null 310 Jul 31, 2022
An apple IIe emulator for the Raspberry Pi.

ApplePi "applepi" is an apple IIe emulator for the Raspberry Pi, but can be built (I think) on most Linux distributions. It runs easily on a Pi4B, and

J.B.Ward 11 Jul 31, 2022
Swift Framework for Apple Health Integration with Terra Enabling Developers LTD.

TerraSwift This library allows developers to connect to TERRA ENABLING DEVELOPERS LTD. through Swift (implemented with Swift5.0). This library uses He

null 7 Mar 18, 2022
Protobuf for Proxyman app - Include Apple Silicon & Intel architecture

Protobuf for Proxyman macOS app Protobuf for Proxyman app - Include Apple Silicon & Intel architecture How to build Open the project on the latest Xco

Proxyman 6 Nov 29, 2021
Get the current average CPU frequency on Apple M1 chips.

M1 CPU Frequency Get the current average CPU frequency on Apple M1 chips. Usage Download the precompiled binary from the releases and run it in the te

BitesPotatoBacks 14 Jul 31, 2022
Adds proper Apple Pencil support to Unity's InputSystem.

This project aims to create an Apple Pencil device for Unity's InputSystem package. The problem: Unity does not fully integrate with Apple Pencil. App

Oliver Smith 9 Jul 15, 2022
A pre-boot execution environment for Apple boards built on top of checkra1n

archOS A pre-boot execution environment for Apple boards built on top of checkra1n - currently based off the Checkra1n/PongoOS Repo. Building on macOS

ScarletAI 2 Jan 17, 2022
Fairplay research - Some RE work on Apple's Fairplay DRM

Poor Man's Kernel Debuger This project loads FairplayIOKit kernel driver into userspace and make it possible for LLDB to debug How to Compile In proje

pwnorz 117 Jul 21, 2022
A library to handle Apple Property List format in binary or XML

libplist A small portable C library to handle Apple Property List files in binary or XML format. Features The project provides an interface to read an

libimobiledevice 408 Jul 24, 2022
C Library for Apple Firmware (Amalgam)

DeviceTree Minimal code to deal with Apple's DeviceTree format. The Makefile builds dt and pmgr binaries, but you should also be able to use dt.c + dt

Hack Different 25 Feb 10, 2022