ghc-android icon indicating copy to clipboard operation
ghc-android copied to clipboard

System.Posix.getEnvironment => []

Open joeyh opened this issue 12 years ago • 3 comments

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 avatar Feb 22 '13 18:02 joeyh

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 avatar Feb 22 '13 18:02 joeyh

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 avatar Nov 12 '13 03:11 joeyh

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.

joeyh avatar Nov 12 '13 17:11 joeyh