0

EDIT 2015-29-10. II. In fact -arch armv7 instead of -arch arm64 and without lowering optimization, worked perfectly.

EDIT 2015-29-10. I. I tried to add

export CFLAGS="-O1"
export CXXFLAGS="-O1"

before configure, and had the same error, with a different file missing this time :

 "/usr/local/cctools-arm64-port/bin/ld" -demangle -dynamic -arch arm64 -iphoneos_version_min 5.0.0 -syslibroot /usr/local/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-4f79ac.o -lstdc++ -lSystem
ld: file not found: N?L

I also tried with -O0 optimization instead of -01, same result.

EDIT 2015-28-10. II. I did this :

./autogen.sh
export CC="clang -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
export CXX="clang++ -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"
./configure -v --host=arm-apple-darwin11 --prefix=/usr/local/lvm-cross/cctools-arm64-port
unset CC CXX
make && sudo make install

Then I tried a simple hello world on iDevice, with testcpp.cpp containing :

#include <iostream>
int main()
{
    std::cout << "oijo" << std::endl;
    return 0;
}

compiled with

clang++ -v -isysroot /usr/local/iPhoneOS8.4.sdk -target arm64-apple-darwin11 testcpp.cpp -o testcpp

which gave me :

clang version 3.7.0 (tags/RELEASE_370/final)
Target: arm64-apple-darwin11
Thread model: posix
 "/usr/local/llvm-ios/bin/clang++" -cc1 -triple arm64-apple-ios5.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name testcpp.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -target-cpu generic -target-feature +neon -target-abi darwinpcs -target-linker-version 253.3.3 -v -dwarf-column-info -resource-dir /usr/local/llvm-ios/bin/../lib/clang/3.7.0 -isysroot /usr/local/iPhoneOS8.4.sdk -fdeprecated-macro -fdebug-compilation-dir /var/mobile/Documents/CODING/MY/TESTS_0/CPP -ferror-limit 19 -fmessage-length 108 -stack-protector 1 -mstackrealign -fallow-half-arguments-and-returns -fblocks -fobjc-runtime=ios-5.0.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/tmp/testcpp-f1de66.o -x c++ testcpp.cpp
clang -cc1 version 3.7.0 based upon LLVM 3.7.0 default target arm-apple-darwin14.0.0
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/arm64-apple-darwin10/"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/iPhoneOS8.4.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1
 /usr/local/iPhoneOS8.4.sdk/usr/include/c++/4.2.1/backward
 /usr/local/llvm-ios/bin/../lib/clang/3.7.0/include
 /usr/local/iPhoneOS8.4.sdk/usr/include
 /usr/local/iPhoneOS8.4.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/usr/local/cctools-arm64-port/bin/ld" -demangle -dynamic -arch arm64 -iphoneos_version_min 5.0.0 -syslibroot /usr/local/iPhoneOS8.4.sdk -o testcpp /var/tmp/testcpp-f1de66.o -lstdc++ -lSystem
ld: file not found: ?4
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

I also tried without the unset CC CXX, with the same "success"...

EDIT 2015-28-10. I. Using cydia solutions as suggested indeed worked, but I definitely want to build it myself, so I followed the https://github.com/tpoechtrager/cctools-port way. As it is way too boring to get/build libtool for mac os, I switched to a vitual box ubuntu 15.10 64 bits, where I sudo apt-get install'ed the following packages : automake, autogen, libtool, clang-3.7, uuid-dev and llvm-3.7-dev. Then I cd'ed to the cctools directory and did :

./autogen.sh
export CC="clang-3.7 -arch arm64"
export CXX="clang++-3.7 -arch arm64"
./configure --prefix=/home/lvm-ubuntu/Desktop/iPad/cctools-produced/ --host=arm-apple-darwin11
make

(The complete output is in the new following gist.) make produced the following warnings and errors :

clang: warning: argument unused during compilation: '-arch arm64'

../include/foreign/libkern/arm/OSByteOrder.h:11:10: error: redefinition of
  '_OSSwapInt16'
uint16_t _OSSwapInt16(uint16_t data)
         ^
