diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 3d34bdbcac676ce1a989b0bfce153aa7e77a7a7a..b5052f2d6452a6afa79d53d51885da148c8063cf 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -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
diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index 2150c6d594823167a89eabd00a14770bda3ab5ed..ad059d7fe645a1893d93f006136b6fc67e8c8d9b 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -1293,7 +1293,8 @@ linkDynLib dflags0 o_files dep_packages
     let pkg_lib_paths = collectLibraryPaths pkgs
     let pkg_lib_path_opts = concatMap get_pkg_lib_path_opts pkg_lib_paths
         get_pkg_lib_path_opts l
-         | osElfTarget (platformOS (targetPlatform dflags)) &&
+         | ( osElfTarget (platformOS (targetPlatform dflags)) ||
+             osMachOTarget (platformOS (targetPlatform dflags)) ) &&
            dynLibLoader dflags == SystemDependent &&
            not (gopt Opt_Static dflags)
             = ["-L" ++ l, "-Wl,-rpath", "-Wl," ++ l]
@@ -1390,9 +1391,7 @@ linkDynLib dflags0 o_files dep_packages
 
             instName <- case dylibInstallName dflags of
                 Just n -> return n
-                Nothing -> do
-                    pwd <- getCurrentDirectory
-                    return $ pwd `combine` output_fn
+                Nothing -> return $ "@rpath" `combine` (takeFileName output_fn)
             runLink dflags (
                     map Option verbFlags
                  ++ [ Option "-dynamiclib"
diff --git a/compiler/utils/Platform.hs b/compiler/utils/Platform.hs
index f69bb4cdf65e83e8d6d9889a09db61233ff40d6a..ea1a3e5e93ea3b7ecfd42d31b9951b2addcaa962 100644
--- a/compiler/utils/Platform.hs
+++ b/compiler/utils/Platform.hs
@@ -12,6 +12,7 @@ module Platform (
         target32Bit,
         isARM,
         osElfTarget,
+        osMachOTarget,
         platformUsesFrameworks,
         platformBinariesAreStaticLibs,
 )
@@ -129,6 +130,11 @@ osElfTarget OSUnknown   = False
  -- portability, otherwise we have to answer this question for every
  -- new platform we compile on (even unreg).
 
+-- | This predicate tells us whether the OS support Mach-O shared libraries.
+osMachOTarget :: OS -> Bool
+osMachOTarget OSDarwin = True
+osMachOTarget _ = False
+
 osUsesFrameworks :: OS -> Bool
 osUsesFrameworks OSDarwin = True
 osUsesFrameworks OSiOS    = True
diff --git a/ghc.mk b/ghc.mk
index f48714ebf47491f7cc2fb97f508a7c739979741e..4bd47c675890183b7db5a10204ac27ef45e4c80e 100644
--- a/ghc.mk
+++ b/ghc.mk
@@ -282,11 +282,6 @@ include rules/dependencies.mk
 include rules/build-dependencies.mk
 include rules/include-dependencies.mk
 
-# -----------------------------------------------------------------------------
-# Dynamic library references
-
-include rules/relative-dynlib-references.mk
-
 # -----------------------------------------------------------------------------
 # Build package-data.mk files
 
diff --git a/rts/ghc.mk b/rts/ghc.mk
index 1e0b6def87fc7bdbbb1bd01327c7c71423bc53c5..3929adbee93b5c059293c282fc2f56fc30b58beb 100644
--- a/rts/ghc.mk
+++ b/rts/ghc.mk
@@ -117,7 +117,7 @@ else
 rts/dist/build/lib$(LIBFFI_NAME)$(soext): libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)
 	cp libffi/build/inst/lib/lib$(LIBFFI_NAME)$(soext)* rts/dist/build
 ifeq "$(TargetOS_CPP)" "darwin"
-	install_name_tool -id @rpath/rts-$(rts_VERSION)/lib$(LIBFFI_NAME)$(soext) rts/dist/build/lib$(LIBFFI_NAME)$(soext)
+	install_name_tool -id @rpath/lib$(LIBFFI_NAME)$(soext) rts/dist/build/lib$(LIBFFI_NAME)$(soext)
 endif
 endif
 endif
@@ -197,6 +197,9 @@ LIBFFI_LIBS = -Lrts/dist/build -l$$(LIBFFI_NAME)
 ifeq "$$(TargetElf)" "YES"
 LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,'$$$$ORIGIN' -optl-Wl,-zorigin
 endif
+ifeq "$(TargetOS_CPP)" "darwin"
+LIBFFI_LIBS += -optl-Wl,-rpath -optl-Wl,@loader_path
+endif
 
 else
 # flags will be taken care of in rts/dist/libs.depend
@@ -207,7 +210,6 @@ $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS) rts/dist/libs.depend $$(
 	"$$(rts_dist_HC)" -package-name rts -shared -dynamic -dynload deploy \
 	  -no-auto-link-packages $$(LIBFFI_LIBS) `cat rts/dist/libs.depend` $$(rts_$1_OBJS) \
 	  $$(rts_$1_DTRACE_OBJS) -o $$@
-	$(call relative-dynlib-references,rts,dist,1,$1)
 endif
 else
 $$(rts_$1_LIB) : $$(rts_$1_OBJS) $$(rts_$1_DTRACE_OBJS)
diff --git a/rules/build-package-way.mk b/rules/build-package-way.mk
index 305252be47e452e6ce80c06042e4a5c86cd6f4bf..294e43274a7404415cad423670a65b39b0da714f 100644
--- a/rules/build-package-way.mk
+++ b/rules/build-package-way.mk
@@ -91,7 +91,6 @@ $$($1_$2_$3_LIB) : $$($1_$2_$3_ALL_OBJS) $$(ALL_RTS_LIBS) $$($1_$2_$3_DEPS_LIBS)
 	 $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES)) $$(addprefix -L,$$($1_$2_EXTRA_LIBDIRS)) \
          -no-auto-link-packages \
          -o $$@
