Fix inplace dynamic linking on OS X (#8266)
[ghc.git] / compiler / main / DriverPipeline.hs
index 3d34bdb..b5052f2 100644 (file)
@@ -1785,6 +1785,15 @@ linkBinary' staticLink dflags o_files dep_packages = do
                               then []
                               else ["-Wl,-rpath-link", "-Wl," ++ l]
               in ["-L" ++ l] ++ rpathlink ++ rpath
+         | osMachOTarget (platformOS platform) &&
+           dynLibLoader dflags == SystemDependent &&
+           not (gopt Opt_Static dflags) &&
+           gopt Opt_RPath dflags
+            = let libpath = if gopt Opt_RelativeDynlibPaths dflags
+                            then "@loader_path" </>
+                                 (l `makeRelativeTo` full_output_fn)
+                            else l
+              in ["-L" ++ l] ++ ["-Wl,-rpath", "-Wl," ++ libpath]
          | otherwise = ["-L" ++ l]
 
     let lib_paths = libraryPaths dflags
@@ -1920,13 +1929,6 @@ linkBinary' staticLink dflags o_files dep_packages = do
                           then ["-Wl,-read_only_relocs,suppress"]
                           else [])
 
-                      ++ (if platformOS platform == OSDarwin &&
-                             not staticLink &&
-                             not (gopt Opt_Static dflags) &&
-                             gopt Opt_RPath dflags
-                          then ["-Wl,-rpath","-Wl," ++ topDir dflags]
-                          else [])
-
                       ++ o_files
                       ++ lib_path_opts)
                       ++ extra_ld_inputs