diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 80a8d27f99ad345b2f980c5d486407a63f0f9901..937bbade3810094f88a24d83b6213225ed17c1a7 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -3785,6 +3785,9 @@ needSourceNotes dflags = debugLevel dflags > 0
 -- | Should we use `-XLinker -rpath` when linking or not?
 -- See Note [-fno-use-rpaths]
 useXLinkerRPath :: DynFlags -> OS -> Bool
+-- wasm shared libs don't have RPATH at all and wasm-ld doesn't accept
+-- any RPATH-related flags
+useXLinkerRPath dflags _ | ArchWasm32 <- platformArch $ targetPlatform dflags = False
 useXLinkerRPath _ OSDarwin = False -- See Note [Dynamic linking on macOS]
 useXLinkerRPath dflags _ = gopt Opt_RPath dflags