-	$(call relative-dynlib-references,$1,$2,$4)
 endif
 else
 # Build the ordinary .a library
diff --git a/rules/build-prog.mk b/rules/build-prog.mk
index 5837bb0c8417bf525222d5938482907d6663b4e9..c6780d1bdec057ef198e703a6e0f4d98deb21e52 100644
--- a/rules/build-prog.mk
+++ b/rules/build-prog.mk
@@ -261,10 +261,6 @@ ifeq "$$($1_$2_LINK_WITH_GCC)" "NO"
 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
 	$$(call cmd,$1_$2_HC) -o $$@ $$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_HC_OPTS) $$(LD_OPTS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_GHC_LD_OPTS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
 
-ifeq "$$($1_$2_PROGRAM_WAY)" "dyn"
-	$(call relative-dynlib-references,$1,$2,$3)
-	$(call relative-dynlib-path,$3)
-endif
 else
 $1/$2/build/tmp/$$($1_$2_PROG) : $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) | $$$$(dir $$$$@)/.
 	$$(call cmd,$1_$2_CC) -o $$@ $$($1_$2_$$($1_$2_PROGRAM_WAY)_ALL_CC_OPTS) $$(LD_OPTS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_HS_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_C_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_S_OBJS) $$($1_$2_OTHER_OBJS) $$($1_$2_$$($1_$2_PROGRAM_WAY)_EXTRA_CC_OPTS) $$(addprefix -l,$$($1_$2_EXTRA_LIBRARIES))
