neurocyte / ghc-android

Build scripts for building ghc cross compilers targeting Android
182 stars 29 forks source link

System.Posix.getEnvironment => [] #7

Open joeyh opened 11 years ago

joeyh commented 11 years ago

This apparently fails, and always returns a null list.

System.Environment.getEnvironment does work.

I have not checked, but it seems likely other functions in System.Posix.Env are also broken.

Also, there is something weird going on, it seems that in some cases even when System.Environment.getEnvironment should be used, a null list is returned. I have a test case involving an internal module:

import System.Environment import qualified Internal.Module

main = print =<< getEnvironment

This prints [], and commenting out the second import fixes it. The module is not used at all, but it does import a lot of other modules including System.Posix.Env.

joeyh commented 11 years ago

FWIW: While getEnvironment fails, getEnv works. This test program prints [] three times and then a username.

import System.Environment import System.FilePath import System.Posix.Env

main :: IO () main = do print =<< System.Environment.getEnvironment print =<< System.Posix.Env.getEnvironment print =<< System.Posix.Env.getEnvironmentPrim print =<< System.Posix.Env.getEnv "USER"

joeyh commented 10 years ago

This is looking likely to be due to the android linker's handling of R_ARM_COPY relocations; the environ symbol is one such and I supect the linker sets it to point to garbage or null rather than the real environ.

On android 4.3/4.4, this apparently instead causes the "ANNOT LINK EXECUTABLE: git-annex invalid R_ARM_COPY relocation against DT_SYMBOLIC shared library libc.so" error -- which I incorrectly earlier thought I'd avoided by upgrading to a newver version of the NDK.

The workaround is to pass -optl-z -optlnocopyreloc to ghc, which avoids using this type of relocation. I think that ghc-android will probably need to either make its cabal wrapper do that, or put a wrapper around the android ld.gold (which would also fix ghc when not using cabal).

Gory details here: http://git-annex.branchable.com/bugs/git-annex_broken_on_Android_4.3/

joeyh commented 10 years ago

While -optl-z -optlnocopyreloc makes getEnvironment work on Android 4.3 and 4.4, it unfortunately yields binaries that segfault on Android 4.0.4 whenever they deal with the environment.