../include/foreign/libkern/i386/_OSByteOrder.h:46:1: note: previous definition
      is here
_OSSwapInt16(
^

and analogue errors for _OSSwapInt32 and _OSSwapInt64... I must be for sure doing something wrong.


Initial question.

I succeed in cross-building clang+llvm for iOS8.4 on a jailbroken iPad mini 3 wifi, mainly thanks to the two following questions :

https://stackoverflow.com/questions/32808144/how-to-cross-compile-clang-llvm-3-7-0-for-ios8-x-on-ipad-mini-3/

and

https://stackoverflow.com/questions/23946851/how-to-cross-compile-clang-llvm-for-ios/

Set all paths etc, and tried a clang++ -v testcpp.cpp -o testcpp where testcpp.cppcontains :

int main()
{
    return 0;
}

and got this :

clang++: error: unable to execute command: Executable "ld" doesn't exist!
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

(the whole verbose output is in this gist.)

Obviously I don't have GNU's ld nor any real "remplacement" of it (by llvm-clang), so that I am asking myself : what is my strategy in this case ? (Having no linker, I can't even try to build binutils on my iPad to use its ld).

Precision : I would like the linking to be done behind the scene, so that I could keep doing clang++ -v testcpp.cpp -o testcpp, that is, I don't want to do the linking "manually" myself in several steps. (But a script could be ok, even if I find more elegant to have a real ld replacement...)

Remark : in llvm-clang bin folder I have this :

XXXXs-iPad:/usr/local/llvm-ios/bin mobile$ ls -l
total 274412
-rwxr-xr-x 1 root wheel   205456 Oct 18 12:49 FileCheck*
-rwxr-xr-x 1 root wheel  7704096 Oct 18 12:48 bugpoint*
-rwxr-xr-x 1 root wheel   122036 Oct 18 12:48 c-index-test*
-rwxr-xr-x 1 root wheel 40802004 Oct 18 12:48 clang*
-rwxr-xr-x 1 root wheel 40802004 Oct 18 12:49 clang++*
-rwxr-xr-x 1 root wheel 31252792 Oct 18 12:49 clang-check*
-rwxr-xr-x 1 root wheel  1225352 Oct 18 12:49 clang-format*
-rwxr-xr-x 1 root wheel   671500 Oct 18 12:49 clang-tblgen*
-rwxr-xr-x 1 root wheel    49684 Oct 18 12:49 count*
-rwxr-xr-x 1 root wheel 22439396 Oct 18 12:49 llc*
-rwxr-xr-x 1 root wheel 10351388 Oct 18 12:49 lli*
-rwxr-xr-x 1 root wheel   208140 Oct 18 12:49 lli-child-target*
-rwxr-xr-x 1 root wheel  9144692 Oct 18 12:49 llvm-ar*
-rwxr-xr-x 1 root wheel  1619592 Oct 18 12:49 llvm-as*
-rwxr-xr-x 1 root wheel   155080 Oct 18 12:49 llvm-bcanalyzer*
-rwxr-xr-x 1 root wheel   120864 Oct 18 12:49 llvm-config*
-rwxr-xr-x 1 root wheel    92232 Oct 18 12:49 llvm-config-host*
-rwxr-xr-x 1 root wheel  1604600 Oct 18 12:49 llvm-cov*
-rwxr-xr-x 1 root wheel  1472656 Oct 18 12:49 llvm-cxxdump*
-rwxr-xr-x 1 root wheel  1471516 Oct 18 12:49 llvm-diff*
-rwxr-xr-x 1 root wheel  1225632 Oct 18 12:49 llvm-dis*
-rwxr-xr-x 1 root wheel 18342488 Oct 18 12:49 llvm-dsymutil*
-rwxr-xr-x 1 root wheel   419892 Oct 18 12:49 llvm-dwarfdump*
-rwxr-xr-x 1 root wheel  1686496 Oct 18 12:49 llvm-extract*
-rwxr-xr-x 1 root wheel  1800856 Oct 18 12:49 llvm-link*
-rwxr-xr-x 1 root wheel 10140692 Oct 18 12:49 llvm-mc*
-rwxr-xr-x 1 root wheel   138552 Oct 18 12:49 llvm-mcmarkup*
-rwxr-xr-x 1 root wheel  9144172 Oct 18 12:49 llvm-nm*
-rwxr-xr-x 1 root wheel 11554352 Oct 18 12:49 llvm-objdump*
-rwxr-xr-x 1 root wheel   220840 Oct 18 12:49 llvm-pdbdump*
-rwxr-xr-x 1 root wheel   469920 Oct 18 12:49 llvm-profdata*
-rwxr-xr-x 1 root wheel  9144692 Oct 18 12:49 llvm-ranlib*
-rwxr-xr-x 1 root wheel  1768528 Oct 18 12:49 llvm-readobj*
-rwxr-xr-x 1 root wheel  8388100 Oct 18 12:50 llvm-rtdyld*
-rwxr-xr-x 1 root wheel  1489124 Oct 18 12:50 llvm-size*
-rwxr-xr-x 1 root wheel  2106052 Oct 18 12:50 llvm-stress*
-rwxr-xr-x 1 root wheel  1610176 Oct 18 12:50 llvm-symbolizer*
-rwxr-xr-x 1 root wheel  1422732 Oct 18 12:50 llvm-tblgen*
-rwxr-xr-x 1 root wheel  1455516 Oct 18 12:50 macho-dump*
-rwxr-xr-x 1 root wheel    71184 Oct 18 12:50 not*
-rwxr-xr-x 1 root wheel  1620520 Oct 18 12:50 obj2yaml*
-rwxr-xr-x 1 root wheel 23007212 Oct 18 12:50 opt*
-rwxr-xr-x 1 root wheel  1768416 Oct 18 12:50 verify-uselistorder*
-rwxr-xr-x 1 root wheel   402360 Oct 18 12:50 yaml2obj*
Community
  • 1
  • 1
Olórin
  • 3,367
  • 2
  • 22
  • 42

1 Answers1

1

Install org.coolstar.cctools and org.coolstar.ld64 via Cydia.

Or, alternatively, build https://github.com/tpoechtrager/cctools-port by hand.

CXX="clang++ -arch arm64" CC="clang -arch arm64" ./configure --host=arm-apple-darwin11

Thomas
  • 3,074
  • 1
  • 25
  • 39
  • I have already tried the first one which includes the second, without success. I will try to build tpoechtrager's port and will keep you posted. – Olórin Oct 19 '15 at 18:00
  • Ok, I miss `libtoolize`, `autoconf`, `automake` and `aclocal`, as I am under mac os. I built `autoconf` and `automake` from source, `aclocal` is part of `automake` so it's ok. I managed to find `libtool` that I can build from source, but no `libtoolize` source. – Olórin Oct 20 '15 at 21:14
  • @user10000100_u: `org.coolstar.ld64` should work anyway, the problem is somewhere else. – Thomas Oct 21 '15 at 16:31
  • Ok, it did work indeed with cydia's packages, but now I would like to build linker myself. So I followed instructions [here](https://github.com/tpoechtrager/cctools-port) under ubuntu 15.10 64bits : I installed llvm-dev, uuid-dev, automake, autogen, libtoo, clang-3.7, and did `export CXX="clang++-3.7 -arch arm64" export CC="clang-3.7 -arch arm64" ./configure --prefix=<...> --host=arm-apple-darwin11`, and got finally error of the following kinds : `error redefinition of OSWriteSwapInt16`, `error redefinition of OSWriteSwapInt32` and `error redefinition of OSWriteSwapInt64`. – Olórin Oct 27 '15 at 21:45
  • See the [gist](https://gist.github.com/MisesEnForce/0f53eddef241394f58b7) for complete output – Olórin Oct 27 '15 at 21:46
  • @user10000100_u: I will take a look at it tomorrow or the following day. – Thomas Oct 27 '15 at 21:59
  • Thank you. I edited the question to describe what I tried precisely, and added a new gist containing all outputs. – Olórin Oct 28 '15 at 09:56
  • 1
    @user10000100_u: You can't build for iOS on Linux (unless you are using a cross compiler). You must build cctools-port either on the device itself or on Mac OS X. You do not need to install LLVM etc. on the host OS. Install automake, autogen and libtool via macports. – Thomas Oct 28 '15 at 18:33
  • Ah ok thanks, this explains it... Ok then, will use macports for libtool then (built from source the others already.) One point if you may know ? I say that there were issue with =>O2 optimization falgs and ld64. Is this happening for cydia's cctools package also or only for the cctools port from Thomas Pöchtrager ? – Olórin Oct 28 '15 at 18:51
  • @user10000100_u: "Thomas Pöchtrager" is me :). I had issues with arm7 (coolstar too, btw.). Try `-O0` or `-O1` if you end up with a crashing linker. – Thomas Oct 28 '15 at 19:18
  • Ah ah ;-) Wanted to ask, but didn't as I felt it intrusive. Well, nice to meet then, and thx for so much help. – Olórin Oct 28 '15 at 19:32
  • Ok, I found `libtool` on gnu ftp, built it from source, and followed your instructions for build cctools : `export CC="clang -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"` then `export CXX="clang++ -arch arm64 -mios-version-min=8.4 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.4.sdk"` then `./configure -v --host=arm-apple-darwin11 --prefix=/usr/local/lvm-cross/cctools-arm64-port` then `make` and `sudo make install`... – Olórin Oct 28 '15 at 20:51
  • ... The complete output is in the following [gist](https://gist.github.com/MisesEnForce/9d4d718d182bfa74e163) Then on my iDevice I uninstalled cctools and ld64 cydia packages, put cctools somewhere, put its path in PATH, and tried to compile a simple hello world, and had errors. Verbose compilation is in the following [gist](https://gist.github.com/MisesEnForce/8a73cd2f3135e41ffa41) – Olórin Oct 28 '15 at 20:57
  • At some point I should have done the `unset CC CXX` before doing `make` but I had then the same kind of errors. – Olórin Oct 28 '15 at 21:23
  • @user10000100_u: Ugh, have you tried `-O0` (via `CFLAGS`/`CXXFLAGS`)? – Thomas Oct 28 '15 at 22:02
  • No. When using `clang++` you mean ? Or in the `export CC` and `export CXX` for the `configure` ? – Olórin Oct 28 '15 at 22:02
  • @user10000100_u: When configuring cctools/ld64. – Thomas Oct 28 '15 at 22:14
  • No confirmed then. Will try to add `export CFLAGS="-O0"` and `export CXXFLAGS="-O0"` before `configure`. Btw, should I unset `CC`, `CXX`, `CFLAGS` and `CXXFLAGS` after `configure` and before `make` ? – Olórin Oct 28 '15 at 22:16
  • Tried with `-O1` and `-O0`, same result. – Olórin Oct 28 '15 at 23:49
  • 1
    @user10000100_u: I can't debug it b/c I do not own an arm64 device. `org.coolstar.ld64` is compiled with `-arch armv7`, I think - so try with `-arch armv7`. – Thomas Oct 29 '15 at 13:18
  • Bingo ! It worked. ;-) I am nevertheless really puzzled : `armv7` working on `arm64` for an iPad mini 3 which has an apple a7 processor whose `arch` is supposed to be `armv8-a`. Are all these `arch`'s the same ? Are at least `armv7` and `arm64` the same ? I guess they aren't, but they seem to be the same "linking wise". – Olórin Oct 29 '15 at 14:00
  • @user10000100_u: You can of course run 32-bit programs on a 64-bit processor. I doesn't really matter what architecture the linker is compiled for. – Thomas Oct 30 '15 at 12:48
  • so you say that a linker compiled for a 32-bits architecture will work on the 64-bits one, and will not have problem to do its job for 64-bits code. Ok then. Fair enough. – Olórin Oct 30 '15 at 16:00
  • @user10000100_u Exactly. You could even link Mac OS X binaries with it. – Thomas Oct 30 '15 at 18:14