Ticket #7720: ios-patch-9a-linking.patch

File ios-patch-9a-linking.patch, 8.0 KB (added by StephenBlackheath, 2 years ago)

iOS patch 9 rev a: Linking

  • compiler/ghci/Linker.lhs

    diff --git a/compiler/ghci/Linker.lhs b/compiler/ghci/Linker.lhs
    index 03189e7..7a2c04b 100644
    a b reallyInitDynLinker dflags = 
    303303
    304304          -- (e) Link any MacOS frameworks
    305305        ; let platform = targetPlatform dflags
    306         ; let framework_paths = case platformOS platform of
    307                                 OSDarwin -> frameworkPaths dflags
    308                                 _        -> []
    309         ; let frameworks = case platformOS platform of
    310                            OSDarwin -> cmdlineFrameworks dflags
    311                            _        -> []
     306        ; let (framework_paths, frameworks) = if platformOS platform `elem` [OSDarwin, OSiOS]
     307                                    then (frameworkPaths dflags, cmdlineFrameworks dflags)
     308                                    else ([], [])
    312309          -- Finally do (c),(d),(e)
    313310        ; let cmdline_lib_specs = [ l | Just l <- classified_ld_inputs ]
    314311                               ++ libspecs
    preloadLib dflags lib_paths framework_paths lib_spec 
    389386                      Just mm -> preloadFailed mm lib_paths lib_spec
    390387
    391388          Framework framework ->
    392               case platformOS (targetPlatform dflags) of
    393               OSDarwin ->
     389              if platformOS (targetPlatform dflags) `elem` [OSDarwin, OSiOS]
     390              then
    394391                do maybe_errstr <- loadFramework framework_paths framework
    395392                   case maybe_errstr of
    396393                      Nothing -> maybePutStrLn dflags "done"
    397394                      Just mm -> preloadFailed mm framework_paths lib_spec
    398               _ -> panic "preloadLib Framework"
     395              else panic "preloadLib Framework"
    399396
    400397  where
    401398    platform = targetPlatform dflags
    load_dyn dll = do r <- loadDLL dll 
    11561153
    11571154loadFrameworks :: Platform -> InstalledPackageInfo_ ModuleName -> IO ()
    11581155loadFrameworks platform pkg
    1159     = case platformOS platform of
    1160       OSDarwin -> mapM_ load frameworks
    1161       _        -> return ()
     1156    = if platformOS platform `elem` [OSDarwin, OSiOS]
     1157        then mapM_ load frameworks
     1158        else return ()
    11621159  where
    11631160    fw_dirs    = Packages.frameworkDirs pkg
    11641161    frameworks = Packages.frameworks pkg
  • compiler/main/DriverPipeline.hs

    diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
    index fa3b9dc..02a8376 100644
    a b runPhase cc_phase input_fn dflags 
    11011101             else getPackageExtraCcOpts dflags pkgs
    11021102
    11031103        framework_paths <-
    1104             case platformOS platform of
    1105             OSDarwin ->
     1104            if platformOS platform `elem` [OSDarwin, OSiOS]
     1105              then
    11061106                do pkgFrameworkPaths <- liftIO $ getPackageFrameworkPath dflags pkgs
    11071107                   let cmdlineFrameworkPaths = frameworkPaths dflags
    11081108                   return $ map ("-F"++)
    11091109                                (cmdlineFrameworkPaths ++ pkgFrameworkPaths)
    1110             _ ->
     1110              else
    11111111                return []
    11121112
    11131113        let split_objs = gopt Opt_SplitObjs dflags
    linkBinary dflags o_files dep_packages = do 
    18501850
    18511851    rc_objs <- maybeCreateManifest dflags output_fn
    18521852
    1853     SysTools.runLink dflags (
     1853    -- On iOS, instead of an executable we create a static library.
     1854    -- We can't use any dynamic libraries when doing this, so here we strip the
     1855    -- ones that would otherwise get added.
     1856    let link opts
     1857            | platformOS (targetPlatform dflags) == OSiOS
     1858                  = SysTools.runLibtool dflags $ [ o | o <- opts,
     1859                          case o of
     1860                              SysTools.FileOption _ _ -> True
     1861                              SysTools.Option opt ->
     1862                                  opt `notElem` ["-ldl", "-liconv", "-lm", "-lpthread"] ]
     1863            | otherwise = SysTools.runLink dflags opts
     1864
     1865    link (
    18541866                       map SysTools.Option verbFlags
    18551867                      ++ [ SysTools.Option "-o"
    18561868                         , SysTools.FileOption "" output_fn
    linkBinary dflags o_files dep_packages = do 
    19141926exeFileName :: DynFlags -> FilePath
    19151927exeFileName dflags
    19161928  | Just s <- outputFile dflags =
    1917       if platformOS (targetPlatform dflags) == OSMinGW32
    1918       then if null (takeExtension s)
    1919            then s <.> "exe"
    1920            else s
    1921       else s
     1929      case platformOS (targetPlatform dflags) of
     1930          OSMinGW32 -> if null (takeExtension s)
     1931                           then s <.> "exe"
     1932                           else s
     1933          OSiOS     -> let (path, file) = splitFileName s   -- On iOS we link a static
     1934                       in  combine path (file++".a")        -- lib into Xcode
     1935          _         -> s
    19221936  | otherwise =
    19231937      if platformOS (targetPlatform dflags) == OSMinGW32
    19241938      then "main.exe"
  • compiler/main/Packages.lhs

    diff --git a/compiler/main/Packages.lhs b/compiler/main/Packages.lhs
    index 52361ce..152f78c 100644
    a b import Util 
    4545import Panic
    4646import Outputable
    4747import Maybes
     48import Platform         ( Platform(..), OS(..) )
    4849
    4950import System.Environment ( getEnv )
    5051import Distribution.InstalledPackageInfo
    collectLinkOpts :: DynFlags -> [PackageConfig] -> [String] 
    876877collectLinkOpts dflags ps = concat (map all_opts ps)
    877878  where
    878879        libs p     = packageHsLibs dflags p ++ extraLibraries p
    879         all_opts p = map ("-l" ++) (libs p) ++ ldOptions p
     880        -- On iOS, instead of creating an executable, we create a static library that
     881        -- we then link into an Xcode project. The iOS libtool doesn't accept most
     882        -- link options, so we just discard any that are specified in packages.
     883        -- Generally they need to be added by hand to the Xcode project instead.
     884        all_opts p = case platformOS (targetPlatform dflags) of
     885                         OSiOS -> map ("-l" ++) (libs p)
     886                         _     -> map ("-l" ++) (libs p) ++ ldOptions p
    880887
    881888packageHsLibs :: DynFlags -> PackageConfig -> [String]
    882889packageHsLibs dflags p = map (mkDynName . addSuffix) (hsLibraries p)
  • compiler/main/SysTools.lhs

    diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
    index 79af4f6..70152d8 100644
    a b module SysTools ( 
    1515        runUnlit, runCpp, runCc, -- [Option] -> IO ()
    1616        runPp,                   -- [Option] -> IO ()
    1717        runSplit,                -- [Option] -> IO ()
    18         runAs, runLink,         -- [Option] -> IO ()
     18        runAs, runLink, runLibtool, -- [Option] -> IO ()
    1919        runMkDLL,
    2020        runWindres,
    2121        runLlvmOpt,
    runLink dflags args = do 
    593593  mb_env <- getGccEnv args1
    594594  runSomethingFiltered dflags id "Linker" p args1 mb_env
    595595
     596runLibtool :: DynFlags -> [Option] -> IO ()
     597runLibtool dflags args = do
     598  let (p,args0) = ("libtool", [Option "-static"])
     599      args1 = args0 ++ args
     600  mb_env <- getGccEnv args1
     601  runSomethingFiltered dflags id "Linker" p args1 mb_env
     602
    596603runMkDLL :: DynFlags -> [Option] -> IO ()
    597604runMkDLL dflags args = do
    598605  let (p,args0) = pgm_dll dflags
    linkDynLib dflags o_files dep_packages 
    11801187                 ++ pkg_lib_path_opts
    11811188                 ++ pkg_link_opts
    11821189                ))
     1190        OSiOS -> throwGhcExceptionIO (ProgramError "dynamic libraries are not supported on iOS target")
    11831191        _ -> do
    11841192            -------------------------------------------------------------------
    11851193            -- Making a DSO
  • compiler/utils/Platform.hs

    diff --git a/compiler/utils/Platform.hs b/compiler/utils/Platform.hs
    index 090ce41..fc1762f 100644
    a b data OS 
    6060        = OSUnknown
    6161        | OSLinux
    6262        | OSDarwin
     63        | OSiOS
    6364        | OSSolaris2
    6465        | OSMinGW32
    6566        | OSFreeBSD
    osElfTarget OSOpenBSD = True 
    107108osElfTarget OSNetBSD    = True
    108109osElfTarget OSSolaris2  = True
    109110osElfTarget OSDarwin    = False
     111osElfTarget OSiOS       = False
    110112osElfTarget OSMinGW32   = False
    111113osElfTarget OSKFreeBSD  = True
    112114osElfTarget OSHaiku     = True