diff --git a/rules/distdir-way-opts.mk b/rules/distdir-way-opts.mk
index a4f525e89653fdfb5bcc805ae64371ef661ed19d..8c0377eff83488f78d79dab46cff715b717caefd 100644
--- a/rules/distdir-way-opts.mk
+++ b/rules/distdir-way-opts.mk
@@ -138,7 +138,9 @@ $1_$2_$3_GHC_LD_OPTS += \
     -fno-use-rpaths \
     $$(foreach d,$$($1_$2_TRANSITIVE_DEPS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'$$$$ORIGIN/../$$d') -optl-Wl,-zorigin
 else ifeq "$$(TargetOS_CPP)" "darwin"
-$1_$2_$3_GHC_LD_OPTS += -optl-Wl,-headerpad_max_install_names
+$1_$2_$3_GHC_LD_OPTS += \
+    -fno-use-rpaths \
+    $$(foreach d,$$($1_$2_TRANSITIVE_DEPS),-optl-Wl$$(comma)-rpath -optl-Wl$$(comma)'@loader_path/../$$d')
 endif
 endif
 endif
diff --git a/rules/relative-dynlib-references.mk b/rules/relative-dynlib-references.mk
deleted file mode 100644
index e117ddefb4baca9c3db1120c599657bb49e994eb..0000000000000000000000000000000000000000
--- a/rules/relative-dynlib-references.mk
+++ /dev/null
@@ -1,55 +0,0 @@
-# -----------------------------------------------------------------------------
-#
-# (c) 2009 The University of Glasgow
-#
-# This file is part of the GHC build system.
-#
-# To understand how the build system works and how to modify it, see
-#      http://ghc.haskell.org/trac/ghc/wiki/Building/Architecture
-#      http://ghc.haskell.org/trac/ghc/wiki/Building/Modifying
-#
-# -----------------------------------------------------------------------------
-
-
-# Make dynlib references use relative paths, so that everything works
-# without the build tree.
-
-define relative-dynlib-references
-# $1 = dir
-# $2 = distdir
-# $3 = GHC stage to use (0 == bootstrapping compiler)
-# $4 = RTSway
-
-ifeq "$$(TargetOS_CPP)" "darwin"
-ifneq "$3" "0"
-# Use relative paths for all the libraries
-ifneq "$$($1_$2_TRANSITIVE_DEP_NAMES)" ""
-	install_name_tool $$(foreach d,$$($1_$2_TRANSITIVE_DEP_NAMES), -change $$(TOP)/$$($$($$d_INSTALL_INFO)_dyn_LIB) @rpath/$$d-$$($$($$d_INSTALL_INFO)_VERSION)/$$($$($$d_INSTALL_INFO)_dyn_LIB_NAME)) $$@
-endif
-# Change absolute library name/path to a relative name/path
-ifeq "$$($1_$2_PROGNAME)" ""
-ifeq "$1" "rts"
-	install_name_tool -id @rpath/rts-$$(rts_VERSION)/$$(rts_$4_LIB_NAME) $$@
-else
-	install_name_tool -id @rpath/$$($1_PACKAGE)-$$($1_$2_VERSION)/$$($1_$2_dyn_LIB_NAME) $$@
-endif
-endif
-# Use relative paths for the RTS. Rather than try to work out which RTS
-# way is being linked, we just change it for all ways
-	install_name_tool $$(foreach w,$$(rts_WAYS), -change $$(TOP)/$$(rts_$$w_LIB) @rpath/rts-$$(rts_VERSION)/$$(rts_$$w_LIB_NAME)) $$@
-	install_name_tool -change $$(TOP)/$$(wildcard libffi/build/inst/lib/libffi.*.dylib) @rpath/rts-$$(rts_VERSION)/libffi.dylib $$@
-endif
-endif
-
-endef
-
-define relative-dynlib-path
-# $1 = GHC stage to use (0 == bootstrapping compiler)
-
-ifeq "$$(TargetOS_CPP)" "darwin"
-ifneq "$1" "0"
-	install_name_tool -rpath $$(TOP)/inplace/lib @loader_path/.. $$@
-endif
-endif
-
-endef