[Haskell-iPhone] ByteString on GHC-iPhone v5

Stephen Blackheath [to GHC-iPhone] likeliest.complexions.stephen at blacksapphire.com
Fri May 25 01:09:36 CEST 2012


All,

GHC-iPhone is now at

https://github.com/mietek/ghc
https://github.com/mietek/packages-base
https://github.com/mietek/packages-Cabal
https://github.com/mietek/hsc2hs
https://github.com/mietek/packages-unix

I spent a whole lot of time on it and now I know what's going on with 
the ByteString issue. Here's what's going on:

This code is brought in when you reference Data.ByteString.unpack or 
Data.ByteString.empty:

foreign import ccall unsafe "static stdlib.h &free" c_free_finalizer
     :: FunPtr (Ptr Word8 -> IO ())

This produces this line of ARM assembly:
     .long _free

Presumably because _free isn't in the executable anywhere (linked when 
it gets started), it adds a flag to the __TEXT section called 
S_ATTR_EXT_RELOC. You can see this with otool on the TestApp executable 
deep inside the $HOME/.Xcode directory - the flag's value is 0x00000200.

For some reason this makes the dyld loader try to set the text section 
to be writeable with vm_protect() and the flag VM_PROT_WRITE. This 
violates the kernel's policy against self-modifying code on the iPhone, 
and vm_protect() returns with a failure status of 2.

So that's what's going on. Why it's happening and how to fix it is next.


Steve

On 23/05/12 07:34, Carl Joachim Svenn wrote:
> * this is a simpler ByteString example failing:
>
> BS.pack [] `seq` return ()
>
> * command options for clang to target iOS (corrected from previous mail):
>
> "-arch armv7 -iphoneos_version_min=5.1.0"
>
>
> best regards,
> Carl Joachim



More information about the iPhone mailing list