RobertWang / iphone-gcc-full

Automatically exported from code.google.com/p/iphone-gcc-full
0 stars 0 forks source link

iOS 6.x compatibility #6

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've a jailbroken (evasi0n) iPad 4th generation, with iOS 6.1.

I've installed Mobile Terminal from Cydia.
Then I've followed all required steps to use GCC, but when in Mobile Terminal I 
type:

$ gcc

I get the following error

Illegal instruction: 4

Is this problem related to iOS 6.x compatibility?

Thanks for any help. 

Original issue reported on code.google.com by roberto3...@gmail.com on 6 Feb 2013 at 10:11

GoogleCodeExporter commented 9 years ago
Some software does not work on new Apple A6 and A6X (ARMv7s).
Need rebuild for ARMv7s arch.

Original comment by sergey.i...@gmail.com on 7 Feb 2013 at 3:40

GoogleCodeExporter commented 9 years ago
Thanks for your reply.
Ok, the problem is the architecture.
Now, how can I solve this problem? 
Thanks for your support.

Original comment by roberto3...@gmail.com on 7 Feb 2013 at 4:36

GoogleCodeExporter commented 9 years ago
Very simple :).
U need just recompile it for ARMv7 support (gcc -arch ARMv7) with latest SDK 
(6.0 or 6.1, i think it wont work on old SDK versions but u can try...).
Also u can create universal file for all architectures with lipo 
(http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages
/man1/lipo.1.html) - it will be the best.

Original comment by sergey.i...@gmail.com on 8 Feb 2013 at 1:05

GoogleCodeExporter commented 9 years ago
Sorry if I'm being stupid sergey, but where can I get the source for 
iphone-gcc-full? 

Original comment by ryleyjan...@gmail.com on 9 Feb 2013 at 1:08

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Sergey, I just wanted to ask you the same question.

Original comment by roberto3...@gmail.com on 9 Feb 2013 at 1:24

GoogleCodeExporter commented 9 years ago
There is not any sources in this project as you see, compiled .deb packages 
only. So we have to wait developers reply :(. Or try build from official gcc 
sources, but it will be hard i think...

Original comment by sergey.i...@gmail.com on 9 Feb 2013 at 4:48

GoogleCodeExporter commented 9 years ago
You can get the iphone-gcc source code from Sauriks Telesphoreo (Rev 770):
http://svn.telesphoreo.org/trunk/

You will find iphone-gcc in data/iphone-gcc/

To get the hole Telesphoreo trunk you have to type in in your Linux machine :
svn co http://svn.telesphoreo.org/trunk ./telesphoreo

But with a (armv6 based) self build toolchain it is a Chicken Egg Problem: You 
need a runnable toolchain to build your own new toolchain :-)

Btw:
It could be that a new build GCC then does not create an Illegal instruction: 4 
error. But the GCC output binary will do that again:-(
The same fresh compiled GCC version will create the same output binary as the 
already existing GCC version.

I think (but I'm not sure) the main problem is that the A6/A6X CPU does not 
support all armv6 instruction.
Just armv7 and armv7s instruction. 
But the iphone-gcc and the self build toolchain just create armv6 instruction.
We need a completly new gcc compiler or we have to use XCode.

Jason

Original comment by J.Anrugas on 10 Feb 2013 at 10:35

GoogleCodeExporter commented 9 years ago
Thanks for your report, Jason.
Will try to compile GCC for ARMv7.
80% of old software works which use ARMv6. So I think this GCC will be useful.

Original comment by sergey.i...@gmail.com on 10 Feb 2013 at 11:52

GoogleCodeExporter commented 9 years ago
Thanks for that J.Anrugas. So would it be possible to base a new iphone-gcc off 
the iOS 6.1 SDK/XCode? Because I've had no issues using that to compile armv7s 
code so far. Or it it be more involved then just updating iphone-gcc to use a 
new sdk?

Original comment by ryleyjan...@gmail.com on 10 Feb 2013 at 1:02

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The question is: Does Apples A6/A6X support (all) ARMv6 instructions?
If so, I don't know!!! If not, then we need a new compiler with just ARMv7 
support. Apples own ARMv7s variant is not important (right now). 

A6/A6X Links:
http://www.primatelabs.com/blog/2012/09/apple-a6/
http://wanderingcoder.net/2010/07/19/ought-arm

The original and newst llvm-gcc sources (with ARMv7 support) are on 
https://llvm.org/svn/llvm-project/llvm-gcc-4.2/trunk
Please have a look at the files README.Apple and README.LLVM 
It looks like that you have to compile the LLVM core and then gcc....

If you have an OSX machine and Xcode (I don't have it) you can get Xcode based 
LLVM-GCC sources direct from Apple: 
http://www.opensource.apple.com/release/developer-tools-45/ then click on 
llvmgcc42-2336.11

It seems there is a build script called 'build_gcc' which compile it under/with 
Xcode.

I don't know if this is the only necessary step. What about the bootstraps 
crt1.o/crt2.0/crt3.o and dylib1.o for iOS???

Sorry, I'm out of time. I can just give you some opinions and information. I 
can't try to compile something....

Jason

Original comment by J.Anrugas on 10 Feb 2013 at 2:14

GoogleCodeExporter commented 9 years ago
I took your advice Jason and started trying to compile llvmgcc in a Mac VM. I 
got no complaints from the build_gcc script about building gcc for an ARM host 
and an ARM target, but I couldn't get it to stop asking where my llvmcore path 
is ("specify path with --enable-llvm=DIR...). I installed the latest llvm from 
svn but this didn't seem to work. If anyone has any tips/help let me know.

Original comment by ryleyjan...@gmail.com on 11 Feb 2013 at 1:50

GoogleCodeExporter commented 9 years ago
@ryleyjan
To figure out what is happend with the A6/A6X 'illegal instruction: 4' problem, 
I found a lot of websites. I think I can help you: 
https://github.com/Tatsh/xchain

I have successful compiled arm-apple-darwin-llvm-gcc and I can build binaries 
for several ARM CPUs. The compiler switch key is -target-cpu=cortex-a8 and then 
-march=armv6 or armv7.

But both (armv6 and armv7) binaries are running well on an iPad4 :-(
-> A6X support armv6 Instruction.
Have a look at http://en.wikipedia.org/wiki/List_of_iOS_devices#Features

Original comment by J.Anrugas on 15 Feb 2013 at 11:27

GoogleCodeExporter commented 9 years ago
Hurra!!!
I figured out what the problem is.

I have tested a lot of instructions to build a arm-apple-darwin C/C++/Objc 
cross compiler.

All my own built cross compiler (plane GCC and newer LLVM-GCC) can successful 
create running binaries for iPad 4 and iPhone 5. 
But I have just tested it with a simple test.c file and a very simple iOS SDK 
environment.

Strangely enough Sauriks GCC, which is used in Telesphoreo, also built running 
binaries for iPad4/iPhone5 :-(

That means not the A6X CPU and not the Compiler faults. The problem is deep 
inside the SDK.    

Sauriks iOS SDK build howto ( http://www.saurik.com/id/4 ) describes the using 
of the tool CSU from iphone-dev.googlecode.com . This tool generates selfmade 
crt1.o and dylib1.o startups for the linker. This tool is used and included in 
!every! build iOS SDK script you will find in the www.

I know nothing about ARM but the included few commands confuses the A6X ARM CPU.

Don't build a new toolchain! Just remove everything with crt1*.o and dylib1*.o 
from your BUILD_SYS/usr/lib folder and copy crt1.o and dylib1.o from an iOS SDK 
DMG file
in it. I think you can use every version. Rebuild your source code, done!

Have fun
Jason

Original comment by J.Anrugas on 16 Feb 2013 at 12:28

GoogleCodeExporter commented 9 years ago
Thanks for the tip Jason, I've now got clang (from iNinjas repo) producing good 
binaries on the iPhone 5. Unfortunately I'm still getting the illegal 
instruction error with gcc from Telesphereo. I'm going to do a clean restore 
and try again, I guess I must've stuffed up some libraries 

Original comment by ryleyjan...@gmail.com on 16 Feb 2013 at 1:50

GoogleCodeExporter commented 9 years ago
Just to clarify, when I get the "Illegal Instruction: 4" error, this is caused 
by running gcc on the iphone. Any programs I cross-compile in OS X work without 
issue

Original comment by ryleyjan...@gmail.com on 16 Feb 2013 at 3:18

GoogleCodeExporter commented 9 years ago
Thank you very much, Jason! You helped me alot! Now I can successfully compile 
c/c++ code on iPad 4 using iNinjas LLVM and CLANG. You're right: just remove 
everything with crt1*.0 and dylib1*.0 from /usr/lib and copy that files from 
iOS SDK.
First time I used libs from iOS SDK 6.1, it worked but ld linker was writing 
alot of warnings (bad symbol version). I took libs from iOS SDK 4.3 and did 
what you said (to prevent illegal instruction 4, it appeared on old libs) and 
all warnings and other problems gone!

Original comment by mikor.a...@gmail.com on 22 Feb 2013 at 1:13

GoogleCodeExporter commented 9 years ago
Same problem on iPhone5+IO6.1 

I use iNinjas LLVM and CLANG,but i get this

dyld: Library not loaded: /usr/local/lib/libintl.8.dylib
  Referenced from: /usr/local/bin/gcc
  Reason: Incompatible library version: gcc requires version 10.0.0 or later, but libintl.8.dylib provides version 9.0.0

Original comment by Tibet.L...@gmail.com on 22 Feb 2013 at 4:32

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I don't tested it but for all iPad 4 and iPhone 5 enduse with an 'illegal 
instruction 4' problem -> please have a look here: 
http://iphonesdkdev.blogspot.de/2013/02/illegal-instruction-4.html

Original comment by J.Anrugas on 28 Feb 2013 at 9:05

GoogleCodeExporter commented 9 years ago
I didn't actually use any old sdk's to get rid of those $ld$hide$os warnings, I 
just copied libgcc_s.dylib to overwrite /usr/lib/system/libunwind.dylib and 
/usr/lib/system/libcompiler_rt.dylib. I don't think it matters what file you 
use, as long as its non-zero. These files don't even in appear in the older 
sdk's I have. I look forward to finding out what horrible error this has caused 
lol.

When using that patched gcc, I had to disable all optimizations because I was 
getting an undefined symbol error for "__sync_fetch_and_add_4" in all my c++ 
stuff. The fix is to comment out the line "#define _GLIBCXX_ATOMIC_BUILTINS 1" 
in usr/include/c++/4.2.1/bits/c++config.h Thanks to 
http://www.galloway.me.uk/2010/05/iphone-sdk-bug-hunting-gcc-atomic-builtins/ 
for the tip, I just had to slightly change the file path. Now all my c and c++ 
code is working without errors/warnings!

Original comment by ryleyjan...@gmail.com on 2 Mar 2013 at 3:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi guys, I've followed the discussion from the beginning, and I appreciated so 
much your suggestions.

I've an iPad 4, with iOS 6.1.2. Following the link provided by J. Anrugas, I've 
successfully installed GCC patched for iPhone 5 / iPad 4.

After this, I've copied from XCode (v. 4.6) the contents of folder 

/Contents/Developer/Platforms/iPhoneOS.platform/SDKs/iPhoneOS6.1.sdk/usr/lib to 
/usr/lib iPad's folder.

and

/Contents/Developer/Platforms/iPhoneOS.platform/SDKs/iPhoneOS6.1.sdk/usr/include
 to /usr/include iPad's folder.

Then, when I type

$ gcc hello.c

I get 

ld: in /usr/lib/system/libcache.dylib, file is not of required architecture

I've found this post

http://stackoverflow.com/questions/9894170/in-usr-lib-system-libcache-dylib-miss
ing-required-architecture-armv6

but if I type 

$ gcc -L$ISYSROOT/usr/lib/system --sysroot=$ISYSROOT hello.c

I get

error: no include path in which to search for stdio.h

I don't know what to do now. 

Thanks for any help.

Original comment by roberto3...@gmail.com on 5 Mar 2013 at 12:23

GoogleCodeExporter commented 9 years ago
I think gcc for iOS can only produce armv6 binaries at the moment, so if you 
have some armv7 only libraries that could be an issue. I've got gcc working by 
only copying the files that it says are missing, not copying the entire 
/usr/lib dir. You might want to try re-installing iOS and copying files as 
requested by gcc. Just make sure you save your SHSH blobs/restore soon.

Original comment by ryleyjan...@gmail.com on 6 Mar 2013 at 11:15

GoogleCodeExporter commented 9 years ago
Thanks for your reply.

I realized I was copying a corrupted libcache.dylib.
So I simply re-copied the right file and now everything is fine.

Then I followed your suggestion (overwrite /usr/lib/system/libunwind.dylib and 
/usr/lib/system/libcompiler_rt.dylib with libgcc_s.dylib) in order to avoid bad 
symbol version warnings and is worked!

Thanks so much for your help!

Original comment by roberto3...@gmail.com on 6 Mar 2013 at 4:41

GoogleCodeExporter commented 9 years ago
gcc Patched Installed(iPhone5)
$gcc test.c -o test
$./test
Illegal instruction: 4
$sed -i'' 
's/\x00\x30\x93\xe4/\x00\x30\x93\xe5/g;s/\x00\x30\xd3\xe4/\x00\x30\xd3\xe5/g;' 
test
$./test
TEST
$

Do I need to run the patch every time?

Original comment by NEXTi4H...@gmail.com on 8 Mar 2013 at 8:52

GoogleCodeExporter commented 9 years ago
If you replace the shipped crt1.o and dylib1.o with the files from the latest 
iOS SDK you won't have to use the patching command on the produced files. I can 
upload them if you want.

Original comment by ryleyjan...@gmail.com on 9 Mar 2013 at 11:36

GoogleCodeExporter commented 9 years ago
I really need crt1.o and dylib1.o for ios 6 sdk, can somebody upload it? many 
thanks!

Original comment by cchenyy...@gmail.com on 9 Mar 2013 at 4:59

GoogleCodeExporter commented 9 years ago
I zipped crt1.o, dylib1.o and a couple of other libs you might need. Get it 
here: http://www.mediafire.com/?kd2fuu7m1xdt3w8

Original comment by ryleyjan...@gmail.com on 10 Mar 2013 at 1:29

GoogleCodeExporter commented 9 years ago
thank you.

Original comment by NEXTi4H...@gmail.com on 11 Mar 2013 at 5:51

GoogleCodeExporter commented 9 years ago
I have overwritten the new files crt1.oe dylib1.o same problem but nothing 
illegal and I always use the patch ....

Original comment by repoguer...@gmail.com on 11 Apr 2013 at 8:04

GoogleCodeExporter commented 9 years ago
I was directed here from stackoverflow.com, and thanks to the files uploaded by 
ryleyjan I am now successfully compiling C code on my iphone 5! Much 
appreciation for the help you guys provide so freely.

Original comment by boots....@gmail.com on 19 Apr 2013 at 3:57

GoogleCodeExporter commented 9 years ago
@sergey
>>gcc -arch ARMv7
My iphone-gcc not support "-arch ARMv7" option, could you help me?

Original comment by onlyboy...@gmail.com on 28 Apr 2013 at 2:40

GoogleCodeExporter commented 9 years ago
For support to the ARMv7 download repo FreeYourApple 
http://freeyourapple.com/repo and download the package Toolchain for iOS 
includes the headers you need .....

Original comment by repoguer...@gmail.com on 17 May 2013 at 2:59

GoogleCodeExporter commented 9 years ago
Just to let other interested people know:
 - you'd have to patch any non-working binaries
 - on leot3o.wordpress.com there are instructions on how to build a LLVM capable gcc compiler ON an iDevice.
 - sometimes ininjas' clang doesn't work, though most of tre binaries produced does so.
 - the libintl problem means that you have an outdated gettext library in /usr/local. Either get another newer ot build your own. 

Original comment by cosimoca...@gmail.com on 9 Jun 2013 at 9:09

GoogleCodeExporter commented 9 years ago
To understand how this patch works, please see following link:  
http://theiostream.tumblr.com/post/63923259800/patching-iphone-gcc-binaries-to-a
rmv7s

Original comment by J.Anrugas on 21 Jan 2014 at 1:39

GoogleCodeExporter commented 9 years ago
I'd like to suggest CppCode. It's the first and the only offline C/C++ IDE & 
Compiler on iOS!
No jailbreak required, no internet connection required, no ads, free(mium) app.

App feature list, screenshots and video on Vimeo/Youtube and even quick start 
at http://cppcode.info

Video:
https://www.youtube.com/watch?v=yKMQAE-DAJw

AppStore:
https://itunes.apple.com/app/cppcode-offline-c-c++-ide/id936694712

Original comment by d...@antonsmirnov.name on 4 Dec 2014 at 7:02

GoogleCodeExporter commented 9 years ago
CppCode looks interesting, but can you actually run the binary produced on the 
device?

Original comment by ryleyjan...@gmail.com on 5 Dec 2014 at 3:35